source: nanovis/trunk/shaders/zincblende_volume.cg @ 4587

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