source: nanovis/trunk/shaders/volqd_volume.cg @ 4795

Last change on this file since 4795 was 3630, checked in by ldelgass, 11 years ago

Nanovis refactoring to fix problems with scaling and multiple results.
Do rendering in world space to properly place and scale multiple data sets.
Also fix flows to reduce resets of animations. More work toward removing
Cg dependency. Fix panning to convert viewport coords to world coords.

File size: 1.9 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 float4 renderParameters)
16{
17    PixelOut OUT;
18
19    float tf_coord_s, tf_coord_p, tf_coord_d, tf_coord_ss;
20
21    float4 twice_cell_size = cell_size*2.0;
22    float4 tex_coord = IN.TexCoord;
23    float4 tex_coord_a = tex_coord - float4(twice_cell_size.x, twice_cell_size.y, 0, 0);
24    float4 tex_coord_b = tex_coord - float4(twice_cell_size.x, 0, twice_cell_size.z, 0);
25    float4 tex_coord_c = tex_coord - float4(0, twice_cell_size.y, twice_cell_size.z, 0);
26
27    float4 voxel_corner = tex3D(vol_grid_s, tex_coord);
28    float4 voxel_face_center_a = tex3D(vol_grid_s, tex_coord_a);
29    float4 voxel_face_center_b = tex3D(vol_grid_s, tex_coord_b);
30    float4 voxel_face_center_c = tex3D(vol_grid_s, tex_coord_c); 
31    float sample = (voxel_corner.x + voxel_face_center_a.y + voxel_face_center_b.z + voxel_face_center_c.w)*0.25;
32
33    //sample the transfer function texture
34    float4 color = tex1D(tf, sample.x);
35
36    if (renderParameters.x < 0.5) {
37        //If single slice render, only flat shading, completely opaque.
38        color.w = 1;
39    } else {
40        //regular volume rendering, we do FLAT SHADING
41        //since all 4 components of the volume texture has been used to store orbital data,
42        //there is no room to store normal vector. If we really need PHONG shading we have to pass more volumes to
43        //the shader. We might add this later.
44
45        //opacity is modulated by the number of total slices
46        //to avoid very opaque volume when number of slices is high
47        color.w = renderParameters.y * color.w / renderParameters.x;
48    }
49
50    OUT.Color = color;
51
52    return OUT;
53}
Note: See TracBrowser for help on using the repository browser.