# Efficient way to generate normal map (from height) for all 360 degrees of a rotated image

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

## Recommended Posts

I already have a fragment shader that generates a normal map from a height map. Now I need to apply the effect to all 360 degrees of the rotated heightmap.

Of coarse I could just apply the effect 360 times to each heighmap, but if I have already done it once then is it possible to use what I have to efficiently generate the remaining 359 maps?

Im guessing that each pixel gets offset (in r,g,b) by some constant amount depending on the rotation:

##### Share on other sites

Given the normal that you unpack from the normalmap, I think all you need to do is transform that normal by a matrix that specifies a rotation about the z-axis by the number of degrees you need.

##### Share on other sites

Awesome. It ended up being much simpler than I made it out to be, thanks!

sampler2D input : register(s0);

float degree : register(C0);

float3 rotatedVec(float3 original)
{
float3x3 rotationMat =
{
0,0,1
};

return mul( rotationMat , original);
}

float4 main(float2 uv : TEXCOORD) : COLOR
{

float3 norm = normalize(tex2D(input, uv.xy).rgb * 2.0 - 1.0);

float3 newColor = rotatedVec(norm);

newColor = newColor * 0.5 + 0.5;

return float4(newColor,1.0);
}


##### Share on other sites

You could further optimize the shader by calculating the sine (and the cosine) of the rotation angle in CPU and pass it as a shader constant

Edited by Nik02

1. 1
2. 2
Rutin
21
3. 3
4. 4
A4L
15
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633737
• Total Posts
3013607
×