source: trunk/packages/vizservers/nanovis/shaders/volqd_volume.cg @ 1018

Last change on this file since 1018 was 581, checked in by vrinside, 18 years ago
File size: 1.8 KB
Line 
1#include "common.cg"
2
3PixelOut main(v2f IN,
4    uniform sampler1D tf,
5    uniform sampler3D vol_grid_s,
6    uniform float4 cell_size,
7    uniform float4x4 ModelViewInv,
8    uniform float4 renderParameters)
9{
10    PixelOut OUT;
11
12    float tf_coord_s, tf_coord_p, tf_coord_d, tf_coord_ss;
13                   
14
15    float4 twice_cell_size = cell_size*2.0;
16    float4 tex_coord = mul(ModelViewInv, IN.TexCoord);
17    float4 tex_coord_a = tex_coord - float4(twice_cell_size.x, twice_cell_size.y, 0, 0);
18    float4 tex_coord_b = tex_coord - float4(twice_cell_size.x, 0, twice_cell_size.z, 0);
19    float4 tex_coord_c = tex_coord - float4(0, twice_cell_size.y, twice_cell_size.z, 0);
20
21
22    float4 voxel_corner = f4tex3D(vol_grid_s, tex_coord);
23    float4 voxel_face_center_a = f4tex3D(vol_grid_s, tex_coord_a);
24    float4 voxel_face_center_b = f4tex3D(vol_grid_s, tex_coord_b);
25    float4 voxel_face_center_c = f4tex3D(vol_grid_s, tex_coord_c); 
26    float sample = (voxel_corner.x + voxel_face_center_a.y + voxel_face_center_b.z + voxel_face_center_c.w)*0.25;
27
28    //sample the transfer function texture
29    float4 color = tex1D(tf, sample.x);
30
31    if(renderParameters.x < 0.5)
32    {
33        //If single slice render, only flat shading, completely opaque.
34        color.w = 1;
35    }
36    else
37    {   //regular volume rendering, we do FLAT SHADING
38        //since all 4 components of the volume texture has been used to store orbital data,
39        //there is no room to store normal vector. If we really need PHONG shading we have to pass more volumes to
40        //the shader. We might add this later.
41
42        //opacity is modulated by the number of total slices
43        //to avoid very opaque volume when number of slices is high
44        color.w = renderParameters.y * color.w / renderParameters.x;
45    }
46
47    OUT.Color = color;
48
49    return OUT;
50}
51
Note: See TracBrowser for help on using the repository browser.