Sign in to follow this  
hflong325

Deferred decal and texel offset

Recommended Posts

hflong325    247
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
hflong325    247
[quote name='Hodgman' timestamp='1352703549' post='5000133']
Can you post up the code for how you calculate the screen-space texture-coordinates from vertices ([i]with and without your not-working 0.5 fix[/i])?
[/quote]

here is my code
[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;
}
[/CODE]

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

[CODE]
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));
}
[/CODE]

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
ankhd    2304
could be values outside of the volume.



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

}
else
{

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