🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

My X axis on my light needs flipping... what?

Started by
1 comment, last by Tape_Worm 2 years, 11 months ago

I'm experiencing something weird with my point light in HLSL. Hell, I don't know how to even ask this correctly…

My world space is … uh.. left handed I think ( X positive goes to the right, Y positive is up, and Z positive goes into the screen).

OK, so, I have my point light, let's say I've positioned it at <5, 2, -3>. When I take that position into my calculations for the light in the pixel shader, the light shows up at 5 units on the x-axis, but instead of 5 units to the right, it actually shows up 5 units on the left. This is baffling to me, but I will admit my math is weak and I haven't deal with this kind of code much in the last few years, so it's probably something simple and stupid.

Here's my pixel shader code:

// When X is negative, it works, when it's positive it's on the wrong side!
float3 lightPos = float3(-light.LightPosition.x, light.LightPosition.y, light.LightPosition.z);  

float3 lightRange = lightPos - vertex.worldPos;
float distance = length(lightRange);
float3 lightDirection = lightRange / distance; 
float atten = 1.0f - saturate(1.0f / (distance * attenuation));
float ndotl = saturate(dot(lightDirection, normal));

Other than being on the wrong horizontal side, everything else renders beautifully.

I'm just at a loss as to why it's on the wrong side. The light position is in world space, the vertical and depth positions are correct…. I'm sure I did something stupid.

Anyway, if you can help, that'd be swell. If you need more code/info, let me know and I'll do what I can.

Advertisement

@Tape_Worm

Good lord I'm an idiot.

See that 1.0f - saturate etc, etc, etc…? Yeah I totally missed that. Everything is working super neat now.

This topic is closed to new replies.

Advertisement