Jump to content
  • Advertisement
Sign in to follow this  
PhillipHamlyn

Imposter Lighting

This topic is 1135 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

Hi,

 

I am trying to implement an imposter lighting scheme where I record a texture atlas of my model taken at various Y axis rotation angles (to pre-calculate  a set of textures I can render as imposters, lerping between them). I have a system where I write a second texture atlas containing the model normals instead of the texture values, as a kind of deferred rendering process in my pipeline.

 

Aside from having some trouble using my low grade maths skills to rotate the normal stored in the appropriate pixel, I get some reasonable results; i.e. the lighting on the 3D model somewhat smoothly interpolates into the imposter, which lights itself using the normals stored in the normals texture atlas.

 

I am having one issue though and am looking for help. In my Imposter VS I pass in a radian angle of rotation which matches the angle I will use in my Model matrix when rendering the full 3D model. I use this to select the appropriate texture and normal pixels from my texture atlas. This works OK. In order for my Normal to work I need to rotate my normal in the PS from the pre-baked model normal value rotated via the Y-axis rotation value (Y is UP in my world) - this should then present the same value for the normal as though I'd read it via more standard means through the 3D model VS input structure rotated using a Model matrix.

 

My code fragments are;

imposter VS;

// Matrix def from http://gamedev.stackexchange.com/questions/103002/how-to-rotate-a-3d-instance-using-an-hlsl-shader
	output.ModelRotation =
		float3x3(
		cos(modelRotation), 0.0f, -sin(modelRotation),
		0.0f, 1.0f, 0.0f,
		sin(modelRotation), 0.0f, cos(modelRotation));

imposter PS;

// LERP between my two possible pre-baked normal textures. These are stored in model space, not tangent space.
	float3 normalSample =
		((tex2D(TextureSampler1, ps_input.TextureCoordinate0.xy) * ps_input.TextureCoordinate0.z) +
		(tex2D(TextureSampler1, ps_input.TextureCoordinate1.xy) * ps_input.TextureCoordinate1.z)).rgb;
	
	// Correct them into -1->1 range.
	float3 normal = (2 * (normalSample)) - 1.0f;
	
	// The normal is in model space. We need to apply the specific model rotation on top of it, for this particular instance of the imposter
	normal = normalize(mul(normal, ps_input.ModelRotation)); // Rotate

I then use the standard lighting calculation I use elsewhere to light the pixel using the normal.

 

My problem is that I think my Y-axis rotation matrix is incorrect, but I struggle with the row-vs-column ordering concepts in HLSL vs. DirectX, so cannot easily verify the matrix has the correct effect on the Normal via a C# unit test. If anyone can guide me to the correct method of constructing that matrix, I'd be grateful.

 

Any other comments on the basic methods also gratefully received.

 

Phillip

Edited by PhillipHamlyn

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!