Sign in to follow this  
BuraCULa

Normal packing problem with spheremap transform

Recommended Posts

BuraCULa    153
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 [url="http://aras-p.info/texts/CompactNormalStorage.html"]here[/url].

Share this post


Link to post
Share on other sites
jischneider    253
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:

[code]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);
}[/code]

[code]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);
}[/code]

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this