PageRenderTime 11ms CodeModel.GetById 7ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/app_settings/shaders/class2/effects/nightVisionF.glsl

https://bitbucket.org/lindenlab/viewer-beta/
text | 62 lines | 51 code | 11 blank | 0 comment | 0 complexity | 38d158967e100df3b793ff3ad42f2840 MD5 | raw file
 1/**
 2 * @file nightVisionF.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
28uniform sampler2DRect RenderTexture;
29uniform sampler2D NoiseTexture;
30uniform float brightMult;
31uniform float noiseStrength;
32
33float luminance(vec3 color)
34{
35	/// CALCULATING LUMINANCE (Using NTSC lum weights)
36	/// http://en.wikipedia.org/wiki/Luma_%28video%29
37	return dot(color, vec3(0.299, 0.587, 0.114));
38}
39
40void main(void) 
41{
42	/// Get scene color
43	vec3 color = vec3(texture2DRect(RenderTexture, gl_TexCoord[0].st));
44	
45	/// Extract luminance and scale up by night vision brightness
46	float lum = luminance(color) * brightMult;
47
48	/// Convert into night vision color space
49	/// Newer NVG colors (crisper and more saturated)
50	vec3 outColor = (lum * vec3(0.91, 1.21, 0.9)) + vec3(-0.07, 0.1, -0.12); 
51
52	/// Add noise
53	float noiseValue = texture2D(NoiseTexture, gl_TexCoord[1].st).r;
54	noiseValue = (noiseValue - 0.5) * noiseStrength;
55
56	/// Older NVG colors (more muted)
57	// vec3 outColor = (lum * vec3(0.82, 0.75, 0.83)) + vec3(0.05, 0.32, -0.11); 
58	
59	outColor += noiseValue;
60
61	gl_FragColor = vec4(outColor, 1.0);
62}