Sign in to follow this  

Positional Light and need to have fall off infinite?

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

How do I make a positional light source stay constant all the way through the scene?

I have the sun at 0,0,0 and need to have all my planets far away be illuminated the same amount regardless of how far away they are.

I am using GLSL 1.2, and uploading the data through the built in types if that matters.

Thanks!

Share this post


Link to post
Share on other sites
hi,

i´m not shure if i get you right, but turning off the depth testing should help you here.
Or if you are calculating the vertex/light distance in the shader yourself, this one need to be tuned of.

cu
uwi

Share this post


Link to post
Share on other sites
this is all I have in my VS

[code]
#version 120
varying vec3 lightDir, viewDir;
varying vec4 diffuse, ambient;
attribute vec3 Tangent, BiTangent;
void main()
{
vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
vec3 tangent = normalize(gl_NormalMatrix * Tangent);
vec3 bitangent = normalize(gl_NormalMatrix * BiTangent);
vec3 eyePosition = vec3(gl_ModelViewMatrix * gl_Vertex);
mat3 TBN = mat3(tangent, bitangent, normal);

lightDir = normalize(vec3(gl_LightSource[0].position) - (vec3(gl_Vertex) * gl_LightSource[0].position.w));
lightDir = lightDir * TBN;
viewDir = -eyePosition * TBN;

diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
ambient += gl_LightModel.ambient * gl_FrontMaterial.ambient;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
[/code]

and in the FS

[code]
#version 120
varying vec3 lightDir, viewDir;
varying vec4 diffuse, ambient;
uniform sampler2D texture, normalmap;
void main()
{
vec4 modelColor = texture2D(texture, gl_TexCoord[0].xy);
vec4 lightColor = ambient;
vec3 normal = vec3(texture2D(normalmap, gl_TexCoord[0].xy));
normal = vec3(2.0) * (normal - vec3(.5));
float NdotL = max(dot(normal, lightDir), 0.0);
if(NdotL > 0.0)
{
lightColor +=(diffuse * NdotL);
vec3 halfVec = normalize(normalize(lightDir) + normalize(viewDir));
float NdotHV = max(dot(normal, halfVec), 0.0);
lightColor +=(gl_FrontMaterial.specular * gl_LightSource[0].specular * pow(NdotHV, gl_FrontMaterial.shininess));
}
gl_FragColor = lightColor * modelColor;
}
[/code]

Share this post


Link to post
Share on other sites
Yeah, there is no distance attenuation in that; any face which points towards the light source should get lit accordingly regardless of distance.

However your normal adjustment looks... strange.

Normally (pun not intended) it would look like this; normal = texture2D(normalMap, coord) * 2.0f - 1.0f

So if you are seeing bad lighting that might be one cause; you might also want to normalise the vector post conversion as it needs to be unit length

Share this post


Link to post
Share on other sites

This topic is 1955 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.

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