Positional Light and need to have fall off infinite?

Started by
6 comments, last by _the_phantom_ 11 years, 8 months ago
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!
Advertisement
You're using gl_FrontLightProduct or something?

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

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

uwi2k2 - parttime Game-Dev
---------------------------------------------------------
OpebGL Trainer: www.opengl-trainer.com
deCode Company: www.decode.ro

Just don't apply the distance fall off calculation to the light in your shader...
this is all I have in my VS


#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();
}


and in the FS


#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;
}
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
vec3 normal = vec3(texture2D(normalmap, gl_TexCoord[0].xy)) * 2.0 - 1.0;
normal = normalize(normal);

I think this may have fixed it... Thanks!
No worries.

btw, you don't need to 'vec3' it, you could just use the component selection;

vec3 normal = texture2D(normalmap, gl_TexCoord[0].xy).xyz * 2.0 - 1.0;

This topic is closed to new replies.

Advertisement