diff options
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred')
72 files changed, 1578 insertions, 1503 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 02b2daf0ac..f4ec1ec532 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -25,305 +25,11 @@  //class1/deferred/alphaF.glsl -#extension GL_ARB_texture_rectangle : enable -/*[EXTRA_CODE_HERE]*/ - -#define INDEXED 1 -#define NON_INDEXED 2 -#define NON_INDEXED_NO_COLOR 3 - -#ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform mat3 env_mat; -uniform vec3 sun_dir; -uniform vec3 moon_dir; - -#ifdef USE_DIFFUSE_TEX -uniform sampler2D diffuseMap; -#endif - -VARYING vec3 vary_fragcoord; -VARYING vec3 vary_position; -VARYING vec2 vary_texcoord0; -VARYING vec3 vary_norm; - -#ifdef USE_VERTEX_COLOR -VARYING vec4 vertex_color; //vertex color should be treated as sRGB -#endif - -#ifdef HAS_ALPHA_MASK -uniform float minimum_alpha; -#endif - -uniform mat4 proj_mat; -uniform mat4 inv_proj; -uniform vec2 screen_res; -uniform int sun_up_factor; -uniform vec4 light_position[8]; -uniform vec3 light_direction[8]; -uniform vec4 light_attenuation[8];  -uniform vec3 light_diffuse[8]; - -#ifdef WATER_FOG -vec4 applyWaterFogView(vec3 pos, vec4 color); -#endif - -vec3 srgb_to_linear(vec3 c); -vec3 linear_to_srgb(vec3 c); - -vec2 encode_normal (vec3 n); -vec3 scaleSoftClipFrag(vec3 l); -vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); - -void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive, bool use_ao); - -#ifdef HAS_SHADOW -float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); -#endif - -float getAmbientClamp(); - -vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, float ambiance) -{ -    // SL-14895 inverted attenuation work-around -    // This routine is tweaked to match deferred lighting, but previously used an inverted la value. To reconstruct -    // that previous value now that the inversion is corrected, we reverse the calculations in LLPipeline::setupHWLights() -    // to recover the `adjusted_radius` value previously being sent as la. -    float falloff_factor = (12.0 * fa) - 9.0; -    float inverted_la = falloff_factor / la; -    // Yes, it makes me want to cry as well. DJH -     -    vec3 col = vec3(0); - -	//get light vector -	vec3 lv = lp.xyz-v; - -	//get distance -	float dist = length(lv); -	float da = 1.0; -    /*if (dist > inverted_la) -    { -        return col; -    } - -    clip to projector bounds -     vec4 proj_tc = proj_mat * lp; - -    if (proj_tc.z < 0 -     || proj_tc.z > 1 -     || proj_tc.x < 0 -     || proj_tc.x > 1  -     || proj_tc.y < 0 -     || proj_tc.y > 1) -    { -        return col; -    }*/ - -	if (dist > 0.0 && inverted_la > 0.0) -	{ -        dist /= inverted_la; - -		//normalize light vector -		lv = normalize(lv); -	 -		//distance attenuation -		float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); -		dist_atten *= dist_atten; -        dist_atten *= 2.0f; - -        if (dist_atten <= 0.0) -        { -           return col; -        } - -		// spotlight coefficient. -		float spot = max(dot(-ln, lv), is_pointlight); -		da *= spot*spot; // GL_SPOT_EXPONENT=2 - -		//angular attenuation -		da *= dot(n, lv); -        da = max(0.0, da); - -		float lit = 0.0f; - -        float amb_da = 0.0;//ambiance; -        if (da > 0) -        { -		    lit = max(da * dist_atten,0.0); -            col = lit * light_col * diffuse; -            amb_da += (da*0.5+0.5) * ambiance; -        } -        amb_da += (da*da*0.5 + 0.5) * ambiance; -        amb_da *= dist_atten; -        amb_da = min(amb_da, 1.0f - lit); - -        // SL-10969 ... need to work out why this blows out in many setups... -        //col.rgb += amb_da * light_col * diffuse; - -        // no spec for alpha shader... -    } -    col = max(col, vec3(0)); -    return col; -} - -void main()  +void main()  { -    vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; -    frag *= screen_res; -     -    vec4 pos = vec4(vary_position, 1.0); -    vec3 norm = vary_norm; - -    float shadow = 1.0f; - -#ifdef HAS_SHADOW -    shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, frag); -#endif - -#ifdef USE_DIFFUSE_TEX -    vec4 diffuse_tap = texture2D(diffuseMap,vary_texcoord0.xy); -#endif - -#ifdef USE_INDEXED_TEX -    vec4 diffuse_tap = diffuseLookup(vary_texcoord0.xy); -#endif - -    vec4 diffuse_srgb = diffuse_tap; - -#ifdef FOR_IMPOSTOR -    vec4 color; -    color.rgb = diffuse_srgb.rgb; -    color.a = 1.0; - -    float final_alpha = diffuse_srgb.a * vertex_color.a; -    diffuse_srgb.rgb *= vertex_color.rgb; -     -    // Insure we don't pollute depth with invis pixels in impostor rendering -    // -    if (final_alpha < minimum_alpha) -    { -        discard; -    } - -    color.rgb = diffuse_srgb.rgb; -    color.a = final_alpha; - -#else // FOR_IMPOSTOR - -    vec4 diffuse_linear = vec4(srgb_to_linear(diffuse_srgb.rgb), diffuse_srgb.a); - -    vec3 light_dir = (sun_up_factor == 1) ? sun_dir: moon_dir; - -    float final_alpha = diffuse_linear.a; - -#ifdef USE_VERTEX_COLOR -    final_alpha *= vertex_color.a; - -    if (final_alpha < minimum_alpha) -    { // TODO: figure out how to get invisible faces out of  -        // render batches without breaking glow -        discard; -    } - -    diffuse_srgb.rgb *= vertex_color.rgb; -    diffuse_linear.rgb = srgb_to_linear(diffuse_srgb.rgb); -#endif // USE_VERTEX_COLOR - -    vec3 sunlit; -    vec3 amblit; -    vec3 additive; -    vec3 atten; - -    calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); - -    vec2 abnormal = encode_normal(norm.xyz); - -    float da = dot(norm.xyz, light_dir.xyz); -          da = clamp(da, -1.0, 1.0); -          da = pow(da, 1.0/1.3); -  -    float final_da = da; -          final_da = clamp(final_da, 0.0f, 1.0f); - -    vec4 color = vec4(0.0); - -    color.a   = final_alpha; - -    float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); -    ambient *= 0.5; -    ambient *= ambient; -    ambient = (1.0 - ambient); - -    vec3 sun_contrib = min(final_da, shadow) * sunlit; - -#if !defined(AMBIENT_KILL) -    color.rgb = amblit; -    color.rgb *= ambient; -#endif // !defined(AMBIENT_KILL) - -vec3 post_ambient = color.rgb; - -#if !defined(SUNLIGHT_KILL) -    color.rgb += sun_contrib; -#endif // !defined(SUNLIGHT_KILL) - -vec3 post_sunlight = color.rgb; - -    color.rgb *= diffuse_srgb.rgb; - -vec3 post_diffuse = color.rgb; - -    color.rgb = atmosFragLighting(color.rgb, additive, atten); - -vec3 post_atmo = color.rgb; - -    vec4 light = vec4(0,0,0,0); -     -    color.rgb = scaleSoftClipFrag(color.rgb); - -    //convert to linear before applying local lights -    color.rgb = srgb_to_linear(color.rgb); - -   #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diffuse_linear.rgb, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w); - -    LIGHT_LOOP(1) -    LIGHT_LOOP(2) -    LIGHT_LOOP(3) -    LIGHT_LOOP(4) -    LIGHT_LOOP(5) -    LIGHT_LOOP(6) -    LIGHT_LOOP(7) - -    // sum local light contrib in linear colorspace -#if !defined(LOCAL_LIGHT_KILL) -    color.rgb += light.rgb; -#endif // !defined(LOCAL_LIGHT_KILL) -    // back to sRGB as we're going directly to the final RT post-deferred gamma correction -    color.rgb = linear_to_srgb(color.rgb); - -//color.rgb = amblit; -//color.rgb = vec3(ambient); -//color.rgb = sunlit; -//color.rgb = vec3(final_da); -//color.rgb = post_ambient; -//color.rgb = post_sunlight; -//color.rgb = sun_contrib; -//color.rgb = diffuse_srgb.rgb; -//color.rgb = post_diffuse; -//color.rgb = post_atmo; - -#ifdef WATER_FOG -    color = applyWaterFogView(pos.xyz, color); -#endif // WATER_FOG - -#endif // #else // FOR_IMPOSTOR - -    frag_color = color; +    frag_color = vec4(1,0,1,0.5);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl index 23adbded5e..37fe8287be 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl @@ -24,8 +24,8 @@   */  uniform sampler2D       noiseMap; -uniform sampler2DRect   normalMap; -uniform sampler2DRect   depthMap; +uniform sampler2D   normalMap; +uniform sampler2D   depthMap;  uniform float ssao_radius;  uniform float ssao_max_radius; @@ -38,16 +38,12 @@ uniform vec2 screen_res;  vec2 getScreenCoordinateAo(vec2 screenpos)  {      vec2 sc = screenpos.xy * 2.0; -    if (screen_res.x > 0 && screen_res.y > 0) -    { -       sc /= screen_res; -    }      return sc - vec2(1.0, 1.0);  }  float getDepthAo(vec2 pos_screen)  { -    float depth = texture2DRect(depthMap, pos_screen).r; +    float depth = texture2D(depthMap, pos_screen).r;      return depth;  } @@ -75,7 +71,7 @@ vec2 getKern(int i)      kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875;      kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; -    return kern[i]; +    return kern[i] / screen_res;  }  //calculate decreases in ambient lighting when crowded out (SSAO) @@ -83,8 +79,8 @@ float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen)  {      float ret = 1.0;      vec3 pos_world = pos.xyz; -    vec2 noise_reflect = texture2D(noiseMap, pos_screen.xy/128.0).xy; -         +    vec2 noise_reflect = texture2D(noiseMap, pos_screen.xy * (screen_res / 128)).xy; +      float angle_hidden = 0.0;      float points = 0; @@ -95,7 +91,7 @@ float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen)      {          vec2 samppos_screen = pos_screen + scale * reflect(getKern(i), noise_reflect);          vec3 samppos_world = getPositionAo(samppos_screen).xyz;  -         +          vec3 diff = pos_world - samppos_world;          float dist2 = dot(diff, diff); diff --git a/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaMaskShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaMaskShadowF.glsl index c64b6ba240..c2372fcbc0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaMaskShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaMaskShadowF.glsl @@ -58,7 +58,7 @@ void main()  	frag_color = vec4(1,1,1,1); -#if !DEPTH_CLAMP	 +#if !defined(DEPTH_CLAMP)  	gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0);  #endif  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaShadowF.glsl index b54c580ce9..d0a049d372 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaShadowF.glsl @@ -35,7 +35,7 @@ uniform sampler2D diffuseMap;  VARYING float pos_w;  VARYING float target_pos_x; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP)  VARYING vec4 post_pos;  #endif @@ -61,7 +61,7 @@ void main()  	frag_color = vec4(1,1,1,1); -#if !DEPTH_CLAMP	 +#if !defined(DEPTH_CLAMP)  	gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0);  #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaShadowV.glsl index 31b93dc36a..a7bf4d7780 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaShadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/attachmentAlphaShadowV.glsl @@ -1,5 +1,5 @@  /**  - * @file attachmentShadowV.glsl + * @file attachmentAlphaShadowV.glsl   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code   * Copyright (C) 2007, Linden Research, Inc. @@ -35,7 +35,7 @@ ATTRIBUTE vec2 texcoord0;  mat4 getObjectSkinnedTransform();  void passTextureIndex(); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP)  VARYING vec4 post_pos;  #endif  VARYING vec2 vary_texcoord0; @@ -61,7 +61,7 @@ void main()  	vertex_color = diffuse_color; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP)  	p.z = max(p.z, -p.w+0.01);      post_pos = p;  	gl_Position = p; diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaMaskShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaMaskShadowF.glsl index b8ce54bcb1..f231213ac8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaMaskShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaMaskShadowF.glsl @@ -1,5 +1,5 @@  /**  - * @file treeShadowF.glsl + * @file avatarAlphaMaskShadowF.glsl   *   * $LicenseInfo:firstyear=2005&license=viewerlgpl$   * Second Life Viewer Source Code @@ -32,7 +32,7 @@ out vec4 frag_color;  uniform float minimum_alpha;  uniform sampler2D diffuseMap; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP)  VARYING vec4 post_pos;  #endif @@ -59,7 +59,7 @@ void main()  	frag_color = vec4(1,1,1,1); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP)  	gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0);  #endif  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl deleted file mode 100644 index bbdc8fdd1c..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaNoColorV.glsl +++ /dev/null @@ -1,112 +0,0 @@ -/**  - * @file avatarAlphaNoColorV.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$ - */ - -uniform mat4 projection_matrix; - -ATTRIBUTE vec3 position; -ATTRIBUTE vec3 normal; -ATTRIBUTE vec2 texcoord0; - -mat4 getSkinnedTransform(); -void calcAtmospherics(vec3 inPositionEye); - -float calcDirectionalLight(vec3 n, vec3 l); - -vec3 atmosAmbient(); -vec3 atmosAffectDirectionalLight(float lightIntensity); - -VARYING vec3 vary_position; -VARYING vec3 vary_ambient; -VARYING vec3 vary_directional; -VARYING vec3 vary_fragcoord; -VARYING vec3 vary_pointlight_col; -VARYING vec2 vary_texcoord0; -VARYING vec3 vary_norm; - - -uniform float near_clip; - -uniform vec4 color; - -uniform vec4 light_position[8]; -uniform vec3 light_direction[8]; -uniform vec3 light_attenuation[8];  -uniform vec3 light_diffuse[8]; - -float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight); - -void main() -{ -	vary_texcoord0 = texcoord0; -				 -	vec4 pos; -	vec3 norm; -	 -	mat4 trans = getSkinnedTransform(); -	vec4 pos_in = vec4(position.xyz, 1.0); -	pos.x = dot(trans[0], pos_in); -	pos.y = dot(trans[1], pos_in); -	pos.z = dot(trans[2], pos_in); -	pos.w = 1.0; -	 -	norm.x = dot(trans[0].xyz, normal); -	norm.y = dot(trans[1].xyz, normal); -	norm.z = dot(trans[2].xyz, normal); -	norm = normalize(norm); -	vary_norm = norm; -		 -	vec4 frag_pos = projection_matrix * pos; -	gl_Position = frag_pos; -	 -	vary_position = pos.xyz; -	 -	calcAtmospherics(pos.xyz); - -	vec4 col = vec4(0.0, 0.0, 0.0, 1.0); - -	// Collect normal lights -	col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].y, light_attenuation[2].z); -	col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].y, light_attenuation[3].z); -	col.rgb += light_diffuse[4].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[4], light_direction[4], light_attenuation[4].x, light_attenuation[4].y, light_attenuation[4].z); -	col.rgb += light_diffuse[5].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[5], light_direction[5], light_attenuation[5].x, light_attenuation[5].y, light_attenuation[5].z); -	col.rgb += light_diffuse[6].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[6], light_direction[6], light_attenuation[6].x, light_attenuation[6].y, light_attenuation[6].z); -	col.rgb += light_diffuse[7].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[7], light_direction[7], light_attenuation[7].x, light_attenuation[7].y, light_attenuation[7].z); -	 -	vary_pointlight_col = col.rgb*color.rgb; - -	col.rgb = vec3(0,0,0); - -	// Add windlight lights -	col.rgb = atmosAmbient(); -	 -	vary_ambient = col.rgb*color.rgb; -	vary_directional = color.rgb*atmosAffectDirectionalLight(max(calcDirectionalLight(norm, light_position[0].xyz), 0.0)); -	 -	col.rgb = col.rgb * color.rgb; -	 -	vary_fragcoord.xyz = frag_pos.xyz + vec3(0,0,near_clip); -} - - diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaShadowF.glsl index 1b16e4eb09..0e66c722b6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaShadowF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaShadowF.glsl @@ -33,7 +33,7 @@ uniform float minimum_alpha;  uniform sampler2D diffuseMap; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP)  VARYING vec4 post_pos;  #endif @@ -61,7 +61,7 @@ void main()  	frag_color = vec4(1,1,1,1); -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP)  	gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0);  #endif diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaShadowV.glsl index 1c5b142ebd..40ac7b1f95 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaShadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarAlphaShadowV.glsl @@ -1,5 +1,5 @@  /**  - * @file avatarShadowV.glsl + * @file avatarAlphaShadowV.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -34,7 +34,7 @@ ATTRIBUTE vec3 position;  ATTRIBUTE vec3 normal;  ATTRIBUTE vec2 texcoord0; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP)  VARYING vec4 post_pos;  #endif  VARYING float pos_w; @@ -66,7 +66,7 @@ void main()  	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; -#if !DEPTH_CLAMP +#if !defined(DEPTH_CLAMP)  	post_pos = pos;  	gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl index 60d83cc623..22b3bd1463 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl @@ -52,6 +52,6 @@ void main()  	frag_data[0] = vec4(diff.rgb, 0.0);  	frag_data[1] = vec4(0,0,0,0);  	vec3 nvn = normalize(vary_normal); -	frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0); +	frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index 596d0274af..9bead273ff 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -33,8 +33,8 @@ out vec4 frag_color;  #define frag_color gl_FragColor  #endif -uniform sampler2DRect normalMap; -uniform sampler2DRect lightMap; +uniform sampler2D normalMap; +uniform sampler2D lightMap;  uniform float dist_factor;  uniform float blur_size; @@ -52,7 +52,7 @@ void main()      vec2 tc = vary_fragcoord.xy;      vec3 norm = getNorm(tc);      vec3 pos = getPosition(tc).xyz; -    vec4 ccol = texture2DRect(lightMap, tc).rgba; +    vec4 ccol = texture2D(lightMap, tc).rgba;      vec2 dlt = kern_scale * delta / (1.0+norm.xy*norm.xy);      dlt /= max(-pos.z*dist_factor, 1.0); @@ -69,36 +69,47 @@ void main()      tc_mod *= 2.0;      tc += ( (tc_mod - 0.5) * kern[1].z * dlt * 0.5 ); -    for (int i = 1; i < 4; i++) +    // TODO: move this to kern instead of building kernel per pixel +    vec3 k[7]; +    k[0] = kern[0]; +    k[2] = kern[1]; +    k[4] = kern[2]; +    k[6] = kern[3]; + +    k[1] = (k[0]+k[2])*0.5f; +    k[3] = (k[2]+k[4])*0.5f; +    k[5] = (k[4]+k[6])*0.5f; +     +    for (int i = 1; i < 7; i++)      { -        vec2 samptc = tc + kern[i].z*dlt; +        vec2 samptc = tc + k[i].z*dlt*2.0;          vec3 samppos = getPosition(samptc).xyz;           float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane          if (d*d <= pointplanedist_tolerance_pow2)          { -            col += texture2DRect(lightMap, samptc)*kern[i].xyxx; -            defined_weight += kern[i].xy; +            col += texture2D(lightMap, samptc)*k[i].xyxx; +            defined_weight += k[i].xy;          }      } -    for (int i = 1; i < 4; i++) +    for (int i = 1; i < 7; i++)      { -        vec2 samptc = tc - kern[i].z*dlt; +        vec2 samptc = tc - k[i].z*dlt*2.0;          vec3 samppos = getPosition(samptc).xyz;           float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane          if (d*d <= pointplanedist_tolerance_pow2)          { -            col += texture2DRect(lightMap, samptc)*kern[i].xyxx; -            defined_weight += kern[i].xy; +            col += texture2D(lightMap, samptc)*k[i].xyxx; +            defined_weight += k[i].xy;          }      }      col /= defined_weight.xyxx; -    col.y *= col.y; +    //col.y *= max(col.y, 0.75);      frag_color = col; diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightV.glsl index 212f7e56ad..5e0f01981b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightV.glsl @@ -23,8 +23,6 @@   * $/LicenseInfo$   */ -uniform mat4 modelview_projection_matrix; -  ATTRIBUTE vec3 position;  VARYING vec2 vary_fragcoord; @@ -33,7 +31,7 @@ uniform vec2 screen_res;  void main()  {  	//transform vertex -	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); +	vec4 pos = vec4(position.xyz, 1.0);  	gl_Position = pos;  -	vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; +	vary_fragcoord = (pos.xy*0.5+0.5);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl index b5677a07ee..749ec3a6ac 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl @@ -64,5 +64,5 @@ void main()  		frag_data[1] = vertex_color.aaaa; // spec  		//frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested  		vec3 nvn = normalize(tnorm); -		frag_data[2] = vec4(encode_normal(nvn), vertex_color.a, 0.0);	 +		frag_data[2] = vec4(encode_normal(nvn), vertex_color.a, GBUFFER_FLAG_HAS_ATMOS);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl deleted file mode 100644 index 0157d166e0..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowF.glsl +++ /dev/null @@ -1,127 +0,0 @@ -/**  - * @file class3/deferred/cloudsF.glsl - * - * $LicenseInfo:firstyear=2005&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2005, 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 - -uniform sampler2D diffuseMap; - -VARYING vec4 pos; -VARYING float target_pos_x; -VARYING float vary_CloudDensity; -VARYING vec2 vary_texcoord0; -VARYING vec2 vary_texcoord1; -VARYING vec2 vary_texcoord2; -VARYING vec2 vary_texcoord3; - -uniform sampler2D cloud_noise_texture; -uniform sampler2D cloud_noise_texture_next; -uniform float blend_factor; -uniform vec4 cloud_pos_density1; -uniform vec4 cloud_pos_density2; -uniform vec4 sunlight_color; -uniform vec4 cloud_color; -uniform float cloud_shadow; -uniform float cloud_scale; -uniform float cloud_variance; -uniform vec3 camPosLocal; -uniform vec3 sun_dir; -uniform float sun_size; -uniform float far_z; - -#if !defined(DEPTH_CLAMP) -VARYING vec4 post_pos; -#endif - -vec4 cloudNoise(vec2 uv) -{ -   vec4 a = texture2D(cloud_noise_texture, uv); -   vec4 b = texture2D(cloud_noise_texture_next, uv); -   vec4 cloud_noise_sample = mix(a, b, blend_factor); -   return normalize(cloud_noise_sample); -} - -void main() -{ -    // Set variables -    vec2 uv1 = vary_texcoord0.xy; -    vec2 uv2 = vary_texcoord1.xy; -    vec2 uv3 = vary_texcoord2.xy; -    float cloudDensity = 2.0 * (cloud_shadow - 0.25); - -    if (cloud_scale >= 0.0001) -    { -        vec2 uv4 = vary_texcoord3.xy; -     -        vec2 disturbance  = vec2(cloudNoise(uv1 / 8.0f).x, cloudNoise((uv3 + uv1) / 16.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); -        vec2 disturbance2 = vec2(cloudNoise((uv1 + uv3) / 4.0f).x, cloudNoise((uv4 + uv2) / 8.0f).x) * cloud_variance * (1.0f - cloud_scale * 0.25f); -     -        // Offset texture coords -        uv1 += cloud_pos_density1.xy + (disturbance * 0.2);    //large texture, visible density -        uv2 += cloud_pos_density1.xy;   //large texture, self shadow -        uv3 += cloud_pos_density2.xy;   //small texture, visible density -        uv4 += cloud_pos_density2.xy;   //small texture, self shadow -     -        float density_variance = min(1.0, (disturbance.x* 2.0 + disturbance.y* 2.0 + disturbance2.x + disturbance2.y) * 4.0); -     -        cloudDensity *= 1.0 - (density_variance * density_variance); -     -        // Compute alpha1, the main cloud opacity -        float alpha1 = (cloudNoise(uv1).x - 0.5) + (cloudNoise(uv3).x - 0.5) * cloud_pos_density2.z; -        alpha1 = min(max(alpha1 + cloudDensity, 0.) * 10 * cloud_pos_density1.z, 1.); -     -        // And smooth -        alpha1 = 1. - alpha1 * alpha1; -        alpha1 = 1. - alpha1 * alpha1;   -     -        if (alpha1 < 0.001f) -        { -            discard; -        } -     -        // Compute alpha2, for self shadowing effect -        // (1 - alpha2) will later be used as percentage of incoming sunlight -        float alpha2 = (cloudNoise(uv2).x - 0.5); -        alpha2 = min(max(alpha2 + cloudDensity, 0.) * 2.5 * cloud_pos_density1.z, 1.); -     -        // And smooth -        alpha2 = 1. - alpha2; -        alpha2 = 1. - alpha2 * alpha2;   -     -        frag_color = vec4(alpha1, alpha1, alpha1, 1); -    } -    else -    { -        frag_color = vec4(1); -    } - -#if !defined(DEPTH_CLAMP) -    gl_FragDepth = max(post_pos.z/post_pos.w*0.5+0.5, 0.0); -#endif - -} diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl index ae1ac5de7f..b45dfcd550 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsF.glsl @@ -34,15 +34,15 @@ out vec4 frag_data[3];  // The fragment shader for the sky  ///////////////////////////////////////////////////////////////////////// -VARYING vec4 vary_CloudColorSun; -VARYING vec4 vary_CloudColorAmbient; +VARYING vec3 vary_CloudColorSun; +VARYING vec3 vary_CloudColorAmbient;  VARYING float vary_CloudDensity;  uniform sampler2D cloud_noise_texture;  uniform sampler2D cloud_noise_texture_next;  uniform float blend_factor; -uniform vec4 cloud_pos_density1; -uniform vec4 cloud_pos_density2; +uniform vec3 cloud_pos_density1; +uniform vec3 cloud_pos_density2;  uniform float cloud_scale;  uniform float cloud_variance; @@ -69,8 +69,8 @@ void main()      vec2 uv1 = vary_texcoord0.xy;      vec2 uv2 = vary_texcoord1.xy; -    vec4 cloudColorSun = vary_CloudColorSun; -    vec4 cloudColorAmbient = vary_CloudColorAmbient; +    vec3 cloudColorSun = vary_CloudColorSun; +    vec3 cloudColorAmbient = vary_CloudColorAmbient;      float cloudDensity = vary_CloudDensity;      vec2 uv3 = vary_texcoord2.xy;      vec2 uv4 = vary_texcoord3.xy; @@ -115,7 +115,7 @@ void main()      alpha2 = 1. - alpha2 * alpha2;        // Combine -    vec4 color; +    vec3 color;      color = (cloudColorSun*(1.-alpha2) + cloudColorAmbient);      color.rgb= max(vec3(0), color.rgb);      color.rgb *= 2.0; @@ -124,8 +124,8 @@ void main()      /// Gamma correct for WL (soft clip effect).      frag_data[0] = vec4(color.rgb, alpha1);      frag_data[1] = vec4(0.0,0.0,0.0,0.0); -    frag_data[2] = vec4(0,0,0,1); +    frag_data[2] = vec4(0,0,0,GBUFFER_FLAG_SKIP_ATMOS); -    gl_FragDepth = 0.99995f; +    gl_FragDepth = LL_SHADER_CONST_CLOUD_MOON_DEPTH; // SL-14113 Stars and Clouds need same depth  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl index 8e0a001403..5ca210863e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cloudsV.glsl @@ -33,8 +33,8 @@ ATTRIBUTE vec2 texcoord0;  ///////////////////////////////////////////////////////////////////////////////  // Output parameters -VARYING vec4 vary_CloudColorSun; -VARYING vec4 vary_CloudColorAmbient; +VARYING vec3 vary_CloudColorSun; +VARYING vec3 vary_CloudColorAmbient;  VARYING float vary_CloudDensity;  VARYING vec2 vary_texcoord0; @@ -46,13 +46,13 @@ VARYING float altitude_blend_factor;  // Inputs  uniform vec3 camPosLocal; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 moonlight_color; +uniform vec3 lightnorm; +uniform vec3 sunlight_color; +uniform vec3 moonlight_color;  uniform int sun_up_factor; -uniform vec4 ambient_color; -uniform vec4 blue_horizon; -uniform vec4 blue_density; +uniform vec3 ambient_color; +uniform vec3 blue_horizon; +uniform vec3 blue_density;  uniform float haze_horizon;  uniform float haze_density; @@ -60,10 +60,10 @@ uniform float cloud_shadow;  uniform float density_multiplier;  uniform float max_y; -uniform vec4 glow; +uniform vec3 glow;  uniform float sun_moon_glow_factor; -uniform vec4 cloud_color; +uniform vec3 cloud_color;  uniform float cloud_scale; @@ -114,17 +114,17 @@ void main()      float rel_pos_len  = length(rel_pos);  	// Initialize temp variables -	vec4 sunlight = sunlight_color; -	vec4 light_atten; +	vec3 sunlight = sunlight_color; +	vec3 light_atten;  	// Sunlight attenuation effect (hue and brightness) due to atmosphere  	// this is used later for sunlight modulation at various altitudes -    light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); +    light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y);  	// Calculate relative weights -    vec4 combined_haze = abs(blue_density) + vec4(abs(haze_density)); -    vec4 blue_weight   = blue_density / combined_haze; -    vec4 haze_weight   = haze_density / combined_haze; +    vec3 combined_haze = abs(blue_density) + vec3(abs(haze_density)); +    vec3 blue_weight   = blue_density / combined_haze; +    vec3 haze_weight   = haze_density / combined_haze;      // Compute sunlight from rel_pos & lightnorm (for long rays like sky)      float off_axis = 1.0 / max(1e-6, max(0., rel_pos_norm.y) + lightnorm.y); @@ -155,14 +155,14 @@ void main()      haze_glow = (sun_moon_glow_factor < 1.0) ? 0.0 : (haze_glow + 0.25);  	// Increase ambient when there are more clouds -	vec4 tmpAmbient = ambient_color; +	vec3 tmpAmbient = ambient_color;  	tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5;   	// Dim sunlight by cloud shadow percentage  	sunlight *= (1. - cloud_shadow);  	// Haze color below cloud -    vec4 additiveColorBelowCloud = +    vec3 additiveColorBelowCloud =          (blue_horizon * blue_weight * (sunlight + tmpAmbient) + (haze_horizon * haze_weight) * (sunlight * haze_glow + tmpAmbient));  	// CLOUDS @@ -178,7 +178,7 @@ void main()      combined_haze = sqrt(combined_haze);  // less atmos opacity (more transparency) below clouds      vary_CloudColorSun *= combined_haze;      vary_CloudColorAmbient *= combined_haze; -    vec4 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - combined_haze); +    vec3 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - combined_haze);  	// Make a nice cloud density based on the cloud_shadow value that was passed in.  	vary_CloudDensity = 2. * (cloud_shadow - 0.25); diff --git a/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl b/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl index 079d8458c9..1e640d95ae 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/cofF.glsl @@ -33,8 +33,8 @@ out vec4 frag_color;  #define frag_color gl_FragColor  #endif -uniform sampler2DRect diffuseRect; -uniform sampler2DRect depthMap; +uniform sampler2D diffuseRect; +uniform sampler2D depthMap;  uniform sampler2D bloomMap;  uniform float depth_cutoff; @@ -69,19 +69,19 @@ void main()  {  	vec2 tc = vary_fragcoord.xy; -    float z = texture2DRect(depthMap, tc).r; +    float z = texture2D(depthMap, tc).r;  	z = z*2.0-1.0;  	vec4 ndc = vec4(0.0, 0.0, z, 1.0);  	vec4 p = inv_proj*ndc;  	float depth = p.z/p.w; -	vec4 diff = texture2DRect(diffuseRect, vary_fragcoord.xy); +	vec4 diff = texture2D(diffuseRect, vary_fragcoord.xy);  	float sc = calc_cof(depth);  	sc = min(sc, max_cof);  	sc = max(sc, -max_cof); -	vec4 bloom = texture2D(bloomMap, vary_fragcoord.xy/screen_res); +	vec4 bloom = texture2D(bloomMap, vary_fragcoord.xy);  	frag_color.rgb = diff.rgb + bloom.rgb;  	frag_color.a = sc/max_cof*0.5+0.5;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index e27bbce094..c87e754eca 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -23,25 +23,129 @@   * $/LicenseInfo$   */ -uniform sampler2DRect   normalMap; -uniform sampler2DRect   depthMap; + +/*  Parts of this file are taken from Sascha Willem's Vulkan GLTF refernce implementation +MIT License + +Copyright (c) 2018 Sascha Willems + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +uniform sampler2D   normalMap; +uniform sampler2D   depthMap; +uniform sampler2D projectionMap; // rgba +uniform sampler2D brdfLut; + +// projected lighted params +uniform mat4 proj_mat; //screen space to light space projector +uniform vec3 proj_n; // projector normal +uniform vec3 proj_p; //plane projection is emitting from (in screen space) +uniform float proj_focus; // distance from plane to begin blurring +uniform float proj_lod  ; // (number of mips in proj map) +uniform float proj_range; // range between near clip and far clip plane of projection +uniform float proj_ambiance; + +// light params +uniform vec3 color; // light_color +uniform float size; // light_size  uniform mat4 inv_proj;  uniform vec2 screen_res; -vec2 getScreenCoordinate(vec2 screenpos) +const float M_PI = 3.14159265; +const float ONE_OVER_PI = 0.3183098861; + +vec3 srgb_to_linear(vec3 cs); +vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten); +vec3 scaleSoftClipFragLinear(vec3 light); + +float calcLegacyDistanceAttenuation(float distance, float falloff)  { -    vec2 sc = screenpos.xy * 2.0; -    if (screen_res.x > 0 && screen_res.y > 0) +    float dist_atten = 1.0 - clamp((distance + falloff)/(1.0 + falloff), 0.0, 1.0); +    dist_atten *= dist_atten; + +    // Tweak falloff slightly to match pre-EEP attenuation +    // NOTE: this magic number also shows up in a great many other places, search for dist_atten *= to audit +    dist_atten *= 2.0; +    return dist_atten; +} + +// In: +//   lv  unnormalized surface to light vector +//   n   normal of the surface +//   pos unnormalized camera to surface vector +// Out: +//   l   normalized surace to light vector +//   nl  diffuse angle +//   nh  specular angle +void calcHalfVectors(vec3 lv, vec3 n, vec3 v, +    out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist) +{ +    l  = normalize(lv); +    h  = normalize(l + v); +    nh = clamp(dot(n, h), 0.0, 1.0); +    nl = clamp(dot(n, l), 0.0, 1.0); +    nv = clamp(dot(n, v), 0.0, 1.0); +    vh = clamp(dot(v, h), 0.0, 1.0); + +    lightDist = length(lv); +} + +// In: +//   light_center +//   pos +// Out: +//   dist +//   l_dist +//   lv +//   proj_tc  Projector Textue Coordinates +bool clipProjectedLightVars(vec3 light_center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc ) +{ +    lv = light_center - pos.xyz; +    dist = length(lv); +    bool clipped = (dist >= size); +    if ( !clipped )      { -       sc /= screen_res; +        dist /= size; + +        l_dist = -dot(lv, proj_n); +        vec4 projected_point = (proj_mat * vec4(pos.xyz, 1.0)); +        clipped = (projected_point.z < 0.0); +        projected_point.xyz /= projected_point.w; +        proj_tc = projected_point;      } + +    return clipped; +} + +vec2 getScreenCoordinate(vec2 screenpos) +{ +    vec2 sc = screenpos.xy * 2.0;      return sc - vec2(1.0, 1.0);  } +// See: https://aras-p.info/texts/CompactNormalStorage.html +//      Method #4: Spheremap Transform, Lambert Azimuthal Equal-Area projection  vec3 getNorm(vec2 screenpos)  { -   vec2 enc = texture2DRect(normalMap, screenpos.xy).xy; +   vec2 enc = texture2D(normalMap, screenpos.xy).xy;     vec2 fenc = enc*4-2;     float f = dot(fenc,fenc);     float g = sqrt(1-f/4); @@ -51,12 +155,160 @@ vec3 getNorm(vec2 screenpos)     return n;  } +vec3 getNormalFromPacked(vec4 packedNormalEnvIntensityFlags) +{ +   vec2 enc = packedNormalEnvIntensityFlags.xy; +   vec2 fenc = enc*4-2; +   float f = dot(fenc,fenc); +   float g = sqrt(1-f/4); +   vec3 n; +   n.xy = fenc*g; +   n.z = 1-f/2; +   return normalize(n); // TODO: Is this normalize redundant? +} + +// return packedNormalEnvIntensityFlags since GBUFFER_FLAG_HAS_PBR needs .w +// See: C++: addDeferredAttachments(), GLSL: softenLightF +vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity) +{ +    vec4 packedNormalEnvIntensityFlags = texture2D(normalMap, screenpos.xy); +    n = getNormalFromPacked( packedNormalEnvIntensityFlags ); +    envIntensity = packedNormalEnvIntensityFlags.z; +    return packedNormalEnvIntensityFlags; +} + +// get linear depth value given a depth buffer sample d and znear and zfar values +float linearDepth(float d, float znear, float zfar) +{ +    d = d * 2.0 - 1.0; +    return znear * 2.0 * zfar / (zfar + znear - d * (zfar - znear)); +} + +float linearDepth01(float d, float znear, float zfar) +{ +    return linearDepth(d, znear, zfar) / zfar; +} +  float getDepth(vec2 pos_screen)  { -    float depth = texture2DRect(depthMap, pos_screen).r; +    float depth = texture2D(depthMap, pos_screen).r;      return depth;  } +vec4 getTexture2DLodAmbient(vec2 tc, float lod) +{ +#ifndef FXAA_GLSL_120 +    vec4 ret = textureLod(projectionMap, tc, lod); +#else +    vec4 ret = texture2D(projectionMap, tc); +#endif +    ret.rgb = srgb_to_linear(ret.rgb); + +    vec2 dist = tc-vec2(0.5); +    float d = dot(dist,dist); +    ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); + +    return ret; +} + +vec4 getTexture2DLodDiffuse(vec2 tc, float lod) +{ +#ifndef FXAA_GLSL_120 +    vec4 ret = textureLod(projectionMap, tc, lod); +#else +    vec4 ret = texture2D(projectionMap, tc); +#endif +    ret.rgb = srgb_to_linear(ret.rgb); + +    vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); +    float det = min(lod/(proj_lod*0.5), 1.0); +    float d = min(dist.x, dist.y); +    float edge = 0.25*det; +    ret *= clamp(d/edge, 0.0, 1.0); + +    return ret; +} + +// lit     This is set by the caller: if (nl > 0.0) { lit = attenuation * nl * noise; } +// Uses: +//   color   Projected spotlight color +vec3 getProjectedLightAmbiance(float amb_da, float attenuation, float lit, float nl, float noise, vec2 projected_uv) +{ +    vec4 amb_plcol = getTexture2DLodAmbient(projected_uv, proj_lod); +    vec3 amb_rgb   = amb_plcol.rgb * amb_plcol.a; + +    amb_da += proj_ambiance; +    amb_da += (nl*nl*0.5+0.5) * proj_ambiance; +    amb_da *= attenuation * noise; +    amb_da = min(amb_da, 1.0-lit); + +    return (amb_da * color.rgb * amb_rgb); +} + +// Returns projected light in Linear +// Uses global spotlight color: +//  color +// NOTE: projected.a will be pre-multiplied with projected.rgb +vec3 getProjectedLightDiffuseColor(float light_distance, vec2 projected_uv) +{ +    float diff = clamp((light_distance - proj_focus)/proj_range, 0.0, 1.0); +    float lod = diff * proj_lod; +    vec4 plcol = getTexture2DLodDiffuse(projected_uv.xy, lod); + +    return color.rgb * plcol.rgb * plcol.a; +} + +vec4 texture2DLodSpecular(vec2 tc, float lod) +{ +#ifndef FXAA_GLSL_120 +    vec4 ret = textureLod(projectionMap, tc, lod); +#else +    vec4 ret = texture2D(projectionMap, tc); +#endif +    ret.rgb = srgb_to_linear(ret.rgb); + +    vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); +    float det = min(lod/(proj_lod*0.5), 1.0); +    float d = min(dist.x, dist.y); +    d *= min(1, d * (proj_lod - lod)); // BUG? extra factor compared to diffuse causes N repeats +    float edge = 0.25*det; +    ret *= clamp(d/edge, 0.0, 1.0); + +    return ret; +} + +// See: clipProjectedLightVars() +vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n ) +{ +    vec3 slit = vec3(0); +    vec3 ref = reflect(normalize(pos), n); + +    //project from point pos in direction ref to plane proj_p, proj_n +    vec3 pdelta = proj_p-pos; +    float l_dist = length(pdelta); +    float ds = dot(ref, proj_n); +    if (ds < 0.0) +    { +        vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; +        vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); +        if (stc.z > 0.0) +        { +            stc /= stc.w; +            slit = getProjectedLightDiffuseColor( l_dist, stc.xy ); // NOTE: Using diffuse due to texture2DLodSpecular() has extra: d *= min(1, d * (proj_lod - lod)); +        } +    } +    return slit; // specular light +} + +vec3 getProjectedLightSpecularColor(float light_distance, vec2 projected_uv) +{ +    float diff = clamp((light_distance - proj_focus)/proj_range, 0.0, 1.0); +    float lod = diff * proj_lod; +    vec4 plcol = getTexture2DLodDiffuse(projected_uv.xy, lod); // NOTE: Using diffuse due to texture2DLodSpecular() has extra: d *= min(1, d * (proj_lod - lod)); + +    return color.rgb * plcol.rgb * plcol.a; +} +  vec4 getPosition(vec2 pos_screen)  {      float depth = getDepth(pos_screen); @@ -68,12 +320,249 @@ vec4 getPosition(vec2 pos_screen)      return pos;  } +// get position given a normalized device coordinate +vec3 getPositionWithNDC(vec3 ndc) +{ +    vec4 pos = inv_proj * vec4(ndc, 1.0); +    return pos.xyz / pos.w; +} +  vec4 getPositionWithDepth(vec2 pos_screen, float depth)  {      vec2 sc = getScreenCoordinate(pos_screen); -    vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); -    vec4 pos = inv_proj * ndc; -    pos /= pos.w; -    pos.w = 1.0; -    return pos; +    vec3 ndc = vec3(sc.x, sc.y, 2.0*depth-1.0); +    return vec4(getPositionWithNDC(ndc), 1.0); +} + +vec2 getScreenCoord(vec4 clip) +{ +    vec4 ndc = clip; +         ndc.xyz /= clip.w; +    vec2 screen = vec2( ndc.xy * 0.5 ); +         screen += 0.5; +    return screen; +} + +vec2 getScreenXY(vec4 clip) +{ +    vec4 ndc = clip; +         ndc.xyz /= clip.w; +    vec2 screen = vec2( ndc.xy * 0.5 ); +         screen += 0.5; +         screen *= screen_res; +    return screen; +} + +// Color utils + +vec3 colorize_dot(float x) +{ +    if (x > 0.0) return vec3( 0, x, 0 ); +    if (x < 0.0) return vec3(-x, 0, 0 ); +                 return vec3( 0, 0, 1 ); +} + +vec3 hue_to_rgb(float hue) +{ +    if (hue > 1.0) return vec3(0.5); +    vec3 rgb = abs(hue * 6. - vec3(3, 2, 4)) * vec3(1, -1, -1) + vec3(-1, 2, 2); +    return clamp(rgb, 0.0, 1.0); +} + +// PBR Utils + +vec2 BRDF(float NoV, float roughness) +{ +    return texture(brdfLut, vec2(NoV, roughness)).rg; +} + +// set colorDiffuse and colorSpec to the results of GLTF PBR style IBL +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 perceptualRough) +{ +    // retrieve a scale and bias to F0. See [1], Figure 3 +	vec2 brdf = BRDF(clamp(nv, 0, 1), 1.0-perceptualRough); +	vec3 diffuseLight = irradiance; +	vec3 specularLight = radiance; +     +	vec3 diffuse = diffuseLight * diffuseColor; +	vec3 specular = specularLight * (specularColor * brdf.x + brdf.y); + +	return (diffuse + specular*0.5) * ao;  //reduce by half to place in appropriate color space for atmospherics +} + +// Encapsulate the various inputs used by the various functions in the shading equation +// We store values in this struct to simplify the integration of alternative implementations +// of the shading terms, outlined in the Readme.MD Appendix. +struct PBRInfo +{ +	float NdotL;                  // cos angle between normal and light direction +	float NdotV;                  // cos angle between normal and view direction +	float NdotH;                  // cos angle between normal and half vector +	float LdotH;                  // cos angle between light direction and half vector +	float VdotH;                  // cos angle between view direction and half vector +	float perceptualRoughness;    // roughness value, as authored by the model creator (input to shader) +	float metalness;              // metallic value at the surface +	vec3 reflectance0;            // full reflectance color (normal incidence angle) +	vec3 reflectance90;           // reflectance color at grazing angle +	float alphaRoughness;         // roughness mapped to a more linear change in the roughness (proposed by [2]) +	vec3 diffuseColor;            // color contribution from diffuse lighting +	vec3 specularColor;           // color contribution from specular lighting +}; + +// Basic Lambertian diffuse +// Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog +// See also [1], Equation 1 +vec3 diffuse(PBRInfo pbrInputs) +{ +	return pbrInputs.diffuseColor / M_PI; +} + +// The following equation models the Fresnel reflectance term of the spec equation (aka F()) +// Implementation of fresnel from [4], Equation 15 +vec3 specularReflection(PBRInfo pbrInputs) +{ +	return pbrInputs.reflectance0 + (pbrInputs.reflectance90 - pbrInputs.reflectance0) * pow(clamp(1.0 - pbrInputs.VdotH, 0.0, 1.0), 5.0);  } + +// This calculates the specular geometric attenuation (aka G()), +// where rougher material will reflect less light back to the viewer. +// This implementation is based on [1] Equation 4, and we adopt their modifications to +// alphaRoughness as input as originally proposed in [2]. +float geometricOcclusion(PBRInfo pbrInputs) +{ +	float NdotL = pbrInputs.NdotL; +	float NdotV = pbrInputs.NdotV; +	float r = pbrInputs.alphaRoughness; + +	float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL))); +	float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV))); +	return attenuationL * attenuationV; +} + +// The following equation(s) model the distribution of microfacet normals across the area being drawn (aka D()) +// Implementation from "Average Irregularity Representation of a Roughened Surface for Ray Reflection" by T. S. Trowbridge, and K. P. Reitz +// Follows the distribution function recommended in the SIGGRAPH 2013 course notes from EPIC Games [1], Equation 3. +float microfacetDistribution(PBRInfo pbrInputs) +{ +	float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness; +	float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0; +	return roughnessSq / (M_PI * f * f); +} + +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 +{ +    // make sure specular highlights from punctual lights don't fall off of polished surfaces +    perceptualRoughness = max(perceptualRoughness, 8.0/255.0); +     +	float alphaRoughness = perceptualRoughness * perceptualRoughness; + +	// Compute reflectance. +	float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b); + +	// For typical incident reflectance range (between 4% to 100%) set the grazing reflectance to 100% for typical fresnel effect. +	// For very low reflectance range on highly diffuse objects (below 4%), incrementally reduce grazing reflecance to 0%. +	float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0); +	vec3 specularEnvironmentR0 = specularColor.rgb; +	vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90; + +	vec3 h = normalize(l+v);                        // Half vector between both l and v +	vec3 reflection = -normalize(reflect(v, n)); +	reflection.y *= -1.0f; + +	float NdotL = clamp(dot(n, l), 0.001, 1.0); +	float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0); +	float NdotH = clamp(dot(n, h), 0.0, 1.0); +	float LdotH = clamp(dot(l, h), 0.0, 1.0); +	float VdotH = clamp(dot(v, h), 0.0, 1.0); + +	PBRInfo pbrInputs = PBRInfo( +		NdotL, +		NdotV, +		NdotH, +		LdotH, +		VdotH, +		perceptualRoughness, +		metallic, +		specularEnvironmentR0, +		specularEnvironmentR90, +		alphaRoughness, +		diffuseColor, +		specularColor +	); + +	// Calculate the shading terms for the microfacet specular shading model +	vec3 F = specularReflection(pbrInputs); +	float G = geometricOcclusion(pbrInputs); +	float D = microfacetDistribution(pbrInputs); + +	const vec3 u_LightColor = vec3(1.0); + +	// Calculation of analytical lighting contribution +	vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs); +	vec3 specContrib = F * G * D / (4.0 * NdotL * NdotV); +	// Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law) +	vec3 color = NdotL * u_LightColor * (diffuseContrib + specContrib); + +    return color; +} + +void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor) +{ +    vec3 f0 = vec3(0.04); +    diffuseColor = baseColor*(vec3(1.0)-f0); +    diffuseColor *= 1.0 - metallic; +    specularColor = mix(f0, baseColor, metallic); +} + +vec3 pbrBaseLight(vec3 diffuseColor, vec3 specularColor, float metallic, vec3 v, vec3 norm, float perceptualRoughness, vec3 light_dir, vec3 sunlit, float scol, vec3 radiance, vec3 irradiance, vec3 colorEmissive, float ao, vec3 additive, vec3 atten) +{ +    vec3 color = vec3(0); + +    float NdotV = clamp(abs(dot(norm, v)), 0.001, 1.0); +     +    color += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness); +     +    color += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm, v, normalize(light_dir)) * sunlit * 2.75 * scol; +    color += colorEmissive*0.5; + +    color = atmosFragLightingLinear(color, additive, atten); +    color = scaleSoftClipFragLinear(color); + +    return color; +} + +uniform vec4 waterPlane; +uniform float waterSign; + +// discard if given position in eye space is on the wrong side of the waterPlane according to waterSign +void waterClip(vec3 pos) +{ +    // TODO: make this less branchy +    if (waterSign > 0) +    { +        if ((dot(pos.xyz, waterPlane.xyz) + waterPlane.w) < -0.1) +        { +            discard; +        } +    } +    else +    { +        if ((dot(pos.xyz, waterPlane.xyz) + waterPlane.w) > -0.1) +        { +            discard; +        } +    } + +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl index b328ee9483..3bf148502c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl @@ -53,6 +53,6 @@ void main()  	frag_data[0] = vec4(col.rgb, 0.0);  	frag_data[1] = vec4(0,0,0,0); // spec  	vec3 nvn = normalize(vary_normal); -	frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0); +	frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl index fc5c86b4d6..e15239b59d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl @@ -52,5 +52,5 @@ void main()  	frag_data[0] = vec4(col.rgb, 0.0);  	frag_data[1] = vec4(0,0,0,0);  	vec3 nvn = normalize(vary_normal); -	frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0); +	frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl index 1bb8eb8bd0..b0ff233414 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl @@ -52,6 +52,6 @@ void main()  	frag_data[0] = vec4(col.rgb, 0.0);  	frag_data[1] = vec4(0,0,0,0); // spec  	vec3 nvn = normalize(vary_normal); -	frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0); +	frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl index 8319e61242..b2d2e2fa71 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl @@ -46,6 +46,6 @@ void main()  	frag_data[1] = vertex_color.aaaa; // spec  	//frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested  	vec3 nvn = normalize(vary_normal); -	frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, 0.0); +	frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, GBUFFER_FLAG_HAS_ATMOS);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl index ccd1df84f9..b4bc114dd5 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl @@ -48,5 +48,5 @@ void main()  	frag_data[0] = vec4(col, 0.0);  	frag_data[1] = vec4(spec, vertex_color.a); // spec  	vec3 nvn = normalize(vary_normal); -	frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, 0.0); +	frag_data[2] = vec4(encode_normal(nvn.xyz), vertex_color.a, GBUFFER_FLAG_HAS_ATMOS);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/dofCombineF.glsl b/indra/newview/app_settings/shaders/class1/deferred/dofCombineF.glsl index 8d48bb016b..d9c0e590c8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/dofCombineF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/dofCombineF.glsl @@ -33,8 +33,8 @@ out vec4 frag_color;  #define frag_color gl_FragColor  #endif -uniform sampler2DRect diffuseRect; -uniform sampler2DRect lightMap; +uniform sampler2D diffuseRect; +uniform sampler2D lightMap;  uniform mat4 inv_proj;  uniform vec2 screen_res; @@ -46,12 +46,12 @@ uniform float dof_height;  VARYING vec2 vary_fragcoord; -vec4 dofSample(sampler2DRect tex, vec2 tc) +vec4 dofSample(sampler2D tex, vec2 tc)  {  	tc.x = min(tc.x, dof_width);  	tc.y = min(tc.y, dof_height); -	return texture2DRect(tex, tc); +	return texture2D(tex, tc);  }  void main()  @@ -60,7 +60,7 @@ void main()  	vec4 dof = dofSample(diffuseRect, vary_fragcoord.xy*res_scale); -	vec4 diff = texture2DRect(lightMap, vary_fragcoord.xy); +	vec4 diff = texture2D(lightMap, vary_fragcoord.xy);  	float a = min(abs(diff.a*2.0-1.0) * max_cof*res_scale*res_scale, 1.0); @@ -69,10 +69,10 @@ void main()  		float sc = a/res_scale;  		vec4 col; -		col = texture2DRect(lightMap, vary_fragcoord.xy+vec2(sc,sc)); -		col += texture2DRect(lightMap, vary_fragcoord.xy+vec2(-sc,sc)); -		col += texture2DRect(lightMap, vary_fragcoord.xy+vec2(sc,-sc)); -		col += texture2DRect(lightMap, vary_fragcoord.xy+vec2(-sc,-sc)); +		col = texture2D(lightMap, vary_fragcoord.xy+vec2(sc,sc)/screen_res); +		col += texture2D(lightMap, vary_fragcoord.xy+vec2(-sc,sc)/screen_res); +		col += texture2D(lightMap, vary_fragcoord.xy+vec2(sc,-sc)/screen_res); +		col += texture2D(lightMap, vary_fragcoord.xy+vec2(-sc,-sc)/screen_res);  		diff = mix(diff, col*0.25, a);  	} diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl index 57420158ca..73e5b401c0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl @@ -54,35 +54,44 @@ vec3 fullbrightScaleSoftClip(vec3 light);  uniform float minimum_alpha;  #endif +#ifdef IS_ALPHA +void waterClip(vec3 pos); +#endif +  void main()   { + +#ifdef IS_ALPHA +    waterClip(vary_position.xyz); +#endif +  #ifdef HAS_DIFFUSE_LOOKUP -	vec4 color = diffuseLookup(vary_texcoord0.xy); +    vec4 color = diffuseLookup(vary_texcoord0.xy);  #else -	vec4 color = texture2D(diffuseMap, vary_texcoord0.xy); +    vec4 color = texture2D(diffuseMap, vary_texcoord0.xy);  #endif -	float final_alpha = color.a * vertex_color.a; +    float final_alpha = color.a * vertex_color.a;  #ifdef HAS_ALPHA_MASK -	if (color.a < minimum_alpha) -	{ -		discard; -	} +    if (color.a < minimum_alpha) +    { +        discard; +    }  #endif -	color.rgb *= vertex_color.rgb; +    color.rgb *= vertex_color.rgb;  #ifdef WATER_FOG -	vec3 pos = vary_position; -	vec4 fogged = applyWaterFogView(pos, vec4(color.rgb, final_alpha)); -	color.rgb = fogged.rgb; -	color.a   = fogged.a; +    vec3 pos = vary_position; +    vec4 fogged = applyWaterFogView(pos, vec4(color.rgb, final_alpha)); +    color.rgb = fogged.rgb; +    color.a   = fogged.a;  #else      color.a   = final_alpha;  #endif -	frag_color.rgb = color.rgb; -	frag_color.a   = color.a; +    frag_color.rgb = srgb_to_linear(color.rgb); +    frag_color.a   = color.a;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl index 9fcee04c32..f693323d45 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl @@ -38,7 +38,7 @@ uniform sampler2D diffuseMap;  VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0;  VARYING vec3 vary_texcoord1; -VARYING vec4 vary_position; +VARYING vec3 vary_position;  uniform samplerCube environmentMap; @@ -74,7 +74,7 @@ void main()  	vec3 amblit;  	vec3 additive;  	vec3 atten; -		vec3 pos = vary_position.xyz/vary_position.w; +	vec3 pos = vary_position.xyz;  	calcAtmosphericVars(pos.xyz, vec3(0), 1.0, sunlit, amblit, additive, atten, false); diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl index 3bd6b693fa..0e461b4004 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyV.glsl @@ -45,7 +45,7 @@ ATTRIBUTE vec2 texcoord0;  VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0;  VARYING vec3 vary_texcoord1; -VARYING vec4 vary_position; +VARYING vec3 vary_position;  #ifdef HAS_SKIN  mat4 getObjectSkinnedTransform(); @@ -62,17 +62,18 @@ void main()      mat4 mat = getObjectSkinnedTransform();      mat = modelview_matrix * mat;      vec4 pos = mat * vert; -    vary_position = gl_Position = projection_matrix * pos; +    gl_Position = projection_matrix * pos;  	vec3 norm = normalize((mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz);  #else  	vec4 pos = (modelview_matrix * vert); -	vary_position = gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0); +	gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0);  	vec3 norm = normalize(normal_matrix * normal);  #endif -	vec3 ref = reflect(pos.xyz, -norm); +    vary_position = pos.xyz;  	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; -	vary_texcoord1 = (texture_matrix1 * vec4(ref,1.0)).xyz; + +    vary_texcoord1 = norm;  	calcAtmospherics(pos.xyz); diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl index e71636f2c9..e565722164 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl @@ -38,9 +38,7 @@ void calcAtmospherics(vec3 inPositionEye);  vec3 atmosAmbient();  vec3 atmosAffectDirectionalLight(float lightIntensity); -#ifdef WATER_FOG  VARYING vec3 vary_position; -#endif  VARYING vec4 vertex_color;  VARYING vec2 vary_texcoord0; @@ -66,9 +64,7 @@ void main()  	gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0);  #endif -#ifdef WATER_FOG  	vary_position = pos.xyz; -#endif  	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; diff --git a/indra/newview/app_settings/shaders/class1/deferred/genbrdflutF.glsl b/indra/newview/app_settings/shaders/class1/deferred/genbrdflutF.glsl new file mode 100644 index 0000000000..9e6c853015 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/genbrdflutF.glsl @@ -0,0 +1,141 @@ +/**  + * @file class1/deferred/genbrdflut.glsl + * + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, 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$ + */ + +/*  Taken from Sascha Willem's Vulkan GLTF refernce implementation +MIT License + +Copyright (c) 2018 Sascha Willems + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/*[EXTRA_CODE_HERE]*/ + +VARYING vec2 vary_uv; + +out vec4 outColor; + +#define NUM_SAMPLES 1024u + +const float PI = 3.1415926536; + +// Based omn http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/ +float random(vec2 co) +{ +	float a = 12.9898; +	float b = 78.233; +	float c = 43758.5453; +	float dt= dot(co.xy ,vec2(a,b)); +	float sn= mod(dt,3.14); +	return fract(sin(sn) * c); +} + +vec2 hammersley2d(uint i, uint N)  +{ +	// Radical inverse based on http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html +	uint bits = (i << 16u) | (i >> 16u); +	bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u); +	bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u); +	bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u); +	bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u); +	float rdi = float(bits) * 2.3283064365386963e-10; +	return vec2(float(i) /float(N), rdi); +} + +// Based on http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_slides.pdf +vec3 importanceSample_GGX(vec2 Xi, float roughness, vec3 normal)  +{ +	// Maps a 2D point to a hemisphere with spread based on roughness +	float alpha = roughness * roughness; +	float phi = 2.0 * PI * Xi.x + random(normal.xz) * 0.1; +	float cosTheta = sqrt((1.0 - Xi.y) / (1.0 + (alpha*alpha - 1.0) * Xi.y)); +	float sinTheta = sqrt(1.0 - cosTheta * cosTheta); +	vec3 H = vec3(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta); + +	// Tangent space +	vec3 up = abs(normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0); +	vec3 tangentX = normalize(cross(up, normal)); +	vec3 tangentY = normalize(cross(normal, tangentX)); + +	// Convert to world Space +	return normalize(tangentX * H.x + tangentY * H.y + normal * H.z); +} + +// Geometric Shadowing function +float G_SchlicksmithGGX(float dotNL, float dotNV, float roughness) +{ +	float k = (roughness * roughness) / 2.0; +	float GL = dotNL / (dotNL * (1.0 - k) + k); +	float GV = dotNV / (dotNV * (1.0 - k) + k); +	return GL * GV; +} + +vec2 BRDF(float NoV, float roughness) +{ +	// Normal always points along z-axis for the 2D lookup  +	const vec3 N = vec3(0.0, 0.0, 1.0); +	vec3 V = vec3(sqrt(1.0 - NoV*NoV), 0.0, NoV); + +	vec2 LUT = vec2(0.0); +	for(uint i = 0u; i < NUM_SAMPLES; i++) { +		vec2 Xi = hammersley2d(i, NUM_SAMPLES); +		vec3 H = importanceSample_GGX(Xi, roughness, N); +		vec3 L = 2.0 * dot(V, H) * H - V; + +		float dotNL = max(dot(N, L), 0.0); +		float dotNV = max(dot(N, V), 0.0); +		float dotVH = max(dot(V, H), 0.0);  +		float dotNH = max(dot(H, N), 0.0); + +		if (dotNL > 0.0) { +			float G = G_SchlicksmithGGX(dotNL, dotNV, roughness); +			float G_Vis = (G * dotVH) / (dotNH * dotNV); +			float Fc = pow(1.0 - dotVH, 5.0); +			LUT += vec2((1.0 - Fc) * G_Vis, Fc * G_Vis); +		} +	} +	return LUT / float(NUM_SAMPLES); +} + +void main()  +{ +	outColor = vec4(BRDF(vary_uv.s, 1.0-vary_uv.t), 0.0, 1.0); +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowV.glsl b/indra/newview/app_settings/shaders/class1/deferred/genbrdflutV.glsl index effb070f93..682244478b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/cloudShadowV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/genbrdflutV.glsl @@ -1,9 +1,9 @@  /**  - * @file cloudShadowV.glsl + * @file class3\deferred\genbrdflutV.glsl   * - * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * $LicenseInfo:firstyear=2022&license=viewerlgpl$   * Second Life Viewer Source Code - * Copyright (C) 2011, Linden Research, Inc. + * Copyright (C) 2022, 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 @@ -23,41 +23,17 @@   * $/LicenseInfo$   */ -uniform mat4 texture_matrix0;  uniform mat4 modelview_projection_matrix; -uniform float shadow_target_width;  ATTRIBUTE vec3 position; -ATTRIBUTE vec4 diffuse_color; -ATTRIBUTE vec2 texcoord0; -#if !defined(DEPTH_CLAMP) -VARYING float pos_zd2; -#endif - -VARYING vec4 pos; -VARYING float target_pos_x; -VARYING vec2 vary_texcoord0; -VARYING vec4 vertex_color; - -void passTextureIndex(); +VARYING vec2 vary_uv;  void main()  {  	//transform vertex -	vec4 pre_pos = vec4(position.xyz, 1.0); -	pos = modelview_projection_matrix * pre_pos; -	target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; - -#if !defined(DEPTH_CLAMP) -	pos_zd2 = pos.z * 0.5; -	gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); -#else -	gl_Position = pos; -#endif -	 -	passTextureIndex(); +	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); +	vary_uv = position.xy*0.5+0.5; -	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; -	vertex_color = diffuse_color; +	gl_Position = vec4(position.xyz, 1.0);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/highlightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/highlightF.glsl index 90566393d2..75f914cb02 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/highlightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/highlightF.glsl @@ -38,5 +38,5 @@ void main()  {  	frag_data[0] = color*texture2D(diffuseMap, vary_texcoord0.xy);  	frag_data[1] = vec4(0.0); -	frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0); +	frag_data[2] = vec4(0.0, 1.0, 0.0, GBUFFER_FLAG_SKIP_ATMOS);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl index a58cc3d12d..51afda2791 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl @@ -41,6 +41,7 @@ uniform sampler2D specularMap;  VARYING vec2 vary_texcoord0;  vec3 linear_to_srgb(vec3 c); +vec2 encode_normal (vec3 n);  void main()   { @@ -56,5 +57,5 @@ void main()  	frag_data[0] = vec4(col.rgb, 0.0);  	frag_data[1] = spec; -	frag_data[2] = norm; +	frag_data[2] = vec4(encode_normal(norm.xyz),0,GBUFFER_FLAG_HAS_ATMOS);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl index be1003a7e0..185c1150ef 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/luminanceF.glsl @@ -31,10 +31,10 @@ out vec4 frag_color;  #define frag_color gl_FragColor  #endif -uniform sampler2DRect diffuseMap; +uniform sampler2D diffuseMap;  VARYING vec2 vary_fragcoord;  void main()   { -	frag_color = texture2DRect(diffuseMap, vary_fragcoord.xy); +	frag_color = texture2D(diffuseMap, vary_fragcoord.xy);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/luminanceV.glsl b/indra/newview/app_settings/shaders/class1/deferred/luminanceV.glsl index f2dc60aa5d..5488a63c6a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/luminanceV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/luminanceV.glsl @@ -39,7 +39,7 @@ void main()  	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);  	gl_Position = pos; -	vary_fragcoord = (pos.xy * 0.5 + 0.5)*screen_res;	 +	vary_fragcoord = (pos.xy * 0.5 + 0.5);	  	vertex_color = diffuse_color;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index b30d7655db..51a36935f2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -23,431 +23,30 @@  * $/LicenseInfo$  */ +  /*[EXTRA_CODE_HERE]*/  //class1/deferred/materialF.glsl -// This shader is used for both writing opaque/masked content to the gbuffer and writing blended content to the framebuffer during the alpha pass. +// Debug stub for non-pbr material -#define DIFFUSE_ALPHA_MODE_NONE     0  #define DIFFUSE_ALPHA_MODE_BLEND    1 -#define DIFFUSE_ALPHA_MODE_MASK     2 -#define DIFFUSE_ALPHA_MODE_EMISSIVE 3 - -uniform float emissive_brightness;  // fullbright flag, 1.0 == fullbright, 0.0 otherwise -uniform int sun_up_factor; - -#ifdef WATER_FOG -vec4 applyWaterFogView(vec3 pos, vec4 color); -#endif - -vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 scaleSoftClipFrag(vec3 l); - -vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); -vec3 fullbrightScaleSoftClip(vec3 light); - -void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao); - -vec3 srgb_to_linear(vec3 cs); -vec3 linear_to_srgb(vec3 cs);  #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - -#ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_color;  #else -#define frag_color gl_FragColor -#endif - -#ifdef HAS_SUN_SHADOW -float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen); +out vec4 frag_data[4];  #endif -uniform samplerCube environmentMap; -uniform sampler2D     lightFunc; - -// Inputs -uniform vec4 morphFactor; -uniform vec3 camPosLocal; -uniform mat3 env_mat; - -uniform vec3 sun_dir; -uniform vec3 moon_dir; -VARYING vec2 vary_fragcoord; - -VARYING vec3 vary_position; - -uniform mat4 proj_mat; -uniform mat4 inv_proj; -uniform vec2 screen_res; - -uniform vec4 light_position[8]; -uniform vec3 light_direction[8]; -uniform vec4 light_attenuation[8]; -uniform vec3 light_diffuse[8]; - -float getAmbientClamp(); - -vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spec, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight, inout float glare, float ambiance) -{ -    // SL-14895 inverted attenuation work-around -    // This routine is tweaked to match deferred lighting, but previously used an inverted la value. To reconstruct -    // that previous value now that the inversion is corrected, we reverse the calculations in LLPipeline::setupHWLights() -    // to recover the `adjusted_radius` value previously being sent as la. -    float falloff_factor = (12.0 * fa) - 9.0; -    float inverted_la = falloff_factor / la; -    // Yes, it makes me want to cry as well. DJH -     -    vec3 col = vec3(0); - -    //get light vector -    vec3 lv = lp.xyz - v; - -    //get distance -    float dist = length(lv); -    float da = 1.0; - -    dist /= inverted_la; - -    if (dist > 0.0 && inverted_la > 0.0) -    { -        //normalize light vector -        lv = normalize(lv); - -        //distance attenuation -        float dist_atten = clamp(1.0 - (dist - 1.0*(1.0 - fa)) / fa, 0.0, 1.0); -        dist_atten *= dist_atten; -        dist_atten *= 2.0f; - -        if (dist_atten <= 0.0) -        { -            return col; -        } - -        // spotlight coefficient. -        float spot = max(dot(-ln, lv), is_pointlight); -        da *= spot*spot; // GL_SPOT_EXPONENT=2 - -        //angular attenuation -        da *= dot(n, lv); - -        float lit = 0.0f; - -        float amb_da = ambiance; -        if (da >= 0) -        { -            lit = max(da * dist_atten, 0.0); -            col = lit * light_col * diffuse; -            amb_da += (da*0.5 + 0.5) * ambiance; -        } -        amb_da += (da*da*0.5 + 0.5) * ambiance; -        amb_da *= dist_atten; -        amb_da = min(amb_da, 1.0f - lit); - -        // SL-10969 need to see why these are blown out -        //col.rgb += amb_da * light_col * diffuse; - -        if (spec.a > 0.0) -        { -            //vec3 ref = dot(pos+lv, norm); -            vec3 h = normalize(lv + npos); -            float nh = dot(n, h); -            float nv = dot(n, npos); -            float vh = dot(npos, h); -            float sa = nh; -            float fres = pow(1 - dot(h, npos), 5)*0.4 + 0.5; - -            float gtdenom = 2 * nh; -            float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - -            if (nh > 0.0) -            { -                float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt / (nh*da); -                vec3 speccol = lit*scol*light_col.rgb*spec.rgb; -                speccol = clamp(speccol, vec3(0), vec3(1)); -                col += speccol; - -                float cur_glare = max(speccol.r, speccol.g); -                cur_glare = max(cur_glare, speccol.b); -                glare = max(glare, speccol.r); -                glare += max(cur_glare, 0.0); -            } -        } -    } - -    return max(col, vec3(0.0, 0.0, 0.0)); -} - -#else -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif -#endif - -uniform sampler2D diffuseMap;  //always in sRGB space - -#ifdef HAS_NORMAL_MAP -uniform sampler2D bumpMap; -#endif - -#ifdef HAS_SPECULAR_MAP -uniform sampler2D specularMap; - -VARYING vec2 vary_texcoord2; -#endif - -uniform float env_intensity; -uniform vec4 specular_color;  // specular color RGB and specular exponent (glossiness) in alpha - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) -uniform float minimum_alpha; -#endif - -#ifdef HAS_NORMAL_MAP -VARYING vec3 vary_mat0; -VARYING vec3 vary_mat1; -VARYING vec3 vary_mat2; -VARYING vec2 vary_texcoord1; -#else -VARYING vec3 vary_normal; -#endif - -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; - -vec2 encode_normal(vec3 n); -  void main()  { -    vec2 pos_screen = vary_texcoord0.xy; - -    vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); -	diffcol.rgb *= vertex_color.rgb; - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) - -    // Comparing floats cast from 8-bit values, produces acne right at the 8-bit transition points -    float bias = 0.001953125; // 1/512, or half an 8-bit quantization (SL-18637) -    if (diffcol.a < minimum_alpha-bias) -    { -        discard; -    } -#endif -  #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) -	vec3 gamma_diff = diffcol.rgb; -	diffcol.rgb = srgb_to_linear(diffcol.rgb); -#endif - -#ifdef HAS_SPECULAR_MAP -    vec4 spec = texture2D(specularMap, vary_texcoord2.xy); -    spec.rgb *= specular_color.rgb; +    frag_color = vec4(1, 0, 0, 0.5);  #else -    vec4 spec = vec4(specular_color.rgb, 1.0); -#endif - -#ifdef HAS_NORMAL_MAP -	vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); - -	norm.xyz = norm.xyz * 2 - 1; - -	vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), -			  dot(norm.xyz,vary_mat1), -			  dot(norm.xyz,vary_mat2)); -#else -	vec4 norm = vec4(0,0,0,1.0); -	vec3 tnorm = vary_normal; -#endif - -    norm.xyz = normalize(tnorm.xyz); - -    vec2 abnormal = encode_normal(norm.xyz); - -    vec4 final_color = diffcol; - -#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) -	final_color.a = emissive_brightness; -#else -	final_color.a = max(final_color.a, emissive_brightness); -#endif - -    vec4 final_specular = spec; -     -#ifdef HAS_SPECULAR_MAP -    vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity * spec.a, 0.0); -	final_specular.a = specular_color.a * norm.a; -#else -	vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); -	final_specular.a = specular_color.a; -#endif - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - -    //forward rendering, output just lit sRGBA -    vec3 pos = vary_position; - -    float shadow = 1.0f; - -#ifdef HAS_SUN_SHADOW -    shadow = sampleDirectionalShadow(pos.xyz, norm.xyz, pos_screen); -#endif - -    spec = final_specular; -    vec4 diffuse = final_color; -    float envIntensity = final_normal.z; - -    vec3 color = vec3(0,0,0); - -    vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; - -    float bloom = 0.0; -    vec3 sunlit; -    vec3 amblit; -    vec3 additive; -    vec3 atten; - -    calcAtmosphericVars(pos.xyz, light_dir, 1.0, sunlit, amblit, additive, atten, false); -     -        // This call breaks the Mac GLSL compiler/linker for unknown reasons (17Mar2020) -        // The call is either a no-op or a pure (pow) gamma adjustment, depending on GPU level -        // TODO: determine if we want to re-apply the gamma adjustment, and if so understand & fix Mac breakage -        //color = fullbrightScaleSoftClip(color); - -    vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - -    //we're in sRGB space, so gamma correct this dot product so  -    // lighting from the sun stays sharp -    float da = clamp(dot(normalize(norm.xyz), light_dir.xyz), 0.0, 1.0); -    da = pow(da, 1.0 / 1.3); - -    color = amblit; - -    //darken ambient for normals perpendicular to light vector so surfaces in shadow  -    // and facing away from light still have some definition to them. -    // do NOT gamma correct this dot product so ambient lighting stays soft -    float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); -    ambient *= 0.5; -    ambient *= ambient; -    ambient = (1.0 - ambient); - -    vec3 sun_contrib = min(da, shadow) * sunlit; -     -    color *= ambient; - -    color += sun_contrib; - -    color *= gamma_diff.rgb; - -    float glare = 0.0; - -    if (spec.a > 0.0)  // specular reflection -    { -        /*  // Reverting this specular calculation to previous 'dumbshiny' version - DJH 6/17/2020 -            // Preserving the refactored version as a comment for potential reconsideration, -            // overriding the general rule to avoid pollutiong the source with commented code. -            // -            //  If you're reading this in 2021+, feel free to obliterate. - -        vec3 npos = -normalize(pos.xyz); - -        //vec3 ref = dot(pos+lv, norm); -        vec3 h = normalize(light_dir.xyz + npos); -        float nh = dot(norm.xyz, h); -        float nv = dot(norm.xyz, npos); -        float vh = dot(npos, h); -        float sa = nh; -        float fres = pow(1 - dot(h, npos), 5)*0.4 + 0.5; - -        float gtdenom = 2 * nh; -        float gt = max(0, min(gtdenom * nv / vh, gtdenom * da / vh)); - -        if (nh > 0.0) -        { -            float scol = fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt / (nh*da); -            vec3 sp = sun_contrib*scol / 6.0f; -            sp = clamp(sp, vec3(0), vec3(1)); -            bloom = dot(sp, sp) / 4.0; -            color += sp * spec.rgb; -        } -        */ - -        float sa        = dot(refnormpersp, sun_dir.xyz); -        vec3  dumbshiny = sunlit * shadow * (texture2D(lightFunc, vec2(sa, spec.a)).r); - -        // add the two types of shiny together -        vec3 spec_contrib = dumbshiny * spec.rgb; -        bloom             = dot(spec_contrib, spec_contrib) / 6; - -        glare = max(spec_contrib.r, spec_contrib.g); -        glare = max(glare, spec_contrib.b); - -        color += spec_contrib; -    } - -    color = mix(color.rgb, diffcol.rgb, diffuse.a); - -    if (envIntensity > 0.0) -    { -        //add environmentmap -        vec3 env_vec = env_mat * refnormpersp; - -        vec3 reflected_color = textureCube(environmentMap, env_vec).rgb; - -        color = mix(color, reflected_color, envIntensity); - -        float cur_glare = max(reflected_color.r, reflected_color.g); -        cur_glare = max(cur_glare, reflected_color.b); -        cur_glare *= envIntensity*4.0; -        glare += cur_glare; -    } - -    color = atmosFragLighting(color, additive, atten); -    color = scaleSoftClipFrag(color); - -    //convert to linear before adding local lights -    color = srgb_to_linear(color); - -    vec3 npos = normalize(-pos.xyz); - -    vec3 light = vec3(0, 0, 0); -     -    final_specular.rgb = srgb_to_linear(final_specular.rgb); // SL-14035 - -#define LIGHT_LOOP(i) light.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, light_attenuation[i].w ); - -    LIGHT_LOOP(1) -        LIGHT_LOOP(2) -        LIGHT_LOOP(3) -        LIGHT_LOOP(4) -        LIGHT_LOOP(5) -        LIGHT_LOOP(6) -        LIGHT_LOOP(7) - -    color += light; - -    glare = min(glare, 1.0); -    float al = max(diffcol.a, glare)*vertex_color.a; - -    //convert to srgb as this color is being written post gamma correction -    color = linear_to_srgb(color); - -#ifdef WATER_FOG -    vec4 temp = applyWaterFogView(pos, vec4(color, al)); -    color = temp.rgb; -    al = temp.a; -#endif - -    frag_color = vec4(color, al); - -#else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer  - -    // deferred path -    frag_data[0] = final_color; //gbuffer is sRGB -    frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. -    frag_data[2] = final_normal; // XY = Normal.  Z = Env. intensity. +    // emissive red 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(1, 0, 0, 0);  #endif  } - diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl index 7e29ada205..a1cab87092 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl @@ -1,5 +1,5 @@  /**  - * @file bumpV.glsl + * @file materialV.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code diff --git a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl index 35068899ee..7032c45603 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/moonF.glsl @@ -34,8 +34,7 @@ out vec4 frag_data[3];  #endif  uniform vec4 color; -uniform vec4 sunlight_color; -uniform vec4 moonlight_color; +uniform vec3 moonlight_color;  uniform vec3 moon_dir;  uniform float moon_brightness;  uniform sampler2D diffuseMap; @@ -55,6 +54,12 @@ void main()          fade = clamp( moon_dir.z*moon_dir.z*4.0, 0.0, 1.0 );      vec4 c      = texture2D(diffuseMap, vary_texcoord0.xy); + +    // SL-14113 Don't write to depth; prevent moon's quad from hiding stars which should be visible +    // Moon texture has transparent pixels <0x55,0x55,0x55,0x00> +    if (c.a <= 2./255.) // 0.00784 +        discard; +  //       c.rgb  = srgb_to_linear(c.rgb);           c.rgb *= moonlight_color.rgb;           c.rgb *= moon_brightness; @@ -66,8 +71,8 @@ void main()      frag_data[0] = vec4(c.rgb, c.a);      frag_data[1] = vec4(0.0); -    frag_data[2] = vec4(0.0f); +    frag_data[2] = vec4(0.0, 0.0, 0.0, GBUFFER_FLAG_HAS_ATMOS); -    gl_FragDepth = 0.999985f; +    gl_FragDepth = LL_SHADER_CONST_CLOUD_MOON_DEPTH; // SL-14113  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 09c47165dd..6763e2de7b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -33,10 +33,9 @@ out vec4 frag_color;  #define frag_color gl_FragColor  #endif -uniform sampler2DRect depthMap; -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform samplerCube   environmentMap; +uniform sampler2D depthMap; +uniform sampler2D diffuseRect; +uniform sampler2D specularRect;  uniform sampler2D     noiseMap;  uniform sampler2D     lightFunc; @@ -55,6 +54,8 @@ VARYING vec4 vary_fragcoord;  vec4 getPosition(vec2 pos_screen);  vec3 getNorm(vec2 pos_screen);  vec3 srgb_to_linear(vec3 c); +float getDepth(vec2 tc); +vec2 getScreenCoord(vec4 clip);  void main()  { @@ -63,7 +64,7 @@ void main()  #endif      vec3 out_col = vec3(0, 0, 0); -    vec2 frag    = (vary_fragcoord.xy * 0.5 + 0.5) * screen_res; +    vec2 frag    = getScreenCoord(vary_fragcoord);      vec3 pos     = getPosition(frag.xy).xyz;      if (pos.z < far_z)      { @@ -72,10 +73,10 @@ void main()      vec3 norm = getNorm(frag.xy); -    vec4 spec = texture2DRect(specularRect, frag.xy); -    vec3 diff = texture2DRect(diffuseRect, frag.xy).rgb; +    vec4 spec = texture2D(specularRect, frag.xy); +    vec3 diff = texture2D(diffuseRect, frag.xy).rgb; -    float noise = texture2D(noiseMap, frag.xy / 128.0).b; +    float noise = texture2D(noiseMap, frag.xy).b;      vec3  npos  = normalize(-pos);      // As of OSX 10.6.7 ATI Apple's crash when using a variable size loop diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightV.glsl index eefefa640d..d71dc76423 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightV.glsl @@ -23,8 +23,6 @@   * $/LicenseInfo$   */ -uniform mat4 modelview_projection_matrix; -  ATTRIBUTE vec3 position;  VARYING vec4 vary_fragcoord; @@ -32,7 +30,7 @@ VARYING vec4 vary_fragcoord;  void main()  {  	//transform vertex -	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); +	vec4 pos = vec4(position.xyz, 1.0);  	vary_fragcoord = pos;  	gl_Position = pos; diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index ec3fb9c543..e9dac711c3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -38,11 +38,10 @@ out vec4 frag_color;  #define frag_color gl_FragColor  #endif -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect depthMap; -uniform sampler2DRect normalMap; -uniform samplerCube environmentMap; +uniform sampler2D diffuseRect; +uniform sampler2D specularRect; +uniform sampler2D depthMap; +uniform sampler2D normalMap;  uniform sampler2D noiseMap;  uniform sampler2D projectionMap;  uniform sampler2D lightFunc; @@ -73,6 +72,7 @@ uniform vec2 screen_res;  uniform mat4 inv_proj;  vec3 getNorm(vec2 pos_screen);  vec3 srgb_to_linear(vec3 c); +float getDepth(vec2 tc);  vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod)  { @@ -138,7 +138,6 @@ void main()  	vec4 frag = vary_fragcoord;  	frag.xyz /= frag.w;  	frag.xyz = frag.xyz*0.5+0.5; -	frag.xy *= screen_res;  	vec3 pos = getPosition(frag.xy).xyz;  	vec3 lv = center.xyz-pos.xyz; @@ -149,7 +148,7 @@ void main()  		discard;  	} -	float envIntensity = texture2DRect(normalMap, frag.xy).z; +	float envIntensity = texture2D(normalMap, frag.xy).z;  	vec3 norm = getNorm(frag.xy);  	float l_dist = -dot(lv, proj_n); @@ -173,7 +172,7 @@ void main()  		discard;  	} -	float noise = texture2D(noiseMap, frag.xy/128.0).b; +	float noise = texture2D(noiseMap, frag.xy).b;  	dist_atten *= noise;  	lv = proj_origin-pos.xyz; @@ -181,7 +180,7 @@ void main()  	float da = dot(norm, lv); -	vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; +	vec3 diff_tex = texture2D(diffuseRect, frag.xy).rgb;  	vec3 dlit = vec3(0, 0, 0); @@ -221,7 +220,7 @@ void main()  	} -	vec4 spec = texture2DRect(specularRect, frag.xy); +	vec4 spec = texture2D(specularRect, frag.xy);  	if (spec.a > 0.0)  	{ diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbralphaF.glsl index 44f2a73e1f..fc1024f4f1 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbralphaF.glsl @@ -1,9 +1,9 @@  /**  - * @file shadowAlphaMaskF.glsl + * @file class1\deferred\pbralphaF.glsl   * - * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * $LicenseInfo:firstyear=2022&license=viewerlgpl$   * Second Life Viewer Source Code - * Copyright (C) 2011, Linden Research, Inc. + * Copyright (C) 2022, 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 @@ -25,31 +25,10 @@  /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif -uniform sampler2D diffuseMap; - -#if !defined(DEPTH_CLAMP) -VARYING float pos_zd2; -#endif - -VARYING float pos_w; - -VARYING float target_pos_x; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; - -void main()  +void main()  { -	float alpha = diffuseLookup(vary_texcoord0.xy).a * vertex_color.a; - -	frag_color = vec4(alpha, alpha, alpha, 1); -	 -#if !defined(DEPTH_CLAMP) -	gl_FragDepth = max(pos_zd2/pos_w+0.5, 0.0); -#endif +    frag_color = vec4(0,1,0,0.5);  } + diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl new file mode 100644 index 0000000000..a2ad1b70fb --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/pbralphaV.glsl @@ -0,0 +1,120 @@ +/**  + * @file class1\deferred\pbralphaV.glsl + * + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, 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$ + */ + +#define DIFFUSE_ALPHA_MODE_IGNORE 0 +#define DIFFUSE_ALPHA_MODE_BLEND 1 +#define DIFFUSE_ALPHA_MODE_MASK 2 +#define DIFFUSE_ALPHA_MODE_EMISSIVE 3 + +#ifdef HAS_SKIN +uniform mat4 modelview_matrix; +uniform mat4 projection_matrix; +mat4 getObjectSkinnedTransform(); +#else +uniform mat3 normal_matrix; +uniform mat4 modelview_projection_matrix; +#endif +uniform mat4 texture_matrix0; + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) +  #if !defined(HAS_SKIN) +    uniform mat4 modelview_matrix; +  #endif +    VARYING vec3 vary_position; +#endif + +uniform mat3 texture_basecolor_matrix; +uniform mat3 texture_normal_matrix; +uniform mat3 texture_metallic_roughness_matrix; +uniform mat3 texture_emissive_matrix; + +#ifdef HAS_SUN_SHADOW +out vec3 vary_fragcoord; +uniform float near_clip; +#endif + +in vec3 position; +in vec4 diffuse_color; +in vec3 normal; +in vec4 tangent; +in vec2 texcoord0; + +out vec2 basecolor_texcoord; +out vec2 normal_texcoord; +out vec2 metallic_roughness_texcoord; +out vec2 emissive_texcoord; + +out vec4 vertex_color; + +out vec3 vary_tangent; +flat out float vary_sign; +out vec3 vary_normal; + + +void main() +{ +#ifdef HAS_SKIN +	mat4 mat = getObjectSkinnedTransform(); +	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 +    vec4 vert = projection_matrix * vec4(pos,1.0); +#else +	//transform vertex +    vec4 vert = modelview_projection_matrix * vec4(position.xyz, 1.0); +#endif +    gl_Position = vert; + +#ifdef HAS_SUN_SHADOW +    vary_fragcoord.xyz = vert.xyz + vec3(0,0,near_clip); +#endif + +	basecolor_texcoord = (texture_matrix0 * vec4(texture_basecolor_matrix * vec3(texcoord0,1), 1)).xy; +	normal_texcoord = (texture_matrix0 * vec4(texture_normal_matrix * vec3(texcoord0,1), 1)).xy; +	metallic_roughness_texcoord = (texture_matrix0 * vec4(texture_metallic_roughness_matrix * vec3(texcoord0,1), 1)).xy; +	emissive_texcoord = (texture_matrix0 * vec4(texture_emissive_matrix * vec3(texcoord0,1), 1)).xy; + +#ifdef HAS_SKIN +	vec3 n = (mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz; +	vec3 t = (mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz; +#else //HAS_SKIN +	vec3 n = normal_matrix * normal; +  	vec3 t = normal_matrix * tangent.xyz; +#endif //HAS_SKIN + +    vary_tangent = normalize(t); +    vary_sign = tangent.w; +    vary_normal = normalize(n); + +	vertex_color = diffuse_color; + +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) +  #if !defined(HAS_SKIN) +	vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz; +  #endif +#endif +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl new file mode 100644 index 0000000000..39419e9d78 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl @@ -0,0 +1,103 @@ +/**  + * @file pbropaqueF.glsl + * + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, 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$ + */ + +/*[EXTRA_CODE_HERE]*/ + +uniform sampler2D diffuseMap;  //always in sRGB space + +uniform float metallicFactor; +uniform float roughnessFactor; +uniform vec3 emissiveColor; +uniform sampler2D bumpMap; +uniform sampler2D emissiveMap; +uniform sampler2D specularMap; // Packed: Occlusion, Metal, Roughness + +out vec4 frag_data[4]; + +in vec3 vary_position; +in vec4 vertex_color; +in vec3 vary_normal; +in vec3 vary_tangent; +flat in float vary_sign; + +in vec2 basecolor_texcoord; +in vec2 normal_texcoord; +in vec2 metallic_roughness_texcoord; +in vec2 emissive_texcoord; + +uniform float minimum_alpha; // PBR alphaMode: MASK, See: mAlphaCutoff, setAlphaCutoff() + +vec2 encode_normal(vec3 n); +vec3 linear_to_srgb(vec3 c); +vec3 srgb_to_linear(vec3 c); + +uniform mat3 normal_matrix; + +void main() +{ +    vec4 basecolor = texture2D(diffuseMap, basecolor_texcoord.xy).rgba; +    if (basecolor.a < minimum_alpha) +    { +        discard; +    } + +    vec3 col = vertex_color.rgb * srgb_to_linear(basecolor.rgb); + +    // from mikktspace.com +    vec3 vNt = texture2D(bumpMap, normal_texcoord.xy).xyz*2.0-1.0; +    float sign = vary_sign; +    vec3 vN = vary_normal; +    vec3 vT = vary_tangent.xyz; +     +    vec3 vB = sign * cross(vN, vT); +    vec3 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN ); + +    // RGB = Occlusion, Roughness, Metal +    // default values, see LLViewerTexture::sDefaultPBRORMImagep +    //   occlusion 1.0 +    //   roughness 0.0 +    //   metal     0.0 +    vec3 spec = texture2D(specularMap, metallic_roughness_texcoord.xy).rgb; +     +    spec.g *= roughnessFactor; +    spec.b *= metallicFactor; + +    vec3 emissive = emissiveColor; +    emissive *= srgb_to_linear(texture2D(emissiveMap, emissive_texcoord.xy).rgb); + +    tnorm *= gl_FrontFacing ? 1.0 : -1.0; + +    //spec.rgb = vec3(1,1,0); +    //col = vec3(0,0,0); +    //emissive = vary_tangent.xyz*0.5+0.5; +    //emissive = vec3(sign*0.5+0.5); +    //emissive = vNt * 0.5 + 0.5; +    //emissive = tnorm*0.5+0.5; +    // See: C++: addDeferredAttachments(), GLSL: softenLightF +    frag_data[0] = vec4(col, 0.0);                                                   // Diffuse +    frag_data[1] = vec4(spec.rgb,vertex_color.a);                                    // PBR linear packed Occlusion, Roughness, Metal. +    frag_data[2] = vec4(encode_normal(tnorm), vertex_color.a, GBUFFER_FLAG_HAS_PBR); // normal, environment intensity, flags +    frag_data[3] = vec4(emissive,0);                                                // PBR sRGB Emissive +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl new file mode 100644 index 0000000000..5a69da641a --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl @@ -0,0 +1,97 @@ +/**  + * @file pbropaqueV.glsl + * + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, 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$ + */ + +#define DIFFUSE_ALPHA_MODE_IGNORE 0 +#define DIFFUSE_ALPHA_MODE_BLEND 1 +#define DIFFUSE_ALPHA_MODE_MASK 2 +#define DIFFUSE_ALPHA_MODE_EMISSIVE 3 + +#ifdef HAS_SKIN +uniform mat4 modelview_matrix; +uniform mat4 projection_matrix; +mat4 getObjectSkinnedTransform(); +#else +uniform mat3 normal_matrix; +uniform mat4 modelview_projection_matrix; +#endif +uniform mat4 texture_matrix0; + +uniform mat3 texture_basecolor_matrix; +uniform mat3 texture_normal_matrix; +uniform mat3 texture_metallic_roughness_matrix; +uniform mat3 texture_emissive_matrix; + +in vec3 position; +in vec4 diffuse_color; +in vec3 normal; +in vec4 tangent; +in vec2 texcoord0; + +out vec2 basecolor_texcoord; +out vec2 normal_texcoord; +out vec2 metallic_roughness_texcoord; +out vec2 emissive_texcoord; +  +out vec4 vertex_color; + +out vec3 vary_tangent; +flat out float vary_sign; +out vec3 vary_normal; + +void main() +{ +#ifdef HAS_SKIN +	mat4 mat = getObjectSkinnedTransform(); + +	mat = modelview_matrix * mat; + +	vec3 pos = (mat*vec4(position.xyz,1.0)).xyz; + +	gl_Position = projection_matrix*vec4(pos,1.0); + +#else +	//transform vertex +	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);  +#endif +	 +	basecolor_texcoord = (texture_matrix0 * vec4(texture_basecolor_matrix * vec3(texcoord0,1), 1)).xy; +	normal_texcoord = (texture_matrix0 * vec4(texture_normal_matrix * vec3(texcoord0,1), 1)).xy; +	metallic_roughness_texcoord = (texture_matrix0 * vec4(texture_metallic_roughness_matrix * vec3(texcoord0,1), 1)).xy; +	emissive_texcoord = (texture_matrix0 * vec4(texture_emissive_matrix * vec3(texcoord0,1), 1)).xy; + +#ifdef HAS_SKIN +	vec3 n = (mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz; +	vec3 t = (mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz; +#else //HAS_SKIN +	vec3 n = normal_matrix * normal; +	vec3 t = normal_matrix * tangent.xyz; +#endif + +    vary_tangent = normalize(t); +    vary_sign = tangent.w; +    vary_normal = normalize(n); +	 +	vertex_color = diffuse_color; +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 18616a9bb3..f07ef92b26 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -1,5 +1,5 @@  /**  - * @file pointLightF.glsl + * @file class1\deferred\pointLightF.glsl   *   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code @@ -33,13 +33,12 @@ out vec4 frag_color;  #define frag_color gl_FragColor  #endif -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect normalMap; -uniform samplerCube environmentMap; +uniform sampler2D diffuseRect; +uniform sampler2D specularRect; +uniform sampler2D normalMap;  uniform sampler2D noiseMap;  uniform sampler2D lightFunc; -uniform sampler2DRect depthMap; +uniform sampler2D depthMap;  uniform vec3 env_mat[3];  uniform float sun_wash; @@ -58,6 +57,7 @@ uniform vec4 viewport;  vec3 getNorm(vec2 pos_screen);  vec4 getPosition(vec2 pos_screen); +float getDepth(vec2 pos);  vec3 srgb_to_linear(vec3 c);  void main()  @@ -65,7 +65,6 @@ void main()      vec4 frag = vary_fragcoord;      frag.xyz /= frag.w;      frag.xyz = frag.xyz*0.5+0.5; -    frag.xy *= screen_res;      vec3 pos = getPosition(frag.xy).xyz;      vec3 lv = trans_center.xyz-pos; @@ -87,9 +86,9 @@ void main()      lv = normalize(lv);      da = dot(norm, lv); -    float noise = texture2D(noiseMap, frag.xy/128.0).b; +    float noise = texture2D(noiseMap, frag.xy).b; -    vec3 col = texture2DRect(diffuseRect, frag.xy).rgb; +    vec3 col = texture2D(diffuseRect, frag.xy).rgb;      float fa = falloff+1.0;      float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); @@ -100,7 +99,7 @@ void main()      col = color.rgb*lit*col; -    vec4 spec = texture2DRect(specularRect, frag.xy); +    vec4 spec = texture2D(specularRect, frag.xy);      if (spec.a > 0.0)      {          lit = min(da*6.0, 1.0) * dist_atten; @@ -126,6 +125,7 @@ void main()      {          discard;      } +    final_color.rgb = vec3(getDepth(frag.xy));      frag_color.rgb = col;         frag_color.a = 0.0; diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl index f06f8c870b..5ca39d6966 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredF.glsl @@ -33,7 +33,7 @@ out vec4 frag_color;  #define frag_color gl_FragColor  #endif -uniform sampler2DRect diffuseRect; +uniform sampler2D diffuseRect;  uniform mat4 inv_proj;  uniform vec2 screen_res; @@ -44,7 +44,7 @@ VARYING vec2 vary_fragcoord;  void dofSample(inout vec4 diff, inout float w, float min_sc, vec2 tc)  { -	vec4 s = texture2DRect(diffuseRect, tc); +	vec4 s = texture2D(diffuseRect, tc);  	float sc = abs(s.a*2.0-1.0)*max_cof; @@ -63,7 +63,7 @@ void dofSample(inout vec4 diff, inout float w, float min_sc, vec2 tc)  void dofSampleNear(inout vec4 diff, inout float w, float min_sc, vec2 tc)  { -	vec4 s = texture2DRect(diffuseRect, tc); +	vec4 s = texture2D(diffuseRect, tc);  	float wg = 0.25; @@ -79,7 +79,7 @@ void main()  {  	vec2 tc = vary_fragcoord.xy; -	vec4 diff = texture2DRect(diffuseRect, vary_fragcoord.xy); +	vec4 diff = texture2D(diffuseRect, vary_fragcoord.xy);  	{   		float w = 1.0; @@ -93,14 +93,14 @@ void main()  		{  			while (sc > 0.5)  			{ -				int its = int(max(1.0,(sc*3.7))); +				int its = int(max(1.0,(sc*3.7)));	  				for (int i=0; i<its; ++i)  				{  					float ang = sc+i*2*PI/its; // sc is added for rotary perturbance  					float samp_x = sc*sin(ang);  					float samp_y = sc*cos(ang);  					// you could test sample coords against an interesting non-circular aperture shape here, if desired. -					dofSampleNear(diff, w, sc, vary_fragcoord.xy + vec2(samp_x,samp_y)); +					dofSampleNear(diff, w, sc, vary_fragcoord.xy + (vec2(samp_x,samp_y) / screen_res));  				}  				sc -= 1.0;  			} @@ -117,7 +117,7 @@ void main()  					float samp_x = sc*sin(ang);  					float samp_y = sc*cos(ang);  					// you could test sample coords against an interesting non-circular aperture shape here, if desired. -					dofSample(diff, w, sc, vary_fragcoord.xy + vec2(samp_x,samp_y)); +					dofSample(diff, w, sc, vary_fragcoord.xy + (vec2(samp_x,samp_y) / screen_res));  				}  				sc -= 1.0;  			} @@ -125,6 +125,6 @@ void main()  		diff /= w;  	} -		 +	  	frag_color = diff;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index cd37a34e0d..a73a59bc6f 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -33,7 +33,7 @@ out vec4 frag_color;  #define frag_color gl_FragColor  #endif -uniform sampler2DRect diffuseRect; +uniform sampler2D diffuseRect;  uniform vec2 screen_res;  VARYING vec2 vary_fragcoord; @@ -41,12 +41,53 @@ uniform float display_gamma;  vec3 linear_to_srgb(vec3 cl); +//================================= +// borrowed noise from: +//	<https://www.shadertoy.com/view/4dS3Wd> +//	By Morgan McGuire @morgan3d, http://graphicscodex.com +// +float hash(float n) { return fract(sin(n) * 1e4); } +float hash(vec2 p) { return fract(1e4 * sin(17.0 * p.x + p.y * 0.1) * (0.1 + abs(sin(p.y * 13.0 + p.x)))); } + +float noise(float x) { +	float i = floor(x); +	float f = fract(x); +	float u = f * f * (3.0 - 2.0 * f); +	return mix(hash(i), hash(i + 1.0), u); +} + +float noise(vec2 x) { +	vec2 i = floor(x); +	vec2 f = fract(x); + +	// Four corners in 2D of a tile +	float a = hash(i); +	float b = hash(i + vec2(1.0, 0.0)); +	float c = hash(i + vec2(0.0, 1.0)); +	float d = hash(i + vec2(1.0, 1.0)); + +	// Simple 2D lerp using smoothstep envelope between the values. +	// return vec3(mix(mix(a, b, smoothstep(0.0, 1.0, f.x)), +	//			mix(c, d, smoothstep(0.0, 1.0, f.x)), +	//			smoothstep(0.0, 1.0, f.y))); + +	// Same code, with the clamps in smoothstep and common subexpressions +	// optimized away. +	vec2 u = f * f * (3.0 - 2.0 * f); +	return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y; +} + +//============================= +  void main()   {      //this is the one of the rare spots where diffuseRect contains linear color values (not sRGB) -    vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); -    //diff.rgb = pow(diff.rgb, vec3(display_gamma)); +    vec4 diff = texture2D(diffuseRect, vary_fragcoord);      diff.rgb = linear_to_srgb(diff.rgb); +    vec3 seed = (diff.rgb+vec3(1.0))*vec3(vary_fragcoord.xy, vary_fragcoord.x+vary_fragcoord.y); +    vec3 nz = vec3(noise(seed.rg), noise(seed.gb), noise(seed.rb)); +    diff.rgb += nz*0.008; +    //diff.rgb = nz;      frag_color = diff;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl index 058941bfb2..a79f644aef 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoDoFF.glsl @@ -33,7 +33,7 @@ out vec4 frag_color;  #define frag_color gl_FragColor  #endif -uniform sampler2DRect diffuseRect; +uniform sampler2D diffuseRect;  uniform sampler2D bloomMap;  uniform vec2 screen_res; @@ -41,9 +41,9 @@ VARYING vec2 vary_fragcoord;  void main()   { -	vec4 diff = texture2DRect(diffuseRect, vary_fragcoord.xy); +	vec4 diff = texture2D(diffuseRect, vary_fragcoord.xy); -	vec4 bloom = texture2D(bloomMap, vary_fragcoord.xy/screen_res); +	vec4 bloom = texture2D(bloomMap, vary_fragcoord.xy);  	frag_color = diff + bloom;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoTCV.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoTCV.glsl index bd0cb50464..4d24b4de9a 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoTCV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredNoTCV.glsl @@ -23,8 +23,6 @@   * $/LicenseInfo$   */ -uniform mat4 modelview_projection_matrix; -  ATTRIBUTE vec3 position;  VARYING vec2 vary_fragcoord; @@ -34,7 +32,7 @@ uniform vec2 screen_res;  void main()  {  	//transform vertex -	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); +	vec4 pos = vec4(position.xyz, 1.0);  	gl_Position = pos;	 -	vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; +	vary_fragcoord = (pos.xy*0.5+0.5);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredV.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredV.glsl index 8edf5b2723..86f0077edb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredV.glsl @@ -23,8 +23,6 @@   * $/LicenseInfo$   */ -uniform mat4 modelview_projection_matrix; -  ATTRIBUTE vec3 position;  VARYING vec2 vary_fragcoord; @@ -37,8 +35,8 @@ uniform vec2 screen_res;  void main()  {  	//transform vertex -	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); +	vec4 pos = vec4(position.xyz, 1.0);  	gl_Position = pos;	  	vary_tc = (pos.xy*0.5+0.5)*tc_scale; -	vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; +	vary_fragcoord = (pos.xy*0.5+0.5);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl b/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl index cf994d3547..8111f43c28 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postgiF.glsl @@ -31,9 +31,9 @@ out vec4 frag_color;  #define frag_color gl_FragColor  #endif -uniform sampler2DRect depthMap; -uniform sampler2DRect normalMap; -uniform sampler2DRect giLightMap; +uniform sampler2D depthMap; +uniform sampler2D normalMap; +uniform sampler2D giLightMap;  uniform sampler2D	noiseMap;  uniform vec2 kern[32]; @@ -53,11 +53,11 @@ vec4 getPosition(vec2 pos_screen);  void main()   { -	vec3 norm = texture2DRect(normalMap, vary_fragcoord.xy).xyz; +	vec3 norm = texture2D(normalMap, vary_fragcoord.xy).xyz;  	norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm  	vec3 pos = getPosition(vary_fragcoord.xy).xyz; -	vec3 ccol = texture2DRect(giLightMap, vary_fragcoord.xy).rgb; +	vec3 ccol = texture2D(giLightMap, vary_fragcoord.xy).rgb;  	vec2 dlt = kern_scale * delta/(1.0+norm.xy*norm.xy);  	dlt /= max(-pos.z*dist_factor, 1.0);  	float defined_weight = kern[0].x; @@ -66,7 +66,7 @@ void main()  	for (int i = 0; i < kern_length; i++)  	{  		vec2 tc = vary_fragcoord.xy + kern[i].y*dlt; -		vec3 sampNorm = texture2DRect(normalMap, tc.xy).xyz; +		vec3 sampNorm = texture2D(normalMap, tc.xy).xyz;  		sampNorm = vec3((sampNorm.xy-0.5)*2.0,sampNorm.z); // unpack norm  		float d = dot(norm.xyz, sampNorm); @@ -77,7 +77,7 @@ void main()  			samppos -= pos;  			if (dot(samppos,samppos) < -0.05*pos.z)  			{ -	    		col += texture2DRect(giLightMap, tc).rgb*kern[i].x; +	    		col += texture2D(giLightMap, tc).rgb*kern[i].x;  				defined_weight += kern[i].x;  			}  		} diff --git a/indra/newview/app_settings/shaders/class1/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class1/deferred/reflectionProbeF.glsl new file mode 100644 index 0000000000..dd850ff97c --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/reflectionProbeF.glsl @@ -0,0 +1,58 @@ +/** + * @file class1/deferred/reflectionProbeF.glsl + * + * $LicenseInfo:firstyear=2022&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2022, 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$ + */ + +// fallback stub -- will be used if actual reflection probe shader failed to load (output pink so it's obvious) +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, +        vec3 pos, vec3 norm, float glossiness, bool errorCorrect) +{ +    ambenv = vec3(1,0,1); +    glossenv = vec3(1,0,1); +} + +void sampleReflectionProbes(inout vec3 ambenv, inout vec3 glossenv, +    vec3 pos, vec3 norm, float glossiness) +{ +    sampleReflectionProbes(ambenv, glossenv, +        pos, norm, glossiness, false); +} + +void sampleReflectionProbesLegacy(inout vec3 ambenv, inout vec3 glossenv, inout vec3 legacyenv,  +        vec3 pos, vec3 norm, float glossiness, float envIntensity) +{ +    ambenv = vec3(1,0,1); +    glossenv = vec3(1,0,1); +    legacyenv = vec3(1,0,1); +} + +void applyGlossEnv(inout vec3 color, vec3 glossenv, vec4 spec, vec3 pos, vec3 norm) +{ +     +} + +void applyLegacyEnv(inout vec3 color, vec3 legacyenv, vec4 spec, vec3 pos, vec3 norm, float envIntensity) +{ + +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflPostF.glsl b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflPostF.glsl new file mode 100644 index 0000000000..8373567bb0 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflPostF.glsl @@ -0,0 +1,57 @@ +/** + * @file class3/deferred/screenSpaceReflPostF.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_color; +#else +#define frag_color gl_FragColor +#endif + +uniform vec2 screen_res; +uniform mat4 projection_matrix; +uniform mat4 inv_proj; +uniform float zNear; +uniform float zFar; + +VARYING vec2 vary_fragcoord; + +uniform sampler2D depthMap; +uniform sampler2D normalMap; +uniform sampler2D sceneMap; +uniform sampler2D diffuseRect; + +vec3 getNorm(vec2 screenpos); +float getDepth(vec2 pos_screen); +float linearDepth(float d, float znear, float zfar); + +void main() { +    vec2  tc = vary_fragcoord.xy; +    vec4 pos = getPositionWithDepth(tc, getDepth(tc)); +    frag_color = pos; +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflPostV.glsl b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflPostV.glsl new file mode 100644 index 0000000000..966e7e1cbb --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflPostV.glsl @@ -0,0 +1,39 @@ +/** + * @file class3/deferred/screenSpaceReflPostV.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$ + */ + +ATTRIBUTE vec3 position; + +uniform vec2 screen_res; + +VARYING vec2 vary_fragcoord; + +void main() +{ +	//transform vertex +	vec4 pos = vec4(position.xyz, 1.0); +	gl_Position = pos;  +     +	vary_fragcoord = pos.xy * 0.5 + 0.5; +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl new file mode 100644 index 0000000000..6dfc89a6c6 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/screenSpaceReflUtil.glsl @@ -0,0 +1,120 @@ +/** + * @file class3/deferred/screenSpaceReflUtil.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$ + */ + +uniform sampler2D depthMap; +uniform sampler2D normalMap; +uniform sampler2D sceneMap; +uniform vec2 screen_res; +uniform mat4 projection_matrix; + +// Shamelessly taken from http://casual-effects.blogspot.com/2014/08/screen-space-ray-tracing.html +// Original paper: https://jcgt.org/published/0003/04/04/ +// By Morgan McGuire and Michael Mara at Williams College 2014 +// Released as open source under the BSD 2-Clause License +// http://opensource.org/licenses/BSD-2-Clause + +float distanceSquared(vec2 a, vec2 b) { a -= b; return dot(a, a); } + +bool traceScreenSpaceRay1(vec3 csOrig, vec3 csDir, mat4 proj, float zThickness,  +                            float nearPlaneZ, float stride, float jitter, const float maxSteps, float maxDistance, +                            out vec2 hitPixel, out vec3 hitPoint) +{ + +    // Clip to the near plane     +    float rayLength = ((csOrig.z + csDir.z * maxDistance) > nearPlaneZ) ? +        (nearPlaneZ - csOrig.z) / csDir.z : maxDistance; +    vec3 csEndPoint = csOrig + csDir * rayLength; + +    // Project into homogeneous clip space +    vec4 H0 = proj * vec4(csOrig, 1.0); +    vec4 H1 = proj * vec4(csEndPoint, 1.0); +    float k0 = 1.0 / H0.w, k1 = 1.0 / H1.w; + +    // The interpolated homogeneous version of the camera-space points   +    vec3 Q0 = csOrig * k0, Q1 = csEndPoint * k1; + +    // Screen-space endpoints +    vec2 P0 = H0.xy * k0, P1 = H1.xy * k1; + +    // If the line is degenerate, make it cover at least one pixel +    // to avoid handling zero-pixel extent as a special case later +    P1 += vec2((distanceSquared(P0, P1) < 0.0001) ? 0.01 : 0.0); +    vec2 delta = P1 - P0; + +    // Permute so that the primary iteration is in x to collapse +    // all quadrant-specific DDA cases later +    bool permute = false; +    if (abs(delta.x) < abs(delta.y)) {  +        // This is a more-vertical line +        permute = true; delta = delta.yx; P0 = P0.yx; P1 = P1.yx;  +    } + +    float stepDir = sign(delta.x); +    float invdx = stepDir / delta.x; + +    // Track the derivatives of Q and k +    vec3  dQ = (Q1 - Q0) * invdx; +    float dk = (k1 - k0) * invdx; +    vec2  dP = vec2(stepDir, delta.y * invdx); + +    // Scale derivatives by the desired pixel stride and then +    // offset the starting values by the jitter fraction +    dP *= stride; dQ *= stride; dk *= stride; +    P0 += dP * jitter; Q0 += dQ * jitter; k0 += dk * jitter; + +    // Slide P from P0 to P1, (now-homogeneous) Q from Q0 to Q1, k from k0 to k1 +    vec3 Q = Q0;  + +    // Adjust end condition for iteration direction +    float  end = P1.x * stepDir; + +    float k = k0, stepCount = 0.0, prevZMaxEstimate = csOrig.z; +    float rayZMin = prevZMaxEstimate, rayZMax = prevZMaxEstimate; +    float sceneZMax = rayZMax + 100; +    for (vec2 P = P0;  +         ((P.x * stepDir) <= end) && (stepCount < maxSteps) && +         ((rayZMax < sceneZMax - zThickness) || (rayZMin > sceneZMax)) && +          (sceneZMax != 0);  +         P += dP, Q.z += dQ.z, k += dk, ++stepCount) { +         +        rayZMin = prevZMaxEstimate; +        rayZMax = (dQ.z * 0.5 + Q.z) / (dk * 0.5 + k); +        prevZMaxEstimate = rayZMax; +        if (rayZMin > rayZMax) {  +           float t = rayZMin; rayZMin = rayZMax; rayZMax = t; +        } + +        hitPixel = permute ? P.yx : P; +        hitPixel.y = screen_res.y - hitPixel.y; +        // You may need hitPixel.y = screen_res.y - hitPixel.y; here if your vertical axis +        // is different than ours in screen space +        sceneZMax = texelFetch(depthMap, ivec2(hitPixel)).r; +    } +     +    // Advance Q based on the number of steps +    Q.xy += dQ.xy * stepCount; +    hitPoint = Q * (1.0 / k); +    return (rayZMax >= sceneZMax - zThickness) && (rayZMin < sceneZMax); +} diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl deleted file mode 100644 index f45c343066..0000000000 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaBlendV.glsl +++ /dev/null @@ -1,67 +0,0 @@ -/**  - * @file shadowAlphaMaskV.glsl - * - * $LicenseInfo:firstyear=2011&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2011, 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$ - */ - -uniform mat4 texture_matrix0; -uniform mat4 modelview_projection_matrix; -uniform float shadow_target_width; - -ATTRIBUTE vec3 position; -ATTRIBUTE vec4 diffuse_color; -ATTRIBUTE vec2 texcoord0; - -#if !defined(DEPTH_CLAMP) -VARYING float pos_zd2; -#endif - -VARYING float pos_w; - -VARYING float target_pos_x; -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; - -void passTextureIndex(); - -void main() -{ -	//transform vertex -	vec4 pre_pos = vec4(position.xyz, 1.0); -	vec4 pos = modelview_projection_matrix * pre_pos; -	target_pos_x = 0.5 * (shadow_target_width - 1.0) * pos.x; - -	pos_w = pos.w; - -#if !defined(DEPTH_CLAMP) -	pos_zd2 = pos.z * 0.5; -	 -	gl_Position = vec4(pos.x, pos.y, pos.w*0.5, pos.w); -#else -	gl_Position = pos; -#endif -	 -	passTextureIndex(); - -	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy; -	vertex_color = diffuse_color; -} diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl index 9b8df0a5a4..1a344045fe 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowAlphaMaskF.glsl @@ -43,8 +43,7 @@ void main()  {  	float alpha = diffuseLookup(vary_texcoord0.xy).a; -    // mask cutoff 0 -> no shadow SL-11051 -    if (minimum_alpha == 0) +    if (alpha < minimum_alpha)      {          discard;      } @@ -53,18 +52,19 @@ void main()      alpha *= vertex_color.a;  #endif -	if (alpha < 0.05) // treat as totally transparent -	{ -		discard; -	} +    if (alpha < 0.05) // treat as totally transparent +    { +        discard; +    } + +    if (alpha < 0.88) // treat as semi-transparent +    { +        if (fract(0.5*floor(target_pos_x / post_pos.w )) < 0.25) +        { +            discard; +        } +    } -	if (alpha < 0.88) // treat as semi-transparent -	{ -	  if (fract(0.5*floor(target_pos_x / post_pos.w )) < 0.25) -	  { -	    discard; -	  } -	}  	frag_color = vec4(1,1,1,1); diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index 4134220306..5dc219702d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -23,8 +23,8 @@   * $/LicenseInfo$   */ -uniform sampler2DRect   normalMap; -uniform sampler2DRect   depthMap; +uniform sampler2D   normalMap; +uniform sampler2D   depthMap;  uniform sampler2DShadow shadowMap0;  uniform sampler2DShadow shadowMap1;  uniform sampler2DShadow shadowMap2; diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl index 331249dc33..adc2db60b6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyF.glsl @@ -35,7 +35,7 @@ out vec4 frag_data[3];  // The fragment shader for the sky  ///////////////////////////////////////////////////////////////////////// -VARYING vec4 vary_HazeColor; +VARYING vec3 vary_HazeColor;  /// Soft clips the light with a gamma correction  vec3 scaleSoftClip(vec3 light); @@ -48,7 +48,7 @@ void main()      // the fragment) if the sky wouldn't show up because the clouds       // are fully opaque. -    vec4 color; +    vec3 color;      color = vary_HazeColor;      color.rgb *= 2.; @@ -57,7 +57,7 @@ void main()      /// Gamma correct for WL (soft clip effect).      frag_data[0] = vec4(color.rgb, 0.0);      frag_data[1] = vec4(0.0,0.0,0.0,0.0); -    frag_data[2] = vec4(0.0,0.0,0.0,1.0); //1.0 in norm.w masks off fog +    frag_data[2] = vec4(0.0,0.0,0.0,GBUFFER_FLAG_SKIP_ATMOS); //1.0 in norm.w masks off fog      gl_FragDepth = 0.99999f;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl index 28a1faf24f..ff53646fd4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/skyV.glsl @@ -32,18 +32,18 @@ ATTRIBUTE vec3 position;  ///////////////////////////////////////////////////////////////////////////////  // Output parameters -VARYING vec4 vary_HazeColor; +VARYING vec3 vary_HazeColor;  // Inputs  uniform vec3 camPosLocal; -uniform vec4  lightnorm; -uniform vec4  sunlight_color; -uniform vec4  moonlight_color; +uniform vec3  lightnorm; +uniform vec3  sunlight_color; +uniform vec3  moonlight_color;  uniform int   sun_up_factor; -uniform vec4  ambient_color; -uniform vec4  blue_horizon; -uniform vec4  blue_density; +uniform vec3  ambient_color; +uniform vec3  blue_horizon; +uniform vec3  blue_density;  uniform float haze_horizon;  uniform float haze_density; @@ -52,11 +52,9 @@ uniform float density_multiplier;  uniform float distance_multiplier;  uniform float max_y; -uniform vec4  glow; +uniform vec3  glow;  uniform float sun_moon_glow_factor; -uniform vec4 cloud_color; -  // NOTE: Keep these in sync!  //       indra\newview\app_settings\shaders\class1\deferred\skyV.glsl  //       indra\newview\app_settings\shaders\class1\deferred\cloudsV.glsl @@ -87,17 +85,17 @@ void main()      float rel_pos_len = length(rel_pos);      // Initialize temp variables -    vec4 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; -    vec4 light_atten; +    vec3 sunlight = (sun_up_factor == 1) ? sunlight_color : moonlight_color; +    vec3 light_atten;      // Sunlight attenuation effect (hue and brightness) due to atmosphere      // this is used later for sunlight modulation at various altitudes -    light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); +    light_atten = (blue_density + vec3(haze_density * 0.25)) * (density_multiplier * max_y);      // Calculate relative weights -    vec4 combined_haze = abs(blue_density) + vec4(abs(haze_density)); -    vec4 blue_weight   = blue_density / combined_haze; -    vec4 haze_weight   = haze_density / combined_haze; +    vec3 combined_haze = abs(blue_density) + vec4(abs(haze_density)); +    vec3 blue_weight   = blue_density / combined_haze; +    vec3 haze_weight   = haze_density / combined_haze;      // Compute sunlight from rel_pos & lightnorm (for long rays like sky)      float off_axis = 1.0 / max(1e-6, max(0., rel_pos_norm.y) + lightnorm.y); @@ -125,21 +123,21 @@ void main()      // For sun, add to glow.  For moon, remove glow entirely. SL-13768      haze_glow = (sun_moon_glow_factor < 1.0) ? 0.0 : (haze_glow + 0.25); -    vec4 color = +    vec3 color =          (blue_horizon * blue_weight * (sunlight + ambient_color) + (haze_horizon * haze_weight) * (sunlight * haze_glow + ambient_color));      // Final atmosphere additive      color *= (1. - combined_haze);      // Increase ambient when there are more clouds -    vec4 tmpAmbient = ambient_color; -    tmpAmbient += max(vec4(0), (1. - ambient_color)) * cloud_shadow * 0.5; +    vec3 tmpAmbient = ambient_color; +    tmpAmbient += max(vec3(0), (1. - ambient_color)) * cloud_shadow * 0.5;      // Dim sunlight by cloud shadow percentage      sunlight *= max(0.0, (1. - cloud_shadow));      // Haze color below cloud -    vec4 additiveColorBelowCloud = +    vec3 additiveColorBelowCloud =          (blue_horizon * blue_weight * (sunlight + tmpAmbient) + (haze_horizon * haze_weight) * (sunlight * haze_glow + tmpAmbient));      // Attenuate cloud color by atmosphere diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 7f2c603f87..152402907b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -34,11 +34,11 @@ out vec4 frag_color;  #define frag_color gl_FragColor  #endif -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect normalMap; -uniform sampler2DRect lightMap; -uniform sampler2DRect depthMap; +uniform sampler2D diffuseRect; +uniform sampler2D specularRect; +uniform sampler2D normalMap; +uniform sampler2D lightMap; +uniform sampler2D depthMap;  uniform samplerCube environmentMap;  uniform sampler2D     lightFunc; @@ -58,6 +58,7 @@ uniform vec2 screen_res;  vec3 getNorm(vec2 pos_screen);  vec4 getPositionWithDepth(vec2 pos_screen, float depth); +float getDepth(vec2 pos_screen);  void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten, bool use_ao);  float getAmbientClamp(); @@ -76,9 +77,9 @@ vec4 applyWaterFogView(vec3 pos, vec4 color);  void main()   {      vec2 tc = vary_fragcoord.xy; -    float depth = texture2DRect(depthMap, tc.xy).r; +    float depth = getDepth(tc);      vec4 pos = getPositionWithDepth(tc, depth); -    vec4 norm = texture2DRect(normalMap, tc); +    vec4 norm = texture2D(normalMap, tc);      float envIntensity = norm.z;      norm.xyz = getNorm(tc); @@ -87,12 +88,12 @@ void main()      float light_gamma = 1.0/1.3;      da = pow(da, light_gamma); -    vec4 diffuse = texture2DRect(diffuseRect, tc); +    vec4 diffuse = texture2D(diffuseRect, tc);      //convert to gamma space      diffuse.rgb = linear_to_srgb(diffuse.rgb); // SL-14035 -    vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); +    vec4 spec = texture2D(specularRect, vary_fragcoord.xy);      vec3 color = vec3(0);      float bloom = 0.0;      { @@ -142,7 +143,7 @@ void main()              color = mix(color.rgb, reflected_color, envIntensity);          } -        if (norm.w < 0.5) +        if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_ATMOS))          {              color = mix(atmosFragLighting(color, additive, atten), fullbrightAtmosTransportFrag(color, additive, atten), diffuse.a);              color = mix(scaleSoftClipFrag(color), fullbrightScaleSoftClip(color), diffuse.a); @@ -156,12 +157,6 @@ void main()      } -// linear debuggables -//color.rgb = vec3(final_da); -//color.rgb = vec3(ambient); -//color.rgb = vec3(scol); -//color.rgb = diffuse_srgb.rgb; -      // convert to linear as fullscreen lights need to sum in linear colorspace      // and will be gamma (re)corrected downstream... diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl index 8891315e15..23ad332db4 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightV.glsl @@ -22,8 +22,6 @@   * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA   * $/LicenseInfo$   */ -  -uniform mat4 modelview_projection_matrix;  ATTRIBUTE vec3 position; @@ -36,10 +34,10 @@ VARYING vec2 vary_fragcoord;  void main()  {      //transform vertex -    vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); +    vec4 pos = vec4(position.xyz, 1.0);      gl_Position = pos;       // appease OSX GLSL compiler/linker by touching all the varyings we said we would      setAtmosAttenuation(vec3(1));      setAdditiveColor(vec3(0)); -    vary_fragcoord = (pos.xy*0.5+0.5)*screen_res; +    vary_fragcoord = (pos.xy*0.5+0.5);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 694b19cdfb..0376f42319 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -36,10 +36,10 @@ out vec4 frag_color;  //class 1 -- no shadows -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect depthMap; -uniform sampler2DRect normalMap; +uniform sampler2D diffuseRect; +uniform sampler2D specularRect; +uniform sampler2D depthMap; +uniform sampler2D normalMap;  uniform samplerCube environmentMap;  uniform sampler2D noiseMap;  uniform sampler2D projectionMap; @@ -137,7 +137,6 @@ void main()  	vec4 frag = vary_fragcoord;  	frag.xyz /= frag.w;  	frag.xyz = frag.xyz*0.5+0.5; -	frag.xy *= screen_res;  	vec3 pos = getPosition(frag.xy).xyz;  	vec3 lv = trans_center.xyz-pos.xyz; @@ -148,7 +147,7 @@ void main()  		discard;  	} -	vec3 norm = texture2DRect(normalMap, frag.xy).xyz; +	vec3 norm = texture2D(normalMap, frag.xy).xyz;  	float envIntensity = norm.z;  	norm = getNorm(frag.xy);  	norm = normalize(norm); @@ -176,13 +175,13 @@ void main()  	lv = normalize(lv);  	float da = dot(norm, lv); -	vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; +	vec3 diff_tex = texture2D(diffuseRect, frag.xy).rgb;  	//light shaders output linear and are gamma corrected later in postDeferredGammaCorrectF.glsl      diff_tex.rgb = srgb_to_linear(diff_tex.rgb); -	vec4 spec = texture2DRect(specularRect, frag.xy); +	vec4 spec = texture2D(specularRect, frag.xy); -	float noise = texture2D(noiseMap, frag.xy/128.0).b; +	float noise = texture2D(noiseMap, frag.xy).b;  	vec3 dlit = vec3(0, 0, 0);  	if (proj_tc.z > 0.0 && diff --git a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl index bac79a9fdc..6376527273 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/starsF.glsl @@ -46,8 +46,13 @@ float twinkle(){      return abs(d);  } +// See: +// ALM off: class1/environment/starsF.glsl +// ALM on : class1/deferred/starsF.glsl  void main()   { +	// camera above water: class1\deferred\starsF.glsl +	// camera below water: class1\environment\starsF.glsl      vec4 col_a = texture2D(diffuseMap, vary_texcoord0.xy);      vec4 col_b = texture2D(diffuseMap, vary_texcoord0.xy);      vec4 col = mix(col_b, col_a, blend_factor); @@ -60,8 +65,8 @@ void main()      frag_data[0] = col;      frag_data[1] = vec4(0.0f); -    frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0); +    frag_data[2] = vec4(0.0, 1.0, 0.0, GBUFFER_FLAG_SKIP_ATMOS); -    gl_FragDepth = 0.99995f; +    gl_FragDepth = LL_SHADER_CONST_STAR_DEPTH; // SL-14113 Moon Haze -- Stars need to depth test behind the moon  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl index b2fa5d8a25..4ab8747629 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunDiscF.glsl @@ -57,7 +57,7 @@ void main()      frag_data[0] = c;      frag_data[1] = vec4(0.0f); -    frag_data[2] = vec4(0.0, 1.0, 0.0, 1.0); +    frag_data[2] = vec4(0.0, 1.0, 0.0, GBUFFER_FLAG_SKIP_ATMOS);      gl_FragDepth = 0.999988f;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index 15f141cbe5..d9a0b6c702 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -35,7 +35,7 @@ out vec4 frag_color;  //class 1 -- no shadow, SSAO only -uniform sampler2DRect normalMap; +uniform sampler2D normalMap;  // Inputs  VARYING vec2 vary_fragcoord; diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightV.glsl index 473d6df8fa..9d70b9d98d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightV.glsl @@ -22,8 +22,6 @@   * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA   * $/LicenseInfo$   */ - -uniform mat4 modelview_projection_matrix;  ATTRIBUTE vec3 position; @@ -34,8 +32,8 @@ uniform vec2 screen_res;  void main()  {  	//transform vertex -	vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0); +	vec4 pos = vec4(position.xyz, 1.0);  	gl_Position = pos;  -	vary_fragcoord = (pos.xy * 0.5 + 0.5)*screen_res;	 +	vary_fragcoord = (pos.xy * 0.5 + 0.5);	  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl index 6b6eed9db8..d6c14c48c9 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/terrainF.glsl @@ -63,6 +63,6 @@ void main()      frag_data[0] = outColor;      frag_data[1] = vec4(0.0,0.0,0.0,-1.0);      vec3 nvn = normalize(vary_normal); -    frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0); +    frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl index 89e354558a..dc0e5b0ce3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl @@ -52,5 +52,5 @@ void main()  	frag_data[0] = vec4(vertex_color.rgb*col.rgb, 0.0);  	frag_data[1] = vec4(0,0,0,0);  	vec3 nvn = normalize(vary_normal); -	frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, 0.0); +	frag_data[2] = vec4(encode_normal(nvn.xyz), 0.0, GBUFFER_FLAG_HAS_ATMOS);  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl index 9a5debb3c1..14c337e608 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl @@ -78,5 +78,5 @@ void main()  	frag_data[0] = vec4(fb.rgb, 1.0); // diffuse  	frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec -	frag_data[2] = vec4(encode_normal(wavef), 0.0, 0.0); // normalxyz, env intens, atmo kill +	frag_data[2] = vec4(encode_normal(wavef), 0.0, GBUFFER_FLAG_HAS_ATMOS); // normalxyz, env intens, flags (atmo kill)  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index a157e9c017..876422f86b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -22,163 +22,15 @@   * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA   * $/LicenseInfo$   */ -  -#extension GL_ARB_texture_rectangle : enable -/*[EXTRA_CODE_HERE]*/ +// debug stub +out vec4 frag_data[4]; -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#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.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(color.rgb, color);  // Effectively, color.rgbr - - -    frag_data[1] = vec4(0);		// speccolor, spec -	frag_data[2] = vec4(encode_normal(screenspacewavef.xyz), 0.05, 0);// normalxy, 0, 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/deferred/waterV.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl index 8863869e44..38276859a0 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterV.glsl @@ -70,7 +70,7 @@ void main()  	d *= d;  	oPosition = vec4(position, 1.0); -	oPosition.z = mix(oPosition.z, max(eyeVec.z*0.75, 0.0), d); +//	oPosition.z = mix(oPosition.z, max(eyeVec.z*0.75, 0.0), d); // SL-11589 remove "U" shaped horizon  	vary_position = modelview_matrix * oPosition;  	oPosition = modelViewProj * oPosition;  | 
