Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualdragon.R

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

#1dragon.R

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.

PARTNERS