cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / glslparsertest / glsl2 / xreal-lighting-db-omni.frag
blob34ac6c435e318bf465dbfde0f41a0c78bc839d36
1 // [config]
2 // expect_result: pass
3 // glsl_version: 1.10
4 //
5 // [end config]
7 /*
8 ===========================================================================
9 Copyright (C) 2006 Robert Beckebans <trebor_7@users.sourceforge.net>
11 This file is part of XreaL source code.
13 XreaL source code is free software; you can redistribute it
14 and/or modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the License,
16 or (at your option) any later version.
18 XreaL source code is distributed in the hope that it will be
19 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with XreaL source code; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
26 ===========================================================================
29 uniform sampler2D       u_DiffuseMap;
30 uniform sampler2D       u_BumpMap;
31 uniform sampler2D       u_AttenuationMapXY;
32 uniform sampler2D       u_AttenuationMapZ;
33 uniform vec3            u_LightOrigin;
34 uniform vec3            u_LightColor;
35 uniform float       u_LightScale;
37 varying vec3            var_Vertex;
38 varying vec2            var_TexDiffuse;
39 varying vec2            var_TexBump;
40 varying vec4            var_TexAtten;
41 varying mat3            var_OS2TSMatrix;
43 void    main()
44 {       
45         // compute light direction in tangent space
46         vec3 L = normalize(var_OS2TSMatrix * (u_LightOrigin - var_Vertex));
47         
48         // compute normal in tangent space from bumpmap
49         vec3 N = 2.0 * (texture2D(u_BumpMap, var_TexBump).xyz - 0.5);
50         N = normalize(N);
51         
52         // compute the diffuse term
53         vec4 diffuse = texture2D(u_DiffuseMap, var_TexDiffuse);
54         diffuse.rgb *= u_LightColor * clamp(dot(N, L), 0.0, 1.0);
55         
56         // compute attenuation
57 //      vec3 attenuationXY = texture2D(u_AttenuationMapXY, var_TexAtten.xy).rgb;
58         vec3 attenuationXY = texture2DProj(u_AttenuationMapXY, vec3(var_TexAtten.x, var_TexAtten.y, var_TexAtten.w)).rgb;
59         vec3 attenuationZ  = texture2D(u_AttenuationMapZ, vec2(var_TexAtten.z, 0)).rgb;
60                                         
61         // compute final color
62         vec4 color = diffuse;
63         color.rgb *= attenuationXY;
64         color.rgb *= attenuationZ;
65         color.rgb *= u_LightScale;
67         gl_FragColor = color;