PDA

View Full Version : GLSL Fresnel, can't find whats wrong...



M/\dm/\n
02-22-2004, 03:06 AM
This is what I draw:



glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Floor.id);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,/*GL_MIRRORED_REPEAT_ARB*/GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,/*GL_MIRRORED_REPEAT_ARB*/GL_REPEAT);
if(GLSL)
{
glUseProgramObjectARB(FresnelGLSL);
glUniform1iARB(glGetUniformLocationARB(BumpGLSL, "diffuse"), 0);
glUniform3fARB(glGetUniformLocationARB(BumpGLSL, "eyepos"), px, py, pz);
}
glBegin(GL_QUADS);
glColor4f(1,1,1,1);
glNormal3f(0,1,0);
for (tx=-16; tx<16; tx+=4)
for (tz=-6; tz<6; tz+=4)
if(Frustum.SphereInFrustum(tx+2, 0, tz+2, 2.83))
{
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0);
glVertex3f(tx, 0, tz+4);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 2, 0);
glVertex3f(tx+4, 0, tz+4);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 2, 2);
glVertex3f(tx+4, 0, tz);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 2);
glVertex3f(tx, 0, tz);
}
glEnd();
if(GLSL)
glUseProgramObjectARB(0);


and GLSL shaders
VSH:



uniform vec3 eyepos;
varying float f;
void main(void)
{
vec3 vtol = vec3(0,1,0);
vec3 vtoe = normalize(eyepos-gl_Position);
vec3 hway = normalize(vtoe+vtol);
float vdoth = dot(vtoe,hway);
float f = pow((1-vdoth),4);
gl_Position = mul(gl_ModelViewProjectionMatrix, gl_Vertex);
gl_TexCoord[0] = gl_MultiTexCoord0;
}


FSH:



uniform sampler2D diffuse;
varying float f;
void main (void)
{
gl_FragColor.rgb = 1;//texture2D(diffuse, gl_TexCoord[0]);
gl_FragColor.a = f;
}


and the screenie
http://www.lapas.dau.lv/salitis/out.bmp
It seems that I'm doing fresnel in object space, but gl_Vertex is given in world space & px,py,pz are eye pos in world space too -> (gluLookAt(px,py,pz,....

I'm sure it's my bug, but after 2 nights of coding I'm stuck http://www.opengl.org/discussion_boards/ubb/frown.gif

ml
02-23-2004, 02:08 AM
glUseProgramObjectARB(FresnelGLSL);glUniform1iARB( glGetUniformLocationARB(BumpGLSL, "diffuse"), 0);glUniform3fARB(glGetUniformLocationARB(BumpGLSL , "eyepos"), px, py, pz);

Did you mean to do the above or is it just a copy'n'paste mistake?
(UseProgram FresnelGLSL, then BumpGLSL for the variables) I suppose that would explain why it looks like your screenshot.

M/\dm/\n
02-23-2004, 04:42 AM
Goosh, frikin cpy'n'paste bug :'( Hate'em http://www.opengl.org/discussion_boards/ubb/frown.gif

But the problem was:
I MUST LEARN DIFFERENCE BETWEEN gl_Vertex & gl_Position!!!!, I MUST LEARN DIFFERENCE BETWEEN gl_Vertex & gl_Position!!!!, I MUST LEARN DIFFERENCE BETWEEN gl_Vertex & gl_Position!!!!, I MUST LEARN DIFFERENCE BETWEEN gl_Vertex & gl_Position!!!!, I MUST LEARN DIFFERENCE BETWEEN gl_Vertex & gl_Position!!!!, I MUST LEARN DIFFERENCE BETWEEN gl_Vertex & gl_Position!!!!, I MUST LEARN DIFFERENCE BETWEEN gl_Vertex & gl_Position!!!!, I MUST LEARN DIFFERENCE BETWEEN gl_Vertex & gl_Position!!!!, I MUST LEARN DIFFERENCE BETWEEN gl_Vertex & gl_Position!!!!, I MUST LEARN DIFFERENCE BETWEEN gl_Vertex & gl_Position!!!!, I MUST LEARN DIFFERENCE BETWEEN gl_Vertex & gl_Position!!!!, I MUST LEARN DIFFERENCE BETWEEN gl_Vertex & gl_Position!!!!, I MUST LEARN DIFFERENCE BETWEEN gl_Vertex & gl_Position!!!!, I MUST LEARN DIFFERENCE BETWEEN gl_Vertex & gl_Position!!!!, I MUST LEARN DIFFERENCE BETWEEN gl_Vertex & gl_Position!!!!, I MUST LEARN DIFFERENCE BETWEEN gl_Vertex & gl_Position!!!!
http://www.opengl.org/discussion_boards/ubb/mad.gif http://www.opengl.org/discussion_boards/ubb/mad.gif http://www.opengl.org/discussion_boards/ubb/mad.gif http://www.opengl.org/discussion_boards/ubb/mad.gif http://www.opengl.org/discussion_boards/ubb/mad.gif http://www.opengl.org/discussion_boards/ubb/mad.gif http://www.opengl.org/discussion_boards/ubb/mad.gif http://www.opengl.org/discussion_boards/ubb/mad.gif

[This message has been edited by M/\dm/\n (edited 02-23-2004).]

Zengar
02-23-2004, 07:43 AM
Oh...
I would love to buy you a beer but there is probably tousands of km separating us.

Not a joke - i really mean it.

[This message has been edited by Zengar (edited 02-23-2004).]

M/\dm/\n
02-23-2004, 10:13 AM
You know, when you have fixed bug like this & everything runs and looks flawlessly you're so happy, that you even forget about beer http://www.opengl.org/discussion_boards/ubb/biggrin.gif

Now me must go work on data structures for BM http://www.opengl.org/discussion_boards/ubb/smile.gif