DirectX 11 Volume Rendering Advice Needed

Started by
4 comments, last by Aaron Smith 8 years ago

Hi All

I have been following a few different tutorials on volume rendering using ray casting but i have come across a few issues which im hoping someone will be able to give me advice on

1. So I first render a cube front and back and then save these to textures which I use for the actual volume rendering after..... when I move the camera into the volume cube I notice the render of the front side no longer draws and only the back side draws, which this means I no longer can draw the actual volume render

[attachment=31493:display1.png]
What could I do to get around this problem as I really want to be able to move freely through the volume renders

[attachment=31494:display2.png]
2. this theory is based on the bounding volume being a area that goes from 0,0,0 to 1,1,1 and this works fine ....but if I want the volume area to only be scaled to 0.5,0.5,0.5 this now ruins the volume and its very confusing to why this would happen? I will try provide as much code for the area as possible but any advice would be great

[attachment=31495:progress.png]

Pixel Shader code for the volume render


float2 texC = input.pos.xy /= input.pos.w;
	texC.x = 0.5f*texC.x +0.5f;
	texC.y = 0.5f*texC.y +0.5f;


	float3 frontTex = txDiffuse2.Sample(samLinear, texC).xyz;
	float3 backTex =  txDiffuse.Sample(samLinear, texC).xyz;

	float3 direction = normalize(backTex - frontTex);// input.PosW);
	
	float4 pos = float4(frontTex, 0.0);
	float4 dst = float4(0, 0, 0, 0);
	float4 src = 0;

	float value = 0;

	float3 Step = normalize(direction) * 0.01;

	for (int i = 1; i < 50; i ++)
	{
		pos.w = 0.0;
		value = volume.Sample(samLinear, pos).r;
		src = (float4)value;
		src.a *= 0.5f;

		dst.rgb = dst.rgb + (1 - dst.a) * src.a * src.rgb;
		dst.a = dst.a + (1 - dst.a) * src.a;
		//src.rgb *= src.a;
		//dst = (1.0f - dst.a) * src + dst;
		if (dst.a >= .95f)
			break;

		////advance the current position
		pos.xyz += Step;

		////break if the position is greater than <1, 1, 1>
		if (pos.x > 1.0f ||  pos.y > 1.0f || pos.z > 1.0f)
			break;
	}

Vertex code for rendering the two textures


VS_OUTPUT VS(VS_INPUT input)
{
    VS_OUTPUT output = (VS_OUTPUT)0;

	input.PosL = input.PosL *float4(1, 1, 1, 1);
	float4 posW = mul(input.PosL, LocalWorld);
	//output.PosH = posW;
	output.PosW = posW.xyz;
	posW = mul(input.PosL, World);
	output.PosH = mul(posW, View);
	output.PosH = mul(output.PosH, Projection);
	output.Tex = input.Tex;

	float3 normalW = mul(float4(input.NormL, 0.0f), LocalWorld).xyz;
	output.NormW = normalize(normalW);

    return output;
}


Id be happy to help anyone who also is trying this but I fear I have either done something wrong or I am missing something

Thank You

Advertisement

For #1, you are clipping the geometry that goes behind the near clipping plane of the view frustrum. If you want to keep that from happening, you can modify your vertex shader to transform your vertices such that their Z component is set to 0 if it has a negative value after the transformation has been applied. This will make the vertices get pushed back by your camera, and should keep your cube from being cut.

I don't really understand the issue in #2 - can you clarify that a bit more?

http://www.gamedev.net/topic/656419-volume-texture-for-clouds/ This thread might help

more efficient and simpler would be to do all in one pass.
render just the back faces, calculate with a simple ray intersection the near-distance of the cube (if t<0.0, then t=0.0); and trace through the volume.

Thanks guys I have been looking through replies ...

Kyrpt0n - when you say to render the back faces, do you mean still render them to a texture and then draw the actual cube and pass that texture through to do the ray trace with?

Hi all,

So I have come across a new problem, when the cube is rendered at 0,0,0 with a scale 1,1,1 and it seems to work well, but now i move the cube left and right hoping the volume would look the same but move and this happens

Can anyone help me understand why this now happens please?

I get that the vertex shader takes in position of the object and then this is used within the pixel shader to reference from the backtexture but I cannot see how to get the volume to move while keeping the image consistent as i am hoping to use this for particle system

Thank You

This topic is closed to new replies.

Advertisement