Debian Codegraph @

src/vcglib/wrap/gl/splatting_apss/shaders/Finalization.glsl

raw
1 /****************************************************************************
2 * MeshLab o o *
3 * An extendible mesh processor o o *
4 * _ O _ *
5 * Copyright(C) 2005, 2009 \/)\/ *
6 * Visual Computing Lab /\/| *
7 * ISTI - Italian National Research Council | *
8 * \ *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
20 * for more details. *
21 * *
22 ****************************************************************************/
23
24 #extension GL_ARB_texture_rectangle : enable
25
26 #ifndef EXPE_DEPTH_INTERPOLATION
27 #define EXPE_DEPTH_INTERPOLATION 0
28 #endif
29
30 #ifndef EXPE_OUTPUT_DEPTH
31 #define EXPE_OUTPUT_DEPTH 0
32 #endif
33
34 // avoid an annoying bug with the nvidia driver 87XX serie.
35 #define epsilon 0.000001
36
37 uniform vec4 viewport;
38
39 #ifndef EXPE_DEFERRED_SHADING
40
41 uniform sampler2DRect ColorWeight;
42 #if (EXPE_OUTPUT_DEPTH==1)
43 uniform sampler2DRect Depth;
44 #endif
45
46 void Finalization(void)
47 {
48 vec4 color = texture2DRect(ColorWeight, gl_FragCoord.st - viewport.xy + epsilon);
49 #if (EXPE_OUTPUT_DEPTH==1)
50 gl_FragDepth = texture2DRect(Depth, gl_FragCoord.st + epsilon).x;
51 #endif
52 if (color.w<0.001)
53 discard;
54 gl_FragColor = color/color.w;
55 gl_FragColor.a = 1.;
56 }
57
58 #else
59
60 uniform vec2 unproj;
61
62 uniform sampler2DRect ColorWeight;
63 uniform sampler2DRect NormalWeight;
64
65 #if ( (EXPE_DEPTH_INTERPOLATION==0) || (EXPE_OUTPUT_DEPTH==1))
66 uniform sampler2DRect Depth;
67 #endif
68
69 void Finalization(void)
70 {
71 vec4 color = texture2DRect(ColorWeight, gl_FragCoord.st - viewport.xy + epsilon);
72
73 if (color.w<0.001)
74 discard;
75
76
77 if(color.w>0.001)
78 color.xyz /= color.w;
79
80 vec3 viewVec = normalize(gl_TexCoord[0].xyz);
81 vec4 normaldepth = texture2DRect(NormalWeight, gl_FragCoord.st + epsilon);
82
83 normaldepth.xyz = normaldepth.xyz/normaldepth.w;
84
85 #if (EXPE_OUTPUT_DEPTH==1)
86 gl_FragDepth = texture2DRect(Depth, gl_FragCoord.st + epsilon).x;
87 #endif
88
89 #if EXPE_DEPTH_INTERPOLATION==2
90 float depth = -normaldepth.z;
91 #elif EXPE_DEPTH_INTERPOLATION==1
92 float depth = unproj.y/(2.0*normaldepth.z+unproj.x-1.0);
93 #else
94 float depth = texture2DRect(Depth, gl_FragCoord.st + epsilon).x;
95 depth = unproj.y/(2.0*depth+unproj.x-1.0);
96 #endif
97
98 vec3 normal = normaldepth.xyz;
99 #if EXPE_DEPTH_INTERPOLATION!=0
100 normal.z = sqrt(1. - dot(vec3(normal.xy,0),vec3(normal.xy,0)));
101 #endif
102 normal = normalize(normal);
103 vec3 eyePos = gl_TexCoord[0].xyz * depth;
104
105 gl_FragColor = meshlabLighting(color, eyePos, normal);
106 gl_FragColor.a = 1.0;
107 }
108
109 #endif
110
111
112