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
Zitat
Beachte außerdem dass du, wenn du einen Vektor im VertexShader über das Kreuzprodukt berechnest, trotzdem dessen Vorzeichen an den Shader übergeben musst da der Tangentspace vielleicht eine andere Handedness haben könnte.
Wenn ich mir Normale, Tangente und Binormale als Farbe anseh, stimmt da alles.
Nur die Normalen aus der Normalmap, die eigentlich WorldNormalen sein sollten, stimmen nicht. Es kommt mir so vor, als würden die Normalen mit doppelter Geschwindigkeit rotiert werden, als das Objekt.
Zitat
Beachte außerdem dass du, wenn du einen Vektor im VertexShader über das Kreuzprodukt berechnest, trotzdem dessen Vorzeichen an den Shader übergeben musst da der Tangentspace vielleicht eine andere Handedness haben könnte.
Bitte was?
Quellcode |
|
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 |
<Mesh NumTriangles="2"> <VertexBuffer NumVertices="4"> <POSITION Encoding="Text"> 9.99999905 0.00000000 9.99999809 9.99999905 0.00000000 -10.00000095 -10.00000191 0.00000000 -9.99999905 -9.99999714 0.00000000 10.00000191 </POSITION> <NORMAL Encoding="Text"> 0.00000000 1.00000000 0.00000000 0.00000000 1.00000000 0.00000000 0.00000000 1.00000000 0.00000000 0.00000000 1.00000000 0.00000000 </NORMAL> <TANGENT Encoding="Text"> 1.00000000 -0.00000000 0.00000002 1.00000000 -0.00000000 -0.00000001 1.00000000 -0.00000000 0.00000002 1.00000000 0.00000000 0.00000005 </TANGENT> <TEXCOORD Encoding="Text"> 0.99999994 0.00000024 0.99999988 1.00000000 0.00000000 0.99999982 0.00000033 0.00000000 </TEXCOORD> </VertexBuffer> <IndexBuffer NumIndices="6" Encoding="Text"> 0 2 3 0 1 2 </IndexBuffer> </Mesh> |
HLSL-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 |
////////////////////////////////////////////////////////////////// //Includes #include"Constants.fx" #include"Sampler.fx" #include"Textures.fx" #include"Lighting.fx" ////////////////////////////////////////////////////////////////// //Layout struct VSInput { uint IID : SV_InstanceID; float3 vPosition : POSITION0; float3 vNormal : NORMAL0; float3 vTangent : TANGENT0; float2 vTextureCoord : TEXCOORD0; }; struct PSInput { uint IID : INSTANCEID; float4 vPosition : SV_Position; float3 vWorldPosition : POSITION0; float3 vViewDir : VIEWDIR0; float3 vNormal : NORMAL0; float3 vTangent : TANGENT0; float3 vBinormal : BINORMAL0; float2 vTextureCoord : TEXCOORD0; }; struct PSOutput { float4 Color : SV_Target0; }; //VertexShader PSInput VertexShaderProc(VSInput In) { PSInput Out; Out.IID= In.IID; float4 vWorldPosition= mul(float4(In.vPosition, 1.0), Instance[In.IID].mWorld); Out.vPosition= mul(vWorldPosition, mViewProjection); Out.vWorldPosition= vWorldPosition.xyz; Out.vViewDir= normalize(Out.vWorldPosition - vCameraPosition); float3 vNormal= mul(In.vNormal, (float3x3)Instance[In.IID].mWorld); Out.vNormal= vNormal; Out.vTangent= mul(In.vTangent, (float3x3)Instance[In.IID].mWorld); Out.vBinormal= cross(Out.vNormal, Out.vTangent); Out.vTextureCoord= In.vTextureCoord; return(Out); } //PixelShader PSOutput PixelShaderProc(PSInput In) { PSOutput Out; //NormalMapping row_major float3x3 mTSToWS= {In.vTangent, In.vBinormal, In.vNormal}; float3 vNormal= mul(TexNormalHeight.Sample(TextureSamplerWrap, In.vTextureCoord).rgb * 2.0 - 1.0, mTSToWS); //Illumination float3 DiffuseLight= float3(0, 0, 0); float3 SpecularLight= float3(0, 0, 0); LightSource Light; uint LightIndex; //Light #0 (Directional) LightIndex= Instance[In.IID].aLightIndices[0].LID; if(LightIndex != 0xFFFFFFFF) { Light= aLights[LightIndex]; DiffuseLight+= DirectionalLightDiffuse(Light, vNormal); SpecularLight+= DirectionalLightSpecular(Light, vNormal, MatSpecularColorPower.a, In.vViewDir); } //Color-Sources float4 ColorAlpha= MatColorAlpha; float4 SpecularColorPower= MatSpecularColorPower; float4 EmissiveAmbient= MatEmissiveAmbient; float4 MirrorColorSaturation= MatMirrorColorSaturation; ColorAlpha*= TexColorAlpha.Sample(TextureSamplerWrap, In.vTextureCoord); Out.Color= float4(0, 0, 0, 1); Out.Color.rgb+= AmbientLight.rgb * EmissiveAmbient.a * ColorAlpha.rgb; Out.Color.rgb+= DiffuseLight * ColorAlpha.rgb; Out.Color.rgb+= SpecularLight * SpecularColorPower.rgb; Out.Color.rgb= (vNormal) / 2 + 0.5; return(Out); } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »BlazeX« (14.11.2010, 10:12)
Werbeanzeige