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 | * render one volume |
---|
17 | */ |
---|
18 | |
---|
19 | |
---|
20 | PixelOut main(v2f IN, |
---|
21 | uniform sampler3D volume, |
---|
22 | uniform sampler1D tf, |
---|
23 | //uniform sampler1D tf_cutplane, |
---|
24 | uniform float4x4 modelViewInv, |
---|
25 | uniform float4x4 modelView, |
---|
26 | uniform float4 renderParameters) |
---|
27 | { |
---|
28 | |
---|
29 | PixelOut OUT; |
---|
30 | float4 tex_coord = mul(modelViewInv, IN.TexCoord); |
---|
31 | float4 sample = tex3D(volume, tex_coord.xyz); |
---|
32 | |
---|
33 | //sample the transfer function texture |
---|
34 | float4 color = tex1D(tf, sample.x); |
---|
35 | |
---|
36 | if(renderParameters.x < 0.5) |
---|
37 | { //If single slice render, only flat shading, completely opaque. |
---|
38 | //color = tex1D(tf_cutplane, sample.x); |
---|
39 | color.w = 1; |
---|
40 | //color.w = renderParameters.y*color.w/renderParameters.x; |
---|
41 | } |
---|
42 | else |
---|
43 | { //regular volume rendering, we do PHONG SHADING |
---|
44 | |
---|
45 | //lighting parameters |
---|
46 | float3 normal; |
---|
47 | if(length(sample.yzw)>0.0) |
---|
48 | { |
---|
49 | normal = sample.yzw * 2.0 - 1.0; |
---|
50 | normal = normalize(normal); |
---|
51 | } |
---|
52 | |
---|
53 | float3 light_vector = normalize(IN.Light); |
---|
54 | float3 eye_vector = normalize(IN.EyeVector); |
---|
55 | float3 half_vector = normalize(eye_vector+light_vector); |
---|
56 | |
---|
57 | //lighting computation |
---|
58 | float normal_dot_light = max(dot(normal, light_vector), 0); |
---|
59 | float normal_dot_half = max(dot(normal, half_vector), 0); |
---|
60 | //float normal_dot_light = abs(dot(normal, light_vector)); |
---|
61 | //float normal_dot_half = abs(dot(normal, half_vector)); |
---|
62 | |
---|
63 | float ambient = 0.8; |
---|
64 | //float ambient = 0.2; |
---|
65 | float diffuse = normal_dot_light * renderParameters.z; |
---|
66 | float specular = pow(normal_dot_half, renderParameters.w)*(1-ambient-diffuse); |
---|
67 | |
---|
68 | float lighting = ambient + diffuse + specular; |
---|
69 | color.xyz = color.xyz * lighting; |
---|
70 | color.w = renderParameters.y*color.w/renderParameters.x; //opacity is modulated by the number of total slices |
---|
71 | //to avoid very opaque volume when number of slices is high |
---|
72 | } |
---|
73 | |
---|
74 | OUT.Color = color; |
---|
75 | //debug |
---|
76 | //OUT.Color = float4(tex_coord.xyz, 1); |
---|
77 | |
---|
78 | return OUT; |
---|
79 | } |
---|