PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl

https://bitbucket.org/lindenlab/viewer-beta/
Unknown | 59 lines | 46 code | 13 blank | 0 comment | 0 complexity | c65d51acf5b9beb0f310f298ab74d6a2 MD5 | raw file
 1/** 
 2 * @file lightFuncV.glsl
 3 *
 4 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
 5 * Second Life Viewer Source Code
 6 * Copyright (C) 2007, Linden Research, Inc.
 7 * 
 8 * This library is free software; you can redistribute it and/or
 9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation;
11 * version 2.1 of the License only.
12 * 
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * Lesser General Public License for more details.
17 * 
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 * 
22 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
23 * $/LicenseInfo$
24 */
25 
26
27
28
29float calcDirectionalLight(vec3 n, vec3 l)
30{
31	float a = max(dot(n,l),0.0);
32	return a;
33}
34
35
36float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_pointlight)
37{
38	//get light vector
39	vec3 lv = lp.xyz-v;
40	
41	//get distance
42	float d = length(lv);
43	
44	//normalize light vector
45	lv *= 1.0/d;
46	
47	//distance attenuation
48	float da = clamp(1.0/(la * d), 0.0, 1.0);
49	
50	// spotlight coefficient.
51	float spot = max(dot(-ln, lv), is_pointlight);
52	da *= spot*spot; // GL_SPOT_EXPONENT=2
53
54	//angular attenuation
55	da *= calcDirectionalLight(n, lv);
56
57	return da;	
58}
59