PageRenderTime 323ms CodeModel.GetById 161ms app.highlight 1ms RepoModel.GetById 160ms app.codeStats 0ms

/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl

https://bitbucket.org/lindenlab/viewer-beta/
Unknown | 105 lines | 85 code | 20 blank | 0 comment | 0 complexity | 8862ad3fc33eeb274b847e38e480bc03 MD5 | raw file
  1/** 
  2 * @file WLCloudsF.glsl
  3 *
  4 * $LicenseInfo:firstyear=2005&license=viewerlgpl$
  5 * Second Life Viewer Source Code
  6 * Copyright (C) 2005, 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#ifdef DEFINE_GL_FRAGCOLOR
 28out vec4 gl_FragData[3];
 29#endif
 30
 31/////////////////////////////////////////////////////////////////////////
 32// The fragment shader for the sky
 33/////////////////////////////////////////////////////////////////////////
 34
 35VARYING vec4 vary_CloudColorSun;
 36VARYING vec4 vary_CloudColorAmbient;
 37VARYING float vary_CloudDensity;
 38
 39uniform sampler2D cloud_noise_texture;
 40uniform vec4 cloud_pos_density1;
 41uniform vec4 cloud_pos_density2;
 42uniform vec4 gamma;
 43
 44VARYING vec2 vary_texcoord0;
 45VARYING vec2 vary_texcoord1;
 46VARYING vec2 vary_texcoord2;
 47VARYING vec2 vary_texcoord3;
 48
 49/// Soft clips the light with a gamma correction
 50vec3 scaleSoftClip(vec3 light) {
 51	//soft clip effect:
 52	light = 1. - clamp(light, vec3(0.), vec3(1.));
 53	light = 1. - pow(light, gamma.xxx);
 54
 55	return light;
 56}
 57
 58void main()
 59{
 60	// Set variables
 61	vec2 uv1 = vary_texcoord0.xy;
 62	vec2 uv2 = vary_texcoord1.xy;
 63
 64	vec4 cloudColorSun = vary_CloudColorSun;
 65	vec4 cloudColorAmbient = vary_CloudColorAmbient;
 66	float cloudDensity = vary_CloudDensity;
 67	vec2 uv3 = vary_texcoord2.xy;
 68	vec2 uv4 = vary_texcoord3.xy;
 69
 70	// Offset texture coords
 71	uv1 += cloud_pos_density1.xy;	//large texture, visible density
 72	uv2 += cloud_pos_density1.xy;	//large texture, self shadow
 73	uv3 += cloud_pos_density2.xy;	//small texture, visible density
 74	uv4 += cloud_pos_density2.xy;	//small texture, self shadow
 75
 76
 77	// Compute alpha1, the main cloud opacity
 78	float alpha1 = (texture2D(cloud_noise_texture, uv1).x - 0.5) + (texture2D(cloud_noise_texture, uv3).x - 0.5) * cloud_pos_density2.z;
 79	alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10. * cloud_pos_density1.z, 1.);
 80
 81	// And smooth
 82	alpha1 = 1. - alpha1 * alpha1;
 83	alpha1 = 1. - alpha1 * alpha1;	
 84
 85
 86	// Compute alpha2, for self shadowing effect
 87	// (1 - alpha2) will later be used as percentage of incoming sunlight
 88	float alpha2 = (texture2D(cloud_noise_texture, uv2).x - 0.5);
 89	alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.);
 90
 91	// And smooth
 92	alpha2 = 1. - alpha2;
 93	alpha2 = 1. - alpha2 * alpha2;	
 94
 95	// Combine
 96	vec4 color;
 97	color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient);
 98	color *= 2.;
 99
100	/// Gamma correct for WL (soft clip effect).
101	gl_FragData[0] = vec4(scaleSoftClip(color.rgb), alpha1);
102	gl_FragData[1] = vec4(0.0,0.0,0.0,0.0);
103	gl_FragData[2] = vec4(0,0,1,0);
104}
105