[524] | 1 | /*
|
---|
| 2 | * ======================================================================
|
---|
| 3 | * AUTHOR: Wei Qiao <qiaow@purdue.edu>
|
---|
| 4 | * Purdue Rendering and Perceptualization Lab (PURPL)
|
---|
| 5 | *
|
---|
| 6 | * Copyright (c) 2004-2006 Purdue Research Foundation
|
---|
| 7 | *
|
---|
| 8 | * See the file "license.terms" for information on usage and
|
---|
| 9 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
---|
| 10 | * ======================================================================
|
---|
| 11 | */
|
---|
| 12 |
|
---|
| 13 | #include "common.cg"
|
---|
| 14 |
|
---|
| 15 | /*
|
---|
| 16 | * zincblende shading fragment program:
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 | PixelOut 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 renderParameters)
|
---|
| 26 |
|
---|
| 27 | {
|
---|
| 28 |
|
---|
| 29 | PixelOut OUT;
|
---|
| 30 |
|
---|
[580] | 31 | float4 tex_coord = mul(modelViewInv, IN.TexCoord);
|
---|
[524] | 32 | float4 twice_cell_size = cellSize * 2.0;
|
---|
| 33 |
|
---|
| 34 | float4 tex_coord_a = tex_coord - float4(twice_cell_size.x, twice_cell_size.y, 0, 0);
|
---|
| 35 | float4 tex_coord_b = tex_coord - float4(twice_cell_size.x, 0, twice_cell_size.z, 0);
|
---|
| 36 | float4 tex_coord_c = tex_coord - float4(0, twice_cell_size.y, twice_cell_size.z, 0);
|
---|
| 37 |
|
---|
| 38 | float4 voxel_corner = f4tex3D(volumeA, tex_coord) + f4tex3D(volumeB, tex_coord - cellSize);
|
---|
| 39 | float4 voxel_face_center_a = f4tex3D(volumeA, tex_coord_a) + f4tex3D(volumeB, tex_coord_a - cellSize);
|
---|
| 40 | float4 voxel_face_center_b = f4tex3D(volumeA, tex_coord_b) + f4tex3D(volumeB, tex_coord_b - cellSize);
|
---|
| 41 | float4 voxel_face_center_c = f4tex3D(volumeA, tex_coord_c) + f4tex3D(volumeB, tex_coord_c - cellSize);
|
---|
| 42 |
|
---|
| 43 | //combine 8 sampling results
|
---|
| 44 | float sample = (voxel_corner.x + voxel_face_center_a.y + voxel_face_center_b.z + voxel_face_center_c.w) * 0.125;
|
---|
| 45 |
|
---|
| 46 | //sample transfor function texture
|
---|
| 47 | float4 color = f4tex1D(tf, sample);
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | if(renderParameters.x < 0.5)
|
---|
| 51 | { //If single slice render, only flat shading, completely opaque.
|
---|
| 52 | color.w = 1;
|
---|
| 53 | }
|
---|
| 54 | else
|
---|
| 55 | { //regular volume rendering, we do FLAT SHADING
|
---|
| 56 | //since all 4 components of the volume texture has been used to store orbital data,
|
---|
| 57 | //there is no room to store normal vector. If we really need PHONG shading we have to pass more volumes to
|
---|
| 58 | //the shader. We might add this later.
|
---|
| 59 |
|
---|
| 60 | color.w = renderParameters.y * color.w / renderParameters.x; //opacity is modulated by the number of total slices
|
---|
| 61 | //to avoid very opaque volume when number of slices is high
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | OUT.Color = color;
|
---|
| 65 | return OUT;
|
---|
| 66 | }
|
---|