Jump to content

  • Log In with Google      Sign In   
  • Create Account

Deferred decal and texel offset


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 dragon.R   Members   -  Reputation: 247

Like
0Likes
Like

Posted 12 November 2012 - 12:44 AM

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?

Sponsor:

#2 Hodgman   Moderators   -  Reputation: 30388

Like
0Likes
Like

Posted 12 November 2012 - 12:59 AM

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)?

#3 dragon.R   Members   -  Reputation: 247

Like
0Likes
Like

Posted 12 November 2012 - 01:16 AM

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, 12 November 2012 - 03:55 AM.


#4 ankhd   Members   -  Reputation: 1284

Like
0Likes
Like

Posted 14 November 2012 - 04:33 AM

could be values outside of the volume.



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

}
else
{




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS