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
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(); } } |
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? |
Werbeanzeige