Hello ,
I am vey new to the GLSL shaders. One od project needs to pass the distance value from camera to Game object . Can some one please help me, how to define the distance in GLSL shader.
thanks.
Hello ,
I am vey new to the GLSL shaders. One od project needs to pass the distance value from camera to Game object . Can some one please help me, how to define the distance in GLSL shader.
thanks.
Since that value should only be calculated once per object per frame, you should set it from a script. If for some reason you can’t do that, then you could get the length of modelview*(0,0,0,1)
Hello Mr. Daniel,
Thanks. As I am confused of the terms in GLSL Shaders.
varying vec4 position_in_view_space;
///Vertex Shader
void main()
{
position_in_view_space = gl_ModelViewMatrix * gl_Vertex;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
varying vec4 position_in_view_space;
///Fragment Shader
void main()
{
float dist = distance(position_in_view_space, vec4(0.0, 0.0, 0.0, 1.0);
gl_FragColor = dist ;
}
Is it correct to get the distance between the camera and the game object.??? could you please let me know. Might be am compületely on wrong track .
Are you looking for the distance to the model, to each vertex, or to each fragment? The code you have now should get it for each fragment, which is the most expensive but most precise option.
I need distance to each fragment . My task is to find the distance between the camera and object and need to upodate everytime the gl_FRag.Here I present the complete code of it.
varying vec4 position_in_view_space;
uniform float temperature;
uniform vec4 Graycolor;
///Vertex Shader
void main()
{
position_in_view_space = gl_ModelViewMatrix * gl_Vertex;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
varying vec4 position_in_view_space;
///Fragment Shader
void main()
{
float dist = distance(position_in_view_space, vec4(0.0, 0.0, 0.0, 1.0);
loss = temperature * exp(-dist);
gl_FragColor = Graycolor * loss ;
}