diff options
| author | Graham Linden graham@lindenlab.com <Graham Linden graham@lindenlab.com> | 2018-03-09 21:40:46 +0000 | 
|---|---|---|
| committer | Graham Linden graham@lindenlab.com <Graham Linden graham@lindenlab.com> | 2018-03-09 21:40:46 +0000 | 
| commit | b6b23926340d8a2ac142b02923f04624b7c6b08e (patch) | |
| tree | 211401687ba748beb05ed7323b41e47e80287549 /indra/newview/app_settings/shaders/class1/deferred | |
| parent | b2d8d63890e3ba0a5fe303f8e2de7358e4f9fc23 (diff) | |
De-duplicate water fog code and modify programs to include the shared object as necessary.
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred')
4 files changed, 19 insertions, 190 deletions
| diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index b9c8f34cb0..b36016529c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -98,6 +98,10 @@ uniform vec3 light_direction[8];  uniform vec3 light_attenuation[8];   uniform vec3 light_diffuse[8]; +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color); +#endif +  vec3 srgb_to_linear(vec3 cs)  {  	vec3 low_range = cs / vec3(12.92); @@ -219,52 +223,6 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc)  }  #endif -#ifdef WATER_FOG -uniform vec4 waterPlane; -uniform vec4 waterFogColor; -uniform float waterFogDensity; -uniform float waterFogKS; - -vec4 applyWaterFogDeferred(vec3 pos, vec4 color) -{ -	//normalize view vector -	vec3 view = normalize(pos); -	float es = -(dot(view, waterPlane.xyz)); - -	//find intersection point with water plane and eye vector -	 -	//get eye depth -	float e0 = max(-waterPlane.w, 0.0); -	 -	vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); -	 -	//get object depth -	float depth = length(pos - int_v); -		 -	//get "thickness" of water -	float l = max(depth, 0.1); - -	float kd = waterFogDensity; -	float ks = waterFogKS; -	vec4 kc = waterFogColor; -	 -	float F = 0.98; -	 -	float t1 = -kd * pow(F, ks * e0); -	float t2 = kd + ks * es; -	float t3 = pow(F, t2*l) - 1.0; -	 -	float L = min(t1/t2*t3, 1.0); -	 -	float D = pow(0.98, l*kd); -	 -	color.rgb = color.rgb * D + kc.rgb * L; -	color.a = kc.a + color.a; -	 -	return color; -} -#endif -  vec3 getSunlitColor()  {  	return vary_SunlitColor; @@ -621,9 +579,8 @@ void main()  	color.rgb = linear_to_srgb(color.rgb);  #ifdef WATER_FOG -	color = applyWaterFogDeferred(pos.xyz, color); +	color = applyWaterFogView(pos.xyz, color);  #endif -  #endif  	frag_color = color; diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 756e625d07..d554377220 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -41,6 +41,9 @@ VARYING vec3 vary_position;  VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0; +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color); +#endif  vec3 srgb_to_linear(vec3 cs)  { @@ -94,52 +97,6 @@ vec3 fullbrightScaleSoftClipDeferred(vec3 light)  uniform float minimum_alpha;  #endif -#ifdef WATER_FOG -uniform vec4 waterPlane; -uniform vec4 waterFogColor; -uniform float waterFogDensity; -uniform float waterFogKS; - -vec4 applyWaterFogDeferred(vec3 pos, vec4 color) -{ -	//normalize view vector -	vec3 view = normalize(pos); -	float es = -(dot(view, waterPlane.xyz)); - -	//find intersection point with water plane and eye vector -	 -	//get eye depth -	float e0 = max(-waterPlane.w, 0.0); -	 -	vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); -	 -	//get object depth -	float depth = length(pos - int_v); -		 -	//get "thickness" of water -	float l = max(depth, 0.1); - -	float kd = waterFogDensity; -	float ks = waterFogKS; -	vec4 kc = waterFogColor; -	 -	float F = 0.98; -	 -	float t1 = -kd * pow(F, ks * e0); -	float t2 = kd + ks * es; -	float t3 = pow(F, t2*l) - 1.0; -	 -	float L = min(t1/t2*t3, 1.0); -	 -	float D = pow(0.98, l*kd); -	 -	color.rgb = color.rgb * D + kc.rgb * L; -	color.a = kc.a + color.a; -	 -	return color; -} -#endif -  void main()   {  #if HAS_DIFFUSE_LOOKUP @@ -166,7 +123,7 @@ void main()  #ifdef WATER_FOG  	vec3 pos = vary_position; -	vec4 fogged = applyWaterFogDeferred(pos, vec4(color.rgb, final_alpha)); +	vec4 fogged = applyWaterFogView(pos, vec4(color.rgb, final_alpha));  	color.rgb = fogged.rgb;  	color.a   = fogged.a;  #else diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 76750c400a..6fa625765a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -33,6 +33,10 @@  uniform float emissive_brightness;  uniform float display_gamma; +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color); +#endif +  vec3 srgb_to_linear(vec3 cs)  {  	vec3 low_range = cs / vec3(12.92); @@ -154,52 +158,6 @@ uniform vec3 light_direction[8];  uniform vec3 light_attenuation[8];   uniform vec3 light_diffuse[8]; -#ifdef WATER_FOG -uniform vec4 waterPlane; -uniform vec4 waterFogColor; -uniform float waterFogDensity; -uniform float waterFogKS; - -vec4 applyWaterFogDeferred(vec3 pos, vec4 color) -{ -	//normalize view vector -	vec3 view = normalize(pos); -	float es = -(dot(view, waterPlane.xyz)); - -	//find intersection point with water plane and eye vector -	 -	//get eye depth -	float e0 = max(-waterPlane.w, 0.0); -	 -	vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); -	 -	//get object depth -	float depth = length(pos - int_v); -		 -	//get "thickness" of water -	float l = max(depth, 0.1); - -	float kd = waterFogDensity; -	float ks = waterFogKS; -	vec4 kc = waterFogColor; -	 -	float F = 0.98; -	 -	float t1 = -kd * pow(F, ks * e0); -	float t2 = kd + ks * es; -	float t3 = pow(F, t2*l) - 1.0; -	 -	float L = min(t1/t2*t3, 1.0); -	 -	float D = pow(0.98, l*kd); -	 -	color.rgb = color.rgb * D + kc.rgb * L; -	color.a = kc.a + color.a; -	 -	return color; -} -#endif -  vec3 calcDirectionalLight(vec3 n, vec3 l)  {  	float a = max(dot(n,l),0.0); @@ -773,7 +731,7 @@ void main()  	col.rgb = linear_to_srgb(col.rgb);  #ifdef WATER_FOG -	vec4 temp = applyWaterFogDeferred(pos, vec4(col.rgb, al)); +	vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al));  	col.rgb = temp.rgb;  	al = temp.a;  #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 7f1a8cce0d..b294dba167 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -81,6 +81,10 @@ vec3 vary_AtmosAttenuation;  uniform mat4 inv_proj;  uniform vec2 screen_res; +#ifdef WATER_FOG +vec4 applyWaterFogView(vec3 pos, vec4 color); +#endif +  vec3 srgb_to_linear(vec3 cs)  {  	vec3 low_range = cs / vec3(12.92); @@ -193,53 +197,6 @@ void setAtmosAttenuation(vec3 v)  	vary_AtmosAttenuation = v;  } - -#ifdef WATER_FOG -uniform vec4 waterPlane; -uniform vec4 waterFogColor; -uniform float waterFogDensity; -uniform float waterFogKS; - -vec4 applyWaterFogDeferred(vec3 pos, vec4 color) -{ -	//normalize view vector -	vec3 view = normalize(pos); -	float es = -(dot(view, waterPlane.xyz)); - -	//find intersection point with water plane and eye vector -	 -	//get eye depth -	float e0 = max(-waterPlane.w, 0.0); -	 -	vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); -	 -	//get object depth -	float depth = length(pos - int_v); -		 -	//get "thickness" of water -	float l = max(depth, 0.1); - -	float kd = waterFogDensity; -	float ks = waterFogKS; -	vec4 kc = waterFogColor; -	 -	float F = 0.98; -	 -	float t1 = -kd * pow(F, ks * e0); -	float t2 = kd + ks * es; -	float t3 = pow(F, t2*l) - 1.0; -	 -	float L = min(t1/t2*t3, 1.0); -	 -	float D = pow(0.98, l*kd); -	 -	color.rgb = color.rgb * D + kc.rgb * L; -	color.a = kc.a + color.a; -	 -	return color; -} -#endif -  void calcAtmospherics(vec3 inPositionEye, float ambFactor) {  	vec3 P = inPositionEye; @@ -462,7 +419,7 @@ void main()  		}  		#ifdef WATER_FOG -			vec4 fogged = applyWaterFogDeferred(pos,vec4(col, bloom)); +			vec4 fogged = applyWaterFogView(pos,vec4(col, bloom));  			col = fogged.rgb;  			bloom = fogged.a;  		#endif | 
