PageRenderTime 475ms CodeModel.GetById 208ms app.highlight 2ms RepoModel.GetById 130ms app.codeStats 60ms

/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl

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