cubemapping trouble

Started by
-1 comments, last by Aghis 18 years, 4 months ago
My video card does not support per-pixel normalization of vectors (FP20 profile) and I have, therefore, resorted to normalization cube maps. I do believe to create correct textures for each of the cube map's faces (have rendered them on the screen and they looked like they were supposed to) but the pixel shader is far from functioning properly. The shader code (for bump-mapping) is:

struct Frag
{
	float4 pos	: POSITION;
	float4 color	: COLOR0;
	float2 tex_coord0	: TEXCOORD0;
	float2 tex_coord1	: TEXCOORD1;
};

struct Pixel
{
	float4 color	: COLOR;
};

Pixel main(Frag frag, uniform sampler2D nmap : TEXUNIT0, uniform samplerCUBE ncube_map : TEXUNIT2, uniform sampler2D base_tex : TEXUNIT1)
{
	Pixel pix;
	float3 norm, v;

	norm = tex2D(nmap, frag.tex_coord0);
	norm = (norm - 0.5f) * 2;

	v = texCUBE(ncube_map, frag.color.rgb);
	v.xyz = (v.xyz - 0.5f) * 2;

	pix.color.rgb = dot(norm, v);
	pix.color.a = 1.0f;

	return pix;
}

In frag.color.rgb is supplied the L vector (pixel to light-source) unpacked and unnormalized. The above code compiles and runs but renders a bump-mapped scene which remains unchanged regardless of the movement of the light source. Commenting out the v = texCUBE(ncube_map, frag.color.rgb); line and assigning to v the unnormalized vector in frag.color.rgb results in the expected artifacts due to denormalization across large polygons. In this case, however, the scene responds correctly to the light source's motion. My render code is :

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	gluLookAt(g_Camera.eye.x, g_Camera.eye.y, g_Camera.eye.z, g_Camera.center.x, g_Camera.center.y, g_Camera.center.z, g_Camera.up.x, g_Camera.up.y, g_Camera.up.z);

	cgGLSetStateMatrixParameter(cg_mvp, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
	cgGLSetParameter3f(cg_lpos, lpos.x, lpos.y, lpos.z);

	cgGLEnableProfile(vert_profile);
	cgGLBindProgram(vert_shader);

	cgGLEnableProfile(frag_profile);
	cgGLBindProgram(frag_shader);

	glEnable(GL_TEXTURE_2D);
	glEnable(GL_TEXTURE_CUBE_MAP_ARB);

	glActiveTextureARB(GL_TEXTURE0_ARB);
	glBindTexture(GL_TEXTURE_2D, g_Textures[NORMAL_MAP]);

	glActiveTextureARB(GL_TEXTURE1_ARB);
	glBindTexture(GL_TEXTURE_2D, g_Textures[BASE_TEXTURE]);

	glActiveTextureARB(GL_TEXTURE2_ARB);
	glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, g_Textures[NORMAL_CUBE_MAP]);

	cgGLEnableTextureParameter(cg_nmap);
	cgGLEnableTextureParameter(cg_ncube_map);
	cgGLEnableTextureParameter(cg_base_tex);


	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);

	glVertexPointer(3, GL_FLOAT, sizeof(CVector3), quad);
	glNormalPointer(GL_FLOAT, sizeof(CVector3), normals);

	glClientActiveTextureARB(GL_TEXTURE0_ARB);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glTexCoordPointer(2, GL_FLOAT, sizeof(CVector2), tcoords);

	glClientActiveTextureARB(GL_TEXTURE1_ARB);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glTexCoordPointer(2, GL_FLOAT, sizeof(CVector2), tcoords);

	glDrawArrays(GL_QUADS, 0, 4);

	glActiveTextureARB(GL_TEXTURE0_ARB);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisable(GL_TEXTURE_2D);

	glDisable(GL_TEXTURE_CUBE_MAP_ARB);

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);

	cgGLDisableProfile(vert_profile);
	cgGLDisableProfile(frag_profile);

	glColor3ub(255, 0, 255);
	glPointSize(10.0f);
	glBegin(GL_POINTS);
		glVertex3f(lpos.x, lpos.y, lpos.z);
	glEnd();

	SwapBuffers(g_hDC);

It seems that the problem lies in the cube map. Could you guys please check my code to see if I am doing something wrong because I am horribly stuck. Thanks a lot!

This topic is closed to new replies.

Advertisement