# Normal packing problem with spheremap transform

This topic is 2752 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
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.

##### Share on other sites
Take a look at here.

hth.
-R

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 24
• 43
• 75