PageRenderTime 24ms CodeModel.GetById 17ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

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

https://bitbucket.org/lindenlab/viewer-beta/
Unknown | 66 lines | 52 code | 14 blank | 0 comment | 0 complexity | 18c2b4889cf53c450e050bd2b8a87f1f MD5 | raw file
 1/** 
 2 * @file lightFuncSpecularV.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
28float calcDirectionalLight(vec3 n, vec3 l)
29{
30	float a = max(dot(n,l),0.0);
31	return a;
32}
33
34float calcDirectionalSpecular(vec3 view, vec3 n, vec3 l)
35{
36	return pow(max(dot(reflect(view, n),l), 0.0),8.0);
37}
38
39float calcDirectionalLightSpecular(inout vec4 specular, vec3 view, vec3 n, vec3 l, vec3 lightCol, float da)
40{
41	
42	specular.rgb += calcDirectionalSpecular(view,n,l)*lightCol*da;
43	return max(dot(n,l),0.0);
44}
45
46vec3 calcPointLightSpecular(inout vec4 specular, vec3 view, vec3 v, vec3 n, vec3 l, float r, float pw, vec3 lightCol)
47{
48	//get light vector
49	vec3 lv = l-v;
50	
51	//get distance
52	float d = length(lv);
53	
54	//normalize light vector
55	lv *= 1.0/d;
56	
57	//distance attenuation
58	float da = clamp(1.0/(r * d), 0.0, 1.0);
59	
60	//angular attenuation
61	
62	da *= calcDirectionalLightSpecular(specular, view, n, lv, lightCol, da);
63	
64	return da*lightCol;	
65}
66