Merge remote-tracking branch 'upstream/master'

Conflicts:
	indra/newview/app_settings/shaders/class1/deferred/alphaNonIndexedNoColorF.glsl
	indra/newview/app_settings/shaders/class1/deferred/fullbrightShinyF.glsl
	indra/newview/app_settings/shaders/class1/deferred/fxaaF.glsl
	indra/newview/app_settings/shaders/class1/deferred/giF.glsl
	indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl
	indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl
	indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl
	indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl
	indra/newview/app_settings/shaders/class2/deferred/alphaNonIndexedF.glsl
	indra/newview/app_settings/shaders/class2/deferred/alphaNonIndexedNoColorF.glsl
	indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl
	indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl
This commit is contained in:
Andros Baphomet
2013-11-03 12:17:50 -05:00
150 changed files with 8594 additions and 3387 deletions

View File

@@ -38,7 +38,6 @@ uniform sampler2DRect lightMap;
uniform sampler2DRect depthMap;
uniform samplerCube environmentMap;
uniform sampler2D lightFunc;
uniform vec3 gi_quad;
uniform float blur_size;
uniform float blur_fidelity;
@@ -60,16 +59,13 @@ uniform float density_multiplier;
uniform float distance_multiplier;
uniform float max_y;
uniform vec4 glow;
uniform float global_gamma;
uniform float scene_light_strength;
uniform mat3 env_mat;
uniform vec4 shadow_clip;
uniform float ssao_effect;
uniform mat4 inv_proj;
uniform vec2 screen_res;
uniform vec3 sun_dir;
VARYING vec2 vary_fragcoord;
vec3 vary_PositionEye;
@@ -79,11 +75,61 @@ vec3 vary_AmblitColor;
vec3 vary_AdditiveColor;
vec3 vary_AtmosAttenuation;
float luminance(vec3 color)
uniform mat4 inv_proj;
uniform vec2 screen_res;
vec3 srgb_to_linear(vec3 cs)
{
/// CALCULATING LUMINANCE (Using NTSC lum weights)
/// http://en.wikipedia.org/wiki/Luma_%28video%29
return dot(color, vec3(0.299, 0.587, 0.114));
vec3 low_range = cs / vec3(12.92);
vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4));
bvec3 lte = lessThanEqual(cs,vec3(0.04045));
#ifdef OLD_SELECT
vec3 result;
result.r = lte.r ? low_range.r : high_range.r;
result.g = lte.g ? low_range.g : high_range.g;
result.b = lte.b ? low_range.b : high_range.b;
return result;
#else
return mix(high_range, low_range, lte);
#endif
}
vec3 linear_to_srgb(vec3 cl)
{
cl = clamp(cl, vec3(0), vec3(1));
vec3 low_range = cl * 12.92;
vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055;
bvec3 lt = lessThan(cl,vec3(0.0031308));
#ifdef OLD_SELECT
vec3 result;
result.r = lt.r ? low_range.r : high_range.r;
result.g = lt.g ? low_range.g : high_range.g;
result.b = lt.b ? low_range.b : high_range.b;
return result;
#else
return mix(high_range, low_range, lt);
#endif
}
vec2 encode_normal(vec3 n)
{
float f = sqrt(8 * n.z + 8);
return n.xy / f + 0.5;
}
vec3 decode_normal (vec2 enc)
{
vec2 fenc = enc*4-2;
float f = dot(fenc,fenc);
float g = sqrt(1-f/4);
vec3 n;
n.xy = fenc*g;
n.z = 1-f/2;
return n;
}
vec4 getPosition_d(vec2 pos_screen, float depth)
@@ -125,7 +171,6 @@ vec3 getAtmosAttenuation()
return vary_AtmosAttenuation;
}
void setPositionEye(vec3 v)
{
vary_PositionEye = v;
@@ -211,7 +256,7 @@ void calcAtmospherics(vec3 inPositionEye, float ambFactor) {
//increase ambient when there are more clouds
vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow * 0.5;
//haze color
setAdditiveColor(
vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient)
@@ -220,13 +265,63 @@ void calcAtmospherics(vec3 inPositionEye, float ambFactor) {
// decrease ambient value for occluded areas
tmpAmbient *= mix(ssao_effect, 1.0, ambFactor);
//brightness of surface both sunlight and ambient
/*setSunlitColor(pow(vec3(sunlight * .5), vec3(global_gamma)) * global_gamma);
setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(global_gamma)) * global_gamma);
setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(global_gamma)) * global_gamma);*/
setSunlitColor(vec3(sunlight * .5));
setAmblitColor(vec3(tmpAmbient * .25));
setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1));
}
#ifdef WATER_FOG
uniform vec4 waterPlane;
uniform vec4 waterFogColor;
uniform float waterFogDensity;
uniform float waterFogKS;
vec4 applyWaterFogDeferred(vec3 pos, vec4 color)
{
//normalize view vector
vec3 view = normalize(pos);
float es = -(dot(view, waterPlane.xyz));
//find intersection point with water plane and eye vector
//get eye depth
float e0 = max(-waterPlane.w, 0.0);
vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0);
//get object depth
float depth = length(pos - int_v);
//get "thickness" of water
float l = max(depth, 0.1);
float kd = waterFogDensity;
float ks = waterFogKS;
vec4 kc = waterFogColor;
float F = 0.98;
float t1 = -kd * pow(F, ks * e0);
float t2 = kd + ks * es;
float t3 = pow(F, t2*l) - 1.0;
float L = min(t1/t2*t3, 1.0);
float D = pow(0.98, l*kd);
color.rgb = color.rgb * D + kc.rgb * L;
color.a = kc.a + color.a;
return color;
}
#endif
vec3 atmosLighting(vec3 light)
{
light *= getAtmosAttenuation().r;
@@ -239,6 +334,15 @@ vec3 atmosTransport(vec3 light) {
light += getAdditiveColor() * 2.0;
return light;
}
vec3 fullbrightAtmosTransport(vec3 light) {
float brightness = dot(light.rgb, vec3(0.33333));
return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness);
}
vec3 atmosGetDiffuseSunlightColor()
{
return getSunlitColor();
@@ -273,18 +377,18 @@ vec3 scaleSoftClip(vec3 light)
return light;
}
vec3 unpack(vec2 tc)
vec3 fullbrightScaleSoftClip(vec3 light)
{
//#define PACK_NORMALS
#ifdef PACK_NORMALS
vec2 enc = texture2DRect(normalMap, tc).xy;
enc = enc*4.0-2.0;
float prod = dot(enc,enc);
return vec3(enc*sqrt(1.0-prod*.25),1.0-prod*.5);
#else
vec3 norm = texture2DRect(normalMap, tc).xyz;
return norm*2.0-1.0;
#endif
//soft clip effect:
return light;
}
float luminance(vec3 color)
{
/// CALCULATING LUMINANCE (Using NTSC lum weights)
/// http://en.wikipedia.org/wiki/Luma_%28video%29
return dot(color, vec3(0.299, 0.587, 0.114));
}
void main()
@@ -292,61 +396,107 @@ void main()
vec2 tc = vary_fragcoord.xy;
float depth = texture2DRect(depthMap, tc.xy).r;
vec3 pos = getPosition_d(tc, depth).xyz;
vec3 norm = unpack(tc); // unpack norm
vec4 norm = texture2DRect(normalMap, tc);
float envIntensity = norm.z;
norm.xyz = decode_normal(norm.xy); // unpack norm
float da = max(dot(norm.xyz, sun_dir.xyz), 0.0);
vec4 diffuse = texture2DRect(diffuseRect, tc);
vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy);
float light_gamma = 1.0/1.3;
da = pow(da, light_gamma);
vec4 diffuse = texture2DRect(diffuseRect, tc);
//convert to gamma space
diffuse.rgb = linear_to_srgb(diffuse.rgb);
vec3 col;
float bloom = 0.0;
if (diffuse.a < 0.9)
{
vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy);
bloom = spec.r*norm.w;
if (norm.w < 0.5)
{
vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg;
scol_ambocc = pow(scol_ambocc, vec2(light_gamma));
float scol = max(scol_ambocc.r, diffuse.a);
float ambocc = scol_ambocc.g;
calcAtmospherics(pos.xyz, ambocc);
col = atmosAmbient(vec3(0));
col += atmosAffectDirectionalLight(max(min(da, scol), diffuse.a));
float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0);
ambient *= 0.5;
ambient *= ambient;
ambient = (1.0-ambient);
col.rgb *= ambient;
col += atmosAffectDirectionalLight(max(min(da, scol), 0.0));
col *= diffuse.rgb;
vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz));
if (spec.a > 0.0) // specular reflection
{
// the old infinite-sky shiny reflection
//
vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz));
float sa = dot(refnormpersp, sun_dir.xyz);
vec3 dumbshiny = vary_SunlitColor*scol_ambocc.r*(6 * texture2D(lightFunc, vec2(sa, spec.a)).r);
vec3 dumbshiny = vary_SunlitColor*scol_ambocc.r*(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) / 4;
bloom = dot(spec_contrib, spec_contrib) / 6;
col += spec_contrib;
//add environmentmap
vec3 env_vec = env_mat * refnormpersp;
vec3 env = textureCube(environmentMap, env_vec).rgb;
bloom = (luminance(env) - .45)*.25;
col = mix(col.rgb, env,
max(spec.a-diffuse.a*2.0, 0.0));
}
col = atmosLighting(col);
col = scaleSoftClip(col);
col = mix(col, diffuse.rgb, diffuse.a);
}
else
{
bloom = spec.r;
col = diffuse.rgb;
}
}
col = mix(col, diffuse.rgb, diffuse.a);
if (envIntensity > 0.0)
{ //add environmentmap
vec3 env_vec = env_mat * refnormpersp;
vec3 refcol = textureCube(environmentMap, env_vec).rgb*scol_ambocc.r;
bloom = (luminance(refcol) - .45)*.25;
col = mix(col.rgb, refcol,
envIntensity);
}
//if (norm.w < 0.5)
{
col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a);
col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a);
//bloom += (luminance(col))*.075; //This looks nice, but requires a larger glow rendertarget.
}
#ifdef WATER_FOG
vec4 fogged = applyWaterFogDeferred(pos,vec4(col, bloom));
col = fogged.rgb;
bloom = fogged.a;
#endif
}
else
{
col = diffuse.rgb;
}
col = srgb_to_linear(col);
//col = vec3(1,0,1);
//col.g = envIntensity;
}
frag_color.rgb = col;
frag_color.a = bloom;
}