• Advertisement
Sign in to follow this  

Deferred decal and texel offset

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

I have implemented the deferred decal this weekend, I'm using Direct3D9 and hacked the depth buffer as a rendertexture(FOURCC('I','N','T','Z')).Every decal is a cube box.To find the uv coordinate of decal pixels,I have to sample the depth texture and caculate the world position of each pixel,then transform the position to decal space. My problem is, when I have an object in front of the decal,there will be some bright edges around the object.It seems that the depth result on the edge is not currect. I've tried to add 0.5 pixel offset, but it not works.Can someone help me?

Share this post


Link to post
Share on other sites
Advertisement

Can you post up the code for how you calculate the screen-space texture-coordinates from vertices (with and without your not-working 0.5 fix)?


here is my code

void VolumeDecl_vp(
float4 iPosition:POSITION,
out float4 oUV:TEXCOORD0,
out float4 oPos:TEXCOORD1,
out float4 oPosition:POSITION
)
{
iPosition = mul(iPosition,WorldMatrix);

oPosition = mul(iPosition,ViewProj);
float2 tPos = oPosition.xy/oPosition.w;
float2 vPos = float2(0.5*tPos.x,-0.5*tPos.y)+float2(0.5+0.5/screenSize.x,0.5+0.5/screenSize.y);
oUV = float4(vPos,0,1)*oPosition.w;
oPos = oPosition;
}


In the pixel shader I use oUV.xy/oUV.w as texture coordinate.


void VolumeDecl_fp(
float4 iUV : TEXCOORD0,
float4 iPos : TEXCOORD1,
out float4 oColor : COLOR
)
{
float2 spos = float2(iPos.x / iPos.w, iPos.y / iPos.w);
float2 uv = iUV.xy/iUV.w;

float depth = tex2Dlod(depthTex,float4(uv,0,0)).r;

float4 pos=mul(float4(spos,depth,1),InverseViewProj);
pos.xyz/=pos.w;
pos.w = 1.f;

float4 tPos = mul(pos,DeclMat);
float3 uvw = float3(tPos.x,tPos.y,tPos.z);

uvw.x = (uvw.x + 1.f) * 0.5f;
uvw.y = 0.5f - uvw.y * 0.5f;
uvw.z = (uvw.z + 1.f) * 0.5f;
clip(uvw.xyz);
clip(1 - uvw.xyz);

oColor = tex2D(decalTex,float2(uvw.x*DeclParam.z + DeclParam.x,uvw.y*DeclParam.w + DeclParam.y));
}


I found that the bright color of edge was came from the transparent part of my decal texture,when I changed the transparent part color to black,the egde became grey. Edited by dragon.R

Share this post


Link to post
Share on other sites
could be values outside of the volume.



// Points outside the light volume are in projection.
if( [color="#000000"]spos .x < -1.0f || [color="#000000"]spos .x > 1.0f ||
[color="#000000"]spos .y < -1.0f || [color="#000000"]spos .y > 1.0f ||
[color="#000000"]spos .z < 0.0f )
{
not in the volume here;

}
else
{

Share this post


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

  • Advertisement