root/OpenSceneGraph-Data/trunk/shaders/depthpeel_final.frag

Revision 7347 (checked in by robert, 1 year ago)

Added depth peeling shaders from Steffen Frey

Line 
1 /*
2   Steffen Frey
3   Fachpraktikum Graphik-Programmierung 2007
4   Institut fuer Visualisierung und Interaktive Systeme
5   Universitaet Stuttgart
6  */
7
8 //these are for debugging purposes only
9 uniform sampler2D normalDepthMap0;
10 uniform sampler2D normalDepthMap1;
11
12 uniform sampler2D edgeMap;
13 uniform sampler2D colorMap;
14 uniform sampler2D noiseMap;
15
16 uniform bool sketchy;
17 uniform bool colored;
18 uniform bool edgy;
19
20 uniform float sketchiness;
21
22 void main( void )
23 {
24   vec4 color;
25   vec4 edge;
26   //sketchy
27   if(sketchy)
28     {
29       vec2 off = vec2(texture2D(noiseMap, gl_TexCoord[1].st).x,
30                       texture2D(noiseMap, vec2(1. - gl_TexCoord[1].s, 1. - gl_TexCoord[1].t)).x);
31       off = 2. * off - 1.;
32       vec4 a = sketchiness * vec4(0.007, 0.005, 0.006, 0.004);
33       vec2 stEdge = gl_TexCoord[1].st + vec2(a[0]*off[0] + a[1]*off[1], a[2]*off[0] + a[3] * off[1]);
34      
35       vec4 b = sketchiness * vec4(0.014, 0.012, 0.016, 0.01);
36       vec2 stColor = gl_TexCoord[1].st + vec2(b[0]*off[0] + b[1]*off[1], b[2]*off[0] + b[3] * off[1]);
37  
38       float borderWidth = 0.005;
39      
40       color = texture2D(colorMap, vec2(clamp(stColor.s, borderWidth, 1.-borderWidth) ,
41                                        clamp(stColor.t, borderWidth, 1.-borderWidth)));
42       edge = texture2D(edgeMap, vec2(clamp(stEdge.s, borderWidth, 1.-borderWidth) ,
43                                       clamp(stEdge.t, borderWidth, 1.-borderWidth)));
44      
45     }
46   else
47   {
48       color = texture2D(colorMap, gl_TexCoord[1].st);
49       edge = texture2D(edgeMap, gl_TexCoord[1].st);
50     }
51  
52   vec4 composed = vec4(max(color.x - (1.0 - edge.x), 0.0),
53                        max(color.y - (1.0 - edge.y), 0.0),
54                        max(color.z - (1.0 - edge.z), 0.0),
55                        1.0);
56  
57  
58   if(colored && edgy)
59   {
60       gl_FragColor = composed;
61   }
62   else if(edgy)
63   {
64       gl_FragColor = vec4(edge.xyz, 1.0);
65   }
66   else if(colored)
67   {
68       gl_FragColor = vec4(color.xyz, 1.0);
69   }
70   else
71   {
72       gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
73   }
74  
75 }
Note: See TracBrowser for help on using the browser.