diff options
| author | Graham Linden <graham@lindenlab.com> | 2013-07-10 09:47:46 -0700 | 
|---|---|---|
| committer | Graham Linden <graham@lindenlab.com> | 2013-07-10 09:47:46 -0700 | 
| commit | 326e20b0e5cd8e30d4b52c662a29aa2fc816b40d (patch) | |
| tree | f9c766719839a8948ac4ff3463a420525169ee1b /indra/newview/app_settings/shaders/class1 | |
| parent | 167fc262734dfb72e33e57a0b309d0ce6a17ce47 (diff) | |
NORSPEC-291 WIP materials underwater w and wo alpha, water fog color broken, no refl, no water dis
Diffstat (limited to 'indra/newview/app_settings/shaders/class1')
3 files changed, 131 insertions, 18 deletions
| diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 027c6eeadb..393074344b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -51,7 +51,6 @@ vec3 linear_to_srgb(vec3 cl)  	return 1.055 * pow(cl, vec3(0.41666)) - 0.055;  } -  #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)  #ifdef DEFINE_GL_FRAGCOLOR @@ -136,6 +135,57 @@ uniform vec3 light_direction[8];  uniform vec3 light_attenuation[8];   uniform vec3 light_diffuse[8]; +#ifdef WATER_FOG +vec3 getPositionEye() +{ +	return vary_PositionEye; +} + +uniform vec4 waterPlane; +uniform vec4 waterFogColor; +uniform float waterFogDensity; +uniform float waterFogKS; + +vec4 applyWaterFogDeferred(vec4 color) +{ +	//normalize view vector +	vec3 view = normalize(getPositionEye()); +	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(getPositionEye() - 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); @@ -221,10 +271,6 @@ vec4 getPosition_d(vec2 pos_screen, float depth)  	return pos;  } -vec3 getPositionEye() -{ -	return vary_PositionEye; -}  vec3 getSunlitColor()  {  	return vary_SunlitColor; @@ -417,6 +463,21 @@ out vec4 frag_data[3];  #else  #define frag_data gl_FragData  #endif + +VARYING vec3 vary_position; + +#ifdef WATER_FOG +vec3 vary_PositionEye; +vec3 getPositionEye() +{ +	return vary_PositionEye; +} +void setPositionEye(vec3 e) +{ +	vary_PositionEye = e; +} +#endif +  #endif  uniform sampler2D diffuseMap; @@ -672,7 +733,6 @@ void main()  	//convert to linear space before adding local lights  	col = srgb_to_linear(col); -			  	vec3 npos = normalize(-pos.xyz);   #define LIGHT_LOOP(i) col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare); @@ -685,17 +745,19 @@ void main()  		LIGHT_LOOP(6)  		LIGHT_LOOP(7) +	glare = min(glare, 1.0); +	float al = max(diffcol.a,glare)*vertex_color.a; -	//convert to gamma space for display on screen -	col.rgb = linear_to_srgb(col.rgb); - +#ifdef WATER_FOG +	frag_color = applyWaterFogDeferred(vec4(col.rgb, al)); +#else  	frag_color.rgb = col.rgb; -	glare = min(glare, 1.0); -	frag_color.a = max(diffcol.a,glare)*vertex_color.a; +	frag_color.a   = al; +#endif  #else  	frag_data[0] = final_color;  	frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent.  	frag_data[2] = final_normal; // XY = Normal.  Z = Env. intensity. -#endif +#endif%  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index b25032866b..154db09583 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -43,10 +43,10 @@ uniform mat4 modelview_projection_matrix;  uniform mat4 modelview_matrix;  #endif -VARYING vec3 vary_position; -  #endif +VARYING vec3 vary_position; +  uniform mat4 texture_matrix0;  ATTRIBUTE vec3 position; @@ -84,15 +84,14 @@ void main()  	mat = modelview_matrix * mat;  	vec3 pos = (mat*vec4(position.xyz,1.0)).xyz; - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)  	vary_position = pos; -#endif +  	gl_Position = projection_matrix*vec4(pos,1.0);  #else  	//transform vertex +	vary_position = (modelview_projection_matrix * vec4(position.xyz, 1.0)).xyz;  	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);   #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index dc2519bd0a..1706d41da0 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -175,6 +175,53 @@ void setAtmosAttenuation(vec3 v)  	vary_AtmosAttenuation = v;  } + +#ifdef WATER_FOG +uniform vec4 waterPlane; +uniform vec4 waterFogColor; +uniform float waterFogDensity; +uniform float waterFogKS; + +vec4 applyWaterFogDeferred(vec4 color) +{ +	//normalize view vector +	vec3 view = normalize(getPositionEye()); +	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(getPositionEye() - 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; @@ -389,6 +436,12 @@ void main()  		{  			col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a);  			col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); + +			#ifdef WATER_FOG +				vec4 fogged = applyWaterFogDeferred(vec4(col, bloom)); +				col = fogged.rgb; +				bloom = fogged.a; +			#endif  		}  		col = srgb_to_linear(col); @@ -398,6 +451,5 @@ void main()  	}  	frag_color.rgb = col; -  	frag_color.a = bloom;  } | 
