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