diff options
Diffstat (limited to 'indra/newview/app_settings/shaders/class2')
16 files changed, 347 insertions, 149 deletions
diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl index 1179b212ae..08f6ec63fe 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl @@ -26,7 +26,9 @@ #extension GL_ARB_texture_rectangle : enable #ifdef DEFINE_GL_FRAGCOLOR -out vec4 gl_FragColor; +out vec4 frag_color; +#else +#define frag_color gl_FragColor #endif VARYING vec4 vertex_color; @@ -78,7 +80,7 @@ void main() vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; frag *= screen_res; - float shadow = 1.0; + float shadow = 0.0; vec4 pos = vec4(vary_position, 1.0); vec4 spos = pos; @@ -87,31 +89,65 @@ void main() { vec4 lpos; - if (spos.z < -shadow_clip.z) + 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; lpos.xy *= shadow_res; - shadow = pcfShadow(shadowMap3, lpos, 1.5); + + float w = 1.0; + w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap3, lpos, 0.25)*w; + weight += w; shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); } - else if (spos.z < -shadow_clip.y) + + if (spos.z < near_split.y && spos.z > far_split.z) { lpos = shadow_matrix[2]*spos; lpos.xy *= shadow_res; - shadow = pcfShadow(shadowMap2, lpos, 1.5); + + 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)*w; + weight += w; } - else if (spos.z < -shadow_clip.x) + + if (spos.z < near_split.x && spos.z > far_split.y) { lpos = shadow_matrix[1]*spos; lpos.xy *= shadow_res; - shadow = pcfShadow(shadowMap1, lpos, 1.5); + + 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)*w; + weight += w; } - else + + if (spos.z > far_split.x) { lpos = shadow_matrix[0]*spos; lpos.xy *= shadow_res; - shadow = pcfShadow(shadowMap0, lpos, 1.5); + + float w = 1.0; + w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; + + shadow += pcfShadow(shadowMap0, lpos, 1.0)*w; + weight += w; } + + + shadow /= weight; + } + else + { + shadow = 1.0; } vec4 diff = diffuseLookup(vary_texcoord0.xy); @@ -125,6 +161,6 @@ void main() color.rgb += diff.rgb * vary_pointlight_col.rgb; - gl_FragColor = color; + frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaNonIndexedF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaNonIndexedF.glsl index 0df557f2aa..aae6a070e2 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaNonIndexedF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaNonIndexedF.glsl @@ -26,7 +26,9 @@ #extension GL_ARB_texture_rectangle : enable #ifdef DEFINE_GL_FRAGCOLOR -out vec4 gl_FragColor; +out vec4 frag_color; +#else +#define frag_color gl_FragColor #endif uniform sampler2DRectShadow shadowMap0; @@ -91,7 +93,7 @@ void main() vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; frag *= screen_res; - float shadow = 1.0; + float shadow = 0.0; vec4 pos = vec4(vary_position, 1.0); vec4 spos = pos; @@ -100,33 +102,68 @@ void main() { vec4 lpos; - if (spos.z < -shadow_clip.z) + 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; lpos.xy *= shadow_res; - shadow = pcfShadow(shadowMap3, lpos, 1.5); + + float w = 1.0; + w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap3, lpos, 0.25)*w; + weight += w; shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); } - else if (spos.z < -shadow_clip.y) + + if (spos.z < near_split.y && spos.z > far_split.z) { lpos = shadow_matrix[2]*spos; lpos.xy *= shadow_res; - shadow = pcfShadow(shadowMap2, lpos, 1.5); + + 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)*w; + weight += w; } - else if (spos.z < -shadow_clip.x) + + if (spos.z < near_split.x && spos.z > far_split.y) { lpos = shadow_matrix[1]*spos; lpos.xy *= shadow_res; - shadow = pcfShadow(shadowMap1, lpos, 1.5); + + 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)*w; + weight += w; } - else + + if (spos.z > far_split.x) { lpos = shadow_matrix[0]*spos; lpos.xy *= shadow_res; - shadow = pcfShadow(shadowMap0, lpos, 1.5); + + float w = 1.0; + w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; + + shadow += pcfShadow(shadowMap0, lpos, 1.0)*w; + weight += w; } + + + shadow /= weight; + } - + else + { + shadow = 1.0; + } + vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); vec4 col = vec4(vary_ambient + vary_directional.rgb*shadow, vertex_color.a); @@ -138,6 +175,6 @@ void main() color.rgb += diff.rgb * vary_pointlight_col.rgb; - gl_FragColor = color; + frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaNonIndexedNoColorF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaNonIndexedNoColorF.glsl index 331dbc7079..931577359e 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaNonIndexedNoColorF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaNonIndexedNoColorF.glsl @@ -26,7 +26,9 @@ #extension GL_ARB_texture_rectangle : enable #ifdef DEFINE_GL_FRAGCOLOR -out vec4 gl_FragColor; +out vec4 frag_color; +#else +#define frag_color gl_FragColor #endif uniform sampler2DRectShadow shadowMap0; @@ -90,7 +92,7 @@ void main() vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5; frag *= screen_res; - float shadow = 1.0; + float shadow = 0.0; vec4 pos = vec4(vary_position, 1.0); vec4 spos = pos; @@ -99,31 +101,65 @@ void main() { vec4 lpos; - if (spos.z < -shadow_clip.z) + 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; lpos.xy *= shadow_res; - shadow = pcfShadow(shadowMap3, lpos, 1.5); + + float w = 1.0; + w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap3, lpos, 0.25)*w; + weight += w; shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); } - else if (spos.z < -shadow_clip.y) + + if (spos.z < near_split.y && spos.z > far_split.z) { lpos = shadow_matrix[2]*spos; lpos.xy *= shadow_res; - shadow = pcfShadow(shadowMap2, lpos, 1.5); + + 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)*w; + weight += w; } - else if (spos.z < -shadow_clip.x) + + if (spos.z < near_split.x && spos.z > far_split.y) { lpos = shadow_matrix[1]*spos; lpos.xy *= shadow_res; - shadow = pcfShadow(shadowMap1, lpos, 1.5); + + 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)*w; + weight += w; } - else + + if (spos.z > far_split.x) { lpos = shadow_matrix[0]*spos; lpos.xy *= shadow_res; - shadow = pcfShadow(shadowMap0, lpos, 1.5); + + float w = 1.0; + w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; + + shadow += pcfShadow(shadowMap0, lpos, 1.0)*w; + weight += w; } + + + shadow /= weight; + } + else + { + shadow = 1.0; } vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy); @@ -137,6 +173,6 @@ void main() color.rgb += diff.rgb * vary_pointlight_col.rgb; - gl_FragColor = color; + frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaSkinnedV.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaSkinnedV.glsl index 83815b1786..9629cfe824 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaSkinnedV.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaSkinnedV.glsl @@ -61,6 +61,12 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; +float calcDirectionalLight(vec3 n, vec3 l) +{ + float a = max(dot(n,l),0.0); + return a; +} + float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) { //get light vector diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaV.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaV.glsl index 1660f9687e..1586aab0f2 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/alphaV.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/alphaV.glsl @@ -63,6 +63,12 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; +float calcDirectionalLight(vec3 n, vec3 l) +{ + float a = max(dot(n,l),0.0); + return a; +} + float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) { //get light vector diff --git a/indra/newview/app_settings/shaders/class2/deferred/avatarAlphaV.glsl b/indra/newview/app_settings/shaders/class2/deferred/avatarAlphaV.glsl index 84c27edb26..44aaa98b97 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/avatarAlphaV.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/avatarAlphaV.glsl @@ -60,6 +60,12 @@ uniform vec3 light_direction[8]; uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; +float calcDirectionalLight(vec3 n, vec3 l) +{ + float a = max(dot(n,l),0.0); + return a; +} + float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float fa, float is_pointlight) { //get light vector diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index 14a683971a..f7f1f649ce 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -26,7 +26,9 @@ #extension GL_ARB_texture_rectangle : enable #ifdef DEFINE_GL_FRAGCOLOR -out vec4 gl_FragColor; +out vec4 frag_color; +#else +#define frag_color gl_FragColor #endif uniform sampler2DRect diffuseRect; @@ -253,6 +255,6 @@ void main() } } - gl_FragColor.rgb = col; - gl_FragColor.a = 0.0; + frag_color.rgb = col; + frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 97f3063a9e..61a7f1e32f 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -26,7 +26,9 @@ #extension GL_ARB_texture_rectangle : enable #ifdef DEFINE_GL_FRAGCOLOR -out vec4 gl_FragColor; +out vec4 frag_color; +#else +#define frag_color gl_FragColor #endif uniform sampler2DRect diffuseRect; @@ -51,12 +53,12 @@ uniform vec4 sunlight_color; uniform vec4 ambient; uniform vec4 blue_horizon; uniform vec4 blue_density; -uniform vec4 haze_horizon; -uniform vec4 haze_density; -uniform vec4 cloud_shadow; -uniform vec4 density_multiplier; -uniform vec4 distance_multiplier; -uniform vec4 max_y; +uniform float haze_horizon; +uniform float haze_density; +uniform float cloud_shadow; +uniform float density_multiplier; +uniform float distance_multiplier; +uniform float max_y; uniform vec4 glow; uniform float scene_light_strength; uniform mat3 env_mat; @@ -161,13 +163,13 @@ void calcAtmospherics(vec3 inPositionEye, float ambFactor) { //sunlight attenuation effect (hue and brightness) due to atmosphere //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density * 1.0 + vec4(haze_density.r) * 0.25) * (density_multiplier.x * max_y.x); + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); //I had thought blue_density and haze_density should have equal weighting, //but attenuation due to haze_density tends to seem too strong - temp1 = blue_density + vec4(haze_density.r); + temp1 = blue_density + vec4(haze_density); blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density.r) / temp1; + haze_weight = vec4(haze_density) / temp1; //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) temp2.y = max(0.0, tmpLightnorm.y); @@ -175,12 +177,12 @@ void calcAtmospherics(vec3 inPositionEye, float ambFactor) { sunlight *= exp( - light_atten * temp2.y); // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier.x; + temp2.z = Plen * density_multiplier; // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier.x in a variable because the ati + // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier.x); + temp1 = exp(-temp1 * temp2.z * distance_multiplier); //final atmosphere attenuation factor setAtmosAttenuation(temp1.rgb); @@ -201,7 +203,7 @@ void calcAtmospherics(vec3 inPositionEye, float ambFactor) { temp2.x += .25; //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow.x * 0.5; + vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; /* decrease value and saturation (that in HSV, not HSL) for occluded areas * // for HSV color/geometry used here, see http://gimp-savvy.com/BOOK/index.html?node52.html @@ -215,8 +217,8 @@ void calcAtmospherics(vec3 inPositionEye, float ambFactor) { //haze color setAdditiveColor( - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow.x) + tmpAmbient) - + (haze_horizon.r * haze_weight) * (sunlight*(1.-cloud_shadow.x) * temp2.x + vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + tmpAmbient))); //brightness of surface both sunlight and ambient @@ -330,6 +332,6 @@ void main() col = diffuse.rgb; } - gl_FragColor.rgb = col; - gl_FragColor.a = bloom; + frag_color.rgb = col; + frag_color.a = bloom; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 31bd0c79da..99a277fbfc 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -26,7 +26,9 @@ #extension GL_ARB_texture_rectangle : enable #ifdef DEFINE_GL_FRAGCOLOR -out vec4 gl_FragColor; +out vec4 frag_color; +#else +#define frag_color gl_FragColor #endif VARYING vec4 vertex_color; @@ -201,6 +203,6 @@ void main() } } - gl_FragColor.rgb = col; - gl_FragColor.a = 0.0; + frag_color.rgb = col; + frag_color.a = 0.0; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl index 229c2f4b67..8c4ccf9cb3 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl @@ -26,7 +26,9 @@ #extension GL_ARB_texture_rectangle : enable #ifdef DEFINE_GL_FRAGCOLOR -out vec4 gl_FragColor; +out vec4 frag_color; +#else +#define frag_color gl_FragColor #endif //class 2, shadows, no SSAO @@ -129,11 +131,11 @@ void main() /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL { - gl_FragColor = vec4(0.0); // doesn't matter + frag_color = vec4(0.0); // doesn't matter return; }*/ - float shadow = 1.0; + float shadow = 0.0; float dp_directional_light = max(0.0, dot(norm, sun_dir.xyz)); vec3 shadow_pos = pos.xyz + displace*norm; @@ -152,32 +154,62 @@ void main() { vec4 lpos; - if (spos.z < -shadow_clip.z) + 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; lpos.xy *= shadow_res; - shadow = pcfShadow(shadowMap3, lpos, 0.25); + + float w = 1.0; + w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap3, lpos, 0.25)*w; + weight += w; shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); } - else if (spos.z < -shadow_clip.y) + + if (spos.z < near_split.y && spos.z > far_split.z) { lpos = shadow_matrix[2]*spos; lpos.xy *= shadow_res; - shadow = pcfShadow(shadowMap2, lpos, 0.5); + + 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)*w; + weight += w; } - else if (spos.z < -shadow_clip.x) + + if (spos.z < near_split.x && spos.z > far_split.y) { lpos = shadow_matrix[1]*spos; lpos.xy *= shadow_res; - shadow = pcfShadow(shadowMap1, lpos, 0.75); + + 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)*w; + weight += w; } - else + + if (spos.z > far_split.x) { lpos = shadow_matrix[0]*spos; lpos.xy *= shadow_res; - shadow = pcfShadow(shadowMap0, lpos, 1.0); + + float w = 1.0; + w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; + + shadow += pcfShadow(shadowMap0, lpos, 1.0)*w; + weight += w; } + + shadow /= weight; + // take the most-shadowed value out of these two: // * the blurred sun shadow in the light (shadow) map // * an unblurred dot product between the sun and this norm @@ -198,19 +230,19 @@ void main() shadow = 1.0; } - gl_FragColor[0] = shadow; - gl_FragColor[1] = 1.0; + frag_color[0] = shadow; + frag_color[1] = 1.0; spos = vec4(shadow_pos+norm*spot_shadow_offset, 1.0); //spotlight shadow 1 vec4 lpos = shadow_matrix[4]*spos; - gl_FragColor[2] = pcfShadow(shadowMap4, lpos, 0.8); + frag_color[2] = pcfShadow(shadowMap4, lpos, 0.8); //spotlight shadow 2 lpos = shadow_matrix[5]*spos; - gl_FragColor[3] = pcfShadow(shadowMap5, lpos, 0.8); + frag_color[3] = pcfShadow(shadowMap5, lpos, 0.8); - //gl_FragColor.rgb = pos.xyz; - //gl_FragColor.b = shadow; + //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 6b420833b9..02075a7687 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl @@ -25,7 +25,9 @@ #extension GL_ARB_texture_rectangle : enable #ifdef DEFINE_GL_FRAGCOLOR -out vec4 gl_FragColor; +out vec4 frag_color; +#else +#define frag_color gl_FragColor #endif //class 2 -- shadows and SSAO @@ -190,11 +192,11 @@ void main() /*if (pos.z == 0.0) // do nothing for sky *FIX: REMOVE THIS IF/WHEN THE POSITION MAP IS BEING USED AS A STENCIL { - gl_FragColor = vec4(0.0); // doesn't matter + frag_color = vec4(0.0); // doesn't matter return; }*/ - float shadow = 1.0; + float shadow = 0.0; float dp_directional_light = max(0.0, dot(norm, sun_dir.xyz)); vec3 shadow_pos = pos.xyz + displace*norm; @@ -212,33 +214,63 @@ void main() else { vec4 lpos; - - if (spos.z < -shadow_clip.z) + + 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; lpos.xy *= shadow_res; - shadow = pcfShadow(shadowMap3, lpos, 0.25); + + float w = 1.0; + w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; + shadow += pcfShadow(shadowMap3, lpos, 0.25)*w; + weight += w; shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); } - else if (spos.z < -shadow_clip.y) + + if (spos.z < near_split.y && spos.z > far_split.z) { lpos = shadow_matrix[2]*spos; lpos.xy *= shadow_res; - shadow = pcfShadow(shadowMap2, lpos, 0.5); + + 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)*w; + weight += w; } - else if (spos.z < -shadow_clip.x) + + if (spos.z < near_split.x && spos.z > far_split.y) { lpos = shadow_matrix[1]*spos; lpos.xy *= shadow_res; - shadow = pcfShadow(shadowMap1, lpos, 0.75); + + 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)*w; + weight += w; } - else + + if (spos.z > far_split.x) { lpos = shadow_matrix[0]*spos; lpos.xy *= shadow_res; - shadow = pcfShadow(shadowMap0, lpos, 1.0); + + float w = 1.0; + w -= max(near_split.x-spos.z, 0.0)/transition_domain.x; + + shadow += pcfShadow(shadowMap0, lpos, 1.0)*w; + weight += w; } + + shadow /= weight; + // take the most-shadowed value out of these two: // * the blurred sun shadow in the light (shadow) map // * an unblurred dot product between the sun and this norm @@ -259,19 +291,19 @@ void main() shadow = 1.0; } - gl_FragColor[0] = shadow; - gl_FragColor[1] = calcAmbientOcclusion(pos, norm); + frag_color[0] = shadow; + frag_color[1] = calcAmbientOcclusion(pos, norm); spos = vec4(shadow_pos+norm*spot_shadow_offset, 1.0); //spotlight shadow 1 vec4 lpos = shadow_matrix[4]*spos; - gl_FragColor[2] = pcfShadow(shadowMap4, lpos, 0.8); + frag_color[2] = pcfShadow(shadowMap4, lpos, 0.8); //spotlight shadow 2 lpos = shadow_matrix[5]*spos; - gl_FragColor[3] = pcfShadow(shadowMap5, lpos, 0.8); + frag_color[3] = pcfShadow(shadowMap5, lpos, 0.8); - //gl_FragColor.rgb = pos.xyz; - //gl_FragColor.b = shadow; + //frag_color.rgb = pos.xyz; + //frag_color.b = shadow; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl index 6a83be1426..da3d922017 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl @@ -47,12 +47,12 @@ uniform vec4 sunlight_color; uniform vec4 ambient; uniform vec4 blue_horizon; uniform vec4 blue_density; -uniform vec4 haze_horizon; -uniform vec4 haze_density; -uniform vec4 cloud_shadow; -uniform vec4 density_multiplier; -uniform vec4 distance_multiplier; -uniform vec4 max_y; +uniform float haze_horizon; +uniform float haze_density; +uniform float cloud_shadow; +uniform float density_multiplier; +uniform float distance_multiplier; +uniform float max_y; uniform vec4 glow; void calcAtmospherics(vec3 inPositionEye) { @@ -61,8 +61,8 @@ void calcAtmospherics(vec3 inPositionEye) { setPositionEye(P); //(TERRAIN) limit altitude - if (P.y > max_y.x) P *= (max_y.x / P.y); - if (P.y < -max_y.x) P *= (-max_y.x / P.y); + if (P.y > max_y) P *= (max_y / P.y); + if (P.y < -max_y) P *= (-max_y / P.y); vec3 tmpLightnorm = lightnorm.xyz; @@ -78,13 +78,13 @@ void calcAtmospherics(vec3 inPositionEye) { //sunlight attenuation effect (hue and brightness) due to atmosphere //this is used later for sunlight modulation at various altitudes - light_atten = (blue_density * 1.0 + vec4(haze_density.r) * 0.25) * (density_multiplier.x * max_y.x); + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); //I had thought blue_density and haze_density should have equal weighting, //but attenuation due to haze_density tends to seem too strong - temp1 = blue_density + vec4(haze_density.r); + temp1 = blue_density + vec4(haze_density); blue_weight = blue_density / temp1; - haze_weight = vec4(haze_density.r) / temp1; + haze_weight = vec4(haze_density) / temp1; //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) temp2.y = max(0.0, tmpLightnorm.y); @@ -92,12 +92,12 @@ void calcAtmospherics(vec3 inPositionEye) { sunlight *= exp( - light_atten * temp2.y); // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier.x; + temp2.z = Plen * density_multiplier; // Transparency (-> temp1) - // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier.x in a variable because the ati + // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier in a variable because the ati // compiler gets confused. - temp1 = exp(-temp1 * temp2.z * distance_multiplier.x); + temp1 = exp(-temp1 * temp2.z * distance_multiplier); //final atmosphere attenuation factor setAtmosAttenuation(temp1.rgb); @@ -122,12 +122,12 @@ void calcAtmospherics(vec3 inPositionEye) { //increase ambient when there are more clouds - vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow.x * 0.5; + vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5; //haze color setAdditiveColor( - vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow.x) + tmpAmbient) - + (haze_horizon.r * haze_weight) * (sunlight*(1.-cloud_shadow.x) * temp2.x + vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x + tmpAmbient))); //brightness of surface both sunlight and ambient diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl index 4ab06c6e21..96c70651b1 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsF.glsl @@ -24,7 +24,9 @@ */ #ifdef DEFINE_GL_FRAGCOLOR -out vec4 gl_FragColor; +out vec4 frag_color; +#else +#define frag_color gl_FragColor #endif ///////////////////////////////////////////////////////////////////////// @@ -96,7 +98,7 @@ void main() color *= 2.; /// Gamma correct for WL (soft clip effect). - gl_FragColor.rgb = scaleSoftClip(color.rgb); - gl_FragColor.a = alpha1; + frag_color.rgb = scaleSoftClip(color.rgb); + frag_color.a = alpha1; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl index c5bb52169c..c1dd45cd67 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl @@ -49,18 +49,18 @@ uniform vec4 sunlight_color; uniform vec4 ambient; uniform vec4 blue_horizon; uniform vec4 blue_density; -uniform vec4 haze_horizon; -uniform vec4 haze_density; +uniform float haze_horizon; +uniform float haze_density; -uniform vec4 cloud_shadow; -uniform vec4 density_multiplier; -uniform vec4 max_y; +uniform float cloud_shadow; +uniform float density_multiplier; +uniform float max_y; uniform vec4 glow; uniform vec4 cloud_color; -uniform vec4 cloud_scale; +uniform float cloud_scale; void main() { @@ -76,7 +76,7 @@ void main() // Set altitude if (P.y > 0.) { - P *= (max_y.x / P.y); + P *= (max_y / P.y); } else { @@ -98,12 +98,12 @@ void main() // Sunlight attenuation effect (hue and brightness) due to atmosphere // this is used later for sunlight modulation at various altitudes - light_atten = (blue_density * 1.0 + haze_density.x * 0.25) * (density_multiplier.x * max_y.x); + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); // Calculate relative weights - temp1 = blue_density + haze_density.x; + temp1 = blue_density + haze_density; blue_weight = blue_density / temp1; - haze_weight = haze_density.x / temp1; + haze_weight = haze_density / temp1; // Compute sunlight from P & lightnorm (for long rays like sky) temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); @@ -111,7 +111,7 @@ void main() sunlight *= exp( - light_atten * temp2.y); // Distance - temp2.z = Plen * density_multiplier.x; + temp2.z = Plen * density_multiplier; // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati @@ -135,14 +135,14 @@ void main() // Increase ambient when there are more clouds vec4 tmpAmbient = ambient; - tmpAmbient += (1. - tmpAmbient) * cloud_shadow.x * 0.5; + tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; // Dim sunlight by cloud shadow percentage - sunlight *= (1. - cloud_shadow.x); + sunlight *= (1. - cloud_shadow); // Haze color below cloud vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) - + (haze_horizon.r * haze_weight) * (sunlight * temp2.x + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) ); // CLOUDS @@ -163,13 +163,13 @@ void main() vec4 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - temp1); // Make a nice cloud density based on the cloud_shadow value that was passed in. - vary_CloudDensity = 2. * (cloud_shadow.x - 0.25); + vary_CloudDensity = 2. * (cloud_shadow - 0.25); // Texture coords vary_texcoord0 = texcoord0; vary_texcoord0.xy -= 0.5; - vary_texcoord0.xy /= cloud_scale.x; + vary_texcoord0.xy /= cloud_scale; vary_texcoord0.xy += 0.5; vary_texcoord1 = vary_texcoord0; diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl index c9d96b2cf4..e2a2367626 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyF.glsl @@ -24,7 +24,9 @@ */ #ifdef DEFINE_GL_FRAGCOLOR -out vec4 gl_FragColor; +out vec4 frag_color; +#else +#define frag_color gl_FragColor #endif ///////////////////////////////////////////////////////////////////////// @@ -57,7 +59,7 @@ void main() color *= 2.; /// Gamma correct for WL (soft clip effect). - gl_FragColor.rgb = scaleSoftClip(color.rgb); - gl_FragColor.a = 1.0; + frag_color.rgb = scaleSoftClip(color.rgb); + frag_color.a = 1.0; } diff --git a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl index 46773cf89f..3788ddaf2d 100644 --- a/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl +++ b/indra/newview/app_settings/shaders/class2/windlight/skyV.glsl @@ -42,19 +42,17 @@ uniform vec4 sunlight_color; uniform vec4 ambient; uniform vec4 blue_horizon; uniform vec4 blue_density; -uniform vec4 haze_horizon; -uniform vec4 haze_density; +uniform float haze_horizon; +uniform float haze_density; -uniform vec4 cloud_shadow; -uniform vec4 density_multiplier; -uniform vec4 max_y; +uniform float cloud_shadow; +uniform float density_multiplier; +uniform float max_y; uniform vec4 glow; uniform vec4 cloud_color; -uniform vec4 cloud_scale; - void main() { @@ -68,7 +66,7 @@ void main() // Set altitude if (P.y > 0.) { - P *= (max_y.x / P.y); + P *= (max_y / P.y); } else { @@ -87,15 +85,14 @@ void main() vec4 sunlight = sunlight_color; vec4 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 * 1.0 + haze_density.x * 0.25) * (density_multiplier.x * max_y.x); + light_atten = (blue_density + vec4(haze_density * 0.25)) * (density_multiplier * max_y); // Calculate relative weights - temp1 = blue_density + haze_density.x; + temp1 = blue_density + haze_density; blue_weight = blue_density / temp1; - haze_weight = haze_density.x / temp1; + haze_weight = haze_density / temp1; // Compute sunlight from P & lightnorm (for long rays like sky) temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); @@ -103,7 +100,7 @@ void main() sunlight *= exp( - light_atten * temp2.y); // Distance - temp2.z = Plen * density_multiplier.x; + temp2.z = Plen * density_multiplier; // Transparency (-> temp1) // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati @@ -128,20 +125,20 @@ void main() // Haze color above cloud vary_HazeColor = ( blue_horizon * blue_weight * (sunlight + ambient) - + (haze_horizon.r * haze_weight) * (sunlight * temp2.x + ambient) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + ambient) ); // Increase ambient when there are more clouds vec4 tmpAmbient = ambient; - tmpAmbient += (1. - tmpAmbient) * cloud_shadow.x * 0.5; + tmpAmbient += (1. - tmpAmbient) * cloud_shadow * 0.5; // Dim sunlight by cloud shadow percentage - sunlight *= (1. - cloud_shadow.x); + sunlight *= (1. - cloud_shadow); // Haze color below cloud vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) - + (haze_horizon.r * haze_weight) * (sunlight * temp2.x + tmpAmbient) + + (haze_horizon * haze_weight) * (sunlight * temp2.x + tmpAmbient) ); // Final atmosphere additive |