Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/Tutorial/Media/DeferredShadingMedia/DeferredShading/post/glsl/Ambient_ps.glsl @ 44

Last change on this file since 44 was 44, checked in by bknecht, 17 years ago

merge from tutorial branche to trunk

  • Property svn:executable set to *
File size: 2.3 KB
Line 
1/******************************************************************************
2Copyright (c) W.J. van der Laan
3
4Permission is hereby granted, free of charge, to any person obtaining a copy of
5this software  and associated documentation files (the "Software"), to deal in
6the Software without restriction, including without limitation the rights to use,
7copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8Software, and to permit persons to whom the Software is furnished to do so, subject
9to the following conditions:
10
11The above copyright notice and this permission notice shall be included in all copies
12or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE
19SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20******************************************************************************/
21/** Deferred shading framework
22        // W.J. :wumpus: van der Laan 2005 //
23       
24        Post shader: Multipass, ambient (base) pass
25*/
26uniform sampler2D tex0;
27uniform sampler2D tex1;
28
29varying vec2 texCoord;
30varying vec3 projCoord;
31
32uniform mat4 proj;
33
34uniform vec3 ambientColor;
35
36void main()
37{
38        vec4 a0 = texture2D(tex0, texCoord); // Attribute 0: Diffuse color+shininess
39    vec4 a1 = texture2D(tex1, texCoord); // Attribute 1: Normal+depth
40   
41    // Clip fragment if depth is too far, so the skybox can be rendered on the background
42    if(a1.w==0.0)
43                discard;
44     
45    // Attributes
46    vec3 colour = a0.rgb;
47    float alpha = a0.a;         // Specularity
48    float distance = a1.w;  // Distance from viewer -- is zero if no lighting wanted
49   
50        // Calculate ambient colour of fragment
51    gl_FragColor = vec4( ambientColor*colour ,0);
52   
53    // Calculate depth of fragment; GL requires a 2.0* here as the range is [-1, 1]
54    // Also, see again how matrix is transposed ([3][2] instead of [2][3])
55    gl_FragDepth = projCoord.z*proj[2][2] + proj[3][2]/(2.0*distance);
56}
Note: See TracBrowser for help on using the repository browser.