Jump to content
  • Advertisement
Sign in to follow this  

Deferred Decal Flipped axis

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

http://uppix.com/f-Screenshot_2014_5428aaf20017b216.png

Y = 4.0f

http://uppix.com/f-Screenshot_2014_5428c2dd0017b236.png

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

 

EDIT:

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.

 

EDIT2:

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
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.

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

Sign me up!