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..
Calculate correct Gradients for texture projection
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement