Public Group

# Calculating Texture Coordinates in shader problem

This topic is 3086 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello everybody!

I'm currently trying to implement volumetric fog in Ogre. The technic is the following:

1. I'm using two additional render target textures to render only volumetric fog meshes - one for back faces and another for front faces. In them I just encode the depth.

2. In the final path I'm using these two textures to decode the depths from them and calculate a thikness for every pixel. For this I have to know texture coordinates in the pixel shader to sample two textures.

I found some code which does this and it generally works all right until the near clip plane is very close to a fog mesh's face and/or this face as some non-right angle to the camera axis.

Here is the final vertex and pixel shaders that are the problematic code:

////////////////////////// Start of code

void w_Vol_Diff_Vert(uniform float4x4 worldviewproj,
float4 position : POSITION,
out float2 oUV : TEXCOORD0,
out float4 oPos : POSITION)
{
oPos = mul(worldviewproj, position);
// Convert to image-space
oUV = float2( oPos.x / oPos.w , (- oPos.y) / oPos.w) * 0.5 + 0.5;
}

void w_Vol_Diff_Frag(uniform sampler backMap : register(s0),
uniform sampler frontMap : register(s1),
float2 uv : TEXCOORD0,
float4 decode : TEXCOORD1,
out float4 oColor : COLOR)
{
float3 backColor = tex2D(backMap , uv).xyz;
float3 frontColor = tex2D(frontMap, uv).xyz;
float depthdiff = dot((backColor - frontColor), CV_DECODE_VECTOR);

// Compensate the possible absense of one of the back faces by 1/8 (full distance)
if(depthdiff < 0.0)
depthdiff += 0.125;

oColor.rgb = 0.4; // Grey color
oColor.a = depthdiff * 50;
}

////////////////////////// End of code

Can anyone please give me advice on how to fix that? I ran out of ideas. :(

Here are two screenshots to illustrate the problem:

There are two volumetric fog spheres and on the bad shot the right sphere (which is very close to camera) is screwed up.

Thanks in advance for any help!

1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633694
• Total Posts
3013372
×