Depth value + Fragment shader

Started by
0 comments, last by Digitalfragment 17 years, 7 months ago
Hi, I have one 3d Texture (T1). I have created two depth textures (DT1 & DT2) based on two different depth tests (Say d1 & d2 - both these value vary based on the geometry being rendered, which means that the d1 and d2 for each fragment can vary). I want to render the part of the 3d texture which has depth value d where d should be d1< d < d2. I want to know how to pass values (d1 & d2)from depth texture (DT1 and DT2) to the fragment program in CG. Second thing is how to get depth value (d) from 3D texture (T1) for comparison with d1 and d2. Please see the code below. I was thinking of doing something like it float4 main(float3 uv : TEXCOORD, uniform sampler2D DT1, uniform sampler2D DT2, uniform sampler3D T1) : COLOR { float2 pos; // getting depth value and color value at uv from T1 float4 col = tex3D(T1, uv); // Dont know how to get the depth value float1 depth = // get the depth value from T1 at uv pos = float2(uv.x, uv.y); // getting the depth value at pos from DT1 and DT2 float depth1 = get the value from DT1 at pos // will tex2D work float depth2 = get the value form DT2 at pos // will tex2D work float4 outcolor; outcolor = float4(col.x,col.y,col.z,0.0); if (d > depth1 && d < depth2) outcolor = float4(col.x,col.y,col.z,col.w); return outcolor; } I am pretty new to CG shading language. Any help/advice would be of great help. Thanks a lot!!
Advertisement
Pass the vertex position (transformed through model, view & projection matricies) from the vertex shader to the fragment shader. The Z value of that vertex is your depth value.

This topic is closed to new replies.

Advertisement