Jump to content
  • Advertisement
Sign in to follow this  
mickeyren

final computed color for a normal and shadow map pixel shader

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

Hi I have 2 separate effect files here - one is use for bump mapping and the other one is use for shadow mapping. I think I have combined them successfully except for the final output color from the pixel shader. On my NormalMap.fx, the final computed color looks like this: float3 color = (ambient + diffuse)*texColor.rgb + spec; On my ShadowMap.fx, the final computed color looks like this: float3 litColor = spot*ambient*texColor.rgb + spot*shadowCoeff*(diffuse*texColor.rgb + spec); I need to modify the final output color in ShadowMap.fx because my scene looks erratic or at least I need to move my spot light way so near the texture just to see the bumps. Let me know if you need additional information. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
In your normal mapping output:

float3 color = (ambient + diffuse)*texColor.rgb + spec;

Where is the normal vector? Usually you'd have a dot(normal,light) term or something similar.

Quote:
I need to move my spot light way so near the texture just to see the bumps.
Sounds to me like you've got some sort of scaling issue. Are you sure your normals are normalized? Also, it's fair game to include a scalar bias in the N•L computation to make the bumps more dramatic or more soft - maybe you need to consider this instead?


hth
Jack

Share this post


Link to post
Share on other sites
Hi Jack

Thanks for trying to help. It happened a little above. I'm posting more code now:

Shows how I pull the normals from the normal map, specular from the specular map and calculate the diffuse, spec and ambient final colors:


// Sample normal map.
float3 normalT = tex2D(NormalMapS, tex0);

// Expand from [0, 1] compressed interval to true [-1, 1] interval.
normalT = 2.0f*normalT - 1.0f;

// Make it a unit vector.
normalT = normalize(normalT);

// Compute the reflection vector.
float3 r = reflect(-lightVecT, normalT);

// Determine how much (if any) specular light makes it into the eye.
float t = pow(max(dot(r, toEyeT), 0.0f), gMtrl.specPower);

// Determine the diffuse light intensity that strikes the vertex.
float s = max(dot(lightVecT, normalT), 0.0f);

// Calculate spec, ambient and diffuse
float3 specT = tex2D(SpecularMapS, tex0);

float spec = t*(specT*gLight.spec).rgb;
float3 diffuse = s*(gMtrl.diffuse*gLight.diffuse).rgb;
float3 ambient = gMtrl.ambient*gLight.ambient;

// and finally sample the diffuse texture color:
float4 texColor = tex2D(TexS, tex0);





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!