Normal packing problem with spheremap transform

Started by
1 comment, last by programci_84 12 years ago
Hi. I am trying to pack my view space normals into two float with spheremap transformation. Actually i can pack and unpack them well but, while packing specific vectors - (0,0,1) and (0,0,-1) - , the algorithm is trying to call normalize(0,0). So this is causing a infinite result. Is there any way to solve this without placing some if statements into packing and unpacking functions ? I am using functions from here.
Advertisement
A year ago, I also have a problem with Crytek's method (don’t remember why).

Now I use a similar method that works well:

float4 CompressNormal(float3 inputNormal)
{
float f = inputNormal.z * 2 + 1;
float g = dot(inputNormal, inputNormal);
float p = sqrt(g + f);
return float4(inputNormal.xy / p * 0.5 + 0.5, 1, 1);
}


float3 SampleNormal(float2 uv, sampler2D textureSampler)
{
float2 normalInformation = tex2Dlod(textureSampler, float4(uv, 0, 0)).xy;
float3 N;
N.xy = -normalInformation * normalInformation + normalInformation;
N.z = -1;
float f = dot(N, float3(1, 1, 0.25));
float m = sqrt(f);
N.xy = (normalInformation * 8 - 4) * m;
N.z = -(1 - 8 * f);
}


I don’t have the Crytek shaders source code in this computer but I think that the use a cool image processing method in the final version. Unfortunately I don’t have time to implement it but with a texture (used to transform the normals to another space) you can implemented easily. I think.

[size=1]Project page: [size=1]<

[size=1] XNA FINAL Engine[size=1] [size=1]>
Take a look at here.

hth.
-R
There's no "hard", and "the impossible" takes just a little time.

This topic is closed to new replies.

Advertisement