pouët.net

Environment/Reflection mapping in GLSL

category: general [glöplog]
 
I want to environment/reflection mapping in GLSL but the reflections are not right. I have a skybox (showing the cube map I'm using) attached to the camera position, so the camera and the skybox are always centered at 0,0,0 in eye space.

Now when I do reflection mapping on an object, I (would) do:
vertex shader:
Code: varying vec3 viewVec; varying vec3 normal; ... normal = normalize(gl_NormalMatrix * gl_Normal); viewVec = vec3(gl_Vertex.xyz - CAMERAPOSITION_IN_WORLDSPACE.xyz); gl_Position = ftransform();


pixel shader:
Code: varying vec3 viewVec; varying vec3 normal; ... vec3 reflected = normalize(reflect(viewVec, normalize(normal))); vec4 color = textureCube(envMap, reflected);


I can't pass the camera position to the shader though... I tried various things including using gl_ModelViewMatrixInverse[3] for the camera position.
The reflections are not right and some of the textures seem to be flipped somehow.

I'm tired and shit, so just ask if I'm not making myself clear. I suppose it has something to with using the wrong space, but I'm not sure.
I can not use OpenGL commands because I'm using a scene graph library, that ignores all kind of GL_TEXTURE_GEN_MODE shit. There are equivalents, but they don't work...

Also: How are the textures mapped when I do cubemapping. Are they supposed to be on the inside or the outside of a cube?

Need to sleep...
added on the 2009-09-23 22:32:40 by raer raer
http://www.ozone3d.net/tutorials/glsl_texturing_p04.php#part_4
added on the 2009-09-24 08:21:07 by aha aha
or search nehe :)
The problem is, as I already said, they all pass the camera position or worl matrix in a uniform to the shader. I can not do that...

Is there a way to retrieve the world matrix in a GLSL shader? I'm tied to GLSL 1.20 (OpenGL version <= 2.1)
added on the 2009-09-24 09:42:01 by raer raer
there's no distinction of view matrix and world matrix in opengl. They're both combined into one, and you can access it with gl_ModelViewMatrix
added on the 2009-09-24 09:46:02 by xTr1m xTr1m
Thanks. I know that. That's why I am asking...
added on the 2009-09-24 10:28:23 by raer raer
I wasn't able to come up with something, so I just pass inverse camera matrix and camera position in world space from the application like everybody does it. Works fine now...
added on the 2009-09-25 13:56:41 by raer raer
jsyk ;)
added on the 2009-09-25 13:56:51 by raer raer
I've made an tutorial about that on http://knuke1.wordpress.com/2011/04/21/environment-reflection-using-glsl/

You just have to use gl_ModelViewMatrixInverse for the transformation.
added on the 2011-04-21 14:55:47 by Knuke Knuke
You can always use custom matrices if the ones you have are not enough (glUniformMatrix4fv(...)).
added on the 2011-04-21 14:58:34 by xernobyl xernobyl

login