source: trunk/packages/vizservers/nanovis/shaders/zincblende_volume.cg @ 3177

Last change on this file since 3177 was 3177, checked in by mmc, 12 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

File size: 3.5 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
20PixelOut main(v2f IN,
21              uniform sampler1D tf,
22              uniform sampler3D volumeA,
23              uniform sampler3D volumeB,
24              uniform float4 cellSize,
25              uniform float4x4 modelViewInv,
26              uniform float4 renderParameters,
27              uniform float4 options)
28
29{
30    PixelOut OUT;
31
32    float4 tex_coord = mul(modelViewInv, IN.TexCoord);
33    float4 twice_cell_size = cellSize * 2.0;
34
35    // volumeA : outer
36    // volumeB : inner
37    float4 tex_coord_2 = tex_coord + float4(twice_cell_size.x, 0,                 twice_cell_size.z, 0);
38    float4 tex_coord_3 = tex_coord + float4(0,                 twice_cell_size.y, twice_cell_size.z, 0);
39    float4 tex_coord_4 = tex_coord + float4(twice_cell_size.x, twice_cell_size.y, 0, 0);
40    float4 voxel_corner = f4tex3D(volumeB, tex_coord) + f4tex3D(volumeA, tex_coord - cellSize);
41    float4 voxel_face_center_2 = f4tex3D(volumeB, tex_coord_2) + f4tex3D(volumeA, tex_coord_2 - cellSize);
42    float4 voxel_face_center_3 = f4tex3D(volumeB, tex_coord_3) + f4tex3D(volumeA, tex_coord_3 - cellSize);
43    float4 voxel_face_center_4 = f4tex3D(volumeB, tex_coord_4) + f4tex3D(volumeA, tex_coord_4 - cellSize);
44
45    float sample = (voxel_corner.x + voxel_face_center_2.y + voxel_face_center_3.z + voxel_face_center_4.w) * 0.125;
46    /*
47      float4 tex_coord_a = tex_coord - float4(twice_cell_size.x, twice_cell_size.y, 0, 0);
48      float4 tex_coord_b = tex_coord - float4(twice_cell_size.x, 0, twice_cell_size.z, 0);
49      float4 tex_coord_c = tex_coord - float4(0, twice_cell_size.y, twice_cell_size.z, 0);
50       
51      float4 voxel_corner = f4tex3D(volumeA, tex_coord) + f4tex3D(volumeB, tex_coord - cellSize);
52      float4 voxel_face_center_a = f4tex3D(volumeA, tex_coord_a) + f4tex3D(volumeB, tex_coord_a - cellSize);
53      float4 voxel_face_center_b = f4tex3D(volumeA, tex_coord_b) + f4tex3D(volumeB, tex_coord_b - cellSize);
54      float4 voxel_face_center_c = f4tex3D(volumeA, tex_coord_c) + f4tex3D(volumeB, tex_coord_c - cellSize);
55      //combine 8 sampling results
56      float sample = (voxel_corner.x + voxel_face_center_a.y + voxel_face_center_b.z + voxel_face_center_c.w) * 0.125;
57    */
58
59    //sample transfor function texture
60    float4 color = f4tex1D(tf, sample);
61
62    if (renderParameters.x < 0.5) {
63        //If single slice render, only flat shading, completely opaque.
64        color.w = 1;
65    } else {
66        //regular volume rendering, we do FLAT SHADING
67        //since all 4 components of the volume texture has been used to store orbital data,
68        //there is no room to store normal vector. If we really need PHONG shading we have to pass more volumes to
69        //the shader. We might add this later.
70
71        //opacity is modulated by the number of total slices
72        //to avoid very opaque volume when number of slices is high
73        color.w = renderParameters.y * color.w / renderParameters.x;
74    }
75
76    OUT.Color = color;
77    return OUT;
78}
Note: See TracBrowser for help on using the repository browser.