Jump to content
  • Advertisement
Sign in to follow this  
Viik

warn light in view space [SOLVED]

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

Kind of a stupid bug, my warn light works in world space, but dosn't work properly in view space. It's directional part keeps following camera.
float3	light_pos = mul(float4(0,10,0,1), viewMatrix);		
float3	light_dir = mul(float4(1,0,0,1), viewMatrix);		

float3	LightVector = frag_view_pos - light_pos.xyz; 
	LightVector = normalize(LightVector);
	float3 	normal = normalize(normal.xyz);
	float	lambert = saturate(dot(-LightVector, normal));
	float	warn_alpha = saturate(dot(LightVector, normalize(light_dir)));
		
	float3	result = lambert * warn_alpha;
this is some kind of stupid bug, it should work in view space if all other vectors are in view space as well. Lambert works just fine, but warn_alpha works like light_dir vector is pointing from camera to light's position. [Edited by - Viik on April 16, 2010 10:44:17 AM]

Share this post


Link to post
Share on other sites
Advertisement
Can you explain what you want warn_alpha to be?
At the first glance I would say you multiply
light_dir with the viewMatrix.
As vieMatrix is applied light_dir will stay in the
same position relative to the camera thus creating
the "effect" of the light beeing attached to the
camera.
It depends on what you want warn_alpha to be, what
you have to change. I think you want to gain the
same effect like lambert, do you?

Share this post


Link to post
Share on other sites
Quote:
It depends on what you want warn_alpha to be, what
you have to change. I think you want to gain the
same effect like lambert, do you?


Basically in my setup it works like half of the omni light.

Warn light without attentuation:

I = cos^a(VL_angle) * cos(NL_angle)

"a" is a Warn exponent, its 1 in my case
"Vl_angle" is angle between light direction and light to fragment direction
"cos(NL_angle)" is a basic N dot L

So warn_alpha should be a dot product between light direction vector and light to fragment position vector.

I'm taking a vector that presents direction where light points and move it into view space by:
float3 light_dir = mul(float4(1,0,0,1), viewMatrix);
I do the same for position and it works, maybe it's not a case for light direction.

Share this post


Link to post
Share on other sites
Found what the issue was, I didn't passed light direction properly, as it should be a vector starting from lights position, not from 0,0,0.

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!