diff options
author | Graham Madarasz (Graham Linden) <graham@lindenlab.com> | 2013-04-19 11:53:58 -0700 |
---|---|---|
committer | Graham Madarasz (Graham Linden) <graham@lindenlab.com> | 2013-04-19 11:53:58 -0700 |
commit | c5410a5d22ac5234226ab8f67144a753ef2d3019 (patch) | |
tree | f14e53417820254d75ec234b3f48837892e77592 /indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | |
parent | 2b3495ae5ef9947b1b779bec725fb45abc1a609a (diff) |
Shader changes for Mac compat
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl')
-rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/materialF.glsl | 172 |
1 files changed, 68 insertions, 104 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 5e75cc3ce6..43848761b3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -29,7 +29,8 @@ #define DIFFUSE_ALPHA_MODE_EMISSIVE 3 -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else @@ -349,39 +350,44 @@ vec3 atmosGetDiffuseSunlightColor() vec3 scaleDownLight(vec3 light) { - return (light / scene_light_strength ); + return (light / vec3(scene_light_strength, scene_light_strength, scene_light_strength)); } vec3 scaleUpLight(vec3 light) { - return (light * scene_light_strength); + return (light * vec3(scene_light_strength, scene_light_strength, scene_light_strength)); } vec3 atmosAmbient(vec3 light) { - return getAmblitColor() + light / 2.0; + return getAmblitColor() + (light * vec3(0.5f, 0.5f, 0.5f)); } vec3 atmosAffectDirectionalLight(float lightIntensity) { - return getSunlitColor() * lightIntensity; + return getSunlitColor() * vec3(lightIntensity, lightIntensity, lightIntensity); } vec3 scaleSoftClip(vec3 light) { //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); + vec3 zeroes = vec3(0.0f, 0.0f, 0.0f); + vec3 ones = vec3(1.0f, 1.0f, 1.0f); + + light = ones - clamp(light, zeroes, ones); + light = ones - pow(light, gamma.xxx); return light; } #else + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_data[3]; #else #define frag_data gl_FragData #endif + #endif uniform sampler2D diffuseMap; @@ -399,7 +405,7 @@ VARYING vec2 vary_texcoord2; uniform float env_intensity; uniform vec4 specular_color; -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) uniform float minimum_alpha; #endif @@ -426,14 +432,14 @@ void main() vec4 diffcol = texture2D(diffuseMap, vary_texcoord0.xy); diffcol.rgb *= vertex_color.rgb; -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) if (diffcol.a < minimum_alpha) { discard; } #endif -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) diffcol.rgb = pow(diffcol.rgb, vec3(2.2)); #endif @@ -456,9 +462,12 @@ void main() vec3 tnorm = vary_normal; #endif + norm.xyz = tnorm; + norm.xyz = normalize(norm.xyz); + vec4 final_color = diffcol; -#if DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE +#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) final_color.a = 0; #endif @@ -475,9 +484,8 @@ void main() #endif -#if DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND - { - //forward rendering, output just lit RGBA +#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) + //forward rendering, output just lit RGBA vec3 pos = vary_position; #if HAS_SUN_SHADOW @@ -549,110 +557,65 @@ void main() float shadow = 1.0; #endif - vec4 diffuse = final_color; - vec3 norm = normalize(tnorm); - vec4 spec = final_specular; - float envIntensity = final_normal.z; + spec = final_specular; + vec4 diffuse = final_color; + float envIntensity = final_normal.z; - vec3 col; - float bloom = 0.0; - { - calcAtmospherics(pos.xyz, 1.0); + vec3 col = vec3(0.0f,0.0f,0.0f); + + float bloom = 0.0; + calcAtmospherics(pos.xyz, 1.0); - float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - da = pow(da, 0.7); + float da =dot(norm.xyz, sun_dir.xyz); + float final_da = pow(da, 0.7f); + final_da = min(final_da, shadow); + final_da = max(final_da, diffuse.a); + final_da = max(final_da, 0.0f); - col = atmosAmbient(vec3(0)); - col += atmosAffectDirectionalLight(max(min(da, shadow), diffuse.a)); - - col *= diffuse.rgb; + col.rgb = atmosAmbient(col); + col.rgb = col.rgb + atmosAffectDirectionalLight(final_da); + col.rgb *= diffuse.rgb; - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - 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 = vary_SunlitColor*shadow*(texture2D(lightFunc, vec2(sa, spec.a)).r); + float sa = dot(refnormpersp, sun_dir.xyz); + vec3 dumbshiny = vary_SunlitColor*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; - col += spec_contrib; - } - - if (envIntensity > 0.0) - { - //add environmentmap - vec3 env_vec = env_mat * refnormpersp; - col = mix(col.rgb, textureCube(environmentMap, env_vec).rgb, - max(envIntensity-diffuse.a*2.0, 0.0)); - } - - col = atmosLighting(col); - col = scaleSoftClip(col); - - //col = mix(col.rgb, diffuse.rgb, diffuse.a); - } - - vec3 light_col = vec3(0,0,0); - - vec3 npos = normalize(-pos.xyz); + // add the two types of shiny together + vec3 spec_contrib = dumbshiny * spec.rgb; + bloom = dot(spec_contrib, spec_contrib) / 6; + col += spec_contrib; + } - - /*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) - - */ - - /* -#ifdef MAC_GEFORCE_HACK - #define LIGHT_LOOP(i) \ - light_col += calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm, light_position[i], light_direction[i], 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) -#else*/ - for (int i = 2; i < 8; i++) + if (envIntensity > 0.0) { - light_col += calcPointLightOrSpotLight( - light_diffuse[i].rgb, - npos, - diffuse.rgb, - final_specular, - pos.xyz, - norm, - light_position[i], - light_direction[i], - light_attenuation[i].x, - light_attenuation[i].y, - light_attenuation[i].z); + //add environmentmap + vec3 env_vec = env_mat * refnormpersp; + col = mix(col.rgb, textureCube(environmentMap, env_vec).rgb, + max(envIntensity-diffuse.a*2.0, 0.0)); } -//#endif + + col = atmosLighting(col); + col = scaleSoftClip(col); - col += light_col; - frag_color.rgb = col; + vec3 npos = normalize(-pos.xyz); - } + #define LIGHT_LOOP(i) \ + frag_color.rgb = frag_color.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); + LIGHT_LOOP(1) + LIGHT_LOOP(2) + LIGHT_LOOP(3) + LIGHT_LOOP(4) + LIGHT_LOOP(5) + LIGHT_LOOP(6) + LIGHT_LOOP(7) frag_color.a = diffcol.a*vertex_color.a; @@ -661,4 +624,5 @@ void main() frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. #endif + } |