Jump to content
  • Advertisement
Sign in to follow this  
JavaCoolDude

OpenGL Tough one (GLSL woes)

This topic is 4913 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.
<Shaders>

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

    <RawData>
      uniform vec4  cameraPosition;
      varying mat3  normalMatrix;
      uniform float bumpScale;

      void main(void)
      {
        normalMatrix = mat3(gl_MultiTexCoord1.xyz*bumpScale,
                            gl_MultiTexCoord2.xyz*bumpScale,
                            gl_Normal);
  
        gl_TexCoord[0] = gl_MultiTexCoord0;
        gl_TexCoord[1] = cameraPosition - gl_Vertex;
        
        gl_Position    = ftransform();
      }
    </RawData>
  </VERTEX_SHADER>

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

    <RawData>
      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);
      }
    </RawData>
  </FRAGMENT_SHADER>
</Shaders>






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

Share this post


Link to post
Share on other sites
Advertisement
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

Lizard

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!