Mr.Twinsen
07-10-2004, 06:18 PM
Hi, I m a newbie to both GLSL and this forum :-)
Anyway, I'm trying to implement screen space effect, and ATI's RenderMonkey help me to concentrate on GLSL itself. My question is this, when I tried to implement screen space effect with GLSL, I've got into strange problems.
In vertex shader, I used the quad vertices(which has coordinate range from -1 to 1) directly without applying any matrix transformation. That is,
uniform sampler2D Texture0;
varying vec2 TexCoord;
void main(void)
{
gl_Position.xy = sign(gl_Vertex.xy);
gl_Position.w=1.0;
gl_Position.z=0.0;
TexCoord.x=(gl_Vertex.x+1.0) * 0.5;
TexCoord.y=(gl_Vertex.y+1.0) * 0.5;
}
For a screen quad mesh, each component of gl_Vertex always range from -1 to 1, so I can directly assign gl_Vertex to gl_Position. TexCoord is used later in the fragment program.
Fragment program is even simpler. That is,
uniform sampler2D Texture0;
varying vec2 TexCoord;
void main(void)
{
vec4 c0= texture2D(Texture0, TexCoord);
gl_FragColor = c0;
}
I thouth these two shader would display the texture named "Texture0" directly on screen, but it only display a full black rectangle without any colored pixel. That makes me crazy, because the program itself is so simple that nothing can be wrong. To find out the problem, I tried the following vertex shader ,
uniform sampler2D Texture0;
varying vec2 TexCoord;
void main(void)
{
// gl_Position.xy = sign(gl_Vertex.xy);
// gl_Position.w=1.0;
// gl_Position.z=0.0;
TexCoord.x=(gl_Vertex.x+1.0) * 0.5;
TexCoord.y=(gl_Vertex.y+1.0) * 0.5;
gl_Position=gl_ModelViewProjectionMatrix * gl_Vertex;
}
With the same fragment shader, it displays OK. But what I intended is not this vertex shader(not a fully screen aligned quad).
Whew, thanks for reading boring wrong thread. Is there anything wrong with the first two shaders? Any reply or suggestins would be appreciated.
Anyway, I'm trying to implement screen space effect, and ATI's RenderMonkey help me to concentrate on GLSL itself. My question is this, when I tried to implement screen space effect with GLSL, I've got into strange problems.
In vertex shader, I used the quad vertices(which has coordinate range from -1 to 1) directly without applying any matrix transformation. That is,
uniform sampler2D Texture0;
varying vec2 TexCoord;
void main(void)
{
gl_Position.xy = sign(gl_Vertex.xy);
gl_Position.w=1.0;
gl_Position.z=0.0;
TexCoord.x=(gl_Vertex.x+1.0) * 0.5;
TexCoord.y=(gl_Vertex.y+1.0) * 0.5;
}
For a screen quad mesh, each component of gl_Vertex always range from -1 to 1, so I can directly assign gl_Vertex to gl_Position. TexCoord is used later in the fragment program.
Fragment program is even simpler. That is,
uniform sampler2D Texture0;
varying vec2 TexCoord;
void main(void)
{
vec4 c0= texture2D(Texture0, TexCoord);
gl_FragColor = c0;
}
I thouth these two shader would display the texture named "Texture0" directly on screen, but it only display a full black rectangle without any colored pixel. That makes me crazy, because the program itself is so simple that nothing can be wrong. To find out the problem, I tried the following vertex shader ,
uniform sampler2D Texture0;
varying vec2 TexCoord;
void main(void)
{
// gl_Position.xy = sign(gl_Vertex.xy);
// gl_Position.w=1.0;
// gl_Position.z=0.0;
TexCoord.x=(gl_Vertex.x+1.0) * 0.5;
TexCoord.y=(gl_Vertex.y+1.0) * 0.5;
gl_Position=gl_ModelViewProjectionMatrix * gl_Vertex;
}
With the same fragment shader, it displays OK. But what I intended is not this vertex shader(not a fully screen aligned quad).
Whew, thanks for reading boring wrong thread. Is there anything wrong with the first two shaders? Any reply or suggestins would be appreciated.