Jump to content
  • Advertisement
Sign in to follow this  
CDeniz

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

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

If you intended to correct an error in the post then please contact us.

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:

 

PgxXgCT.png

Share this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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)
{
	float rad = radians( degree);
	float3x3 rotationMat = 
	{
		cos( rad), -sin(rad), 0,
		sin( rad), cos(rad), 0,
		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 this post


Link to post
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 smile.png

Edited by Nik02

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!