Weird Specular Light

Started by
5 comments, last by Medo Mex 10 years, 8 months ago

I'm getting the following weird specular light:

[attachment=17112:weird_specular.png]

Here is the light pixel shader (Directional light):


float4 PS( VS_OUTPUT IN ) : COLOR
{
    float3 lightDir = -lightDirection;
    float3 viewDir  = cameraPos - IN.worldPos;
    float3 halfVector = normalize(normalize(lightDir) + normalize(viewDir));

    float3 n = normalize(IN.normal);
    float3 h = normalize(halfVector);
    float3 l = normalize(lightDir);
    
    float nDotL = saturate(dot(n, l)) + materialAmbient;
    float nDotH = saturate(dot(n, h));
    float power = (nDotL == 0.0f) ? 0.0f : pow(nDotH, materialPower);

    float3 diffuse  = lightDiffuse * materialDiffuse * nDotL;
    float3 specular = lightSpecular * power;

    float3 texDiffuse = tex2D(colorMap, IN.UV).rgb;
    return float4(texDiffuse * globalAmbient * (diffuse + specular), 1.0);
}

Advertisement

Don't let light position to intersect with geometry!

Have you ever seen light bulb embed in concrete wall?


Here is the light pixel shader (Directional light):

Can some moderator delete my crap posts? sad.png

@belfegor: You could just modify it with a relative post if you have any idea what is going on. smile.png

What happens if you return float4(power, power, power, 1.0)?

@Pink Horror: I get a black mesh, I can hardly see any white, and even when I see white it could be taking the shape similar to the red color in the screenshot above and sometimes it's a valid specular light.

specPower = pow( max( dot( reflectionVec, toEye ), 0.0f ), materialPower );

where:

reflectionVec = lightDirection - (2 * surfaceNormal * dot( lightDirection, surfaceNormal )) // Use reflect( lightDirection, surfaceNormal )

toEye = cameraPos - IN.worldPos // your viewDir

You dot your viewDir to your reflectionVec not your halfVector.

@BrentChua: Great! Thanks!

This topic is closed to new replies.

Advertisement