as usual thanks in advance..
I'm using pixel bender to generate lighting effects for a heightmap based terrain. I'd like to make a normal map of the terrain and from there dot each normal against a given sun direction. Pretty standard stuff really, but pixel bender isn't playing nicely. I have this code:
void
evaluatePixel()
{
float2 pt = outCoord();
pixel3 a = sampleNearest(src,pt);
pixel3 b = sampleNearest(src,float2(pt.x + 1.0, pt.y));
pixel3 c = sampleNearest(src,float2(pt.x, pt.y + 1.0));
float3 v1 = float3(1.0, 0.0, b.r - a.r);
float3 v2 = float3(0.0, 1.0, c.r - a.r);
normalize(v1);
normalize(v2);
float3 n = cross(v1,v2);
dst = pixel3(n.x,n.y,n.z);
}
I would expect this to produce a normal map. To test, I assumed that the light was pointing straight down and just use n.z
as the output colour. This produces a solid colour. If you take the above code and run it, you'll see that whilst there is variation in red and green, blue is always full at 255. Why is this? I'd expect that considering v1
and v2
are normalized that this shouldnt always output full blue?
What am I doing wrong?!?