diff options
Diffstat (limited to 'indra/newview/app_settings/shaders')
17 files changed, 820 insertions, 1018 deletions
| diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 5e3c767460..33e61f2062 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -94,46 +94,46 @@ void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit,  vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight)  { -	//get light vector -	vec3 lv = lp.xyz-v; -	 -	//get distance -	float d = length(lv); -	 -	float da = 1.0; - -	vec3 col = vec3(0); - -	if (d > 0.0 && la > 0.0 && fa > 0.0) -	{ -		//normalize light vector -		lv = normalize(lv); -	 -		//distance attenuation -		float dist = d/la; -		float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); -		dist_atten *= dist_atten; -		dist_atten *= 2.0; - -		// spotlight coefficient. -		float spot = max(dot(-ln, lv), is_pointlight); -		da *= spot*spot; // GL_SPOT_EXPONENT=2 - -		//angular attenuation -		da *= max(dot(n, lv), 0.0);		 - -		float lit = max(da * dist_atten,0.0); - -		col = light_col * lit * diffuse; - -		// no spec for alpha shader... -	} - -	return max(col, vec3(0.0,0.0,0.0)); +    //get light vector +    vec3 lv = lp.xyz-v; +     +    //get distance +    float d = length(lv); +     +    float da = 1.0; + +    vec3 col = vec3(0); + +    if (d > 0.0 && la > 0.0 && fa > 0.0) +    { +        //normalize light vector +        lv = normalize(lv); +     +        //distance attenuation +        float dist = d/la; +        float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); +        dist_atten *= dist_atten; +        dist_atten *= 2.0; + +        // spotlight coefficient. +        float spot = max(dot(-ln, lv), is_pointlight); +        da *= spot*spot; // GL_SPOT_EXPONENT=2 + +        //angular attenuation +        da *= max(dot(n, lv), 0.0);      + +        float lit = max(da * dist_atten,0.0); + +        col = light_col * lit * diffuse; + +        // no spec for alpha shader... +    } + +    return max(col, vec3(0.0,0.0,0.0));  }  #if HAS_SHADOW -float pcfShadow(sampler2DShadow shadowMap, vec4 stc) +float pcfShadowLegacy(sampler2DShadow shadowMap, vec4 stc)  {  	stc.xyz /= stc.w;  	stc.z += shadow_bias; @@ -152,174 +152,175 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc)  }  #endif +float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen);  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; +    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.0; +    float shadow = 1.0;  #if HAS_SHADOW -	vec4 spos = pos; -		 -	if (spos.z > -shadow_clip.w) -	{	 -		shadow = 0.0; - -		vec4 lpos; -		 -		vec4 near_split = shadow_clip*-0.75; -		vec4 far_split = shadow_clip*-1.25; -		vec4 transition_domain = near_split-far_split; -		float weight = 0.0; - -		if (spos.z < near_split.z) -		{ -			lpos = shadow_matrix[3]*spos; -			 -			float w = 1.0; -			w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; -			shadow += pcfShadow(shadowMap3, lpos)*w; -			weight += w; -			shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); -		} - -		if (spos.z < near_split.y && spos.z > far_split.z) -		{ -			lpos = shadow_matrix[2]*spos; -			 -			float w = 1.0; -			w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; -			w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; -			shadow += pcfShadow(shadowMap2, lpos)*w; -			weight += w; -		} - -		if (spos.z < near_split.x && spos.z > far_split.y) -		{ -			lpos = shadow_matrix[1]*spos; -			 -			float w = 1.0; -			w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; -			w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; -			shadow += pcfShadow(shadowMap1, lpos)*w; -			weight += w; -		} - -		if (spos.z > far_split.x) -		{ -			lpos = shadow_matrix[0]*spos; -							 -			float w = 1.0; -			w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; -				 -			shadow += pcfShadow(shadowMap0, lpos)*w; -			weight += w; -		} -		 - -		shadow /= weight; -	} -	else -	{ -		shadow = 1.0; -	} +    vec4 spos = pos; +         +    if (spos.z > -shadow_clip.w) +    {    +        shadow = 0.0; + +        vec4 lpos; +         +        vec4 near_split = shadow_clip*-0.75; +        vec4 far_split = shadow_clip*-1.25; +        vec4 transition_domain = near_split-far_split; +        float weight = 0.0; + +        if (spos.z < near_split.z) +        { +            lpos = shadow_matrix[3]*spos; +             +            float w = 1.0; +            w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; +            shadow += pcfShadowLegacy(shadowMap3, lpos)*w; +            weight += w; +            shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); +        } + +        if (spos.z < near_split.y && spos.z > far_split.z) +        { +            lpos = shadow_matrix[2]*spos; +             +            float w = 1.0; +            w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; +            w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; +            shadow += pcfShadowLegacy(shadowMap2, lpos)*w; +            weight += w; +        } + +        if (spos.z < near_split.x && spos.z > far_split.y) +        { +            lpos = shadow_matrix[1]*spos; +             +            float w = 1.0; +            w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; +            w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; +            shadow += pcfShadowLegacy(shadowMap1, lpos)*w; +            weight += w; +        } + +        if (spos.z > far_split.x) +        { +            lpos = shadow_matrix[0]*spos; +                             +            float w = 1.0; +            w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; +                 +            shadow += pcfShadowLegacy(shadowMap0, lpos)*w; +            weight += w; +        } +         + +        shadow /= weight; +    } +    else +    { +        shadow = 1.0; +    }  #endif  #ifdef USE_INDEXED_TEX -	vec4 diff = diffuseLookup(vary_texcoord0.xy); +    vec4 diff = diffuseLookup(vary_texcoord0.xy);  #else -	vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); +    vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy);  #endif  #ifdef FOR_IMPOSTOR -	vec4 color; -	color.rgb = diff.rgb; -	color.a = 1.0; +    vec4 color; +    color.rgb = diff.rgb; +    color.a = 1.0;  #ifdef USE_VERTEX_COLOR -	float final_alpha = diff.a * vertex_color.a; -	diff.rgb *= vertex_color.rgb; +    float final_alpha = diff.a * vertex_color.a; +    diff.rgb *= vertex_color.rgb;  #else -	float final_alpha = diff.a; +    float final_alpha = diff.a;  #endif -	 -	// Insure we don't pollute depth with invis pixels in impostor rendering -	// -	if (final_alpha < 0.01) -	{ -		discard; -	} +     +    // Insure we don't pollute depth with invis pixels in impostor rendering +    // +    if (final_alpha < 0.01) +    { +        discard; +    }  #else -	 +      #ifdef USE_VERTEX_COLOR -	float final_alpha = diff.a * vertex_color.a; -	diff.rgb *= vertex_color.rgb; +    float final_alpha = diff.a * vertex_color.a; +    diff.rgb *= vertex_color.rgb;  #else -	float final_alpha = diff.a; +    float final_alpha = diff.a;  #endif      vec3 sunlit;      vec3 amblit;      vec3 additive;      vec3 atten; -	calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); +    calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); -	vec2 abnormal	= encode_normal(norm.xyz); -		 norm.xyz   = decode_normal(abnormal.xy); +    vec2 abnormal   = encode_normal(norm.xyz); +         norm.xyz   = decode_normal(abnormal.xy); -	float sun_da  = dot(norm.xyz, sun_dir.xyz); -	float moon_da = dot(norm.xyz, moon_dir.xyz); +    float sun_da  = dot(norm.xyz, sun_dir.xyz); +    float moon_da = dot(norm.xyz, moon_dir.xyz);      float final_da = max(sun_da, moon_da);            final_da = min(final_da, shadow);            final_da = clamp(final_da, 0.0f, 1.0f); -	  final_da = pow(final_da, display_gamma); +      final_da = pow(final_da, display_gamma); -	vec4 color = vec4(0,0,0,0); +    vec4 color = vec4(0,0,0,0); -	color.rgb = atmosFragAmbient(color.rgb, amblit); -	color.a   = final_alpha; +    color.rgb = atmosFragAmbient(color.rgb, amblit); +    color.a   = final_alpha; -	float ambient = abs(final_da); -	ambient *= 0.5; -	ambient *= ambient; -	ambient = (1.0-ambient); +    float ambient = abs(final_da); +    ambient *= 0.5; +    ambient *= ambient; +    ambient = (1.0-ambient); -	color.rgb *= ambient; -	color.rgb += (final_da * sunlit); -	color.rgb *= diff.rgb; +    color.rgb *= ambient; +    color.rgb += (final_da * sunlit); +    color.rgb *= diff.rgb; -	//color.rgb = mix(diff.rgb, color.rgb, final_alpha); -	 -	color.rgb = atmosFragLighting(color.rgb, additive, atten); -	color.rgb = scaleSoftClip(color.rgb); +    //color.rgb = mix(diff.rgb, color.rgb, final_alpha); +     +    color.rgb = atmosFragLighting(color.rgb, additive, atten); +    color.rgb = scaleSoftClip(color.rgb); -	vec4 light = vec4(0,0,0,0); +    vec4 light = vec4(0,0,0,0);     #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diff.rgb, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z); -	LIGHT_LOOP(1) -	LIGHT_LOOP(2) -	LIGHT_LOOP(3) -	LIGHT_LOOP(4) -	LIGHT_LOOP(5) -	LIGHT_LOOP(6) -	LIGHT_LOOP(7) +    LIGHT_LOOP(1) +    LIGHT_LOOP(2) +    LIGHT_LOOP(3) +    LIGHT_LOOP(4) +    LIGHT_LOOP(5) +    LIGHT_LOOP(6) +    LIGHT_LOOP(7) -	// keep it linear -	// -	color.rgb += light.rgb; +    // keep it linear +    // +    color.rgb += light.rgb;  #ifdef WATER_FOG -	color = applyWaterFogView(pos.xyz, color); +    color = applyWaterFogView(pos.xyz, color);  #endif  #endif -	frag_color = color; +    frag_color = color;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl new file mode 100644 index 0000000000..3bb59dd7f9 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/aoUtil.glsl @@ -0,0 +1,93 @@ +/**  + * @file class1/deferred/aoUtil.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       noiseMap; + +uniform float ssao_radius; +uniform float ssao_max_radius; +uniform float ssao_factor; +uniform float ssao_factor_inv; + +vec4 getPosition(vec2 pos_screen); + +vec2 getKern(int i) +{ +    vec2 kern[8]; +    // exponentially (^2) distant occlusion samples spread around origin +    kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; +    kern[1] = vec2(1.0, 0.0) * 0.250*0.250; +    kern[2] = vec2(0.0, 1.0) * 0.375*0.375; +    kern[3] = vec2(0.0, -1.0) * 0.500*0.500; +    kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; +    kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; +    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]; +} + +//calculate decreases in ambient lighting when crowded out (SSAO) +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; +         +    float angle_hidden = 0.0; +    float points = 0; +         +    float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); +     +    // it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations (unrolling?) +    for (int i = 0; i < 8; i++) +    { +        vec2 samppos_screen = pos_screen + scale * reflect(getKern(i), noise_reflect); +        vec3 samppos_world = getPosition(samppos_screen).xyz;  +         +        vec3 diff = pos_world - samppos_world; +        float dist2 = dot(diff, diff); +             +        // assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area +        // --> solid angle shrinking by the square of distance +        //radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 +        //(k should vary inversely with # of samples, but this is taken care of later) +         +        float funky_val = (dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) ? 1.0 : 0.0; +        angle_hidden = angle_hidden + funky_val * min(1.0/dist2, ssao_factor_inv); +             +        // 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion"  +        float diffz_val = (diff.z > -1.0) ? 1.0 : 0.0; +        points = points + diffz_val; +    } +         +    angle_hidden = min(ssao_factor*angle_hidden/points, 1.0); +     +    float points_val = (points > 0.0) ? 1.0 : 0.0; +    ret = (1.0 - (points_val * angle_hidden)); + +    ret = max(ret, 0.0); +    return min(ret, 1.0); +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index b56abb66d1..868eec3926 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -48,82 +48,69 @@ VARYING vec2 vary_fragcoord;  uniform mat4 inv_proj;  uniform vec2 screen_res; -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	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; -} - +vec4 getPosition(vec2 pos_screen); +vec3 getNorm(vec2 pos_screen);  vec3 decode_normal (vec2 enc);  void main()   {      vec2 tc = vary_fragcoord.xy; -	vec3 norm = texture2DRect(normalMap, tc).xyz; -	norm = decode_normal(norm.xy); // unpack norm - -	vec3 pos = getPosition(tc).xyz; -	vec4 ccol = texture2DRect(lightMap, tc).rgba; -	 -	vec2 dlt = kern_scale * delta / (1.0+norm.xy*norm.xy); -	dlt /= max(-pos.z*dist_factor, 1.0); -	 -	vec2 defined_weight = kern[0].xy; // special case the first (centre) sample's weight in the blur; we have to sample it anyway so we get it for 'free' -	vec4 col = defined_weight.xyxx * ccol; - -	// relax tolerance according to distance to avoid speckling artifacts, as angles and distances are a lot more abrupt within a small screen area at larger distances -	float pointplanedist_tolerance_pow2 = pos.z*pos.z*0.00005; - -	// perturb sampling origin slightly in screen-space to hide edge-ghosting artifacts where smoothing radius is quite large -	float tc_mod = 0.5*(tc.x + tc.y); // mod(tc.x+tc.y,2) -	tc_mod -= floor(tc_mod); -	tc_mod *= 2.0; -	tc += ( (tc_mod - 0.5) * kern[1].z * dlt * 0.5 ); - -	for (int i = 1; i < 4; i++) -	{ -		vec2 samptc = tc + kern[i].z*dlt; -	    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; -		} -	} - -	for (int i = 1; i < 4; i++) -	{ -		vec2 samptc = tc - kern[i].z*dlt; -	    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 /= defined_weight.xyxx; -	col.y *= col.y; -	 -	frag_color = col; +    vec3 norm = getNorm(tc); +    vec3 pos = getPosition(tc).xyz; +    vec4 ccol = texture2DRect(lightMap, tc).rgba; +     +    vec2 dlt = kern_scale * delta / (1.0+norm.xy*norm.xy); +    dlt /= max(-pos.z*dist_factor, 1.0); +     +    vec2 defined_weight = kern[0].xy; // special case the first (centre) sample's weight in the blur; we have to sample it anyway so we get it for 'free' +    vec4 col = defined_weight.xyxx * ccol; + +    // relax tolerance according to distance to avoid speckling artifacts, as angles and distances are a lot more abrupt within a small screen area at larger distances +    float pointplanedist_tolerance_pow2 = pos.z*pos.z*0.00005; + +    // perturb sampling origin slightly in screen-space to hide edge-ghosting artifacts where smoothing radius is quite large +    float tc_mod = 0.5*(tc.x + tc.y); // mod(tc.x+tc.y,2) +    tc_mod -= floor(tc_mod); +    tc_mod *= 2.0; +    tc += ( (tc_mod - 0.5) * kern[1].z * dlt * 0.5 ); + +    for (int i = 1; i < 4; i++) +    { +        vec2 samptc = tc + kern[i].z*dlt; +        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; +        } +    } + +    for (int i = 1; i < 4; i++) +    { +        vec2 samptc = tc - kern[i].z*dlt; +        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 /= defined_weight.xyxx; +    col.y *= col.y; +     +    frag_color = col;  #ifdef IS_AMD_CARD -	// If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. -	vec3 dummy1 = kern[0]; -	vec3 dummy2 = kern[3]; +    // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. +    vec3 dummy1 = kern[0]; +    vec3 dummy2 = kern[3];  #endif  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index ec05dab57f..9d7a7f6556 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -25,29 +25,6 @@  uniform sampler2DRect   normalMap;  uniform sampler2DRect   depthMap; -uniform sampler2D       noiseMap; -uniform sampler2DShadow shadowMap0; -uniform sampler2DShadow shadowMap1; -uniform sampler2DShadow shadowMap2; -uniform sampler2DShadow shadowMap3; -uniform sampler2DShadow shadowMap4; -uniform sampler2DShadow shadowMap5; - -uniform float ssao_radius; -uniform float ssao_max_radius; -uniform float ssao_factor; -uniform float ssao_factor_inv; - -uniform vec3 sun_dir; -uniform vec3 moon_dir; -uniform vec2 shadow_res; -uniform vec2 proj_shadow_res; -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; -uniform float shadow_bias; - -uniform float spot_shadow_bias; -uniform float spot_shadow_offset;  uniform mat4 inv_proj;  uniform vec2 screen_res; @@ -87,8 +64,6 @@ vec4 getPosition(vec2 pos_screen)      return pos;  } -#if USE_DEFERRED_SHADER_API -  vec4 getPositionWithDepth(vec2 pos_screen, float depth)  {      vec2 sc = getScreenCoordinate(pos_screen); @@ -98,200 +73,3 @@ vec4 getPositionWithDepth(vec2 pos_screen, float depth)      pos.w = 1.0;      return pos;  } - -float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) -{ -    stc.xyz /= stc.w; -    stc.z += shadow_bias * bias_scale; -         -    stc.x = floor(stc.x*pos_screen.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here -     -    float cs = shadow2D(shadowMap, stc.xyz).x; -    float shadow = cs; -    shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; -    shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; -    shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; -    shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; -    return shadow*0.2; -} - -float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) -{ -    stc.xyz /= stc.w; -    stc.z += spot_shadow_bias * bias_scale; -    stc.x = floor(proj_shadow_res.x * stc.x + fract(pos_screen.y*0.666666666)) / proj_shadow_res.x; // snap - -    float cs = shadow2D(shadowMap, stc.xyz).x; -    float shadow = cs; - -    vec2 off = 1.0/proj_shadow_res; -    off.y *= 1.5; -     -    shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x*2.0, off.y, 0.0)).x; -    shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x, -off.y, 0.0)).x; -    shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x, off.y, 0.0)).x; -    shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)).x; -    return shadow*0.2; -} - -float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) -{ -    float dp_sun = max(0.0, dot(sun_dir.xyz, norm)); -    float dp_moon = max(0.0, dot(moon_dir.xyz, norm)); -    float dp_directional_light = max(dp_sun,dp_moon); -          dp_directional_light = clamp(dp_directional_light, 0.0, 1.0); - -        vec3 light_dir = (dp_moon > dp_sun) ? moon_dir : sun_dir; -    vec3 offset = light_dir * (1.0-dp_directional_light); -    vec3 shadow_pos = pos.xyz + (offset * shadow_bias); - -    float shadow = 0.0f; -    vec4 spos = vec4(shadow_pos,1.0); -    if (spos.z > -shadow_clip.w) -    {    -        vec4 lpos; -        vec4 near_split = shadow_clip*-0.75; -        vec4 far_split = shadow_clip*-1.25; -        vec4 transition_domain = near_split-far_split; -        float weight = 0.0; - -        if (spos.z < near_split.z) -        { -            lpos = shadow_matrix[3]*spos; -             -            float w = 1.0; -            w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; -            shadow += pcfShadow(shadowMap3, lpos, 0.5, pos_screen)*w; -            weight += w; -            shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); -        } - -        if (spos.z < near_split.y && spos.z > far_split.z) -        { -            lpos = shadow_matrix[2]*spos; -             -            float w = 1.0; -            w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; -            w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; -            shadow += pcfShadow(shadowMap2, lpos, 0.75, pos_screen)*w; -            weight += w; -        } - -        if (spos.z < near_split.x && spos.z > far_split.y) -        { -            lpos = shadow_matrix[1]*spos; -             -            float w = 1.0; -            w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; -            w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; -            shadow += pcfShadow(shadowMap1, lpos, 0.88, pos_screen)*w; -            weight += w; -        } - -        if (spos.z > far_split.x) -        { -            lpos = shadow_matrix[0]*spos; -                             -            float w = 1.0; -            w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; -                 -            shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen)*w; -            weight += w; -        } - -        shadow /= weight; -    } -    return shadow; -} - -float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) -{ -    float shadow = 0.0f; -    pos += norm * spot_shadow_offset; - -    vec4 spos = vec4(pos,1.0); -    if (spos.z > -shadow_clip.w) -    {    -        vec4 lpos; -         -        vec4 near_split = shadow_clip*-0.75; -        vec4 far_split = shadow_clip*-1.25; -        vec4 transition_domain = near_split-far_split; -        float weight = 0.0; - -        { -            lpos = shadow_matrix[4 + index]*spos; -            float w = 1.0; -            w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; -         -            shadow += pcfSpotShadow((index == 0) ? shadowMap4 : shadowMap5, lpos, 0.8, spos.xy)*w; -            weight += w; -            shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); -        } - -        shadow /= weight; -    } -    return shadow; -} - -vec2 getKern(int i) -{ -    vec2 kern[8]; -    // exponentially (^2) distant occlusion samples spread around origin -    kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; -    kern[1] = vec2(1.0, 0.0) * 0.250*0.250; -    kern[2] = vec2(0.0, 1.0) * 0.375*0.375; -    kern[3] = vec2(0.0, -1.0) * 0.500*0.500; -    kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; -    kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; -    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]; -} - -//calculate decreases in ambient lighting when crowded out (SSAO) -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; -         -    float angle_hidden = 0.0; -    float points = 0; -         -    float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); -     -    // it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations (unrolling?) -    for (int i = 0; i < 8; i++) -    { -        vec2 samppos_screen = pos_screen + scale * reflect(getKern(i), noise_reflect); -        vec3 samppos_world = getPosition(samppos_screen).xyz;  -         -        vec3 diff = pos_world - samppos_world; -        float dist2 = dot(diff, diff); -             -        // assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area -        // --> solid angle shrinking by the square of distance -        //radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 -        //(k should vary inversely with # of samples, but this is taken care of later) -         -        float funky_val = (dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) ? 1.0 : 0.0; -        angle_hidden = angle_hidden + funky_val * min(1.0/dist2, ssao_factor_inv); -             -        // 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion"  -        float diffz_val = (diff.z > -1.0) ? 1.0 : 0.0; -        points = points + diffz_val; -    } -         -    angle_hidden = min(ssao_factor*angle_hidden/points, 1.0); -     -    float points_val = (points > 0.0) ? 1.0 : 0.0; -    ret = (1.0 - (points_val * angle_hidden)); - -    ret = max(ret, 0.0); -    return min(ret, 1.0); -} - -#endif - diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 211bedee59..a0da8563a2 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -25,9 +25,9 @@  /*[EXTRA_CODE_HERE]*/ -#define DIFFUSE_ALPHA_MODE_IGNORE	0 -#define DIFFUSE_ALPHA_MODE_BLEND	1 -#define DIFFUSE_ALPHA_MODE_MASK		2 +#define DIFFUSE_ALPHA_MODE_IGNORE   0 +#define DIFFUSE_ALPHA_MODE_BLEND    1 +#define DIFFUSE_ALPHA_MODE_MASK     2  #define DIFFUSE_ALPHA_MODE_EMISSIVE 3  uniform float emissive_brightness; @@ -62,7 +62,7 @@ uniform vec4 shadow_clip;  uniform vec2 shadow_res;  uniform float shadow_bias; -float pcfShadow(sampler2DShadow shadowMap, vec4 stc) +float pcfShadowLegacy(sampler2DShadow shadowMap, vec4 stc)  {  	stc.xyz /= stc.w;  	stc.z += shadow_bias; @@ -80,10 +80,11 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc)      return shadow*0.2;  } +float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen);  #endif  uniform samplerCube environmentMap; -uniform sampler2D	  lightFunc; +uniform sampler2D     lightFunc;  // Inputs  uniform vec4 morphFactor; @@ -109,80 +110,80 @@ uniform vec3 light_diffuse[8];  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)  { -	//get light vector -	vec3 lv = lp.xyz-v; -	 -	//get distance -	float d = length(lv); -	 -	float da = 1.0; - -	vec3 col = vec3(0,0,0); - -	if (d > 0.0 && la > 0.0 && fa > 0.0) -	{ -		//normalize light vector -		lv = normalize(lv); -	 -		//distance attenuation -		float dist = d/la; -		float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); -		dist_atten *= dist_atten; -		dist_atten *= 2.0; - -		// spotlight coefficient. -		float spot = max(dot(-ln, lv), is_pointlight); -		da *= spot*spot; // GL_SPOT_EXPONENT=2 - -		//angular attenuation -		da *= max(dot(n, lv), 0.0);		 -		 -		float lit = max(da * dist_atten, 0.0); - -		col = light_col*lit*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; -				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); -				//col += spec.rgb; -			} -		} -	} - -	return max(col, vec3(0.0,0.0,0.0));	 +    //get light vector +    vec3 lv = lp.xyz-v; +     +    //get distance +    float d = length(lv); +     +    float da = 1.0; + +    vec3 col = vec3(0,0,0); + +    if (d > 0.0 && la > 0.0 && fa > 0.0) +    { +        //normalize light vector +        lv = normalize(lv); +     +        //distance attenuation +        float dist = d/la; +        float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0); +        dist_atten *= dist_atten; +        dist_atten *= 2.0; + +        // spotlight coefficient. +        float spot = max(dot(-ln, lv), is_pointlight); +        da *= spot*spot; // GL_SPOT_EXPONENT=2 + +        //angular attenuation +        da *= max(dot(n, lv), 0.0);      +         +        float lit = max(da * dist_atten, 0.0); + +        col = light_col*lit*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; +                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); +                //col += spec.rgb; +            } +        } +    } + +    return max(col, vec3(0.0,0.0,0.0));   }  vec4 getPosition_d(vec2 pos_screen, float depth)  { -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	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; +    vec2 sc = pos_screen.xy*2.0; +    sc /= screen_res; +    sc -= vec2(1.0,1.0); +    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;  } @@ -232,253 +233,253 @@ void main()  {      vec2 pos_screen = vary_texcoord0.xy; -	vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); -	diffcol.rgb *= vertex_color.rgb; +    vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); +    diffcol.rgb *= vertex_color.rgb;  #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) -	if (diffcol.a < minimum_alpha) -	{ -		discard; -	} +    if (diffcol.a < minimum_alpha) +    { +        discard; +    }  #endif  #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) -	vec3 gamma_diff = diffcol.rgb; +    vec3 gamma_diff = diffcol.rgb;  #endif  #if HAS_SPECULAR_MAP -	vec4 spec = texture2D(specularMap, vary_texcoord2.xy); -	spec.rgb *= specular_color.rgb; +    vec4 spec = texture2D(specularMap, vary_texcoord2.xy); +    spec.rgb *= specular_color.rgb;  #else -	vec4 spec = vec4(specular_color.rgb, 1.0); +    vec4 spec = vec4(specular_color.rgb, 1.0);  #endif  #if HAS_NORMAL_MAP -	vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); +    vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); -	norm.xyz = norm.xyz * 2 - 1; +    norm.xyz = norm.xyz * 2 - 1; -	vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), -			  dot(norm.xyz,vary_mat1), -			  dot(norm.xyz,vary_mat2)); +    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; +    vec4 norm = vec4(0,0,0,1.0); +    vec3 tnorm = vary_normal;  #endif      norm.xyz = tnorm;      norm.xyz = normalize(norm.xyz); -	vec2 abnormal	= encode_normal(norm.xyz); -		 norm.xyz   = decode_normal(abnormal.xy); +    vec2 abnormal   = encode_normal(norm.xyz); +         norm.xyz   = decode_normal(abnormal.xy); -	vec4 final_color = diffcol; -	 +    vec4 final_color = diffcol; +      #if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) -	final_color.a = emissive_brightness; +    final_color.a = emissive_brightness;  #else -	final_color.a = max(final_color.a, emissive_brightness); +    final_color.a = max(final_color.a, emissive_brightness);  #endif -	vec4 final_specular = spec; +    vec4 final_specular = spec;  #if 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; +    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; +    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 RGBA -	vec3 pos = vary_position; +        //forward rendering, output just lit RGBA +    vec3 pos = vary_position;  #if HAS_SUN_SHADOW -	float shadow = 0.0; -	 -	vec4 spos = vec4(pos,1.0); -		 -	if (spos.z > -shadow_clip.w) -	{	 -		vec4 lpos; -		 -		vec4 near_split = shadow_clip*-0.75; -		vec4 far_split = shadow_clip*-1.25; -		vec4 transition_domain = near_split-far_split; -		float weight = 0.0; - -		if (spos.z < near_split.z) -		{ -			lpos = shadow_matrix[3]*spos; -			 -			float w = 1.0; -			w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; -			shadow += pcfShadow(shadowMap3, lpos)*w; -			weight += w; -			shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); -		} - -		if (spos.z < near_split.y && spos.z > far_split.z) -		{ -			lpos = shadow_matrix[2]*spos; -			 -			float w = 1.0; -			w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; -			w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; -			shadow += pcfShadow(shadowMap2, lpos)*w; -			weight += w; -		} - -		if (spos.z < near_split.x && spos.z > far_split.y) -		{ -			lpos = shadow_matrix[1]*spos; -			 -			float w = 1.0; -			w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; -			w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; -			shadow += pcfShadow(shadowMap1, lpos)*w; -			weight += w; -		} - -		if (spos.z > far_split.x) -		{ -			lpos = shadow_matrix[0]*spos; -							 -			float w = 1.0; -			w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; -				 -			shadow += pcfShadow(shadowMap0, lpos)*w; -			weight += w; -		} -		 - -		shadow /= weight; -	} -	else -	{ -		shadow = 1.0; -	} +    float shadow = 0.0; +     +    vec4 spos = vec4(pos,1.0); +         +    if (spos.z > -shadow_clip.w) +    {    +        vec4 lpos; +         +        vec4 near_split = shadow_clip*-0.75; +        vec4 far_split = shadow_clip*-1.25; +        vec4 transition_domain = near_split-far_split; +        float weight = 0.0; + +        if (spos.z < near_split.z) +        { +            lpos = shadow_matrix[3]*spos; +             +            float w = 1.0; +            w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; +            shadow += pcfShadowLegacy(shadowMap3, lpos)*w; +            weight += w; +            shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); +        } + +        if (spos.z < near_split.y && spos.z > far_split.z) +        { +            lpos = shadow_matrix[2]*spos; +             +            float w = 1.0; +            w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; +            w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; +            shadow += pcfShadowLegacy(shadowMap2, lpos)*w; +            weight += w; +        } + +        if (spos.z < near_split.x && spos.z > far_split.y) +        { +            lpos = shadow_matrix[1]*spos; +             +            float w = 1.0; +            w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; +            w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; +            shadow += pcfShadowLegacy(shadowMap1, lpos)*w; +            weight += w; +        } + +        if (spos.z > far_split.x) +        { +            lpos = shadow_matrix[0]*spos; +                             +            float w = 1.0; +            w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; +                 +            shadow += pcfShadowLegacy(shadowMap0, lpos)*w; +            weight += w; +        } +         + +        shadow /= weight; +    } +    else +    { +        shadow = 1.0; +    }  #else -	float shadow = 1.0; +    float shadow = 1.0;  #endif -	spec = final_specular; -	vec4 diffuse = final_color; -	float envIntensity = final_normal.z; +    spec = final_specular; +    vec4 diffuse = final_color; +    float envIntensity = final_normal.z;      vec3 col = vec3(0.0f,0.0f,0.0f); -	float bloom = 0.0; +    float bloom = 0.0;          vec3 sunlit;          vec3 amblit;          vec3 additive;          vec3 atten; -	calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); -	 -	vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); +    calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); +     +    vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); -	float sun_da  = dot(norm.xyz, sun_dir.xyz); -	float moon_da = dot(norm.xyz, moon_dir.xyz); +    float sun_da  = dot(norm.xyz, sun_dir.xyz); +    float moon_da = dot(norm.xyz, moon_dir.xyz);      float final_da = max(sun_da,moon_da);            final_da = min(final_da, shadow);            //final_da = max(final_da, diffuse.a);            final_da = max(final_da, 0.0f); -		  final_da = min(final_da, 1.0f); -		  final_da = pow(final_da, display_gamma); +          final_da = min(final_da, 1.0f); +          final_da = pow(final_da, display_gamma); -	col.rgb = (col * 0.5) + amblit; -	 -	float ambient = min(abs(final_da), 1.0); -	ambient *= 0.5; -	ambient *= ambient; -	ambient = (1.0-ambient); +    col.rgb = (col * 0.5) + amblit; +     +    float ambient = min(abs(final_da), 1.0); +    ambient *= 0.5; +    ambient *= ambient; +    ambient = (1.0-ambient); -	col.rgb *= ambient; +    col.rgb *= ambient; -	col.rgb = col.rgb + (final_da * sunlit); +    col.rgb = col.rgb + (final_da * sunlit); -	col.rgb *= gamma_diff.rgb; -	 +    col.rgb *= gamma_diff.rgb; +     -	float glare = 0.0; +    float glare = 0.0; -	if (spec.a > 0.0) // specular reflection -	{ -		// the old infinite-sky shiny reflection -		// -				 +    if (spec.a > 0.0) // specular reflection +    { +        // the old infinite-sky shiny reflection +        // +                          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; +        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); +        glare = max(spec_contrib.r, spec_contrib.g); +        glare = max(glare, spec_contrib.b); -		col += spec_contrib; -	} +        col += spec_contrib; +    } -	col = mix(col.rgb, diffcol.rgb, diffuse.a); +    col = mix(col.rgb, diffcol.rgb, diffuse.a); -	if (envIntensity > 0.0) -	{ -		//add environmentmap -		vec3 env_vec = env_mat * refnormpersp; -		 -		vec3 refcol = textureCube(environmentMap, env_vec).rgb; +    if (envIntensity > 0.0) +    { +        //add environmentmap +        vec3 env_vec = env_mat * refnormpersp; +         +        vec3 refcol = textureCube(environmentMap, env_vec).rgb; -		col = mix(col.rgb, refcol,  -			envIntensity);   +        col = mix(col.rgb, refcol,  +            envIntensity);   -		float cur_glare = max(refcol.r, refcol.g); -		cur_glare = max(cur_glare, refcol.b); -		cur_glare *= envIntensity*4.0; -		glare += cur_glare; -	} +        float cur_glare = max(refcol.r, refcol.g); +        cur_glare = max(cur_glare, refcol.b); +        cur_glare *= envIntensity*4.0; +        glare += cur_glare; +    } -	col = atmosFragLighting(col, additive, atten); +    col = atmosFragLighting(col, additive, atten); -	vec3 npos = normalize(-pos.xyz); -			 -	vec3 light = vec3(0,0,0); +    vec3 npos = normalize(-pos.xyz); +             +    vec3 light = vec3(0,0,0);   #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_LOOP(1) -		LIGHT_LOOP(2) -		LIGHT_LOOP(3) -		LIGHT_LOOP(4) -		LIGHT_LOOP(5) -		LIGHT_LOOP(6) -		LIGHT_LOOP(7) +        LIGHT_LOOP(1) +        LIGHT_LOOP(2) +        LIGHT_LOOP(3) +        LIGHT_LOOP(4) +        LIGHT_LOOP(5) +        LIGHT_LOOP(6) +        LIGHT_LOOP(7) -	col.rgb += light.rgb; +    col.rgb += light.rgb; -	glare = min(glare, 1.0); -	float al = max(diffcol.a,glare)*vertex_color.a; +    glare = min(glare, 1.0); +    float al = max(diffcol.a,glare)*vertex_color.a; -	col = scaleSoftClipFrag(col); +    col = scaleSoftClipFrag(col);  #ifdef WATER_FOG -	vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al)); -	col.rgb = temp.rgb; -	al = temp.a; +    vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al)); +    col.rgb = temp.rgb; +    al = temp.a;  #endif -	frag_color.rgb = col.rgb; -	frag_color.a   = al; +    frag_color.rgb = col.rgb; +    frag_color.a   = al;  #else -	frag_data[0] = final_color; -	frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. -	frag_data[2] = final_normal; // XY = Normal.  Z = Env. intensity. +    frag_data[0] = final_color; +    frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. +    frag_data[2] = final_normal; // XY = Normal.  Z = Env. intensity.  #endif  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index d1ac19270d..e8eef9b94b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -59,18 +59,7 @@ uniform mat4 inv_proj;  vec3 decode_normal (vec2 enc); -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	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; -} +vec4 getPosition(vec2 pos_screen);  void main()   { diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index b3dcd90d98..7438fac8fc 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -123,19 +123,7 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod)  	return ret;  } - -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	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; -} +vec4 getPosition(vec2 pos_screen);  void main()   { diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 13b803e03e..8e756c37bf 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -58,18 +58,7 @@ uniform vec4 viewport;  vec3 decode_normal (vec2 enc); -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	vec2 sc = (pos_screen.xy-viewport.xy)*2.0; -	sc /= viewport.zw; -	sc -= vec2(1.0,1.0); -	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; -} +vec4 getPosition(vec2 pos_screen);  void main()   { diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl new file mode 100644 index 0000000000..ae5cb7cbc1 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -0,0 +1,191 @@ +/**  + * @file class1/deferred/shadowUtil.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 sampler2DRect   normalMap; +uniform sampler2DRect   depthMap; +uniform sampler2D       noiseMap; +uniform sampler2DShadow shadowMap0; +uniform sampler2DShadow shadowMap1; +uniform sampler2DShadow shadowMap2; +uniform sampler2DShadow shadowMap3; +uniform sampler2DShadow shadowMap4; +uniform sampler2DShadow shadowMap5; + +uniform float ssao_radius; +uniform float ssao_max_radius; +uniform float ssao_factor; +uniform float ssao_factor_inv; + +uniform vec3 sun_dir; +uniform vec3 moon_dir; +uniform vec2 shadow_res; +uniform vec2 proj_shadow_res; +uniform mat4 shadow_matrix[6]; +uniform vec4 shadow_clip; +uniform float shadow_bias; + +uniform float spot_shadow_bias; +uniform float spot_shadow_offset; + +uniform mat4 inv_proj; +uniform vec2 screen_res; + +vec3 decode_normal(vec2 enc); + +float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) +{ +    stc.xyz /= stc.w; +    stc.z += shadow_bias; +         +    stc.x = floor(stc.x*pos_screen.x + fract(stc.y*shadow_res.y*12345))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here +     +    float cs = shadow2D(shadowMap, stc.xyz).x; +    float shadow = cs; +    shadow += shadow2D(shadowMap, stc.xyz+vec3(2.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; +    shadow += shadow2D(shadowMap, stc.xyz+vec3(1.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; +    shadow += shadow2D(shadowMap, stc.xyz+vec3(-1.0/shadow_res.x, 1.5/shadow_res.y, 0.0)).x; +    shadow += shadow2D(shadowMap, stc.xyz+vec3(-2.0/shadow_res.x, -1.5/shadow_res.y, 0.0)).x; +    return shadow*0.2; +} + +float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float bias_scale, vec2 pos_screen) +{ +    stc.xyz /= stc.w; +    stc.z += spot_shadow_bias * bias_scale; +    stc.x = floor(proj_shadow_res.x * stc.x + fract(pos_screen.y*0.666666666)) / proj_shadow_res.x; // snap + +    float cs = shadow2D(shadowMap, stc.xyz).x; +    float shadow = cs; + +    vec2 off = 1.0/proj_shadow_res; +    off.y *= 1.5; +     +    shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x*2.0, off.y, 0.0)).x; +    shadow += shadow2D(shadowMap, stc.xyz+vec3(off.x, -off.y, 0.0)).x; +    shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x, off.y, 0.0)).x; +    shadow += shadow2D(shadowMap, stc.xyz+vec3(-off.x*2.0, -off.y, 0.0)).x; +    return shadow*0.2; +} + +float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) +{ +    float dp_sun = max(0.0, dot(sun_dir.xyz, norm)); +    float dp_moon = max(0.0, dot(moon_dir.xyz, norm)); +    float dp_directional_light = max(dp_sun,dp_moon); +          dp_directional_light = clamp(dp_directional_light, 0.0, 1.0); + +        vec3 light_dir = (dp_moon > dp_sun) ? moon_dir : sun_dir; +    vec3 offset = light_dir * (1.0-dp_directional_light); +    vec3 shadow_pos = pos.xyz + (offset * shadow_bias); + +    float shadow = 0.0f; +    vec4 spos = vec4(shadow_pos,1.0); +    if (spos.z > -shadow_clip.w) +    {    +        vec4 lpos; +        vec4 near_split = shadow_clip*-0.75; +        vec4 far_split = shadow_clip*-1.25; +        vec4 transition_domain = near_split-far_split; +        float weight = 0.0; + +        if (spos.z < near_split.z) +        { +            lpos = shadow_matrix[3]*spos; +             +            float w = 1.0; +            w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; +            shadow += pcfShadow(shadowMap3, lpos, 0.5, pos_screen)*w; +            weight += w; +            shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); +        } + +        if (spos.z < near_split.y && spos.z > far_split.z) +        { +            lpos = shadow_matrix[2]*spos; +             +            float w = 1.0; +            w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; +            w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; +            shadow += pcfShadow(shadowMap2, lpos, 0.75, pos_screen)*w; +            weight += w; +        } + +        if (spos.z < near_split.x && spos.z > far_split.y) +        { +            lpos = shadow_matrix[1]*spos; +             +            float w = 1.0; +            w -= max(spos.z-far_split.x, 0.0)/transition_domain.x; +            w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; +            shadow += pcfShadow(shadowMap1, lpos, 0.88, pos_screen)*w; +            weight += w; +        } + +        if (spos.z > far_split.x) +        { +            lpos = shadow_matrix[0]*spos; +                             +            float w = 1.0; +            w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; +                 +            shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen)*w; +            weight += w; +        } + +        shadow /= weight; +    } +    return shadow; +} + +float sampleSpotShadow(vec3 pos, vec3 norm, int index, vec2 pos_screen) +{ +    float shadow = 0.0f; +    pos += norm * spot_shadow_offset; + +    vec4 spos = vec4(pos,1.0); +    if (spos.z > -shadow_clip.w) +    {    +        vec4 lpos; +         +        vec4 near_split = shadow_clip*-0.75; +        vec4 far_split = shadow_clip*-1.25; +        vec4 transition_domain = near_split-far_split; +        float weight = 0.0; + +        { +            lpos = shadow_matrix[4 + index]*spos; +            float w = 1.0; +            w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; +         +            shadow += pcfSpotShadow((index == 0) ? shadowMap4 : shadowMap5, lpos, 0.8, spos.xy)*w; +            weight += w; +            shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); +        } + +        shadow /= weight; +    } +    return shadow; +} + diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 2ba766a0c4..0de38a3d62 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -86,18 +86,14 @@ vec4 getPosition_d(vec2 pos_screen, float depth)      return pos;  } -vec4 getPosition(vec2 pos_screen) -{ //get position in screen space (world units) given window coordinate and depth map -    float depth = texture2DRect(depthMap, pos_screen.xy).a; -    return getPosition_d(pos_screen, depth); -} - +vec4 getPositionWithDepth(vec2 pos_screen, float depth); +vec4 getPosition(vec2 pos_screen);  void main()   {      vec2 tc = vary_fragcoord.xy;      float depth = texture2DRect(depthMap, tc.xy).r; -    vec3 pos = getPosition_d(tc, depth).xyz; +    vec3 pos = getPositionWithDepth(tc, depth).xyz;      vec4 norm = texture2DRect(normalMap, tc);      float envIntensity = norm.z;      norm.xyz = decode_normal(norm.xy); // unpack norm @@ -107,14 +103,14 @@ void main()      float da = max(da_sun, da_moon);      float final_da = clamp(da, 0.0, 1.0); -          final_da = pow(final_da, global_gamma); +          final_da = pow(final_da, global_gamma + 0.3);      vec4 diffuse = texture2DRect(diffuseRect, tc); -	vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); -	vec3 col; -	float bloom = 0.0; -	{ +    vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); +    vec3 col; +    float bloom = 0.0; +    {          vec3 sunlit;          vec3 amblit;          vec3 additive; @@ -162,14 +158,14 @@ void main()              col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a);          } -		#ifdef WATER_FOG -			vec4 fogged = applyWaterFogView(pos.xyz,vec4(col, bloom)); -			col = fogged.rgb; -			bloom = fogged.a; -		#endif -	} +        #ifdef WATER_FOG +            vec4 fogged = applyWaterFogView(pos.xyz,vec4(col, bloom)); +            col = fogged.rgb; +            bloom = fogged.a; +        #endif +    } -	frag_color.rgb = col.rgb; -	frag_color.a = bloom; +    frag_color.rgb = col.rgb; +    frag_color.a = bloom;  } diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index 1abdd4af33..22488944cd 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -121,19 +121,7 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod)  	return ret;  } - -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	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; -} +vec4 getPosition(vec2 pos_screen);  void main()   { diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index 403df87853..6d65ee2add 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -41,82 +41,15 @@ uniform sampler2D noiseMap;  // Inputs -uniform float ssao_radius; -uniform float ssao_max_radius; -uniform float ssao_factor; -uniform float ssao_factor_inv; -  VARYING vec2 vary_fragcoord;  uniform mat4 inv_proj;  uniform vec2 screen_res;  vec3 decode_normal (vec2 enc); - -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	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; -} - -//calculate decreases in ambient lighting when crowded out (SSAO) -float calcAmbientOcclusion(vec4 pos, vec3 norm) -{ -	float ret = 1.0; -	 -	vec2 kern[8]; -	// exponentially (^2) distant occlusion samples spread around origin -	kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; -	kern[1] = vec2(1.0, 0.0) * 0.250*0.250; -	kern[2] = vec2(0.0, 1.0) * 0.375*0.375; -	kern[3] = vec2(0.0, -1.0) * 0.500*0.500; -	kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; -	kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; -	kern[6] = vec2(-0.7071, 0.7071) * 0.875*0.875; -	kern[7] = vec2(0.7071, -0.7071) * 1.000*1.000; - -	vec2 pos_screen = vary_fragcoord.xy; -	vec3 pos_world = pos.xyz; -	vec2 noise_reflect = texture2D(noiseMap, vary_fragcoord.xy/128.0).xy; -		 -	float angle_hidden = 0.0; -	int points = 0; -		 -	float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); -		 -	// it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations unrolling?) -	for (int i = 0; i < 8; i++) -	{ -		vec2 samppos_screen = pos_screen + scale * reflect(kern[i], noise_reflect); -		vec3 samppos_world = getPosition(samppos_screen).xyz;  -			 -		vec3 diff = pos_world - samppos_world; -		float dist2 = dot(diff, diff); -			 -		// assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area -		// --> solid angle shrinking by the square of distance -		//radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 -		//(k should vary inversely with # of samples, but this is taken care of later) -			 -		angle_hidden = angle_hidden + float(dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) * min(1.0/dist2, ssao_factor_inv); -			 -		// 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion"  -		points = points + int(diff.z > -1.0); -	} -		 -	angle_hidden = min(ssao_factor*angle_hidden/float(points), 1.0); -		 -	ret = (1.0 - (float(points != 0) * angle_hidden)); -	 -	return min(ret, 1.0); -} +vec4 getPosition(vec2 pos_screen); +vec3 getNorm(vec2 pos_screen); +float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen);  void main()   { @@ -124,13 +57,11 @@ void main()  	//try doing an unproject here -	vec4 pos = getPosition(pos_screen); -	 -	vec3 norm = texture2DRect(normalMap, pos_screen).xyz; -	norm = decode_normal(norm.xy); +	vec4 pos = getPosition(pos_screen);	 +	vec3 norm = getNorm(pos_screen); -	frag_color[0] = 1.0; -	frag_color[1] = calcAmbientOcclusion(pos, norm); -	frag_color[2] = 1.0;  -	frag_color[3] = 1.0; +	frag_color.r = 1.0; +	frag_color.g = calcAmbientOcclusion(pos, norm, pos_screen); +	frag_color.b = 1.0;  +	frag_color.a = 1.0;  } diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 0a8981a102..1c5d3901f5 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -122,19 +122,7 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod)  	return ret;  } - -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	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; -} +vec4 getPosition(vec2 pos_screen);  void main()   { diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 9de2741725..1b0a1b5d84 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -85,24 +85,8 @@ vec3 atmosTransportFrag(vec3 light, vec3 additive, vec3 atten);  vec3 fullbrightAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten);  vec3 fullbrightShinyAtmosTransportFrag(vec3 light, vec3 additive, vec3 atten); -vec4 getPosition_d(vec2 pos_screen, float depth) -{ -    vec2 sc = pos_screen.xy*2.0; -    sc /= screen_res; -    sc -= vec2(1.0,1.0); -    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; -} - -vec4 getPosition(vec2 pos_screen) -{ //get position in screen space (world units) given window coordinate and depth map -    float depth = texture2DRect(depthMap, pos_screen.xy).r; -    return getPosition_d(pos_screen, depth); -} - +vec4 getPositionWithDepth(vec2 pos_screen, float depth); +vec4 getPosition(vec2 pos_screen);  #ifdef WATER_FOG  vec4 applyWaterFogView(vec3 pos, vec4 color); @@ -110,19 +94,19 @@ vec4 applyWaterFogView(vec3 pos, vec4 color);  void main()   { -    vec2 tc = vary_fragcoord.xy; -    float depth = texture2DRect(depthMap, tc.xy).r; -    vec3 pos = getPosition_d(tc, depth).xyz; -    vec4 norm = texture2DRect(normalMap, tc); -    float envIntensity = norm.z; -    norm.xyz = decode_normal(norm.xy); // unpack norm -         -    float da_sun  = dot(norm.xyz, normalize(sun_dir.xyz)); +	vec2 tc = vary_fragcoord.xy; +	float depth = texture2DRect(depthMap, tc.xy).r; +	vec4 pos = getPositionWithDepth(tc, depth); +	vec4 norm = texture2DRect(normalMap, tc); +	float envIntensity = norm.z; +	norm.xyz = decode_normal(norm.xy); // unpack norm +		 +	float da_sun  = dot(norm.xyz, normalize(sun_dir.xyz));      float da_moon = dot(norm.xyz, normalize(moon_dir.xyz));      float da = max(da_sun, da_moon);            da = clamp(da, 0.0, 1.0); -	da = pow(da, global_gamma); +	da = pow(da, global_gamma + 0.3);  	vec4 diffuse = texture2DRect(diffuseRect, tc); @@ -132,7 +116,7 @@ void main()          vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy);          vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; -        scol_ambocc = pow(scol_ambocc, vec2(global_gamma)); +        scol_ambocc = pow(scol_ambocc, vec2(global_gamma + 0.3));          float scol = max(scol_ambocc.r, diffuse.a);           float ambocc = scol_ambocc.g; diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index d97bd936d9..36854b0e66 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -122,19 +122,7 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod)  	return ret;  } - -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	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; -} +vec4 getPosition(vec2 pos_screen);  void main()   { diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl index f2d04c95fe..5f8f3114a1 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl @@ -68,22 +68,13 @@ uniform float shadow_offset;  uniform float spot_shadow_bias;  uniform float spot_shadow_offset; -vec3 decode_normal (vec2 enc); +vec3 getNorm(vec2 pos_screen); +vec4 getPosition(vec2 pos_screen); -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	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; -} +float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen); +float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen); -float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) +float pcfShadowLegacy(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen)  {  	stc.xyz /= stc.w;  	stc.z += shadow_bias; @@ -102,7 +93,7 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen)      return shadow*0.2;  } -float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) +float pcfSpotShadowLegacy(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen)  {  	stc.xyz /= stc.w;  	stc.z += spot_shadow_bias*scl; @@ -128,10 +119,8 @@ void main()  	//try doing an unproject here -	vec4 pos = getPosition(pos_screen); -	 -	vec3 norm = texture2DRect(normalMap, pos_screen).xyz; -	norm = decode_normal(norm.xy); // unpack norm +	vec4 pos  = getPosition(pos_screen);	 +	vec3 norm = getNorm(pos_screen);  	/*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL  	{ @@ -174,7 +163,7 @@ void main()  				float w = 1.0;  				w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; -				shadow += pcfShadow(shadowMap3, lpos, 0.25, pos_screen)*w; +				shadow += pcfShadowLegacy(shadowMap3, lpos, 0.25, pos_screen)*w;  				weight += w;  				shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0);  			} @@ -186,7 +175,7 @@ void main()  				float w = 1.0;  				w -= max(spos.z-far_split.y, 0.0)/transition_domain.y;  				w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; -				shadow += pcfShadow(shadowMap2, lpos, 0.5, pos_screen)*w; +				shadow += pcfShadowLegacy(shadowMap2, lpos, 0.5, pos_screen)*w;  				weight += w;  			} @@ -197,7 +186,7 @@ void main()  				float w = 1.0;  				w -= max(spos.z-far_split.x, 0.0)/transition_domain.x;  				w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; -				shadow += pcfShadow(shadowMap1, lpos, 0.75, pos_screen)*w; +				shadow += pcfShadowLegacy(shadowMap1, lpos, 0.75, pos_screen)*w;  				weight += w;  			} @@ -208,7 +197,7 @@ void main()  				float w = 1.0;  				w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; -				shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen)*w; +				shadow += pcfShadowLegacy(shadowMap0, lpos, 1.0, pos_screen)*w;  				weight += w;  			} @@ -242,11 +231,11 @@ void main()  	//spotlight shadow 1  	vec4 lpos = shadow_matrix[4]*spos; -	frag_color[2] = pcfSpotShadow(shadowMap4, lpos, 0.8, pos_screen);  +	frag_color[2] = pcfSpotShadowLegacy(shadowMap4, lpos, 0.8, pos_screen);   	//spotlight shadow 2  	lpos = shadow_matrix[5]*spos; -	frag_color[3] = pcfSpotShadow(shadowMap5, lpos, 0.8, pos_screen);  +	frag_color[3] = pcfSpotShadowLegacy(shadowMap5, lpos, 0.8, pos_screen);   	//frag_color.rgb = pos.xyz;  	//frag_color.b = shadow; diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl index fd3256e9c8..10ef1785da 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl @@ -1,5 +1,5 @@  /**  - * @file sunLightSSAOF.glsl + * @file class2/deferred/sunLightSSAOF.glsl   * $LicenseInfo:firstyear=2007&license=viewerlgpl$   * Second Life Viewer Source Code   * Copyright (C) 2007, Linden Research, Inc. @@ -42,110 +42,33 @@ uniform sampler2DShadow shadowMap2;  uniform sampler2DShadow shadowMap3;  uniform sampler2DShadow shadowMap4;  uniform sampler2DShadow shadowMap5; -uniform sampler2D noiseMap; - - -// Inputs -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; -uniform float ssao_radius; -uniform float ssao_max_radius; -uniform float ssao_factor; -uniform float ssao_factor_inv;  VARYING vec2 vary_fragcoord;  uniform mat4 inv_proj;  uniform vec2 screen_res;  uniform vec2 proj_shadow_res; -uniform vec3 sun_dir; -uniform vec3 moon_dir; +uniform mat4 shadow_matrix[6]; +uniform vec4 shadow_clip;  uniform vec2 shadow_res; -  uniform float shadow_bias;  uniform float shadow_offset; -  uniform float spot_shadow_bias;  uniform float spot_shadow_offset; -vec3 decode_normal (vec2 enc); - -vec4 getPosition(vec2 pos_screen) -{ -	float depth = texture2DRect(depthMap, pos_screen.xy).r; -	vec2 sc = pos_screen.xy*2.0; -	sc /= screen_res; -	sc -= vec2(1.0,1.0); -	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; -} - -vec2 getKern(int i) -{ -	vec2 kern[8]; -	// exponentially (^2) distant occlusion samples spread around origin -	kern[0] = vec2(-1.0, 0.0) * 0.125*0.125; -	kern[1] = vec2(1.0, 0.0) * 0.250*0.250; -	kern[2] = vec2(0.0, 1.0) * 0.375*0.375; -	kern[3] = vec2(0.0, -1.0) * 0.500*0.500; -	kern[4] = vec2(0.7071, 0.7071) * 0.625*0.625; -	kern[5] = vec2(-0.7071, -0.7071) * 0.750*0.750; -	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]; -} +uniform vec3 sun_dir; +uniform vec3 moon_dir; -//calculate decreases in ambient lighting when crowded out (SSAO) -float calcAmbientOcclusion(vec4 pos, vec3 norm) -{ -	float ret = 1.0; +vec4 getPosition(vec2 pos_screen); +vec3 getNorm(vec2 pos_screen); -	vec2 pos_screen = vary_fragcoord.xy; -	vec3 pos_world = pos.xyz; -	vec2 noise_reflect = texture2D(noiseMap, vary_fragcoord.xy/128.0).xy; -		 -	float angle_hidden = 0.0; -	float points = 0; -		 -	float scale = min(ssao_radius / -pos_world.z, ssao_max_radius); -	 -	// it was found that keeping # of samples a constant was the fastest, probably due to compiler optimizations (unrolling?) -	for (int i = 0; i < 8; i++) -	{ -		vec2 samppos_screen = pos_screen + scale * reflect(getKern(i), noise_reflect); -		vec3 samppos_world = getPosition(samppos_screen).xyz;  -		 -		vec3 diff = pos_world - samppos_world; -		float dist2 = dot(diff, diff); -			 -		// assume each sample corresponds to an occluding sphere with constant radius, constant x-sectional area -		// --> solid angle shrinking by the square of distance -		//radius is somewhat arbitrary, can approx with just some constant k * 1 / dist^2 -		//(k should vary inversely with # of samples, but this is taken care of later) -		 -		float funky_val = (dot((samppos_world - 0.05*norm - pos_world), norm) > 0.0) ? 1.0 : 0.0; -		angle_hidden = angle_hidden + funky_val * min(1.0/dist2, ssao_factor_inv); -			 -		// 'blocked' samples (significantly closer to camera relative to pos_world) are "no data", not "no occlusion"  -		float diffz_val = (diff.z > -1.0) ? 1.0 : 0.0; -		points = points + diffz_val; -	} -		 -	angle_hidden = min(ssao_factor*angle_hidden/points, 1.0); -	 -	float points_val = (points > 0.0) ? 1.0 : 0.0; -	ret = (1.0 - (points_val * angle_hidden)); +float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen); +float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen); +float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen); -	ret = max(ret, 0.0); -	return min(ret, 1.0); -} -float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) +float pcfShadowLegacy(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen)  {  	stc.xyz /= stc.w;  	stc.z += shadow_bias; @@ -163,7 +86,7 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen)          return shadow*0.2;  } -float pcfSpotShadow(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen) +float pcfSpotShadowLegacy(sampler2DShadow shadowMap, vec4 stc, float scl, vec2 pos_screen)  {  	stc.xyz /= stc.w;  	stc.z += spot_shadow_bias*scl; @@ -189,10 +112,8 @@ void main()  	//try doing an unproject here -	vec4 pos = getPosition(pos_screen); -	 -	vec3 norm = texture2DRect(normalMap, pos_screen).xyz; -	norm = decode_normal(norm.xy); // unpack norm +	vec4 pos  = getPosition(pos_screen); +	vec3 norm = getNorm(pos_screen);  	/*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL  	{ @@ -235,7 +156,7 @@ void main()  				float w = 1.0;  				w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; -				shadow += pcfShadow(shadowMap3, lpos, 0.25, pos_screen)*w; +				shadow += pcfShadowLegacy(shadowMap3, lpos, 0.25, pos_screen)*w;  				weight += w;  				shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0);  			} @@ -247,7 +168,7 @@ void main()  				float w = 1.0;  				w -= max(spos.z-far_split.y, 0.0)/transition_domain.y;  				w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; -				shadow += pcfShadow(shadowMap2, lpos, 0.5, pos_screen)*w; +				shadow += pcfShadowLegacy(shadowMap2, lpos, 0.5, pos_screen)*w;  				weight += w;  			} @@ -258,7 +179,7 @@ void main()  				float w = 1.0;  				w -= max(spos.z-far_split.x, 0.0)/transition_domain.x;  				w -= max(near_split.y-spos.z, 0.0)/transition_domain.y; -				shadow += pcfShadow(shadowMap1, lpos, 0.75, pos_screen)*w; +				shadow += pcfShadowLegacy(shadowMap1, lpos, 0.75, pos_screen)*w;  				weight += w;  			} @@ -269,7 +190,7 @@ void main()  				float w = 1.0;  				w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; -				shadow += pcfShadow(shadowMap0, lpos, 1.0, pos_screen)*w; +				shadow += pcfShadowLegacy(shadowMap0, lpos, 1.0, pos_screen)*w;  				weight += w;  			} @@ -297,7 +218,7 @@ void main()  	}  	frag_color[0] = shadow; -	frag_color[1] = calcAmbientOcclusion(pos, norm); +	frag_color[1] = calcAmbientOcclusion(pos, norm, pos_screen);  	spos = vec4(shadow_pos+norm*spot_shadow_offset, 1.0); | 
