Jump to content
  • Advertisement
Sign in to follow this  
B-Real

DX11 Calculate correct Gradients for texture projection

Recommended Posts

Hi,
I am looking for a way to calculate UV gradients to use with SampleGrad for deferred texture projection. Since I've already implemented tiled based pointlights, I already store ddx_coarse, ddy_coarse(viewpos.z) in my GBuffer which are used to check for multisampling.. But I've no idea if I can use them to compute gradients for projected textures..

Share this post


Link to post
Share on other sites
Advertisement

I use this trick for computing gradients for decals, stored in a texture atlas:

// This part can be precomputed for all decals (this cannot be inside a loop):
const float3 P_dx = ddx_coarse(pixelWorldPosition);
const float3 P_dy = ddy_coarse(pixelWorldPosition);

// This is computed for each decal (this can be inside a loop):
const float2 decalDX = mul(P_dx, (float3x3)decalProjection).xy * decal.texMulAdd.xy;
const float2 decalDY = mul(P_dy, (float3x3)decalProjection).xy * decal.texMulAdd.xy;

// Then sample the texture atlas with offset for each decal (this can be inside a loop):
float4 decalColor = texture_decalatlas.SampleGrad(sampler_linear_clamp, uvw.xy*decal.texMulAdd.xy + decal.texMulAdd.zw, decalDX, decalDY);

Where:

  • pixelWorldPosition is a float3 containing the world position of the shaded screen pixel
  • decalProjection is a 4x4 matrix, the inverse of the decal oriented bounding box matrix
  • decal.texMulAdd is a float4 contatining offset into the texture atlas for each decal
  • uvw is the pixel's position inside the decal's space, transformed into texture coordinate space

I hope this helps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!