source: nanovis/tags/1.1.1/shaders/zincblende_volume.cg @ 4833

Last change on this file since 4833 was 3362, checked in by ldelgass, 11 years ago

Merge nanovis2 branch to trunk

File size: 3.7 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * ======================================================================
4 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
5 *           Purdue Rendering and Perceptualization Lab (PURPL)
6 *
7 *  Copyright (c) 2004-2012  HUBzero Foundation, LLC
8 *
9 *  See the file "license.terms" for information on usage and
10 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 * ======================================================================
12 */
13
14#include "common.cg"
15
16/*
17 * zincblende shading fragment program
18 *
19 * renderParams:
20 *   x: sample distance ratio (0 = single slice)
21 *   y: isosurface flag (opacity scaling on/off)
22 *   z: opacity scale
23 */
24PixelOut main(v2f IN,
25              uniform sampler1D tf,
26              uniform sampler3D volumeA,
27              uniform sampler3D volumeB,
28              uniform float4 cellSize,
29              uniform float4x4 modelViewInv,
30              uniform float4 renderParams)
31
32{
33    PixelOut OUT;
34
35    float4 tex_coord = mul(modelViewInv, IN.TexCoord);
36    float4 twice_cell_size = cellSize * 2.0;
37
38    // volumeA : outer
39    // volumeB : inner
40    float4 tex_coord_2 = tex_coord + float4(twice_cell_size.x, 0,                 twice_cell_size.z, 0);
41    float4 tex_coord_3 = tex_coord + float4(0,                 twice_cell_size.y, twice_cell_size.z, 0);
42    float4 tex_coord_4 = tex_coord + float4(twice_cell_size.x, twice_cell_size.y, 0, 0);
43    float4 voxel_corner = f4tex3D(volumeB, tex_coord) + f4tex3D(volumeA, tex_coord - cellSize);
44    float4 voxel_face_center_2 = f4tex3D(volumeB, tex_coord_2) + f4tex3D(volumeA, tex_coord_2 - cellSize);
45    float4 voxel_face_center_3 = f4tex3D(volumeB, tex_coord_3) + f4tex3D(volumeA, tex_coord_3 - cellSize);
46    float4 voxel_face_center_4 = f4tex3D(volumeB, tex_coord_4) + f4tex3D(volumeA, tex_coord_4 - cellSize);
47
48    float sample = (voxel_corner.x + voxel_face_center_2.y + voxel_face_center_3.z + voxel_face_center_4.w) * 0.125;
49    /*
50      float4 tex_coord_a = tex_coord - float4(twice_cell_size.x, twice_cell_size.y, 0, 0);
51      float4 tex_coord_b = tex_coord - float4(twice_cell_size.x, 0, twice_cell_size.z, 0);
52      float4 tex_coord_c = tex_coord - float4(0, twice_cell_size.y, twice_cell_size.z, 0);
53       
54      float4 voxel_corner = f4tex3D(volumeA, tex_coord) + f4tex3D(volumeB, tex_coord - cellSize);
55      float4 voxel_face_center_a = f4tex3D(volumeA, tex_coord_a) + f4tex3D(volumeB, tex_coord_a - cellSize);
56      float4 voxel_face_center_b = f4tex3D(volumeA, tex_coord_b) + f4tex3D(volumeB, tex_coord_b - cellSize);
57      float4 voxel_face_center_c = f4tex3D(volumeA, tex_coord_c) + f4tex3D(volumeB, tex_coord_c - cellSize);
58      //combine 8 sampling results
59      float sample = (voxel_corner.x + voxel_face_center_a.y + voxel_face_center_b.z + voxel_face_center_c.w) * 0.125;
60    */
61
62    //sample transfer function texture
63    float4 color = f4tex1D(tf, sample);
64
65    if (renderParams.x == 0.0) {
66        //If single slice render, only flat shading, completely opaque.
67        color.w = 1;
68    } else {
69        //regular volume rendering, we do FLAT SHADING
70        //since all 4 components of the volume texture has been used to store orbital data,
71        //there is no room to store normal vector. If we really need PHONG shading we have to pass more volumes to
72        //the shader. We might add this later.
73
74        // Opacity scaling: equivalent to scaling transfer function
75        color.w = color.w * renderParams.z;
76        // Apply opacity correction for ratio of current sample distance
77        // to data set sample distance
78        color.w = (1.0 - pow((1.0 - color.w), renderParams.x));
79    }
80
81    OUT.Color = color;
82    return OUT;
83}
Note: See TracBrowser for help on using the repository browser.