Bump Mapping

FSA

Erfahrenes Mitglied
Hallo. Ich habe ein Problem mit meinem Bump Mapping Shader. Vorweg: C++, DirectX 9.
Im Anhang sind 2 Bilder. Auf Bild eins(weißes Licht Links) sieht man den Fehler. Das weiße Licht ist Links aber auf der Seite erscheint das Licht von Rechts und das Rote von Links. Also genau falsch rum. In Bild 2(die gegenüberliegende Seite des Würfels) stimmt alles. Also 3 Seiten des Würfels stimmen und 3 nicht. Mein Pixelshader:
C++:
////////////////////////////////////////////////////////////////////////////////
// Pixel Shader
////////////////////////////////////////////////////////////////////////////////
float4 BumpMapPixelShader(PixelInputType input) : COLOR
{
    float4 textureColor;
    float4 bumpMap;
    float3 bumpNormal;
    float3 lightDir;
    float lightIntensity;
    float4 color;

    for(int i = 0; i <= 1; i++)
    {
        textureColor = tex2D( ColorMap, input.tex );
    
        bumpMap = tex2D( BumpMap, input.tex );

        // Expand the range of the normal value from (0, +1) to (-1, +1).
        bumpMap = (bumpMap * 2.0f) - 1.0f;

        bumpNormal = input.normal + bumpMap.x * input.tangent + bumpMap.y * input.binormal;
    
        bumpNormal = normalize(bumpNormal);

        float3 lD = lightDirection;
        if(i == 1)
        {
            lD.xy = 0.0f;
            lD.z = 1.0f;
        }

        lightDir = -lD;

        if(!bOn)
        {
            lightIntensity = saturate(dot(input.normal, lightDir));
        }
        else
        {
            lightIntensity = saturate(dot(bumpNormal, lightDir));
        }

        float4 C = diffuseColor;
        if(i == 0)
             C.rgb = 0.7f;
        else
        {
             C.r = 1.0f;
             C.gb = 0.0f;
        }
        color += saturate( C * lightIntensity);
    }
    color = color * textureColor;
    
    return color;
}
Danke im Voraus.
(Crosspost! msvcplusplus = FSA)
 

Anhänge

  • 1.png
    1.png
    605,3 KB · Aufrufe: 16
  • 2.png
    2.png
    628,3 KB · Aufrufe: 12
Zuletzt bearbeitet von einem Moderator:
Du setzt ja alle Koordinaten, für Lichtrichtung und -farbe manuell. Dabei ist das rote Licht in der Richtung (0/0/1), ist das auch wirklich die Koordinate in die das Licht "schaut"?
 
Nein ich setze nur das Rote Licht manuell, da es ein Test zur besseren Veranschaulichung des Problems ist. Und ja das Licht guckt in 0|0|1. Wie soll dies denn falsch sein wenn der Shader die Helligkeit berechnet? :) Kann es sein, dass die Fertige Textur gespiegelt wird?
Danke.
 
Zuletzt bearbeitet:
Es lag/liegt an den Tangenten. Ich habe in meinem Vertexformat einfach vergessen Tangenten anzugeben und auszurechnen. Das werde ich mal tun und gucken ob es geht.
 

Neue Beiträge

Zurück