Alright on another forum saw some interest in higher polygon models than the ones that come with Doom3. People were discussing remodeling the models but that seem kinda crazy to myself really. If we have the nice normal maps generated from models with millions of polys then we should be able to take those normal maps and generate a height map.
Of course the scale and bias would have to be handled subjectively for each normal map but the idea seemed a simple integration issue really. So did a simple integrator that starts in the upper leftcorner with a value of 0 and then working its way from that upper corner to the lower right corner. Unfortunately this results in height maps that smear their height diagonally in that direction as well.
Here's a picture of a sample normal map and resulting height map. And also matlab prototype code (actually written for Octave since at my grandfathers and I didn't bring Matlab cd's with me).
So curious if anyone has any ideas how to fix it up so it doesn't smear? (it makes sense each pixel is based on the data diagonally from it and I've confirmed its not the normal map causing the smearing as well)
Or is this just an issue due to lack of sampling data leading to error propagation.
Of course the scale and bias would have to be handled subjectively for each normal map but the idea seemed a simple integration issue really. So did a simple integrator that starts in the upper leftcorner with a value of 0 and then working its way from that upper corner to the lower right corner. Unfortunately this results in height maps that smear their height diagonally in that direction as well.
Here's a picture of a sample normal map and resulting height map. And also matlab prototype code (actually written for Octave since at my grandfathers and I didn't bring Matlab cd's with me).
So curious if anyone has any ideas how to fix it up so it doesn't smear? (it makes sense each pixel is based on the data diagonally from it and I've confirmed its not the normal map causing the smearing as well)
Or is this just an issue due to lack of sampling data leading to error propagation.
Code:
function HeightMap=IntegrateNormalMap(XNorm,YNorm)
YRes=size(XNorm,1);
XRes=size(XNorm,2);
HeightMap=zeros(YRes,XRes);
for X=2:XRes
HeightMap(1,X)=HeightMap(1,X-1)+XNorm(1,X-1);
end
for Y=2:YRes
HeightMap(Y,1)=HeightMap(Y-1,1)+YNorm(Y-1,1);
end
for Y=2:YRes
for X=2:XRes
HeightMap(Y,X)=(HeightMap(Y-1,X)+HeightMap(Y,X-1)+XNorm(Y,X-1)+YNorm(Y-1,X))/2;
end
end
Average=sum(sum(HeightMap))/(XRes*YRes);
HeightMap=HeightMap-Average;