Jump to content
  • Advertisement
Sign in to follow this  
schupf

[HLSL] Simple per Pixel Lighting

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

Hello, Im trying to implement simple per pixel lighting with HLSL. To calculate the lighting in the pixelshade I have to pass the interpolated normal to the ps - I want to do this with a float3 TEXCOORD - I hope this is correct. But I'm a little bit confused in which coordinate system I should evaluate the lighting equation. Is it possible to transform all lighting relevant parameters (like lightPosition, Normals etc) into the same coordinate system (for example world- or view-space)?

Share this post


Link to post
Share on other sites
Advertisement
Light position should be specified in world-space from the start (so you don't have to transform it every time). You should transform each parameter to world space before calculating light parameters - most likely in the vertex shader (unless you have a reason to do so in PS). As for float3 texcoord - I think it's okay.

Share this post


Link to post
Share on other sites
If you're just looking into using values calculated in the vertex shader for lighting, all that matters is that they share a space, as Lifepower said, and world space is fine for that. If you're looking to add texture normals later, for example for bump mapping, you'd want to use tangent space for that. Google for 'tangent space', and you'd get pages like this, which should make things clearer.

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!