Skip to main content
gamedev.net
🔒 Locked 🎯 Unreal

Differences Rendermonkey - GL application [solved]

Started by Hydrael Aug 12, 2006 at 6:28 AM 2 replies 1.4k views
Original Post
Hydrael
Hydrael
Hello everyone, I'm having a little problem with using the same shader in Rendermonkey and an OpenGL application but getting different results. This is a simple cubemap reflection, and I don't really know, what I could have done wrong. Here is my vertex shader code:

varying vec3  ReflectDir;
varying float LightIntensity;

uniform vec3  LightPos;

void main() 
{
    gl_Position    = ftransform();
    vec3 normal    = normalize(gl_NormalMatrix * gl_Normal);
    vec4 pos       = gl_ModelViewMatrix * gl_Vertex;
    vec3 eyeDir    = pos.xyz;
    ReflectDir     = reflect(eyeDir, normal);
    LightIntensity = max(dot(normalize(LightPos - eyeDir), normal), 0.0);
}
And here the pixel shader:


uniform vec3  BaseColor;
uniform float MixRatio;

uniform samplerCube EnvMap;

varying vec3  ReflectDir;
varying float LightIntensity;

void main()
{
    // Look up environment map value in cube map

    vec3 envColor = vec3(textureCube(EnvMap, ReflectDir));

    // Add lighting to base color and mix

    vec3 base = LightIntensity * BaseColor;
    envColor  = mix(envColor, base, MixRatio);

    gl_FragColor = vec4(envColor, 1.0);
}
This is my renderloop in my GL application:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
glLoadIdentity();
glColor3f(1.0f,1.0f,1.0f);
SetCamera();
EnvMapper->Activate();
TexManager.BindCubeMap(CubeMapID);
glEnable(GL_TEXTURE_CUBE_MAP_EXT); 


//EnvMap
	glUniform1iARB(glGetUniformLocationARB(EnvMapper->Program(),"EnvMap"),0);

//Color
	glUniform3fARB(glGetUniformLocationARB(EnvMapper->Program(),"BaseColor"),0.4f,1.0f,1.0f);

//MixRatio
	glUniform1fARB(glGetUniformLocationARB(EnvMapper->Program(),"MixRatio"),0.0f);

//LightPos
	glUniform3fARB(glGetUniformLocationARB(EnvMapper->Program(),"LightPos"),-7.0f,10.0f,15.0f);
for(int i=0;i<m_ObjectBuffer[0].iFaceCount*3;i+=3)
{
	glBegin(GL_TRIANGLES);
		glVertex3f(va.x		,va.y	,va.z);
		glVertex3f(va[i+1].x	,va[i+1].y	,va[i+1].z);
		glVertex3f(va[i+2].x	,va[i+2].y	,va[i+2].z);
	glEnd();
}
glDisable(GL_TEXTURE_CUBE_MAP_EXT);
EnvMapper->Deactivate();
Can anyone help? Thanks for any response in advance Greets Chris [Edited by - Hydrael on August 12, 2006 9:22:03 AM]
V-man
V-man
Check for errors. Are you binding the shader?

BTW, you don't need glColor3f(1.0f,1.0f,1.0f)
glEnable(GL_TEXTURE_CUBE_MAP_EXT);
EnvMapper->Activate(); (if this calls glTexEnv)
Hydrael
Hydrael
EnvMapper->Activate() just "activates" the environment mapping shader (calls glUseProgramObjectARB(glProgram); )

The shader is bound and compiles correctly.
If you take a look at the screenshot again, you can see, that the blueish color of the OpenGL teapot is part of the sky within the cubemap (as seen the top part of the correct rendermonkey shader) - so the shader itself works.
Seems to me like the cubemap somehow gets scaled, or it gets mapped wrong...but I don't know why :/

Edit: Here is another screenshot, which probably shows the problem a little better
Hydrael
Hydrael
Ok, I got it - I forgot the normals within the renderloop *blush*

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.