Jump to content
  • Advertisement
Sign in to follow this  

Deferred Decal Flipped axis

This topic is 1507 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 all,

I have implemented deferred decal which works very good but I have to scale my box on Y-Axis to have decal more in depth (Z-Axis) :

Y = 1.0f


Y = 4.0f


Here the HLSL Pixel shader used on D3D11 renderer :

float4 main( in PS_INPUT Input ) : SV_TARGET0
  // View space position.
  float PositionDepth = DepthMap.Sample( ClampPointSampler, Input.TexCoord ).r;
  float3 PositionVS = Input.ViewRay * DepthToViewZ( PositionDepth );

  // Compute the decal texcoord.
  float4 DecalTexCoord = mul( float4( PositionVS, 1.0f ), DecalMatrix );
  clip( 0.5f - abs( DecalTexCoord.xyz ) );
  DecalTexCoord.xy += 0.5f;
  DecalTexCoord.y *= -1.0f;
  // Return the decal color.
  return DiffuseMap.Sample( ClampLinearSampler, DecalTexCoord.xy );

Here the DecalMatrix updated each frame when rendering a decal :

DeferredDecalCBuffer->DecalMatrix = View.Inversed() * World.Inversed();

View is the camera view matrix and World is the decal world matrix used to render the box.

Thanks for the help



One solution found but I want to know if another exist or if it's the best I have :

The solution is to create the view matrix using a look at matrix based on the decal translation and forward vector from quaternion and have that in the pixel shader :

float4 DecalTexCoord = mul( float4( PositionVS, 1.0f ), DecalMatrix );
DecalTexCoord.xy *= RcpDecalSize;

DecalMatrix is : View.Inversed() * LookAtMatrix;

RcpDecalSize = float2( 1.0f / DecalSize.x, 1.0f / DecalSize.z );

Surely the DecalSize.y should be used to scale the DecalTexCoord.z.



Finally it's normal because you change the space so Z becomes Y.

Edited by Alundra

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.

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!