Game Development Community

Terrain Dot3 bump mapping...

by Chris \"Hobbiticus\" Weiland · in Torque Game Engine · 12/14/2002 (3:22 pm) · 5 replies

I need some help. I looked at the flipcode tutorial for dot3 bump mapping, and I have it all in torque code, but I'm having a problem with the cube map.

It loads find and everything, but I think my problem is getting the right texture coords for it. mXFVertices->x stores the texture coords in 2d, but I need them in 3d for the cube map. So, I don't think it's rendering correctly (actually, not at all).

This is the only kink in the works that I can possibly imagine to getting full dot3 bump mapping implementation into torque since all the rest is almost exactly the same as the tutorial. I'll release it as a resource when my game reaches the beta stage too (early next year).

#1
12/14/2002 (6:51 pm)
Now that I'm working on it some more, I figure that the 3d coordinates can just be the coordinates to draw the terrain since it's a heightfield (correct me if i'm wrong PLEASE). So, I think the problem is in loading the cube map. Maybe if someone can tell me a method of implementing the way of getting the normalization cube map generated in torque would be great because my implementation is probably wrong.

Right now, I just made a new texture type "CubeTexture" and when it goes through createGLName, it detects that it is a CubeTexture and runs the block of code that creates it, then exits. I'm not sure if this implementation even works because I do not know of a good way of testing it. And, I know this is the problem because I get the same result in the demo source code if I comment out the cube map rendering. Thanks.
#2
12/15/2002 (8:22 pm)
Ok, I'm taking another look at this and playing around with glGetError, and as far as I can tell, nothing bad is happening. The code to generate the normalization cube map is executing, and there are no GL errors. After the texture has been created, a call to glIsTexture returns true. After the texture is bound, there is no error reported. Again, after it draws, there are no GL errors.

Welp, I'm totally stumps, and I don't even know any more tests that I can do. Any help would be great.
#3
12/16/2002 (5:15 am)
I would love to help but I dont know much about it, I guess you would need to load the bump image like you would the DetailTexture but then do the bump light pass on it and a GLBlend call. ( Just guessing )

Sam
#4
12/21/2002 (11:32 am)
Chris, have you (or anyone else) managed to get this working yet? I've just started looking into it but not being an OpenGL wiz it sloooooow going for me.

Here's my port of the cube map code. My major problem is finding where in the heck to place the bump render pass.

bool GenerateNormalisationCubeMap()
{
	U8 * data=new U8[32*32*3];
   
   AssertFatal( data, "Unable to allocate memory for texture data for cube map" );

	//some useful variables
	S32 size=32;
	F32 offset=0.5f;
	F32 halfSize=16.0f;
	Point3F tempVector;
	U8 * bytePtr;

	//positive x
	bytePtr=data;

	for(int j=0; j<size; j++)
	{
		for(int i=0; i<size; i++)
		{
			tempVector.x = halfSize;
			tempVector.y = (-(j+offset-halfSize));
			tempVector.z = (-(i+offset-halfSize));

			tempVector.normalize();
         tempVector = tempVector * 0.5f + Point3F(0.5f, 0.5f, 0.5f);
			//tempVector.PackTo01();

			bytePtr[0]=(unsigned char)(tempVector.x * 255);
			bytePtr[1]=(unsigned char)(tempVector.y * 255);
			bytePtr[2]=(unsigned char)(tempVector.z * 255);

			bytePtr+=3;
		}
	}
	glTexImage2D(	GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
					0, GL_RGBA8, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, data);

	//negative x
	bytePtr=data;

	for(int j=0; j<size; j++)
	{
		for(int i=0; i<size; i++)
		{
			tempVector.x = (-halfSize);
			tempVector.y = (-(j+offset-halfSize));
			tempVector.z = ((i+offset-halfSize));

			tempVector.normalize();
			tempVector = tempVector * 0.5f + Point3F(0.5f, 0.5f, 0.5f);

			bytePtr[0]=(unsigned char)(tempVector.x*255);
			bytePtr[1]=(unsigned char)(tempVector.y*255);
			bytePtr[2]=(unsigned char)(tempVector.z*255);

			bytePtr+=3;
		}
	}
	glTexImage2D(	GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
					0, GL_RGBA8, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, data);

	//positive y
	bytePtr=data;

	for(int j=0; j<size; j++)
	{
		for(int i=0; i<size; i++)
		{
			tempVector.x = (i+offset-halfSize);
			tempVector.y = (halfSize);
			tempVector.z = ((j+offset-halfSize));

			tempVector.normalize();
			tempVector = tempVector * 0.5f + Point3F(0.5f, 0.5f, 0.5f);

			bytePtr[0]=(unsigned char)(tempVector.x*255);
			bytePtr[1]=(unsigned char)(tempVector.y*255);
			bytePtr[2]=(unsigned char)(tempVector.z*255);

			bytePtr+=3;
		}
	}
	glTexImage2D(	GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
					0, GL_RGBA8, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, data);

	//negative y
	bytePtr=data;

	for(int j=0; j<size; j++)
	{
		for(int i=0; i<size; i++)
		{
			tempVector.x = (i+offset-halfSize);
			tempVector.y = (-halfSize);
			tempVector.z = (-(j+offset-halfSize));

			tempVector.normalize();
			tempVector = tempVector * 0.5f + Point3F(0.5f, 0.5f, 0.5f);

			bytePtr[0]=(unsigned char)(tempVector.x*255);
			bytePtr[1]=(unsigned char)(tempVector.y*255);
			bytePtr[2]=(unsigned char)(tempVector.z*255);

			bytePtr+=3;
		}
	}
	glTexImage2D(	GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
					0, GL_RGBA8, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, data);

	//positive z
	bytePtr=data;

	for(int j=0; j<size; j++)
	{
		for(int i=0; i<size; i++)
		{
			tempVector.x = (i+offset-halfSize);
			tempVector.y = (-(j+offset-halfSize));
			tempVector.z = (halfSize);

			tempVector.normalize();
			tempVector = tempVector * 0.5f + Point3F(0.5f, 0.5f, 0.5f);

			bytePtr[0]=(unsigned char)(tempVector.x*255);
			bytePtr[1]=(unsigned char)(tempVector.y*255);
			bytePtr[2]=(unsigned char)(tempVector.z*255);

			bytePtr+=3;
		}
	}
	glTexImage2D(	GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
					0, GL_RGBA8, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, data);

	//negative z
	bytePtr=data;

	for(int j=0; j<size; j++)
	{
		for(int i=0; i<size; i++)
		{
			tempVector.x = (-(i+offset-halfSize));
			tempVector.y = (-(j+offset-halfSize));
			tempVector.z = (-halfSize);

			tempVector.normalize();
			tempVector = tempVector * 0.5f + Point3F(0.5f, 0.5f, 0.5f);

			bytePtr[0]=(unsigned char)(tempVector.x*255);
			bytePtr[1]=(unsigned char)(tempVector.y*255);
			bytePtr[2]=(unsigned char)(tempVector.z*255);

			bytePtr+=3;
		}
	}
	glTexImage2D(	GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
					0, GL_RGBA8, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, data);

	delete [] data;

	return true;
}
#5
12/21/2002 (1:21 pm)
I think he has most of it done, from the screenshots he showed me, it's mainly working except for some reason he gets black lines on the terrain every now and then because his calculations may be off, I think he said.