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 | #define PHONG_SHADING |
---|
21 | |
---|
22 | PixelOut main(v2f IN, /* uniform sampler1D tf,*/ |
---|
23 | uniform sampler3D volume, |
---|
24 | uniform sampler1D tf, |
---|
25 | uniform float4x4 modelViewInv, |
---|
26 | uniform float4x4 modelView, |
---|
27 | uniform float4 renderParameters) |
---|
28 | { |
---|
29 | |
---|
30 | PixelOut OUT; |
---|
31 | float4 tex_coord = mul(modelViewInv, IN.TexCoord); |
---|
32 | |
---|
33 | //if(renderParameters.y==1){ //1 component |
---|
34 | |
---|
35 | float4 sample = tex3D(volume, tex_coord.xyz); |
---|
36 | |
---|
37 | #ifdef PHONG_SHADING |
---|
38 | //lighting parameters |
---|
39 | float3 normal; |
---|
40 | if(length(sample.yzw)>0.0) |
---|
41 | normal = normalize(sample.yzw); |
---|
42 | |
---|
43 | float3 light_vector = normalize(IN.Light); |
---|
44 | float3 eye_vector = normalize(IN.EyeVector); |
---|
45 | float3 half_vector = normalize(eye_vector+light_vector); |
---|
46 | |
---|
47 | #endif |
---|
48 | |
---|
49 | //sample the transfer function texture |
---|
50 | float4 color = tex1D(tf, sample.x); |
---|
51 | color.w = 30*color.w/renderParameters.x; |
---|
52 | |
---|
53 | //float4 color = float4(sample.x, 0, 0, 1); |
---|
54 | |
---|
55 | |
---|
56 | #ifdef PHONG_SHADING |
---|
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 | |
---|
61 | float ambient = 0.1; |
---|
62 | float diffuse = normal_dot_light * renderParameters.z; |
---|
63 | float specular = pow(normal_dot_half, renderParameters.w)*(1-ambient-diffuse); |
---|
64 | |
---|
65 | float lighting = ambient + diffuse + specular; |
---|
66 | color.xyz = color.xyz * lighting; |
---|
67 | |
---|
68 | //debug |
---|
69 | //color.xyz = normal.xyz; //display normals |
---|
70 | #endif |
---|
71 | |
---|
72 | OUT.Color = color; |
---|
73 | // } |
---|
74 | |
---|
75 | /* |
---|
76 | else if(renderParameters.y==0){ |
---|
77 | //3 component |
---|
78 | float3 sample = tex3D(volume, tex_coord.xyz).xyz; |
---|
79 | OUT.Color = float4(3*sample, 2*length(sample)/renderParameters.x); |
---|
80 | } |
---|
81 | */ |
---|
82 | |
---|
83 | //debug |
---|
84 | //OUT.Color = float4(tex_coord, 1); |
---|
85 | |
---|
86 | return OUT; |
---|
87 | } |
---|