Advertisement Jump to content
Sign in to follow this  

OpenGL Tough one (GLSL woes)

This topic is 5071 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've successfully implemented dynamic reflections in an OpenGL scene where I render the environment into a cubemap and then map onto an object. At first I had an issue where moving around the reflective object made the reflection map rotate towards the viewer, but plugging in the inverse modelview matrix in the first texture matrix seemed to fix that problem. Then I decided to spice things up a bit by using GLSL to simulate a per-pixel reflection, things worked really well until I decided to rotate the reflective object a bit, that's when all hell broke loose: The reflection map seems to rotate by the same amount of the object instead of staying stationary, I tried multiplying few things by gl_TextureMatrix[0] but nothing seems to fix the said bug. I'm posting my shaders code right here as well as links to the actual executables and the full source code with hope that someone out there can help me out. PS: You can look into the Data/XML folder and check out the scenelayout.xml file that stores all the info describing the scene, you should be interested in the transforms affecting <Group name="ReflectiveGroup"> PS2: You can manually set shadersSupported to “false” at the end of “initialize” and look at how things are handled through the fixed OpenGL functionality.

    <Uniform name = "cameraPosition" size = "4" type = "float"/>
    <Uniform name = "bumpScale"      size = "1" type = "float"/>

      uniform vec4  cameraPosition;
      varying mat3  normalMatrix;
      uniform float bumpScale;

      void main(void)
        normalMatrix = mat3(*bumpScale,
        gl_TexCoord[0] = gl_MultiTexCoord0;
        gl_TexCoord[1] = cameraPosition - gl_Vertex;
        gl_Position    = ftransform();

    <Uniform name = "Cube" size = "1" type = "int"   x = "1"/>
    <Uniform name = "Bump" size = "1" type = "int"   x = "0"/>

      uniform samplerCube Cube;
      uniform sampler2D   Bump;
      varying mat3        normalMatrix;

      void main(void)
        vec3  viewDirection = normalize(-gl_TexCoord[1].xyz),
              bumpFragment  = (texture2D(Bump, gl_TexCoord[0].xy)* 2.0 - 1.0).xyz,
              normalVector  = normalize(normalMatrix * bumpFragment ),
              reflection    = reflect(viewDirection, normalVector);
        gl_FragColor        = textureCube(Cube, -reflection);

Binaries Source /Drama [Edited by - JavaCoolDude on March 4, 2005 8:21:53 AM]

Share this post

Link to post
Share on other sites
I can't download, either your source or binaries. It says:

Warning: Unexpected character in input: '' (ASCII=29) state=1 in /home/realityf/public_html/abba/C++/Dynamic Reflection/Application Reflection CM PPL.rar on line 269

Parse error: parse error, unexpected '`' in /home/realityf/public_html/abba/C++/Dynamic Reflection/Application Reflection CM PPL.rar on line 269

Try to get rid of the spaces in the filenames.

Happy coding


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!