perturbed UV bump mapping with Cg

Zeross

Regular
I'm trying to do mimick DirectX EMBM to learn Cg, I think I've understood the theory but my program doesn't do what I'm expecting. Here is the code :
Code:
struct VertexOut 
{
	float4 color : COLOR0;
	float4 texCoord0 : TEXCOORD0;
	float4 texCoord1 : TEXCOORD1;
	float4 texCoord2 : TEXCOORD2; 
};

float4 main (VertexOut IN, uniform sampler2D baseMap,
			uniform sampler2D bumpMap, uniform sampler2D lightMap) : COLOR
{
	float4 baseColor = tex2D (baseMap, IN.texCoord0.xy);
	float4 bumpOffset = tex2D (bumpMap, IN.texCoord1.xy);
	float4 identity = float4 (1, 0, 0, 1);
	float4 lightColor = offsettex2D (lightMap, IN.texCoord2.xy, bumpOffset, identity);

	return baseColor + lightColor;
}

The result of it is that I'm only seeing the base texture :?
Any help is welcome :)
 
Well, then obviously lightColor is zero, or close to zero. lightColor coming from a texture would make me look to check if the texture is properly bound and all that, try just outputting it and see if it comes through.
 
OK I'm progressing (the problem for those interested was that texture internal AND external format for an offset texture must be GL_DSDT_NV) but it's not quite perfect yet ;) here is my output :
brick.jpg


And here is the output of the PowerVR demo from which I've stolen the textures ;)
brickPVR.jpg


OK mine is more shiny but that's not the problem (I guess they're not just adding the light contribution like me but doing some more maths to avoid too much specular). My problem is all those small artefacts on my output :? I guess it's comme from my bump texture but I don't know why I've got this result. I take the heightmap (greyscale) and convert it to a DSDT map like that :

Code:
void slsTexture::transformHeightMaptoDsDtMap ()
{
	dsdt *map = new dsdt [_width * _height];
	int v01, v10;
	for (unsigned int i = 0 ; i < _height ; i++)
		for (unsigned int j = 0 ; j < _width ; j++)
		{
			int v00 = _image[i * _width + j];

			if (j == _width - 1) //last column
				v01 = v00;
			else
				v01 = _image[i * _width + j + 1];

			if (i == _height - 1)//last row
				v10 = v00;
			else
				v10 = _image[(i+1) * _width + j];

			map[i * _width + j].ds = (unsigned char) (v00 - v01);
			map[i * _width + j].dt = (unsigned char) (v00 - v10);
		}

		_image = (unsigned char *) map;
}

dsdt is just a struct of two unsigned char. I guess that this part of the code is responsible but I don't know why...
Any idea of what I'm doing wrong ?
 
Well, first of all, those unsigned char you are assigning can be negative. You need to clamp it. I'm not sure, but a DSDT map is signed, right? Then I think you must add 128 before clamping and assigning.
 
Back
Top