Jump to content
  • Advertisement
Sign in to follow this  
Medo Mex

Weird Specular Light

This topic is 2175 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm getting the following weird specular light:



Here is the light pixel shader (Directional light):

    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);


Share this post

Link to post
Share on other sites

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

Edited by belfegor

Share this post

Link to post
Share on other sites

@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.

Edited by Medo3337

Share this post

Link to post
Share on other sites

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



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.

Edited by BrentChua

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!