Sign in to follow this  

Linderdaum Engine reflections rendering problems. Help is needed.

This topic is 4081 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 got a strange rendering problem with my reflections. I render the world into an offscreen framebuffer and then apply a texture to an object. But it seems to be oriented somehow wrong. I guess it could be a problem with a correct modelview matrix calculation, but i was unable to fix it. Could anybody provide an idea what is going wrong and how to fix it? Texture matrix calculation looks as follows:
LMatrix4 clGLRenderDevice::ProjectReflectionTexture( const LMatrix4& Projection, const LMatrix4& ModelView ) const
{
   LMatrix4 Scale;
   LMatrix4 Translate;

   Translate.TranslationMatrix( LVector3(0.5f, 0.5f, 0.0f) );
   Scale.ScaleMatrix( LVector3(0.5f, 0.5f, 1.0f) );

   LMatrix4 TexProjectionMatrix = ModelView * Projection * Scale * Translate;

   return TexProjectionMatrix;
}


Vertex program:
varying vec3  vScaledPosition;
varying vec3  vViewVec;
varying vec3  vNormalES;

varying vec2  TexCoord0;
varying vec4  TexCoord1;

void main()
{
   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

   /* Just output model coordinates for this so marble doesn't swim all over */
   vScaledPosition = gl_Vertex.xyz * 0.5;
   
   /* Put position and normal in eye space */
   vViewVec  = vec3(gl_ModelViewMatrix * gl_Vertex);
   vViewVec.z *=-1.0;
   vNormalES = gl_NormalMatrix * gl_Normal;

   TexCoord0 = vec2(gl_MultiTexCoord0);
   TexCoord1 = gl_TextureMatrix[0] * gl_Vertex;
}


Fragment program:
uniform sampler2D   Texture0;
uniform sampler3D   Texture1;
uniform sampler2D   Texture2;

varying vec3  vScaledPosition;
varying vec3  vViewVec;
varying vec3  vNormalES;

varying vec2  TexCoord0;
varying vec4  TexCoord1;

void main()
{
   vec4 color = vec4(1.0, 0.942717, 0.125152, 1.0); 

   vec4  light_pos = vec4( 5.6, 100.0, 2.6, 1.0 );
   vec4  light_color = vec4( 1.0, 1.0, 1.0, 1.0 );
   vec4  lightDir = vec4( 0.408250, 0.408250, 0.8165, 0.0 );

   float board = float( texture2D(Texture0, TexCoord0) );
   float noisy = texture3D(Texture1, vScaledPosition).x;

   /* Base marble color */
   float marble = (0.2 + 5.0 * abs(noisy - 0.5));

   vec3 normal = normalize(vNormalES);

   /* Simple lighting */
   vec3 reflectionVec = reflect(-normalize(vViewVec), normal);
   float diffuse = 0.5 * dot(lightDir.xyz, normal) + 0.5;
   float specular = pow(clamp(dot(reflectionVec, lightDir.xyz), 0.0, 1.0), 24.0);

   vec4 ReflectionColor = texture2DProj( Texture2, TexCoord1 );

   vec4 BoardColor = vec4(diffuse * board) + vec4(0.2 * marble) + vec4(marble * specular);

   gl_FragColor = 0.7 * BoardColor + 0.3 * ReflectionColor;
}


[Edited by - _Sergey_ on September 28, 2006 6:31:44 AM]

Share this post


Link to post
Share on other sites

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this