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:
pixel shader:
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...
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...
http://www.ozone3d.net/tutorials/glsl_texturing_p04.php#part_4
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)
Is there a way to retrieve the world matrix in a GLSL shader? I'm tied to GLSL 1.20 (OpenGL version <= 2.1)
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
Thanks. I know that. That's why I am asking...
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...
jsyk ;)
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.
You just have to use gl_ModelViewMatrixInverse for the transformation.
You can always use custom matrices if the ones you have are not enough (glUniformMatrix4fv(...)).