[ERLEDIGT] [DX9] Deferred Shading und Normal-Maps
Verfasst: 09.10.2009, 21:42
Die Probleme mit dem deferred Shading hören einfach nicht auf.
Jetzt habe ich ein Problem mit den Normal-Maps und habe mich durch Google gewühlt.
Bei vielen anderen scheint das zu funktionieren, bei mir jedoch nicht.
Ich möchte gerne in meinem G-Buffer die Normalen vorberechnen indem ich sie direkt mit der
Tangent-Space Matrix (oder der transponierten Tangent-Space Matrix) multipliziere.
Das funktioniert aber vorne und hinten nicht. Schon die Normal-Map sieht etwas merkwürdig aus.
Interessanter Weise passt die Normal-Map in Blickrichtung, nicht jedoch auf dem Boden...
Und ich finde den Fehler nicht.
Sieht jemand einen Fehler in diesem Shader-Code?
Jetzt habe ich ein Problem mit den Normal-Maps und habe mich durch Google gewühlt.
Bei vielen anderen scheint das zu funktionieren, bei mir jedoch nicht.
Ich möchte gerne in meinem G-Buffer die Normalen vorberechnen indem ich sie direkt mit der
Tangent-Space Matrix (oder der transponierten Tangent-Space Matrix) multipliziere.
Das funktioniert aber vorne und hinten nicht. Schon die Normal-Map sieht etwas merkwürdig aus.
Interessanter Weise passt die Normal-Map in Blickrichtung, nicht jedoch auf dem Boden...
Und ich finde den Fehler nicht.
Sieht jemand einen Fehler in diesem Shader-Code?
Code: Alles auswählen
float4x4 wvp; // WorldViewProjection
sampler2D tex0 : register(s0); // Albedo-Textur
sampler2D nMap : register(s7); // Normal-Map
struct vs_out
{
float4 Pos : POSITION;
float2 TC0 : TEXCOORD0;
float4 Col : COLOR0;
float4 PosX: TEXCOORD7;
float3 Tng : TEXCOORD2;
float3 BNrm: TEXCOORD3;
float3 Nrm : TEXCOORD4;
};
struct vs_in
{
float4 Pos : POSITION;
float2 TC0 : TEXCOORD0;
float4 Col : COLOR0;
float3 Nrm : NORMAL;
float3 Tng : TANGENT;
float3 BNrm: BINORMAL;
};
struct ps_in
{
float2 TC0 : TEXCOORD0;
float4 Col : COLOR0;
float4 Pos : TEXCOORD7;
float3 Tng : TEXCOORD2;
float3 BNrm: TEXCOORD3;
float3 Nrm : TEXCOORD4;
};
struct ps_out
{
float4 c0 : COLOR0; // Albedo
float4 c1 : COLOR1; // Normals
float4 c2 : COLOR2; // World-Space-Position
};
///
vs_out VS(vs_in ix)
{
vs_out ox;
ox.Pos = mul(ix.Pos, wvp);
ox.TC0 = ix.TC0;
ox.Col = ix.Col;
ox.PosX = ix.Pos;
ox.Tng = ix.Tng;
ox.BNrm= ix.BNrm;
ox.Nrm = ix.Nrm;
return ox;
}
ps_out PS(ps_in ix)
{
ps_out ox;
float3 bumpedNormal = tex2D(nMap, ix.TC0) * 2.f - 1.0f;
float3x3 tSpace = transpose(float3x3(ix.Tng, ix.BNrm, ix.Nrm));
ox.c1 = float4(normalize(mul(bumpedNormal, tSpace)),1);
ox.c0 = tex2D(tex0, ix.TC0);
ox.c2 = ix.Pos;
return ox;
}