source: nanovis/tags/1.2.2/shaders/zincblende_volume.cg @ 6369

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

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

File size: 3.3 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
11/*
12 * zincblende shading fragment program
13 *
14 * renderParams:
15 *   x: sample distance ratio (0 = single slice)
16 *   y: isosurface flag (opacity scaling on/off)
17 *   z: opacity scale
18 */
19PixelOut main(v2f IN,
20              uniform sampler1D tf,
21              uniform sampler3D volumeA,
22              uniform sampler3D volumeB,
23              uniform float4 cellSize,
24              uniform float4x4 modelViewInv,
25              uniform float4 renderParams)
26
27{
28    PixelOut OUT;
29
30    float4 texcoord = mul(modelViewInv, IN.TexCoord);
31    float4 twice_cell_size = cellSize * 2.0;
32
33    // volumeA : outer
34    // volumeB : inner
35    float4 texcoord_2 = texcoord + float4(twice_cell_size.x, 0,                 twice_cell_size.z, 0);
36    float4 texcoord_3 = texcoord + float4(0,                 twice_cell_size.y, twice_cell_size.z, 0);
37    float4 texcoord_4 = texcoord + float4(twice_cell_size.x, twice_cell_size.y, 0, 0);
38    float4 voxel_corner = tex3D(volumeB, texcoord) + tex3D(volumeA, texcoord - cellSize);
39    float4 voxel_face_center_2 = tex3D(volumeB, texcoord_2) + tex3D(volumeA, texcoord_2 - cellSize);
40    float4 voxel_face_center_3 = tex3D(volumeB, texcoord_3) + tex3D(volumeA, texcoord_3 - cellSize);
41    float4 voxel_face_center_4 = tex3D(volumeB, texcoord_4) + tex3D(volumeA, texcoord_4 - cellSize);
42
43    float sample = (voxel_corner.x + voxel_face_center_2.y + voxel_face_center_3.z + voxel_face_center_4.w) * 0.125;
44    /*
45      float4 texcoord_a = texcoord - float4(twice_cell_size.x, twice_cell_size.y, 0, 0);
46      float4 texcoord_b = texcoord - float4(twice_cell_size.x, 0, twice_cell_size.z, 0);
47      float4 texcoord_c = texcoord - float4(0, twice_cell_size.y, twice_cell_size.z, 0);
48       
49      float4 voxel_corner = tex3D(volumeA, texcoord) + tex3D(volumeB, texcoord - cellSize);
50      float4 voxel_face_center_a = tex3D(volumeA, texcoord_a) + tex3D(volumeB, texcoord_a - cellSize);
51      float4 voxel_face_center_b = tex3D(volumeA, texcoord_b) + tex3D(volumeB, texcoord_b - cellSize);
52      float4 voxel_face_center_c = tex3D(volumeA, texcoord_c) + tex3D(volumeB, texcoord_c - cellSize);
53      //combine 8 sampling results
54      float sample = (voxel_corner.x + voxel_face_center_a.y + voxel_face_center_b.z + voxel_face_center_c.w) * 0.125;
55    */
56
57    //sample transfer function texture
58    float4 color = tex1D(tf, sample);
59
60    if (renderParams.x == 0.0) {
61        //If single slice render, only flat shading, completely opaque.
62        color.w = 1;
63    } else {
64        //regular volume rendering, we do FLAT SHADING
65        //since all 4 components of the volume texture has been used to store orbital data,
66        //there is no room to store normal vector. If we really need PHONG shading we have to pass more volumes to
67        //the shader. We might add this later.
68
69        // Opacity scaling: equivalent to scaling transfer function
70        color.w = color.w * renderParams.z;
71        // Apply opacity correction for ratio of current sample distance
72        // to data set sample distance
73        color.w = (1.0 - pow((1.0 - color.w), renderParams.x));
74    }
75
76    OUT.Color = color;
77    return OUT;
78}
Note: See TracBrowser for help on using the repository browser.