Sign in to follow this  

Weird Specular Light

This topic is 1597 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

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

This topic is 1597 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this