Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

1

23.08.2004, 17:03

FVF & shader

hi,

ich wollt grad mal ein hlsl-sample aus dem msdn testen:
//
// Effect file workshop Solution 9 HLSL
// Copyright (c) 2000-2003 Microsoft Corporation. All rights reserved.
//

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
float4 lhtDir;

float3x3 mWld ;    // World

float4x4 mTot ;    // Total


texture tDif;   // diffuse texture of object


texture tDf3;   // normal map for earth



float4 vCPS = {100.0f, 1000.0f, -700.0f, 1.0f};    // Camera Position


//background color

DWORD  BCLR = 0xFF0000FF;


///////////////////////////////////////////////////////

struct VS_INPUT
{
    float4  Pos     : POSITION;
    float3  Normal  : NORMAL;
    float3  Tex0    : TEXCOORD0;
    float3  Tangent : TANGENT;    
};

struct VS_OUTPUT
{
    float4  Pos           : POSITION;
    float3  tLight        : COLOR;
    float3  tNormal       : TEXCOORD0;   
    float3  depRead       : TEXCOORD1;    
    float3  tH            : TEXCOORD2; 
    float3  Tex0          : TEXCOORD3;    
};

VS_OUTPUT VShade(VS_INPUT i, uniform int ShadeMethod)
{
    VS_OUTPUT   o;
    float3      wNormal, wTangent, wBinorm, tLight;
    
    //tranform position    

    o.Pos = mul( i.Pos, mTot); 
           
    //transform normal

    //and tangent

    wNormal = mul( i.Normal, mWld );
    wTangent = mul( i.Tangent, mWld );

    //Cross product to create BiNormal

    wBinorm = cross( wTangent, wNormal );

    // The first method is diffuse dot3 bumpmap

    // transform the light vector into Tangent Space   

    float3x3 tangentMatrix = {wTangent, wBinorm, wNormal};
    tangentMatrix = transpose( tangentMatrix);
    tLight = mul(-lhtDir, tangentMatrix);
   
    // all other methods are specular dot3 bump 

    // and therefore use the half angle instead of the light       

    // compute the half angle vector    

    float3 wPos, H, tH;
        
    wPos = mul( i.Pos, mWld); 
       
    H = vCPS - wPos;
    H = normalize(H);
      
    H = H -lhtDir.xyz;
    H = normalize(H);

    //transform the half angle vector into tangent space

    tH = mul(H, tangentMatrix);
    o.tH = tH;
    o.depRead = tH;    

    if (ShadeMethod==1)
       tLight = tH;

    //mutiply by a half to bias, then add half

    o.tLight = 0.5f + tLight * 0.5f;
   
    // Copy UVs

    o.Tex0 = i.Tex0;                  
    o.tNormal = i.Tex0;                  
    
    return o;
}    

///////////////////////////////////////////////////////

uniform sampler   sampler0 = 
sampler_state 
{
    texture = (tDif);
    MinFilter = Linear;
    MagFilter = Linear;
    MipFilter = Linear;

    AddressU = Clamp;
    AddressV = Clamp;
    AddressW = Clamp;
};

uniform sampler   sampler1 = 
sampler_state 
{
    texture = (tDf3);
    MinFilter = Linear;
    MagFilter = Linear;
    MipFilter = Linear;

    AddressU = Clamp;
    AddressV = Clamp;
    AddressW = Clamp;
};


struct PS_INPUT
{
    float3  tLight        : COLOR;
    float3  tNormal       : TEXCOORD0;    
    float3  depRead       : TEXCOORD1;    
    float3  tH            : TEXCOORD2;    
    float3  Tex0          : TEXCOORD3;    
};

struct PS_OUTPUT
{
    float4  Col        : COLOR;
};
              


PS_OUTPUT PShade2(PS_INPUT i)
{
    PS_OUTPUT o;
    float4    cosang, tDiffuse, tNormal, col;
    float3    tLight;
    
    // Sample diffuse texture and Normal map    

    tDiffuse = tex2D( sampler0, i.Tex0 );    

    // sample tLight

    // _bx2 = 2 * source - 1

    tNormal = 2 * tex2D( sampler1, i.tNormal) - 1;
    tLight = 2 * i.tLight - 1;
      
    // DP Lighting in tangent space (where normal map is based)

    col = dot( tNormal, tLight ) * tDiffuse;    
    
    cosang = dot( tNormal,i.tH );    
    cosang = pow( cosang, 32);    

    // Modulate with diffuse texture    

    col = col  + cosang;

    o.Col = col;
   
    return o;
}




technique tec3
{ 
    pass p0
    {      
        VertexShader = 
compile vs_2_0 VShade(3);

        PixelShader = compile ps_2_0 PShade2();
    }
}


kommt nur leider scheiße raus.:


(Link)


da viel mir auf, wenn ich im vertex-shader eine tangenten-komponente
angebe (siehe oben struct VS_INPUT oder so)
muss ich sowas dann eigentlich mit SetFVF(...) angeben?
das wäre blöd weil es gibt kein D3DFVF_TANGENT...
darum mal allgemein meine frage: werden die FVF-konstanten
beim verwenden von shadern überhaupt beachtet.? immerhin
heißen die fixed-function...
und wenn ja, muss ich tangen manuell berechnen oder wie?

woran könnte das liegen das das bsp. son scheiß ausspuckt,
wenn ich es so wies oben steht in meiner anwwndung verwenden.

ps: es ist auch interessant das er die texturkoordinaten nicht richtig
benutzt, eigentl. ist der würfel auf allen seiten korrekt texturiert
und zeigt jeweils die komplette textur. wie man aber auf dem scr-shot
sieht ist die vordere seite praktisch komplett grau/weis/schwarz....
ein indiz das was mit deb FVF nicht stimmt?
gruß 23h

dot

Supermoderator

Beiträge: 9 757

Wohnort: Graz

  • Private Nachricht senden

2

23.08.2004, 17:42

nein, das fvf wird nicht beachtet wenn du shader benutzt.
dafür gibts vertex declarations.

3

23.08.2004, 18:05

was meinst du mit vertex declerations?
diese struct geschichte?

das heißt ich steck die geometriedaten so wie ich sie als
input für meinen vertex-shader deklariere in die pipeline
und gut ist?

dot

Supermoderator

Beiträge: 9 757

Wohnort: Graz

  • Private Nachricht senden

4

23.08.2004, 18:13

ja das is diese "struct geschichte"

über vertex declarations machst du bekannt wie dein vertex format aufgebaut ist...
ich weis aber nicht ob du das im zusammenhang mit effect dateien brauchst.

5

23.08.2004, 18:19

hm also fvf hat zumindest mit dem iD3dxEffect-interface
sehr wohl eine wirkung.........zumindest bei mir.

angenommen ich würde nicht mit effect-shitt arbeiten sondern
den shader einfach comilieren und dann mit CreateVertexShader
und CreatePixelShader "normal" erstellen und dann benutzen,
wie würde ich denn diese VertexDecleration-interface-geschichte
benutzen, wenn ich Up-funktionen verwende? ich mein was trage ich
bei stream ein 0?

dot

Supermoderator

Beiträge: 9 757

Wohnort: Graz

  • Private Nachricht senden

6

23.08.2004, 18:27

wenn du ohne effekte arbeitest, dann einfach per CreateVertexShader() bzw. CreatePixelShader() die shader erzeugen ( erst natürlich kompilieren mit D3DXAssembleShaderFromFile() ).
dann noch eine vertex declaration mit CreateVertexDeclaration() erzeugen.
wenn du jetzt einen vertexshader aktivieren willst, setzt du den shader mit SetVertexShader() und musst aber die zum shader gehörige vertex declaration mit SetVertexDeclaration() auch setzen.
bei pixel shadern reicht ein einfaches SetPixelShader().

7

23.08.2004, 18:31

wär das ein gültiges bsp.?

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
D3DVERTEXELEMENT9  elem[4];

ZeroMemory(elem, 4*sizeof(D3DVERTEXELEMENT9));
elem[0].Stream =  elem[1].Stream = elem[2].Stream = elem[3].Stream = 0;
elem[0].Method = elem[1].Method = elem[2].Method = elem[3].Methos = D3DDECLMETHOD_DEFAULT;
elem[0].Offset = 0;
elem[1].Offset = 3*sizeof(float); //12

elem[2].Offset = elem[1].Offset + 3*sizeof(float); //24

elem[3].Offset = elem[2].Offset + 2*sizeof(float); //32


elem[0].Type = D3DDECLTYPE_FLOAT3;
elem[1].Type = D3DDECLTYPE_FLOAT3;
elem[2].Type = D3DDECLTYPE_FLOAT2;
elem[3].Type = D3DDECLTYPE_FLOAT3;

elem[0].SemanticType = D3DDECLUSAGE_POSITION;
elem[1].SemanticType = D3DDECLUSAGE_TEXCOORD;
elem[2].SemanticType = D3DDECLUSAGE_NORMAL;
elem[3].SemanticType = .// und jetzt? soll ich einfach irgendwas reinschreiben wenn ich 

                                     //dieses feld als tangente nutzen will?


was soll ich denn nu bei elem[3] reinschreiben?

8

23.08.2004, 18:42

Wie dot schon sagte. Must du für die Benutzung eine Vertex Deklaration erzeugen. Wie du das machst kannst du in diesem Tutorial nachlesen.

Und den Tangent-Vektor must du ebenfalls selbst berechnen. Denn der wird nicht vom Device errechnet. Das selbe gilt für die Bi-Normale.
Wichtig! Ich übernehme keinerlei Verantwortung für eventl. Datenverlust oder Schäden am Rechner ;D

Werbeanzeige