Sign in to follow this  
schupf

[HLSL] Simple per Pixel Lighting

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

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