diff options
| author | Dave Parks <davep@lindenlab.com> | 2022-10-04 12:20:19 -0500 | 
|---|---|---|
| committer | Dave Parks <davep@lindenlab.com> | 2022-10-04 12:20:19 -0500 | 
| commit | 1900df361558313f10e8b27ada03bcefd41241d9 (patch) | |
| tree | 0ec5b6a71723f5f2dd8244ca9a4a74408e2e5b0c /indra/newview/app_settings/shaders | |
| parent | 7d426815019ac5394e5821f1c6ba374e12606aaa (diff) | |
SL-18293, SL-18190 -- Fix for debug displays not showing up (wireframe still busted).  WIP on reflection probe/PBR driven water shader.
Diffstat (limited to 'indra/newview/app_settings/shaders')
5 files changed, 452 insertions, 304 deletions
| diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index 58a444a763..876422f86b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -22,170 +22,15 @@   * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA   * $/LicenseInfo$   */ -  -#extension GL_ARB_texture_rectangle : enable -/*[EXTRA_CODE_HERE]*/ - -#ifdef DEFINE_GL_FRAGCOLOR +// debug stub  out vec4 frag_data[4]; -#else -#define frag_data gl_FragData -#endif - -vec3 scaleSoftClip(vec3 inColor); -vec3 atmosTransport(vec3 inColor); - -uniform sampler2D bumpMap;    -uniform sampler2D bumpMap2; -uniform float blend_factor; -uniform sampler2D screenTex; -uniform sampler2D refTex; -uniform float sunAngle; -uniform float sunAngle2; -uniform vec3 lightDir; -uniform vec3 specular; -uniform float lightExp; -uniform float refScale; -uniform float kd; -uniform vec2 screenRes; -uniform vec3 normScale; -uniform float fresnelScale; -uniform float fresnelOffset; -uniform float blurMultiplier; -uniform vec2 screen_res; -uniform mat4 norm_mat; //region space to screen space -uniform int water_edge; - -//bigWave is (refCoord.w, view.w); -VARYING vec4 refCoord; -VARYING vec4 littleWave; -VARYING vec4 view; -VARYING vec4 vary_position; - -vec2 encode_normal(vec3 n); -vec3 scaleSoftClip(vec3 l); -vec3 srgb_to_linear(vec3 c); -vec3 linear_to_srgb(vec3 c); -vec3 BlendNormal(vec3 bump1, vec3 bump2) +void main()  { -    vec3 n = mix(bump1, bump2, blend_factor); -    return n; -} - -void main()  -{ -    vec4 color; -    float dist = length(view.xyz); -     -    //normalize view vector -    vec3 viewVec = normalize(view.xyz); -     -    //get wave normals -    vec3 wave1_a = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; -    vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; -    vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; - - -    vec3 wave1_b = texture2D(bumpMap2, vec2(refCoord.w, view.w)).xyz*2.0-1.0; -    vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; -    vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; - -    vec3 wave1 = BlendNormal(wave1_a, wave1_b); -    vec3 wave2 = BlendNormal(wave2_a, wave2_b); -    vec3 wave3 = BlendNormal(wave3_a, wave3_b); - -    //get base fresnel components    -     -    vec3 df = vec3( -                    dot(viewVec, wave1), -                    dot(viewVec, (wave2 + wave3) * 0.5), -                    dot(viewVec, wave3) -                 ) * fresnelScale + fresnelOffset; -    df *= df; -             -    vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; -     -    float dist2 = dist; -    dist = max(dist, 5.0); -     -    float dmod = sqrt(dist); -     -    vec2 dmod_scale = vec2(dmod*dmod, dmod); -     -    //get reflected color -    vec2 refdistort1 = wave1.xy*normScale.x; -    vec2 refvec1 = distort+refdistort1/dmod_scale; -    vec4 refcol1 = texture2D(refTex, refvec1); -     -    vec2 refdistort2 = wave2.xy*normScale.y; -    vec2 refvec2 = distort+refdistort2/dmod_scale; -    vec4 refcol2 = texture2D(refTex, refvec2); -     -    vec2 refdistort3 = wave3.xy*normScale.z; -    vec2 refvec3 = distort+refdistort3/dmod_scale; -    vec4 refcol3 = texture2D(refTex, refvec3); - -    vec4 refcol = refcol1 + refcol2 + refcol3; -    float df1 = df.x + df.y + df.z; -	refcol *= df1 * 0.333; -     -    vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; -    wavef.z *= max(-viewVec.z, 0.1); -    wavef = normalize(wavef); -     -    float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; -     -    vec2 refdistort4 = wavef.xy*0.125; -    refdistort4.y -= abs(refdistort4.y); -    vec2 refvec4 = distort+refdistort4/dmod; -    float dweight = min(dist2*blurMultiplier, 1.0); -    vec4 baseCol = texture2D(refTex, refvec4); - -    refcol = mix(baseCol*df2, refcol, dweight); - -    //get specular component -	float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); -		 -	//harden specular -	spec = pow(spec, 128.0); - -	//figure out distortion vector (ripply)    -	vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); -		 -	vec4 fb = texture2D(screenTex, distort2); -	 -	//mix with reflection -	// Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug -	color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999f); -	 -	vec4 pos = vary_position; -	 -	//color.rgb += spec * specular; - -	//color.rgb = atmosTransport(color.rgb); -	//color.rgb = scaleSoftClip(color.rgb); -     -    //color.rgb = refcol.rgb; -    color.rgb = vec3(0.0); -	color.a   = spec * sunAngle2; -     -	vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); - -	//frag_data[0] = color; - -    // TODO: The non-obvious assignment below is copied from the pre-EEP WL shader code -    //       Unfortunately, fixing it causes a mismatch for EEP, and so it remains...  for now -    //       SL-12975 (unfix pre-EEP broken alpha) -    frag_data[0] = vec4(srgb_to_linear(color.rgb), 0.0); -     -    frag_data[1] = vec4(1.0, 0.1, 0.0, 0.0);		// occlusion, roughness, metalness -	frag_data[2] = vec4(encode_normal(screenspacewavef.xyz), 0.0, GBUFFER_FLAG_HAS_PBR);// normalxy, env intens, flags (atmo kill) -    frag_data[3] = vec4(srgb_to_linear(refcol.rgb),0); - -     -    //frag_data[0] = vec4(0.0,0,0,0); -    //frag_data[1] = vec4(0, 1.0, 0.0, 0.0); -    //frag_data[3] = vec4(0); +    // emissive blue PBR material +    frag_data[0] = vec4(0, 0, 0, 0); +    frag_data[1] = vec4(0, 0, 0, 0); +    frag_data[2] = vec4(1, 0, 0, GBUFFER_FLAG_HAS_PBR); +    frag_data[3] = vec4(0, 0, 1, 0);  } diff --git a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl index d370997123..46a6c2021d 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterF.glsl @@ -23,146 +23,9 @@   * $/LicenseInfo$   */ -#ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif -vec3 scaleSoftClip(vec3 inColor); -vec3 atmosTransport(vec3 inColor); - -uniform sampler2D bumpMap; -uniform sampler2D bumpMap2; -uniform float     blend_factor; -uniform sampler2D screenTex; -uniform sampler2D refTex; - -uniform float sunAngle; -uniform float sunAngle2; -uniform vec3 lightDir; -uniform vec3 specular; -uniform float lightExp; -uniform float refScale; -uniform float kd; -uniform vec2 screenRes; -uniform vec3 normScale; -uniform float fresnelScale; -uniform float fresnelOffset; -uniform float blurMultiplier; - - -//bigWave is (refCoord.w, view.w); -VARYING vec4 refCoord; -VARYING vec4 littleWave; -VARYING vec4 view; - -vec3 BlendNormal(vec3 bump1, vec3 bump2) +void main()  { -    vec3 n = mix(bump1, bump2, blend_factor); -    return n; +    frag_color = vec4(0, 0, 1, 0);  } - - -void main()  -{ -	vec4 color; -	 -	float dist = length(view.xy); -	 -	//normalize view vector -	vec3 viewVec = normalize(view.xyz); -	 -	//get wave normals -    vec2 bigwave = vec2(refCoord.w, view.w); -    vec3 wave1_a = texture2D(bumpMap, bigwave      ).xyz*2.0-1.0; -    vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; -    vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; - - -    vec3 wave1_b = texture2D(bumpMap2, bigwave      ).xyz*2.0-1.0; -    vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; -    vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; - -    vec3 wave1 = BlendNormal(wave1_a, wave1_b); -    vec3 wave2 = BlendNormal(wave2_a, wave2_b); -    vec3 wave3 = BlendNormal(wave3_a, wave3_b); - - -	//get base fresnel components	 -	 -	vec3 df = vec3( -					dot(viewVec, wave1), -					dot(viewVec, (wave2 + wave3) * 0.5), -					dot(viewVec, wave3) -				 ) * fresnelScale + fresnelOffset; -	df *= df; -		     -	vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; -	 -	float dist2 = dist; -	dist = max(dist, 5.0); -	 -	float dmod = sqrt(dist); -	 -	vec2 dmod_scale = vec2(dmod*dmod, dmod); -	 -	//get reflected color -	vec2 refdistort1 = wave1.xy*normScale.x; -	vec2 refvec1 = distort+refdistort1/dmod_scale; -	vec4 refcol1 = texture2D(refTex, refvec1); -	 -	vec2 refdistort2 = wave2.xy*normScale.y; -	vec2 refvec2 = distort+refdistort2/dmod_scale; -	vec4 refcol2 = texture2D(refTex, refvec2); -	 -	vec2 refdistort3 = wave3.xy*normScale.z; -	vec2 refvec3 = distort+refdistort3/dmod_scale; -	vec4 refcol3 = texture2D(refTex, refvec3); - -	vec4 refcol = refcol1 + refcol2 + refcol3; -	float df1 = df.x + df.y + df.z; -	refcol *= df1 * 0.333; -	 -	vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; -	 -	wavef.z *= max(-viewVec.z, 0.1); -	wavef = normalize(wavef); -	 -	float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; -	 -	vec2 refdistort4 = wavef.xy*0.125; -	refdistort4.y -= abs(refdistort4.y); -	vec2 refvec4 = distort+refdistort4/dmod; -	float dweight = min(dist2*blurMultiplier, 1.0); -	vec4 baseCol = texture2D(refTex, refvec4); -	refcol = mix(baseCol*df2, refcol, dweight); - -	//get specular component -	float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); -		 -	//harden specular -	spec = pow(spec, 128.0); - -	//figure out distortion vector (ripply)    -	vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); -		 -	vec4 fb = texture2D(screenTex, distort2); -	 -	//mix with reflection -	// Note we actually want to use just df1, but multiplying by 0.999999 gets around and nvidia compiler bug -	color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999); -	color.rgb += spec * specular; -	 -	color.rgb = atmosTransport(color.rgb); -	color.rgb = scaleSoftClip(color.rgb); -	color.a = spec * sunAngle2; -	 -	frag_color = color; - -#if defined(WATER_EDGE) -    gl_FragDepth = 0.9999847f; -#endif -	 -} - diff --git a/indra/newview/app_settings/shaders/class1/environment/waterV.glsl b/indra/newview/app_settings/shaders/class1/environment/waterV.glsl index cc41e3f740..e95f268681 100644 --- a/indra/newview/app_settings/shaders/class1/environment/waterV.glsl +++ b/indra/newview/app_settings/shaders/class1/environment/waterV.glsl @@ -24,6 +24,7 @@   */  uniform mat4 modelview_matrix; +uniform mat3 normal_matrix;  uniform mat4 modelview_projection_matrix;  ATTRIBUTE vec3 position; @@ -36,10 +37,15 @@ uniform vec2 waveDir2;  uniform float time;  uniform vec3 eyeVec;  uniform float waterHeight; +uniform vec3 lightDir;  VARYING vec4 refCoord;  VARYING vec4 littleWave;  VARYING vec4 view; +out vec3 vary_position; +out vec3 vary_light_dir; +out vec3 vary_tangent; +out vec3 vary_normal;  float wave(vec2 v, float t, float f, vec2 d, float s)   { @@ -52,6 +58,11 @@ void main()  	vec4 pos = vec4(position.xyz, 1.0);  	mat4 modelViewProj = modelview_projection_matrix; +    vary_position = (modelview_matrix * pos).xyz; +    vary_light_dir = normal_matrix * lightDir; +    vary_normal = normal_matrix * vec3(0, 0, 1); +    vary_tangent = normal_matrix * vec3(1, 0, 0); +  	vec4 oPosition;  	//get view vector @@ -63,12 +74,13 @@ void main()  	pos.xy = eyeVec.xy + oEyeVec.xy/d*ld;  	view.xyz = oEyeVec; -		 +  	d = clamp(ld/1536.0-0.5, 0.0, 1.0);	  	d *= d;  	oPosition = vec4(position, 1.0);  	oPosition.z = mix(oPosition.z, max(eyeVec.z*0.75, 0.0), d); +  	oPosition = modelViewProj * oPosition;  	refCoord.xyz = oPosition.xyz + vec3(0,0,0.2); @@ -83,8 +95,7 @@ void main()  	pos = modelview_matrix*pos;  	calcAtmospherics(pos.xyz); -	 -	 +		  	//pass wave parameters to pixel shader  	vec2 bigWave =  (v.xy) * vec2(0.04,0.04)  + waveDir1 * time * 0.055;  	//get two normal map (detail map) texture coordinates diff --git a/indra/newview/app_settings/shaders/class2/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class2/deferred/waterF.glsl new file mode 100644 index 0000000000..96739d91d7 --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/deferred/waterF.glsl @@ -0,0 +1,192 @@ +/**  + * @file class1/deferred/waterF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + *  + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + *  + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * Lesser General Public License for more details. + *  + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA + *  + * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA + * $/LicenseInfo$ + */ +  +#extension GL_ARB_texture_rectangle : enable + +/*[EXTRA_CODE_HERE]*/ + +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_data[4]; +#else +#define frag_data gl_FragData +#endif + +vec3 scaleSoftClip(vec3 inColor); +vec3 atmosTransport(vec3 inColor); + +uniform sampler2D bumpMap;    +uniform sampler2D bumpMap2; +uniform float blend_factor; +uniform sampler2D screenTex; +uniform sampler2D refTex; +uniform float sunAngle; +uniform float sunAngle2; +uniform vec3 lightDir; +uniform vec3 specular; +uniform float lightExp; +uniform float refScale; +uniform float kd; +uniform vec2 screenRes; +uniform vec3 normScale; +uniform float fresnelScale; +uniform float fresnelOffset; +uniform float blurMultiplier; +uniform vec2 screen_res; +uniform mat4 norm_mat; //region space to screen space +uniform int water_edge; + +//bigWave is (refCoord.w, view.w); +VARYING vec4 refCoord; +VARYING vec4 littleWave; +VARYING vec4 view; +VARYING vec4 vary_position; + +vec2 encode_normal(vec3 n); +vec3 scaleSoftClip(vec3 l); +vec3 srgb_to_linear(vec3 c); +vec3 linear_to_srgb(vec3 c); + +vec3 BlendNormal(vec3 bump1, vec3 bump2) +{ +    vec3 n = mix(bump1, bump2, blend_factor); +    return n; +} + +void main()  +{ +    vec4 color; +    float dist = length(view.xyz); +     +    //normalize view vector +    vec3 viewVec = normalize(view.xyz); +     +    //get wave normals +    vec3 wave1_a = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0; +    vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; +    vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; + + +    vec3 wave1_b = texture2D(bumpMap2, vec2(refCoord.w, view.w)).xyz*2.0-1.0; +    vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; +    vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; + +    vec3 wave1 = BlendNormal(wave1_a, wave1_b); +    vec3 wave2 = BlendNormal(wave2_a, wave2_b); +    vec3 wave3 = BlendNormal(wave3_a, wave3_b); + +    //get base fresnel components    +     +    vec3 df = vec3( +                    dot(viewVec, wave1), +                    dot(viewVec, (wave2 + wave3) * 0.5), +                    dot(viewVec, wave3) +                 ) * fresnelScale + fresnelOffset; +    df *= df; +             +    vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; +     +    float dist2 = dist; +    dist = max(dist, 5.0); +     +    float dmod = sqrt(dist); +     +    vec2 dmod_scale = vec2(dmod*dmod, dmod); +     +    //get reflected color +    vec2 refdistort1 = wave1.xy*normScale.x; +    vec2 refvec1 = distort+refdistort1/dmod_scale; +    vec4 refcol1 = texture2D(refTex, refvec1); +     +    vec2 refdistort2 = wave2.xy*normScale.y; +    vec2 refvec2 = distort+refdistort2/dmod_scale; +    vec4 refcol2 = texture2D(refTex, refvec2); +     +    vec2 refdistort3 = wave3.xy*normScale.z; +    vec2 refvec3 = distort+refdistort3/dmod_scale; +    vec4 refcol3 = texture2D(refTex, refvec3); + +    vec4 refcol = refcol1 + refcol2 + refcol3; +    float df1 = df.x + df.y + df.z; +	refcol *= df1 * 0.333; +     +    vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; +    wavef.z *= max(-viewVec.z, 0.1); +    wavef = normalize(wavef); +     +    float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset; +     +    vec2 refdistort4 = wavef.xy*0.125; +    refdistort4.y -= abs(refdistort4.y); +    vec2 refvec4 = distort+refdistort4/dmod; +    float dweight = min(dist2*blurMultiplier, 1.0); +    vec4 baseCol = texture2D(refTex, refvec4); + +    refcol = mix(baseCol*df2, refcol, dweight); + +    //get specular component +	float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0); +		 +	//harden specular +	spec = pow(spec, 128.0); + +	//figure out distortion vector (ripply)    +	vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); +		 +	vec4 fb = texture2D(screenTex, distort2); +	 +	//mix with reflection +	// Note we actually want to use just df1, but multiplying by 0.999999 gets around an nvidia compiler bug +	color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999f); +	 +	vec4 pos = vary_position; +	 +	//color.rgb += spec * specular; + +	//color.rgb = atmosTransport(color.rgb); +	//color.rgb = scaleSoftClip(color.rgb); +     +    //color.rgb = refcol.rgb; +    color.rgb = vec3(0.0); +	color.a   = spec * sunAngle2; +     +	vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); + +	//frag_data[0] = color; + +    // TODO: The non-obvious assignment below is copied from the pre-EEP WL shader code +    //       Unfortunately, fixing it causes a mismatch for EEP, and so it remains...  for now +    //       SL-12975 (unfix pre-EEP broken alpha) +    frag_data[0] = vec4(srgb_to_linear(color.rgb), 0.0); +     +    frag_data[1] = vec4(1.0, 0.1, 0.0, 0.0);		// occlusion, roughness, metalness +	frag_data[2] = vec4(encode_normal(screenspacewavef.xyz), 0.0, GBUFFER_FLAG_HAS_PBR);// normalxy, env intens, flags (atmo kill) +    //frag_data[3] = vec4(srgb_to_linear(refcol.rgb),0); +    frag_data[3] = vec4(0, 0, 0, 0); + +     +    //frag_data[0] = vec4(0.0,0,0,0); +    //frag_data[1] = vec4(0, 1.0, 0.0, 0.0); +    //frag_data[3] = vec4(0); +} diff --git a/indra/newview/app_settings/shaders/class2/environment/waterF.glsl b/indra/newview/app_settings/shaders/class2/environment/waterF.glsl new file mode 100644 index 0000000000..2e7efa9b2a --- /dev/null +++ b/indra/newview/app_settings/shaders/class2/environment/waterF.glsl @@ -0,0 +1,237 @@ +/**  + * @file waterF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2007, Linden Research, Inc. + *  + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + *  + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * Lesser General Public License for more details. + *  + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA + *  + * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA + * $/LicenseInfo$ + */ +  +#ifdef DEFINE_GL_FRAGCOLOR +out vec4 frag_color; +#else +#define frag_color gl_FragColor +#endif + +vec3 scaleSoftClipFragLinear(vec3 l); +vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten); +void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); + +// PBR interface +vec3 pbrIbl(vec3 diffuseColor, +    vec3 specularColor, +    vec3 radiance, // radiance map sample +    vec3 irradiance, // irradiance map sample +    float ao,       // ambient occlusion factor +    float nv,       // normal dot view vector +    float perceptualRoughness); + +vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, +    float perceptualRoughness, +    float metallic, +    vec3 n, // normal +    vec3 v, // surface point to camera +    vec3 l); //surface point to light + +uniform sampler2D bumpMap; +uniform sampler2D bumpMap2; +uniform float     blend_factor; +uniform sampler2D screenTex; +uniform sampler2D refTex; + +uniform float sunAngle; +uniform float sunAngle2; +uniform vec3 lightDir; +uniform vec3 specular; +uniform float lightExp; +uniform float refScale; +uniform float kd; +uniform vec2 screenRes; +uniform vec3 normScale; +uniform float fresnelScale; +uniform float fresnelOffset; +uniform float blurMultiplier; +uniform vec4 waterFogColor; + + +//bigWave is (refCoord.w, view.w); +VARYING vec4 refCoord; +VARYING vec4 littleWave; +VARYING vec4 view; +in vec3 vary_position; +in vec3 vary_normal; +in vec3 vary_tangent; +in vec3 vary_light_dir; + +vec3 BlendNormal(vec3 bump1, vec3 bump2) +{ +    vec3 n = mix(bump1, bump2, blend_factor); +    return n; +} + +vec3 srgb_to_linear(vec3 col); + +void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv, +    vec3 pos, vec3 norm, float glossiness, float envIntensity); + +vec3 vN, vT, vB; + +vec3 transform_normal(vec3 vNt) +{ +    return normalize(vNt.x * vT + vNt.y * vB + vNt.z * vN); +} + +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, +    vec3 pos, vec3 norm, float glossiness); + +void main()  +{ +	vec4 color; + +    vN = vary_normal; +    vT = vary_tangent; +    vB = cross(vN, vT); + +    vec3 pos = vary_position.xyz; + +	float dist = length(view.xy); +	 +	//normalize view vector +	vec3 viewVec = normalize(pos.xyz); +	 +	//get wave normals +    vec2 bigwave = vec2(refCoord.w, view.w); +    vec3 wave1_a = texture2D(bumpMap, bigwave      ).xyz*2.0-1.0; +    vec3 wave2_a = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0; +    vec3 wave3_a = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0; + + +    vec3 wave1_b = texture2D(bumpMap2, bigwave      ).xyz*2.0-1.0; +    vec3 wave2_b = texture2D(bumpMap2, littleWave.xy).xyz*2.0-1.0; +    vec3 wave3_b = texture2D(bumpMap2, littleWave.zw).xyz*2.0-1.0; + +    vec3 wave1 = BlendNormal(wave1_a, wave1_b); +    vec3 wave2 = BlendNormal(wave2_a, wave2_b); +    vec3 wave3 = BlendNormal(wave3_a, wave3_b); + +    wave1 = transform_normal(wave1); +    wave2 = transform_normal(wave2); +    wave3 = transform_normal(wave3); + +    vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5; + +    wavef.z *= max(-viewVec.z, 0.1); + +    wavef = normalize(wavef); + +	//get base fresnel components	 +	 +	/*vec3 df = vec3( +					dot(viewVec, wave1), +					dot(viewVec, (wave2 + wave3) * 0.5), +					dot(viewVec, wave3) +				 ) * fresnelScale + fresnelOffset;*/ +		     +	vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5; +	 +	float dist2 = dist; +	dist = max(dist, 5.0); +	 +	float dmod = sqrt(dist); +	 +	vec2 dmod_scale = vec2(dmod*dmod, dmod); +	 +    //float df1 = df.x + df.y + df.z; + +    vec4 refcol = vec4(0, 0, 0, 0); + +	//get specular component +	float spec = clamp(dot(vary_light_dir, (reflect(viewVec,wavef))),0.0,1.0); +		 +	//harden specular +	spec = pow(spec, 128.0); + +	//figure out distortion vector (ripply)    +	//vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0); +		 +	//vec4 fb = texture2D(screenTex, distort2); + +    vec3 sunlit; +    vec3 amblit; +    vec3 additive; +    vec3 atten; + +    calcAtmosphericVarsLinear(pos.xyz, wavef, lightDir, sunlit, amblit, additive, atten); +     +    vec3 v = -viewVec; +    float NdotV = clamp(abs(dot(wavef.xyz, v)), 0.001, 1.0); + +    float metallic = fresnelOffset * 0.1; // fudge -- use fresnelOffset as metalness +    float roughness = 0.08; +    float gloss = 1.0 - roughness; + +    vec3 baseColor = vec3(0); +    vec3 f0 = vec3(0.04); +    vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0); +    diffuseColor *= gloss; + +    vec3 specularColor = mix(f0, baseColor.rgb, metallic); + +     +    vec3 refnorm = normalize(wavef + vary_normal); + +    vec3 irradiance = vec3(0); +    vec3 radiance = vec3(0); +    sampleReflectionProbes(irradiance, radiance, pos, refnorm, gloss); +     +    // fudge -- use refracted color as irradiance +    irradiance = srgb_to_linear(waterFogColor.rgb); + +    color.rgb = pbrIbl(diffuseColor, specularColor, radiance, irradiance, gloss, NdotV, 0.0); + +    //vec4 fb = waterFogColor; +    //fb.rgb = srgb_to_linear(fb.rgb); +	 +    //refcol.rgb = vec3(0, 1, 0); + +	//mix with reflection +	//color.rgb = mix(fb.rgb, refcol.rgb, df1); +	 +    //color.rgb += spec * specular; + +    // fudge -- for punctual lighting, pretend water is metallic +    diffuseColor = vec3(0); +    specularColor = vec3(1); +    roughness = 0.1; +    color.rgb += pbrPunctual(diffuseColor, specularColor, roughness, metallic, wavef, v, vary_light_dir); +	color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); +	color.rgb = scaleSoftClipFragLinear(color.rgb); + +    color.a = 0.f; + +	//color.a = spec * sunAngle2; + +    frag_color = color; + +#if defined(WATER_EDGE) +    gl_FragDepth = 0.9999847f; +#endif +	 +} + | 
