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

Weird Specular Light

This topic is 1817 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:

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

 

Share this post


Link to post
Share on other sites
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

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

 

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.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!