PDA

View Full Version : GLSL how convert position value from app to good for GLSL?


nadro
06-23-2007, 04:35 AM
Hi. I build multilight system and I create pseudo light data for per pixel point light:

struct LightData
{
vec4 Diffuse;
vec4 Ambient;
vec3 Position;
float constantAttenuation;
float linearAttenuation;
float quadraticAttenuation;
};
LightData Light;

I hame one problem with calculate position of light. I have this cos in shader:
[VERTEX]
varying vec4 ecPosition;
...
ecPosition = gl_ModelViewMatrix * gl_Vertex;

[FRAGMENT]
uniform vec3 lightPosition;
varying vec4 ecPosition;
...
vec3 Aux;
Aux = vec3(vec4(glLightPosition,0.0)-ecPosition); // Here is my problem, because if I have: Aux = vec3(gl_LightSource[0].position-ecPosition); shader work good.
In my apllication is one Light in position (Light.Position) vec3(-373,334,-11) and this value has lightPosition. How Can I convert my lightPosition to position good for my shader?

Reedbeta
06-23-2007, 10:55 AM
You probably don't want to do your shading in post-projective space. In the vertex shader, you'll need to send the input position in world-space (gl_Vertex) to the fragment shader by copying it to another varying parameter. Then read from that parameter in the fragment shader and do your lighting calculations with that.