source: nanovis/branches/1.1/shaders/volqd_volume.cg @ 4906

Last change on this file since 4906 was 4904, checked in by ldelgass, 9 years ago

Merge serveral changes from trunk. Does not include threading, world space
changes, etc.

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