diff options
Diffstat (limited to 'indra/newview')
20 files changed, 2483 insertions, 2110 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index c030c23515..589ace086d 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -64,16 +64,39 @@ vec4 getPosition(vec2 pos_screen) return pos; } -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; -} +#ifdef SINGLE_FP_ONLY
+vec2 encode_normal(vec3 n)
+{
+ vec2 sn;
+ sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f);
+ return sn;
+}
+
+vec3 decode_normal (vec2 enc)
+{
+ vec3 n;
+ n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f);
+ n.z = sqrt(1.0f - dot(n.xy,n.xy));
+ return n;
+}
+#else
+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;
+}
+#endif void main() { diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 8d89485e22..f2decdfa7d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -1,685 +1,695 @@ -/** - * @file materialF.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$ - */ - -#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; - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -#if HAS_SUN_SHADOW - -uniform sampler2DShadow shadowMap0; -uniform sampler2DShadow shadowMap1; -uniform sampler2DShadow shadowMap2; -uniform sampler2DShadow shadowMap3; - -uniform mat4 shadow_matrix[6]; -uniform vec4 shadow_clip; -uniform vec2 shadow_res; -uniform float shadow_bias; - -float pcfShadow(sampler2DShadow shadowMap, vec4 stc) -{ - stc.xyz /= stc.w; - stc.z += shadow_bias; - - stc.x = floor(stc.x*shadow_res.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; -} - -#endif - -uniform samplerCube environmentMap; -uniform sampler2D lightFunc; - -// Inputs -uniform vec4 morphFactor; -uniform vec3 camPosLocal; -//uniform vec4 camPosWorld; -uniform vec4 gamma; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 blue_density; -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; -uniform mat3 ssao_effect_mat; - -uniform vec3 sun_dir; -VARYING vec2 vary_fragcoord; - -VARYING vec3 vary_position; - -vec3 vary_PositionEye; - -vec3 vary_SunlitColor; -vec3 vary_AmblitColor; -vec3 vary_AdditiveColor; -vec3 vary_AtmosAttenuation; - -uniform mat4 inv_proj; -uniform vec2 screen_res; - -uniform vec4 light_position[8]; -uniform vec3 light_direction[8]; -uniform vec3 light_attenuation[8]; -uniform vec3 light_diffuse[8]; - -vec3 calcDirectionalLight(vec3 n, vec3 l) -{ - float a = max(dot(n,l),0.0); - return vec3(a,a,a); -} - - -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 = dot(lv,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 dist2 = d/la; - float dist_atten = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.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)); - -} - -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) -{ - 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; -} - -vec3 getPositionEye() -{ - return vary_PositionEye; -} -vec3 getSunlitColor() -{ - return vary_SunlitColor; -} -vec3 getAmblitColor() -{ - return vary_AmblitColor; -} -vec3 getAdditiveColor() -{ - return vary_AdditiveColor; -} -vec3 getAtmosAttenuation() -{ - return vary_AtmosAttenuation; -} - -void setPositionEye(vec3 v) -{ - vary_PositionEye = v; -} - -void setSunlitColor(vec3 v) -{ - vary_SunlitColor = v; -} - -void setAmblitColor(vec3 v) -{ - vary_AmblitColor = v; -} - -void setAdditiveColor(vec3 v) -{ - vary_AdditiveColor = v; -} - -void setAtmosAttenuation(vec3 v) -{ - vary_AtmosAttenuation = v; -} - -void calcAtmospherics(vec3 inPositionEye, float ambFactor) { - - vec3 P = inPositionEye; - setPositionEye(P); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - 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 + 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); - blue_weight = blue_density / 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); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // 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); - - //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - //increase ambient when there are more clouds - 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 - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); - */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - - //haze color - setAdditiveColor( - 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 - setSunlitColor(pow(vec3(sunlight * .5), vec3(2.2)) * 2.2); - setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(2.2)) * 2.2); - setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(2.2)) * 2.2); -} - -vec3 atmosLighting(vec3 light) -{ - light *= getAtmosAttenuation().r; - light += getAdditiveColor(); - return (2.0 * light); -} - -vec3 atmosTransport(vec3 light) { - light *= getAtmosAttenuation().r; - light += getAdditiveColor() * 2.0; - return light; -} -vec3 atmosGetDiffuseSunlightColor() -{ - return getSunlitColor(); -} - -vec3 scaleDownLight(vec3 light) -{ - return (light / vec3(scene_light_strength, scene_light_strength, scene_light_strength)); -} - -vec3 scaleUpLight(vec3 light) -{ - return (light * vec3(scene_light_strength, scene_light_strength, scene_light_strength)); -} - -vec3 atmosAmbient(vec3 light) -{ - return getAmblitColor() + (light * vec3(0.5f, 0.5f, 0.5f)); -} - -vec3 atmosAffectDirectionalLight(float lightIntensity) -{ - return getSunlitColor() * vec3(lightIntensity, lightIntensity, lightIntensity); -} - -vec3 scaleSoftClip(vec3 light) -{ - //soft clip effect: - 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; -} - -vec3 fullbrightAtmosTransport(vec3 light) { - float brightness = dot(light.rgb, vec3(0.33333)); - - return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); -} - -vec3 fullbrightScaleSoftClip(vec3 light) -{ - //soft clip effect: - return light; -} - -#else -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_data[3]; -#else -#define frag_data gl_FragData -#endif -#endif - -uniform sampler2D diffuseMap; - -#if HAS_NORMAL_MAP -uniform sampler2D bumpMap; -#endif - -#if HAS_SPECULAR_MAP -uniform sampler2D specularMap; - -VARYING vec2 vary_texcoord2; -#endif - -uniform float env_intensity; -uniform vec4 specular_color; // specular color RGB and specular exponent (glossiness) in alpha - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK) -uniform float minimum_alpha; -#endif - -#if HAS_NORMAL_MAP -VARYING vec3 vary_mat0; -VARYING vec3 vary_mat1; -VARYING vec3 vary_mat2; -VARYING vec2 vary_texcoord1; -#else -VARYING vec3 vary_normal; -#endif - -VARYING vec4 vertex_color; -VARYING vec2 vary_texcoord0; - -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -void main() -{ - 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; - } -#endif - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - vec3 old_diffcol = diffcol.rgb; - diffcol.rgb = pow(diffcol.rgb, vec3(2.2)); -#endif - -#if HAS_SPECULAR_MAP - vec4 spec = texture2D(specularMap, vary_texcoord2.xy); - spec.rgb *= specular_color.rgb; -#else - vec4 spec = vec4(specular_color.rgb, 1.0); -#endif - -#if HAS_NORMAL_MAP - vec4 norm = texture2D(bumpMap, vary_texcoord1.xy); - - norm.xyz = norm.xyz * 2 - 1; - - vec3 tnorm = vec3(dot(norm.xyz,vary_mat0), - dot(norm.xyz,vary_mat1), - dot(norm.xyz,vary_mat2)); -#else - vec4 norm = vec4(0,0,0,1.0); - vec3 tnorm = vary_normal; -#endif - - norm.xyz = tnorm; - norm.xyz = normalize(norm.xyz); - - vec4 final_color = diffcol; - -#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE) - final_color.a = emissive_brightness; -#else - final_color.a = max(final_color.a, emissive_brightness); -#endif - - vec4 final_specular = spec; -#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; -#else - vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0); - final_specular.a = specular_color.a; -#endif - - -#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - //forward rendering, output just lit 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; - } -#else - float shadow = 1.0; -#endif - - 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; - calcAtmospherics(pos.xyz, 1.0); - - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); - - float da =dot(norm.xyz, sun_dir.xyz); - float final_da = da; - final_da = min(final_da, shadow); - final_da = max(final_da, diffuse.a); - final_da = max(final_da, 0.0f); - - col.rgb = atmosAmbient(col); - - 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.rgb = col.rgb + atmosAffectDirectionalLight(final_da * 2.6); - col.rgb *= diffuse.rgb; - - - float glare = 0.0; - - 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); - - // 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); - - col += spec_contrib; - } - - col = mix(col.rgb, old_diffcol.rgb, diffuse.a); - - if (envIntensity > 0.0) - { - //add environmentmap - vec3 env_vec = env_mat * refnormpersp; - float exponent = mix(2.2, 1.0, diffuse.a); - - vec3 refcol = pow(textureCube(environmentMap, env_vec).rgb, vec3(exponent))*exponent; - - 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 exponent = mix(1.0, 2.2, diffuse.a); - col = pow(col, vec3(exponent)); - - - col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); - col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); - - - vec3 npos = normalize(-pos.xyz); - - #define LIGHT_LOOP(i) col.rgb = col.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) - - - col.rgb = pow(col.rgb, vec3(1.0/2.2)); - - frag_color.rgb = col.rgb; - glare = min(glare, 1.0); - frag_color.a = max(diffcol.a*vertex_color.a, glare); -#else - - frag_data[0] = final_color; - -#ifdef UGLY_MAC_HACK - // magic spec exp clamp fixes rendering artifacts on older mac GF drivers - // - final_specular = min(final_specular, vec4(1.0f, 1.0f, 1.0f, 0.125f)); -#endif - - frag_data[1] = final_specular; // XYZ = Specular color. W = Specular exponent. - frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity. -#endif -} +/**
+ * @file materialF.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$
+ */
+
+#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;
+
+#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
+
+#ifdef DEFINE_GL_FRAGCOLOR
+out vec4 frag_color;
+#else
+#define frag_color gl_FragColor
+#endif
+
+#if HAS_SUN_SHADOW
+
+uniform sampler2DShadow shadowMap0;
+uniform sampler2DShadow shadowMap1;
+uniform sampler2DShadow shadowMap2;
+uniform sampler2DShadow shadowMap3;
+
+uniform mat4 shadow_matrix[6];
+uniform vec4 shadow_clip;
+uniform vec2 shadow_res;
+uniform float shadow_bias;
+
+float pcfShadow(sampler2DShadow shadowMap, vec4 stc)
+{
+ stc.xyz /= stc.w;
+ stc.z += shadow_bias;
+
+ stc.x = floor(stc.x*shadow_res.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;
+}
+
+#endif
+
+uniform samplerCube environmentMap;
+uniform sampler2D lightFunc;
+
+// Inputs
+uniform vec4 morphFactor;
+uniform vec3 camPosLocal;
+//uniform vec4 camPosWorld;
+uniform vec4 gamma;
+uniform vec4 lightnorm;
+uniform vec4 sunlight_color;
+uniform vec4 ambient;
+uniform vec4 blue_horizon;
+uniform vec4 blue_density;
+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;
+uniform mat3 ssao_effect_mat;
+
+uniform vec3 sun_dir;
+VARYING vec2 vary_fragcoord;
+
+VARYING vec3 vary_position;
+
+vec3 vary_PositionEye;
+
+vec3 vary_SunlitColor;
+vec3 vary_AmblitColor;
+vec3 vary_AdditiveColor;
+vec3 vary_AtmosAttenuation;
+
+uniform mat4 inv_proj;
+uniform vec2 screen_res;
+
+uniform vec4 light_position[8];
+uniform vec3 light_direction[8];
+uniform vec3 light_attenuation[8];
+uniform vec3 light_diffuse[8];
+
+vec3 calcDirectionalLight(vec3 n, vec3 l)
+{
+ float a = max(dot(n,l),0.0);
+ return vec3(a,a,a);
+}
+
+
+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 = dot(lv,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 dist2 = d/la;
+ float dist_atten = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.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;
+}
+
+vec3 getPositionEye()
+{
+ return vary_PositionEye;
+}
+vec3 getSunlitColor()
+{
+ return vary_SunlitColor;
+}
+vec3 getAmblitColor()
+{
+ return vary_AmblitColor;
+}
+vec3 getAdditiveColor()
+{
+ return vary_AdditiveColor;
+}
+vec3 getAtmosAttenuation()
+{
+ return vary_AtmosAttenuation;
+}
+
+void setPositionEye(vec3 v)
+{
+ vary_PositionEye = v;
+}
+
+void setSunlitColor(vec3 v)
+{
+ vary_SunlitColor = v;
+}
+
+void setAmblitColor(vec3 v)
+{
+ vary_AmblitColor = v;
+}
+
+void setAdditiveColor(vec3 v)
+{
+ vary_AdditiveColor = v;
+}
+
+void setAtmosAttenuation(vec3 v)
+{
+ vary_AtmosAttenuation = v;
+}
+
+void calcAtmospherics(vec3 inPositionEye, float ambFactor) {
+
+ vec3 P = inPositionEye;
+ setPositionEye(P);
+
+ vec3 tmpLightnorm = lightnorm.xyz;
+
+ vec3 Pn = normalize(P);
+ float Plen = length(P);
+
+ vec4 temp1 = vec4(0);
+ vec3 temp2 = vec3(0);
+ vec4 blue_weight;
+ vec4 haze_weight;
+ 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 + 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);
+ blue_weight = blue_density / 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);
+ temp2.y = 1. / temp2.y;
+ sunlight *= exp( - light_atten * temp2.y);
+
+ // main atmospheric scattering line integral
+ temp2.z = Plen * density_multiplier;
+
+ // Transparency (-> temp1)
+ // 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);
+
+ //final atmosphere attenuation factor
+ setAtmosAttenuation(temp1.rgb);
+
+ //compute haze glow
+ //(can use temp2.x as temp because we haven't used it yet)
+ temp2.x = dot(Pn, tmpLightnorm.xyz);
+ temp2.x = 1. - temp2.x;
+ //temp2.x is 0 at the sun and increases away from sun
+ temp2.x = max(temp2.x, .03); //was glow.y
+ //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot)
+ temp2.x *= glow.x;
+ //higher glow.x gives dimmer glow (because next step is 1 / "angle")
+ temp2.x = pow(temp2.x, glow.z);
+ //glow.z should be negative, so we're doing a sort of (1 / "angle") function
+
+ //add "minimum anti-solar illumination"
+ temp2.x += .25;
+
+ //increase ambient when there are more clouds
+ 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
+ * // The following line of code performs the equivalent of:
+ * float ambAlpha = tmpAmbient.a;
+ * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis
+ * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue);
+ * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha);
+ */
+ tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a);
+
+ //haze color
+ setAdditiveColor(
+ 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
+ setSunlitColor(pow(vec3(sunlight * .5), vec3(2.2)) * 2.2);
+ setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(2.2)) * 2.2);
+ setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(2.2)) * 2.2);
+}
+
+vec3 atmosLighting(vec3 light)
+{
+ light *= getAtmosAttenuation().r;
+ light += getAdditiveColor();
+ return (2.0 * light);
+}
+
+vec3 atmosTransport(vec3 light) {
+ light *= getAtmosAttenuation().r;
+ light += getAdditiveColor() * 2.0;
+ return light;
+}
+vec3 atmosGetDiffuseSunlightColor()
+{
+ return getSunlitColor();
+}
+
+vec3 scaleDownLight(vec3 light)
+{
+ return (light / vec3(scene_light_strength, scene_light_strength, scene_light_strength));
+}
+
+vec3 scaleUpLight(vec3 light)
+{
+ return (light * vec3(scene_light_strength, scene_light_strength, scene_light_strength));
+}
+
+vec3 atmosAmbient(vec3 light)
+{
+ return getAmblitColor() + (light * vec3(0.5f, 0.5f, 0.5f));
+}
+
+vec3 atmosAffectDirectionalLight(float lightIntensity)
+{
+ return getSunlitColor() * vec3(lightIntensity, lightIntensity, lightIntensity);
+}
+
+vec3 scaleSoftClip(vec3 light)
+{
+ //soft clip effect:
+ 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;
+}
+
+vec3 fullbrightAtmosTransport(vec3 light) {
+ float brightness = dot(light.rgb, vec3(0.33333));
+
+ return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness);
+}
+
+vec3 fullbrightScaleSoftClip(vec3 light)
+{
+ //soft clip effect:
+ return light;
+}
+
+#else
+#ifdef DEFINE_GL_FRAGCOLOR
+out vec4 frag_data[3];
+#else
+#define frag_data gl_FragData
+#endif
+#endif
+
+uniform sampler2D diffuseMap;
+
+#if HAS_NORMAL_MAP
+uniform sampler2D bumpMap;
+#endif
+
+#if HAS_SPECULAR_MAP
+uniform sampler2D specularMap;
+
+VARYING vec2 vary_texcoord2;
+#endif
+
+uniform float env_intensity;
+uniform vec4 specular_color; // specular color RGB and specular exponent (glossiness) in alpha
+
+#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_MASK)
+uniform float minimum_alpha;
+#endif
+
+#if HAS_NORMAL_MAP
+VARYING vec3 vary_mat0;
+VARYING vec3 vary_mat1;
+VARYING vec3 vary_mat2;
+VARYING vec2 vary_texcoord1;
+#else
+VARYING vec3 vary_normal;
+#endif
+
+VARYING vec4 vertex_color;
+VARYING vec2 vary_texcoord0;
+
+#ifdef SINGLE_FP_ONLY
+vec2 encode_normal(vec3 n)
+{
+ vec2 sn;
+ sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f);
+ return sn;
+}
+
+vec3 decode_normal (vec2 enc)
+{
+ vec3 n;
+ n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f);
+ n.z = sqrt(1.0f - dot(n.xy,n.xy));
+ return n;
+}
+#else
+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;
+}
+#endif
+
+void main()
+{
+ 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;
+ }
+#endif
+
+#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
+ vec3 old_diffcol = diffcol.rgb;
+ diffcol.rgb = pow(diffcol.rgb, vec3(2.2));
+#endif
+
+#if HAS_SPECULAR_MAP
+ vec4 spec = texture2D(specularMap, vary_texcoord2.xy);
+ spec.rgb *= specular_color.rgb;
+#else
+ vec4 spec = vec4(specular_color.rgb, 1.0);
+#endif
+
+#if HAS_NORMAL_MAP
+ vec4 norm = texture2D(bumpMap, vary_texcoord1.xy);
+
+ norm.xyz = norm.xyz * 2 - 1;
+
+ vec3 tnorm = vec3(dot(norm.xyz,vary_mat0),
+ dot(norm.xyz,vary_mat1),
+ dot(norm.xyz,vary_mat2));
+#else
+ vec4 norm = vec4(0,0,0,1.0);
+ vec3 tnorm = vary_normal;
+#endif
+
+ norm.xyz = tnorm;
+ norm.xyz = normalize(norm.xyz);
+
+ vec4 final_color = diffcol;
+
+#if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE)
+ final_color.a = emissive_brightness;
+#else
+ final_color.a = max(final_color.a, emissive_brightness);
+#endif
+
+ vec4 final_specular = spec;
+#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;
+#else
+ vec4 final_normal = vec4(encode_normal(normalize(tnorm)), env_intensity, 0.0);
+ final_specular.a = specular_color.a;
+#endif
+
+
+#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
+ //forward rendering, output just lit 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;
+ }
+#else
+ float shadow = 1.0;
+#endif
+
+ 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;
+ calcAtmospherics(pos.xyz, 1.0);
+
+ vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz));
+
+ float da =dot(norm.xyz, sun_dir.xyz);
+ float final_da = da;
+ final_da = min(final_da, shadow);
+ final_da = max(final_da, diffuse.a);
+ final_da = max(final_da, 0.0f);
+
+ col.rgb = atmosAmbient(col);
+
+ 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.rgb = col.rgb + atmosAffectDirectionalLight(final_da * 2.6);
+ col.rgb *= diffuse.rgb;
+
+
+ float glare = 0.0;
+
+ 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);
+
+ // 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);
+
+ col += spec_contrib;
+ }
+
+ col = mix(col.rgb, old_diffcol.rgb, diffuse.a);
+
+ if (envIntensity > 0.0)
+ {
+ //add environmentmap
+ vec3 env_vec = env_mat * refnormpersp;
+ float exponent = mix(2.2, 1.0, diffuse.a);
+
+ vec3 refcol = pow(textureCube(environmentMap, env_vec).rgb, vec3(exponent))*exponent;
+
+ 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 exponent = mix(1.0, 2.2, diffuse.a);
+ col = pow(col, vec3(exponent));
+
+
+ col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a);
+ col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a);
+
+
+ vec3 npos = normalize(-pos.xyz);
+
+ #define LIGHT_LOOP(i) col.rgb = col.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)
+
+
+ col.rgb = pow(col.rgb, vec3(1.0/2.2));
+
+ frag_color.rgb = col.rgb;
+ glare = min(glare, 1.0);
+ frag_color.a = max(diffcol.a,glare)*vertex_color.a;
+
+#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.
+#endif
+}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl index 338532e71d..722020ccfe 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiPointLightF.glsl @@ -56,16 +56,39 @@ uniform float far_z; uniform mat4 inv_proj; -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; -} +#ifdef SINGLE_FP_ONLY
+vec2 encode_normal(vec3 n)
+{
+ vec2 sn;
+ sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f);
+ return sn;
+}
+
+vec3 decode_normal (vec2 enc)
+{
+ vec3 n;
+ n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f);
+ n.z = sqrt(1.0f - dot(n.xy,n.xy));
+ return n;
+}
+#else
+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;
+}
+#endif vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl index 79f94fb131..e99d7ee626 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/multiSpotLightF.glsl @@ -67,16 +67,39 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -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; -} +#ifdef SINGLE_FP_ONLY
+vec2 encode_normal(vec3 n)
+{
+ vec2 sn;
+ sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f);
+ return sn;
+}
+
+vec3 decode_normal (vec2 enc)
+{
+ vec3 n;
+ n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f);
+ n.z = sqrt(1.0f - dot(n.xy,n.xy));
+ return n;
+}
+#else
+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;
+}
+#endif vec4 correctWithGamma(vec4 col) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl index 69cdb2ce71..77d59c6ecf 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightF.glsl @@ -54,16 +54,39 @@ uniform vec2 screen_res; uniform mat4 inv_proj; uniform vec4 viewport; -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; -} +#ifdef SINGLE_FP_ONLY
+vec2 encode_normal(vec3 n)
+{
+ vec2 sn;
+ sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f);
+ return sn;
+}
+
+vec3 decode_normal (vec2 enc)
+{
+ vec3 n;
+ n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f);
+ n.z = sqrt(1.0f - dot(n.xy,n.xy));
+ return n;
+}
+#else
+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;
+}
+#endif vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl index 2d6bce02c9..d4803f9aed 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl @@ -1,46 +1,46 @@ -/** - * @file postDeferredGammaCorrect.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#extension GL_ARB_texture_rectangle : enable - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2DRect diffuseRect; - -uniform vec2 screen_res; -VARYING vec2 vary_fragcoord; - -uniform float texture_gamma; - -void main() -{ - vec4 diff = texture2DRect(diffuseRect, vary_fragcoord); - frag_color = pow(diff, vec4(texture_gamma, texture_gamma, texture_gamma, 1.0)); -} - +/**
+ * @file postDeferredGammaCorrect.glsl
+ *
+ * $LicenseInfo:firstyear=2007&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2007, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#extension GL_ARB_texture_rectangle : enable
+
+#ifdef DEFINE_GL_FRAGCOLOR
+out vec4 frag_color;
+#else
+#define frag_color gl_FragColor
+#endif
+
+uniform sampler2DRect diffuseRect;
+
+uniform vec2 screen_res;
+VARYING vec2 vary_fragcoord;
+
+uniform float texture_gamma;
+
+void main()
+{
+ vec4 diff = texture2DRect(diffuseRect, vary_fragcoord);
+ frag_color = pow(diff, vec4(texture_gamma, texture_gamma, texture_gamma, 1.0f));
+}
+
diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 45d672c290..f7920f7595 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -1,379 +1,396 @@ -/** - * @file softenLightF.glsl - * - * $LicenseInfo:firstyear=2007&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2007, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#extension GL_ARB_texture_rectangle : enable - -#ifdef DEFINE_GL_FRAGCOLOR -out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif - -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect positionMap; -uniform sampler2DRect normalMap; -uniform sampler2DRect lightMap; -uniform sampler2DRect depthMap; -uniform samplerCube environmentMap; -uniform sampler2D lightFunc; - -uniform float blur_size; -uniform float blur_fidelity; - -// Inputs -uniform vec4 morphFactor; -uniform vec3 camPosLocal; -//uniform vec4 camPosWorld; -uniform vec4 gamma; -uniform vec4 lightnorm; -uniform vec4 sunlight_color; -uniform vec4 ambient; -uniform vec4 blue_horizon; -uniform vec4 blue_density; -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 global_gamma; -uniform float scene_light_strength; -uniform mat3 env_mat; -uniform mat3 ssao_effect_mat; - -uniform vec3 sun_dir; -VARYING vec2 vary_fragcoord; - -vec3 vary_PositionEye; - -vec3 vary_SunlitColor; -vec3 vary_AmblitColor; -vec3 vary_AdditiveColor; -vec3 vary_AtmosAttenuation; - -uniform mat4 inv_proj; -uniform vec2 screen_res; - -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) -{ - 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).a; - return getPosition_d(pos_screen, depth); -} - -vec3 getPositionEye() -{ - return vary_PositionEye; -} -vec3 getSunlitColor() -{ - return vary_SunlitColor; -} -vec3 getAmblitColor() -{ - return vary_AmblitColor; -} -vec3 getAdditiveColor() -{ - return vary_AdditiveColor; -} -vec3 getAtmosAttenuation() -{ - return vary_AtmosAttenuation; -} - -void setPositionEye(vec3 v) -{ - vary_PositionEye = v; -} - -void setSunlitColor(vec3 v) -{ - vary_SunlitColor = v; -} - -void setAmblitColor(vec3 v) -{ - vary_AmblitColor = v; -} - -void setAdditiveColor(vec3 v) -{ - vary_AdditiveColor = v; -} - -void setAtmosAttenuation(vec3 v) -{ - vary_AtmosAttenuation = v; -} - -void calcAtmospherics(vec3 inPositionEye, float ambFactor) { - - vec3 P = inPositionEye; - setPositionEye(P); - - vec3 tmpLightnorm = lightnorm.xyz; - - vec3 Pn = normalize(P); - float Plen = length(P); - - vec4 temp1 = vec4(0); - vec3 temp2 = vec3(0); - vec4 blue_weight; - vec4 haze_weight; - 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 + 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); - blue_weight = blue_density / 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); - temp2.y = 1. / temp2.y; - sunlight *= exp( - light_atten * temp2.y); - - // main atmospheric scattering line integral - temp2.z = Plen * density_multiplier; - - // Transparency (-> temp1) - // 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); - - //final atmosphere attenuation factor - setAtmosAttenuation(temp1.rgb); - - //compute haze glow - //(can use temp2.x as temp because we haven't used it yet) - temp2.x = dot(Pn, tmpLightnorm.xyz); - temp2.x = 1. - temp2.x; - //temp2.x is 0 at the sun and increases away from sun - temp2.x = max(temp2.x, .03); //was glow.y - //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) - temp2.x *= glow.x; - //higher glow.x gives dimmer glow (because next step is 1 / "angle") - temp2.x = pow(temp2.x, glow.z); - //glow.z should be negative, so we're doing a sort of (1 / "angle") function - - //add "minimum anti-solar illumination" - temp2.x += .25; - - //increase ambient when there are more clouds - 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 - * // The following line of code performs the equivalent of: - * float ambAlpha = tmpAmbient.a; - * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis - * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue); - * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha); - */ - tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a); - - //haze color - setAdditiveColor( - 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 - 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); -} - -vec3 atmosLighting(vec3 light) -{ - light *= getAtmosAttenuation().r; - light += getAdditiveColor(); - return (2.0 * light); -} - -vec3 atmosTransport(vec3 light) { - light *= getAtmosAttenuation().r; - 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(); -} - -vec3 scaleDownLight(vec3 light) -{ - return (light / scene_light_strength ); -} - -vec3 scaleUpLight(vec3 light) -{ - return (light * scene_light_strength); -} - -vec3 atmosAmbient(vec3 light) -{ - return getAmblitColor() + light / 2.0; -} - -vec3 atmosAffectDirectionalLight(float lightIntensity) -{ - return getSunlitColor() * lightIntensity; -} - -vec3 scaleSoftClip(vec3 light) -{ - //soft clip effect: - light = 1. - clamp(light, vec3(0.), vec3(1.)); - light = 1. - pow(light, gamma.xxx); - - return light; -} - - -vec3 fullbrightScaleSoftClip(vec3 light) -{ - //soft clip effect: - return light; -} - -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 = max(dot(norm.xyz, sun_dir.xyz), 0.0); - - vec4 diffuse = texture2DRect(diffuseRect, tc); - vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); - vec3 col; - float bloom = 0.0; - { - calcAtmospherics(pos.xyz, 1.0); - - col = atmosAmbient(vec3(0)); - 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, 1.0) * 2.6, 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 - // - - float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = vary_SunlitColor*(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; - } - - - col = mix(col.rgb, pow(diffuse.rgb, vec3(1.0/2.2)), diffuse.a); - - - if (envIntensity > 0.0) - { //add environmentmap - vec3 env_vec = env_mat * refnormpersp; - - float exponent = mix(2.2, 1.0, diffuse.a); - vec3 refcol = pow(textureCube(environmentMap, env_vec).rgb, vec3(exponent))*exponent; - - col = mix(col.rgb, refcol, - envIntensity); - - } - - float exponent = mix(1.0, 2.2, diffuse.a); - col = pow(col, vec3(exponent)); - - if (norm.w < 0.5) - { - col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); - col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); - } - - //col = vec3(1,0,1); - //col.g = envIntensity; - } - - frag_color.rgb = col; - - frag_color.a = bloom; -} +/**
+ * @file softenLightF.glsl
+ *
+ * $LicenseInfo:firstyear=2007&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2007, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#extension GL_ARB_texture_rectangle : enable
+
+#ifdef DEFINE_GL_FRAGCOLOR
+out vec4 frag_color;
+#else
+#define frag_color gl_FragColor
+#endif
+
+uniform sampler2DRect diffuseRect;
+uniform sampler2DRect specularRect;
+uniform sampler2DRect positionMap;
+uniform sampler2DRect normalMap;
+uniform sampler2DRect lightMap;
+uniform sampler2DRect depthMap;
+uniform samplerCube environmentMap;
+uniform sampler2D lightFunc;
+
+uniform float blur_size;
+uniform float blur_fidelity;
+
+// Inputs
+uniform vec4 morphFactor;
+uniform vec3 camPosLocal;
+//uniform vec4 camPosWorld;
+uniform vec4 gamma;
+uniform vec4 lightnorm;
+uniform vec4 sunlight_color;
+uniform vec4 ambient;
+uniform vec4 blue_horizon;
+uniform vec4 blue_density;
+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 global_gamma;
+uniform float scene_light_strength;
+uniform mat3 env_mat;
+uniform mat3 ssao_effect_mat;
+
+uniform vec3 sun_dir;
+VARYING vec2 vary_fragcoord;
+
+vec3 vary_PositionEye;
+
+vec3 vary_SunlitColor;
+vec3 vary_AmblitColor;
+vec3 vary_AdditiveColor;
+vec3 vary_AtmosAttenuation;
+
+uniform mat4 inv_proj;
+uniform vec2 screen_res;
+
+#ifdef SINGLE_FP_ONLY
+vec2 encode_normal(vec3 n)
+{
+ vec2 sn;
+ sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f);
+ return sn;
+}
+
+vec3 decode_normal (vec2 enc)
+{
+ vec3 n;
+ n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f);
+ n.z = sqrt(1.0f - dot(n.xy,n.xy));
+ return n;
+}
+#else
+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;
+}
+#endif
+
+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).a;
+ return getPosition_d(pos_screen, depth);
+}
+
+vec3 getPositionEye()
+{
+ return vary_PositionEye;
+}
+vec3 getSunlitColor()
+{
+ return vary_SunlitColor;
+}
+vec3 getAmblitColor()
+{
+ return vary_AmblitColor;
+}
+vec3 getAdditiveColor()
+{
+ return vary_AdditiveColor;
+}
+vec3 getAtmosAttenuation()
+{
+ return vary_AtmosAttenuation;
+}
+
+void setPositionEye(vec3 v)
+{
+ vary_PositionEye = v;
+}
+
+void setSunlitColor(vec3 v)
+{
+ vary_SunlitColor = v;
+}
+
+void setAmblitColor(vec3 v)
+{
+ vary_AmblitColor = v;
+}
+
+void setAdditiveColor(vec3 v)
+{
+ vary_AdditiveColor = v;
+}
+
+void setAtmosAttenuation(vec3 v)
+{
+ vary_AtmosAttenuation = v;
+}
+
+void calcAtmospherics(vec3 inPositionEye, float ambFactor) {
+
+ vec3 P = inPositionEye;
+ setPositionEye(P);
+
+ vec3 tmpLightnorm = lightnorm.xyz;
+
+ vec3 Pn = normalize(P);
+ float Plen = length(P);
+
+ vec4 temp1 = vec4(0);
+ vec3 temp2 = vec3(0);
+ vec4 blue_weight;
+ vec4 haze_weight;
+ 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 + 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);
+ blue_weight = blue_density / 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);
+ temp2.y = 1. / temp2.y;
+ sunlight *= exp( - light_atten * temp2.y);
+
+ // main atmospheric scattering line integral
+ temp2.z = Plen * density_multiplier;
+
+ // Transparency (-> temp1)
+ // 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);
+
+ //final atmosphere attenuation factor
+ setAtmosAttenuation(temp1.rgb);
+
+ //compute haze glow
+ //(can use temp2.x as temp because we haven't used it yet)
+ temp2.x = dot(Pn, tmpLightnorm.xyz);
+ temp2.x = 1. - temp2.x;
+ //temp2.x is 0 at the sun and increases away from sun
+ temp2.x = max(temp2.x, .03); //was glow.y
+ //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot)
+ temp2.x *= glow.x;
+ //higher glow.x gives dimmer glow (because next step is 1 / "angle")
+ temp2.x = pow(temp2.x, glow.z);
+ //glow.z should be negative, so we're doing a sort of (1 / "angle") function
+
+ //add "minimum anti-solar illumination"
+ temp2.x += .25;
+
+ //increase ambient when there are more clouds
+ 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
+ * // The following line of code performs the equivalent of:
+ * float ambAlpha = tmpAmbient.a;
+ * float ambValue = dot(vec3(tmpAmbient), vec3(0.577)); // projection onto <1/rt(3), 1/rt(3), 1/rt(3)>, the neutral white-black axis
+ * vec3 ambHueSat = vec3(tmpAmbient) - vec3(ambValue);
+ * tmpAmbient = vec4(RenderSSAOEffect.valueFactor * vec3(ambValue) + RenderSSAOEffect.saturationFactor *(1.0 - ambFactor) * ambHueSat, ambAlpha);
+ */
+ tmpAmbient = vec4(mix(ssao_effect_mat * tmpAmbient.rgb, tmpAmbient.rgb, ambFactor), tmpAmbient.a);
+
+ //haze color
+ setAdditiveColor(
+ 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
+ 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);
+}
+
+vec3 atmosLighting(vec3 light)
+{
+ light *= getAtmosAttenuation().r;
+ light += getAdditiveColor();
+ return (2.0 * light);
+}
+
+vec3 atmosTransport(vec3 light) {
+ light *= getAtmosAttenuation().r;
+ 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();
+}
+
+vec3 scaleDownLight(vec3 light)
+{
+ return (light / scene_light_strength );
+}
+
+vec3 scaleUpLight(vec3 light)
+{
+ return (light * scene_light_strength);
+}
+
+vec3 atmosAmbient(vec3 light)
+{
+ return getAmblitColor() + light / 2.0;
+}
+
+vec3 atmosAffectDirectionalLight(float lightIntensity)
+{
+ return getSunlitColor() * lightIntensity;
+}
+
+vec3 scaleSoftClip(vec3 light)
+{
+ //soft clip effect:
+ light = 1. - clamp(light, vec3(0.), vec3(1.));
+ light = 1. - pow(light, gamma.xxx);
+
+ return light;
+}
+
+
+vec3 fullbrightScaleSoftClip(vec3 light)
+{
+ //soft clip effect:
+ return light;
+}
+
+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 = max(dot(norm.xyz, sun_dir.xyz), 0.0);
+
+ vec4 diffuse = texture2DRect(diffuseRect, tc);
+ vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy);
+ vec3 col;
+ float bloom = 0.0;
+ {
+ calcAtmospherics(pos.xyz, 1.0);
+
+ col = atmosAmbient(vec3(0));
+ 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, 1.0) * 2.6, 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
+ //
+
+ float sa = dot(refnormpersp, sun_dir.xyz);
+ vec3 dumbshiny = vary_SunlitColor*(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;
+ }
+
+
+ col = mix(col.rgb, pow(diffuse.rgb, vec3(1.0/2.2)), diffuse.a);
+
+
+ if (envIntensity > 0.0)
+ { //add environmentmap
+ vec3 env_vec = env_mat * refnormpersp;
+
+ float exponent = mix(2.2, 1.0, diffuse.a);
+ vec3 refcol = pow(textureCube(environmentMap, env_vec).rgb, vec3(exponent))*exponent;
+
+ col = mix(col.rgb, refcol,
+ envIntensity);
+
+ }
+
+ float exponent = mix(1.0, 2.2, diffuse.a);
+ col = pow(col, vec3(exponent));
+
+ if (norm.w < 0.5)
+ {
+ col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a);
+ col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a);
+ }
+
+ //col = vec3(1,0,1);
+ //col.g = envIntensity;
+ }
+
+ frag_color.rgb = col;
+
+ 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 c918a42c73..4e1add3e56 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -65,16 +65,39 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -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; -} +#ifdef SINGLE_FP_ONLY
+vec2 encode_normal(vec3 n)
+{
+ vec2 sn;
+ sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f);
+ return sn;
+}
+
+vec3 decode_normal (vec2 enc)
+{
+ vec3 n;
+ n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f);
+ n.z = sqrt(1.0f - dot(n.xy,n.xy));
+ return n;
+}
+#else
+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;
+}
+#endif vec4 correctWithGamma(vec4 col) { diff --git a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl index 1470239a71..14d35d1f0f 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/sunLightSSAOF.glsl @@ -49,16 +49,39 @@ VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; -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; -} +#ifdef SINGLE_FP_ONLY
+vec2 encode_normal(vec3 n)
+{
+ vec2 sn;
+ sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f);
+ return sn;
+}
+
+vec3 decode_normal (vec2 enc)
+{
+ vec3 n;
+ n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f);
+ n.z = sqrt(1.0f - dot(n.xy,n.xy));
+ return n;
+}
+#else
+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;
+}
+#endif vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl index a6b0f7e7c1..2300487a90 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/multiSpotLightF.glsl @@ -68,16 +68,39 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -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; -} +#ifdef SINGLE_FP_ONLY
+vec2 encode_normal(vec3 n)
+{
+ vec2 sn;
+ sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f);
+ return sn;
+}
+
+vec3 decode_normal (vec2 enc)
+{
+ vec3 n;
+ n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f);
+ n.z = sqrt(1.0f - dot(n.xy,n.xy));
+ return n;
+}
+#else
+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;
+}
+#endif vec4 correctWithGamma(vec4 col) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 31b2a32f7f..520b3bbd47 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -78,16 +78,39 @@ vec3 vary_AtmosAttenuation; uniform mat4 inv_proj; uniform vec2 screen_res; -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; -} +#ifdef SINGLE_FP_ONLY
+vec2 encode_normal(vec3 n)
+{
+ vec2 sn;
+ sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f);
+ return sn;
+}
+
+vec3 decode_normal (vec2 enc)
+{
+ vec3 n;
+ n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f);
+ n.z = sqrt(1.0f - dot(n.xy,n.xy));
+ return n;
+}
+#else
+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;
+}
+#endif vec4 getPosition_d(vec2 pos_screen, float depth) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl index 91ff1f1e76..9e062e46d7 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/spotLightF.glsl @@ -68,16 +68,39 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -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; -} +#ifdef SINGLE_FP_ONLY
+vec2 encode_normal(vec3 n)
+{
+ vec2 sn;
+ sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f);
+ return sn;
+}
+
+vec3 decode_normal (vec2 enc)
+{
+ vec3 n;
+ n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f);
+ n.z = sqrt(1.0f - dot(n.xy,n.xy));
+ return n;
+}
+#else
+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;
+}
+#endif vec4 correctWithGamma(vec4 col) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl index fa2f415e15..334baad8b4 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightF.glsl @@ -65,16 +65,39 @@ uniform float shadow_offset; uniform float spot_shadow_bias; uniform float spot_shadow_offset; -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; -} +#ifdef SINGLE_FP_ONLY
+vec2 encode_normal(vec3 n)
+{
+ vec2 sn;
+ sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f);
+ return sn;
+}
+
+vec3 decode_normal (vec2 enc)
+{
+ vec3 n;
+ n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f);
+ n.z = sqrt(1.0f - dot(n.xy,n.xy));
+ return n;
+}
+#else
+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;
+}
+#endif vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl index 847fea6c08..cfce215faf 100755 --- a/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/sunLightSSAOF.glsl @@ -66,16 +66,39 @@ uniform float shadow_offset; uniform float spot_shadow_bias; uniform float spot_shadow_offset; -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; -} +#ifdef SINGLE_FP_ONLY
+vec2 encode_normal(vec3 n)
+{
+ vec2 sn;
+ sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f);
+ return sn;
+}
+
+vec3 decode_normal (vec2 enc)
+{
+ vec3 n;
+ n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f);
+ n.z = sqrt(1.0f - dot(n.xy,n.xy));
+ return n;
+}
+#else
+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;
+}
+#endif vec4 getPosition(vec2 pos_screen) { diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp index 46d6a1a97f..3e503cb750 100755 --- a/indra/newview/llface.cpp +++ b/indra/newview/llface.cpp @@ -1655,8 +1655,8 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, if (mat && !do_bump) { - do_bump = mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD1) || - mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD2); + do_bump = mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD1) + || mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD2); } bool do_tex_mat = tex_mode && mTextureMatrix; @@ -1780,7 +1780,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume, std::vector<LLVector2> bump_tc; - if (mat) + if (mat && !mat->getNormalID().isNull()) { //writing out normal and specular texture coordinates, not bump offsets do_bump = false; } diff --git a/indra/newview/llpanelface.cpp b/indra/newview/llpanelface.cpp index 01ed6e84b8..30ccbeb917 100755 --- a/indra/newview/llpanelface.cpp +++ b/indra/newview/llpanelface.cpp @@ -89,6 +89,27 @@ const S32 SHINY_TEXTURE = 4; // use supplied specular map // std::string USE_TEXTURE; +// Things the UI provides... +// +LLUUID LLPanelFace::getCurrentNormalMap() { return getChild<LLTextureCtrl>("bumpytexture control")->getImageAssetID(); } +LLUUID LLPanelFace::getCurrentSpecularMap() { return getChild<LLTextureCtrl>("shinytexture control")->getImageAssetID(); } +U32 LLPanelFace::getCurrentShininess() { return getChild<LLComboBox>("combobox shininess")->getCurrentIndex(); } +U32 LLPanelFace::getCurrentBumpiness() { return getChild<LLComboBox>("combobox bumpiness")->getCurrentIndex(); } +U8 LLPanelFace::getCurrentDiffuseAlphaMode() { return (U8)getChild<LLComboBox>("combobox alphamode")->getCurrentIndex(); } +U8 LLPanelFace::getCurrentAlphaMaskCutoff() { return (U8)getChild<LLUICtrl>("maskcutoff")->getValue().asInteger(); } +U8 LLPanelFace::getCurrentEnvIntensity() { return (U8)getChild<LLUICtrl>("environment")->getValue().asInteger(); } +U8 LLPanelFace::getCurrentGlossiness() { return (U8)getChild<LLUICtrl>("glossiness")->getValue().asInteger(); } +F32 LLPanelFace::getCurrentBumpyRot() { return getChild<LLUICtrl>("bumpyRot")->getValue().asReal(); } +F32 LLPanelFace::getCurrentBumpyScaleU() { return getChild<LLUICtrl>("bumpyScaleU")->getValue().asReal(); } +F32 LLPanelFace::getCurrentBumpyScaleV() { return getChild<LLUICtrl>("bumpyScaleV")->getValue().asReal(); } +F32 LLPanelFace::getCurrentBumpyOffsetU() { return getChild<LLUICtrl>("bumpyOffsetU")->getValue().asReal(); } +F32 LLPanelFace::getCurrentBumpyOffsetV() { return getChild<LLUICtrl>("bumpyOffsetV")->getValue().asReal(); } +F32 LLPanelFace::getCurrentShinyRot() { return getChild<LLUICtrl>("shinyRot")->getValue().asReal(); } +F32 LLPanelFace::getCurrentShinyScaleU() { return getChild<LLUICtrl>("shinyScaleU")->getValue().asReal(); } +F32 LLPanelFace::getCurrentShinyScaleV() { return getChild<LLUICtrl>("shinyScaleV")->getValue().asReal(); } +F32 LLPanelFace::getCurrentShinyOffsetU() { return getChild<LLUICtrl>("shinyOffsetU")->getValue().asReal(); } +F32 LLPanelFace::getCurrentShinyOffsetV() { return getChild<LLUICtrl>("shinyOffsetV")->getValue().asReal(); } + // // Methods // @@ -105,19 +126,21 @@ BOOL LLPanelFace::postBuild() childSetCommitCallback("checkbox planar align",&LLPanelFace::onCommitPlanarAlign, this); childSetCommitCallback("TexOffsetU",LLPanelFace::onCommitTextureInfo, this); childSetCommitCallback("TexOffsetV",LLPanelFace::onCommitTextureInfo, this); - childSetCommitCallback("bumpyScaleU",&LLPanelFace::onCommitMaterial, this); - childSetCommitCallback("bumpyScaleV",&LLPanelFace::onCommitMaterial, this); - childSetCommitCallback("bumpyRot",&LLPanelFace::onCommitMaterial, this); - childSetCommitCallback("bumpyOffsetU",&LLPanelFace::onCommitMaterial, this); - childSetCommitCallback("bumpyOffsetV",&LLPanelFace::onCommitMaterial, this); - childSetCommitCallback("shinyScaleU",&LLPanelFace::onCommitMaterial, this); - childSetCommitCallback("shinyScaleV",&LLPanelFace::onCommitMaterial, this); - childSetCommitCallback("shinyRot",&LLPanelFace::onCommitMaterial, this); - childSetCommitCallback("shinyOffsetU",&LLPanelFace::onCommitMaterial, this); - childSetCommitCallback("shinyOffsetV",&LLPanelFace::onCommitMaterial, this); - childSetCommitCallback("glossiness",&LLPanelFace::onCommitMaterial, this); - childSetCommitCallback("environment",&LLPanelFace::onCommitMaterial, this); - childSetCommitCallback("maskcutoff",&LLPanelFace::onCommitMaterial, this); + + childSetCommitCallback("bumpyScaleU",&LLPanelFace::onCommitMaterialBumpyScaleX, this); + childSetCommitCallback("bumpyScaleV",&LLPanelFace::onCommitMaterialBumpyScaleY, this); + childSetCommitCallback("bumpyRot",&LLPanelFace::onCommitMaterialBumpyRot, this); + childSetCommitCallback("bumpyOffsetU",&LLPanelFace::onCommitMaterialBumpyOffsetX, this); + childSetCommitCallback("bumpyOffsetV",&LLPanelFace::onCommitMaterialBumpyOffsetY, this); + childSetCommitCallback("shinyScaleU",&LLPanelFace::onCommitMaterialShinyScaleX, this); + childSetCommitCallback("shinyScaleV",&LLPanelFace::onCommitMaterialShinyScaleY, this); + childSetCommitCallback("shinyRot",&LLPanelFace::onCommitMaterialShinyRot, this); + childSetCommitCallback("shinyOffsetU",&LLPanelFace::onCommitMaterialShinyOffsetX, this); + childSetCommitCallback("shinyOffsetV",&LLPanelFace::onCommitMaterialShinyOffsetY, this); + childSetCommitCallback("glossiness",&LLPanelFace::onCommitMaterialGloss, this); + childSetCommitCallback("environment",&LLPanelFace::onCommitMaterialEnv, this); + childSetCommitCallback("maskcutoff",&LLPanelFace::onCommitMaterialMaskCutoff, this); + childSetAction("button align",&LLPanelFace::onClickAutoFix,this); LLTextureCtrl* mTextureCtrl; @@ -293,10 +316,12 @@ void LLPanelFace::sendTexture() void LLPanelFace::sendBump(U32 bumpiness) { + LLTextureCtrl* bumpytexture_ctrl = getChild<LLTextureCtrl>("bumpytexture control"); + LLUUID current_normal_map = bumpytexture_ctrl->getImageAssetID(); + if (bumpiness < BUMPY_TEXTURE) { - LL_DEBUGS("Materials") << "clearing bumptexture control" << LL_ENDL; - LLTextureCtrl* bumpytexture_ctrl = getChild<LLTextureCtrl>("bumpytexture control"); + LL_DEBUGS("Materials") << "clearing bumptexture control" << LL_ENDL; bumpytexture_ctrl->clear(); bumpytexture_ctrl->setImageAssetID(LLUUID()); } @@ -305,7 +330,7 @@ void LLPanelFace::sendBump(U32 bumpiness) LLSelectMgr::getInstance()->selectionSetBumpmap( bump ); updateBumpyControls(bumpiness == BUMPY_TEXTURE, true); - updateMaterial(); + LLSelectedTEMaterial::setNormalID(this, current_normal_map); } void LLPanelFace::sendTexGen() @@ -328,9 +353,8 @@ void LLPanelFace::sendShiny(U32 shininess) U8 shiny = (U8) shininess & TEM_SHINY_MASK; LLSelectMgr::getInstance()->selectionSetShiny( shiny ); } - updateShinyControls(!texture_ctrl->getImageAssetID().isNull(), true); - updateMaterial(); + LLSelectedTEMaterial::setSpecularID(this, texture_ctrl->getImageAssetID()); } void LLPanelFace::sendFullbright() @@ -568,16 +592,9 @@ void LLPanelFace::sendTextureInfo() { if ((bool)childGetValue("checkbox planar align").asBoolean()) { - struct f1 : public LLSelectedTEGetFunctor<LLFace *> - { - LLFace* get(LLViewerObject* object, S32 te) - { - return (object->mDrawable) ? object->mDrawable->getFace(te): NULL; - } - } get_last_face_func; - LLFace* last_face; - LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&get_last_face_func, last_face); - + LLFace* last_face = NULL; + bool identical_face =false; + LLSelectedTE::getFace(last_face, identical_face); LLPanelFaceSetAlignedTEFunctor setfunc(this, last_face); LLSelectMgr::getInstance()->getSelection()->applyToTEs(&setfunc); } @@ -639,12 +656,12 @@ void LLPanelFace::updateUI() updateVisibility(); - bool identical; - bool identical_diffuse; - bool identical_norm; - bool identical_spec; + bool identical = true; // true because it is anded below + bool identical_diffuse = false; + bool identical_norm = false; + bool identical_spec = false; - LLTextureCtrl* texture_ctrl = getChild<LLTextureCtrl>("texture control"); + LLTextureCtrl* texture_ctrl = getChild<LLTextureCtrl>("texture control"); LLTextureCtrl* shinytexture_ctrl = getChild<LLTextureCtrl>("shinytexture control"); LLTextureCtrl* bumpytexture_ctrl = getChild<LLTextureCtrl>("bumpytexture control"); @@ -657,18 +674,14 @@ void LLPanelFace::updateUI() getChildView("color label")->setEnabled(editable); } LLColorSwatchCtrl* mColorSwatch = getChild<LLColorSwatchCtrl>("colorswatch"); - LLColor4 color = LLColor4::white; + + LLColor4 color = LLColor4::white; + bool identical_color = false; + if(mColorSwatch) { - struct f7 : public LLSelectedTEGetFunctor<LLColor4> - { - LLColor4 get(LLViewerObject* object, S32 face) - { - return object->getTE(face)->getColor(); - } - } func; - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, color ); - + LLSelectedTE::getColor(color, identical_color); + mColorSwatch->setOriginal(color); mColorSwatch->set(color, TRUE); @@ -678,73 +691,44 @@ void LLPanelFace::updateUI() } // Color transparency - { - getChildView("color trans")->setEnabled(editable); - } + getChildView("color trans")->setEnabled(editable); F32 transparency = (1.f - color.mV[VALPHA]) * 100.f; - { - getChild<LLUICtrl>("ColorTrans")->setValue(editable ? transparency : 0); - getChildView("ColorTrans")->setEnabled(editable); - } + getChild<LLUICtrl>("ColorTrans")->setValue(editable ? transparency : 0); + getChildView("ColorTrans")->setEnabled(editable); // Specular map - struct spec_get : public LLSelectedTEGetFunctor<LLUUID> - { - LLUUID get(LLViewerObject* object, S32 te_index) - { - LLUUID id; - - LLMaterial* mat = object->getTE(te_index)->getMaterialParams().get(); + LLSelectedTEMaterial::getSpecularID(specmap_id, identical_spec); + + U8 shiny = 0; + bool identical_shiny = false; - if (mat) - { - id = mat->getSpecularID(); - } + // Shiny + LLSelectedTE::getShiny(shiny, identical_shiny); + identical = identical && identical_shiny; - return id; - } - } spec_get_func; - identical_spec = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &spec_get_func, specmap_id ); + shiny = specmap_id.isNull() ? shiny : SHINY_TEXTURE; - U8 shiny = 0; + LLCtrlSelectionInterface* combobox_shininess = childGetSelectionInterface("combobox shininess"); + if (combobox_shininess) + { + combobox_shininess->selectNthItem((S32)shiny); + } - // Shiny - { - struct f9 : public LLSelectedTEGetFunctor<U8> - { - U8 get(LLViewerObject* object, S32 face) - { - return (U8)(object->getTE(face)->getShiny()); - } - } func; - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, shiny ); + getChildView("label shininess")->setEnabled(editable); + getChildView("combobox shininess")->setEnabled(editable); - LLCtrlSelectionInterface* combobox_shininess = - childGetSelectionInterface("combobox shininess"); + getChildView("label glossiness")->setEnabled(editable); + getChildView("glossiness")->setEnabled(editable); - shiny = specmap_id.isNull() ? shiny : SHINY_TEXTURE; + getChildView("label environment")->setEnabled(editable); + getChildView("environment")->setEnabled(editable); + getChildView("label shinycolor")->setEnabled(editable); - if (combobox_shininess) - { - combobox_shininess->selectNthItem((S32)shiny); - } - else - { - llwarns << "failed childGetSelectionInterface for 'combobox shininess'" << llendl; - } - getChildView("combobox shininess")->setEnabled(editable); - getChild<LLUICtrl>("combobox shininess")->setTentative(!identical); - getChildView("label shininess")->setEnabled(editable); - getChildView("glossiness")->setEnabled(editable); - getChild<LLUICtrl>("glossiness")->setTentative(!identical); - getChildView("label glossiness")->setEnabled(editable); - getChildView("environment")->setEnabled(editable); - getChild<LLUICtrl>("environment")->setTentative(!identical); - getChildView("label environment")->setEnabled(editable); - getChild<LLUICtrl>("shinycolorswatch")->setTentative(!identical); - getChildView("label shinycolor")->setEnabled(editable); - } + getChild<LLUICtrl>("combobox shininess")->setTentative(!identical_spec); + getChild<LLUICtrl>("glossiness")->setTentative(!identical_spec); + getChild<LLUICtrl>("environment")->setTentative(!identical_spec); + getChild<LLUICtrl>("shinycolorswatch")->setTentative(!identical_spec); LLColorSwatchCtrl* mShinyColorSwatch = getChild<LLColorSwatchCtrl>("shinycolorswatch"); if(mShinyColorSwatch) @@ -755,20 +739,12 @@ void LLPanelFace::updateUI() } U8 bumpy = 0; - // Bumpy - { - struct f10 : public LLSelectedTEGetFunctor<U8> - { - U8 get(LLViewerObject* object, S32 face) - { - return object->getTE(face)->getBumpmap(); - } - } func; - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, bumpy ); - - LLUUID norm_map_id = getChild<LLTextureCtrl>("bumpytexture control")->getImageAssetID(); + { + bool identical_bumpy = false; + LLSelectedTE::getBumpmap(bumpy,identical_bumpy); + LLUUID norm_map_id = getCurrentNormalMap(); LLCtrlSelectionInterface* combobox_bumpiness = childGetSelectionInterface("combobox bumpiness"); if (combobox_bumpiness) { @@ -779,78 +755,25 @@ void LLPanelFace::updateUI() llwarns << "failed childGetSelectionInterface for 'combobox bumpiness'" << llendl; } getChildView("combobox bumpiness")->setEnabled(editable); - getChild<LLUICtrl>("combobox bumpiness")->setTentative(!identical); + getChild<LLUICtrl>("combobox bumpiness")->setTentative(!identical_bumpy); getChildView("label bumpiness")->setEnabled(editable); } // Texture { - struct f1 : public LLSelectedTEGetFunctor<LLUUID> - { - LLUUID get(LLViewerObject* object, S32 te_index) - { - LLUUID id; - - LLViewerTexture* image = object->getTEImage(te_index); - if (image) id = image->getID(); - - if (!id.isNull() && LLViewerMedia::textureHasMedia(id)) - { - LLTextureEntry *te = object->getTE(te_index); - if (te) - { - LLViewerTexture* tex = te->getID().notNull() ? gTextureList.findImage(te->getID()) : NULL ; - if(!tex) - { - tex = LLViewerFetchedTexture::sDefaultImagep; - } - if (tex) - { - id = tex->getID(); - } - } - } - return id; - } - } func; - identical_diffuse = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, id ); + LLSelectedTE::getTexId(id,identical_diffuse); // Normal map - struct norm_get : public LLSelectedTEGetFunctor<LLUUID> - { - LLUUID get(LLViewerObject* object, S32 te_index) - { - LLUUID id; - - LLMaterial* mat = object->getTE(te_index)->getMaterialParams().get(); - - if (mat) - { - id = mat->getNormalID(); - } - - return id; - } - } norm_get_func; - identical_norm = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &norm_get_func, normmap_id ); - + LLSelectedTEMaterial::getNormalID(normmap_id, identical_norm); if (bumpy != BUMPY_TEXTURE) + { normmap_id = LLUUID::null; + } mIsAlpha = FALSE; LLGLenum image_format; - struct f2 : public LLSelectedTEGetFunctor<LLGLenum> - { - LLGLenum get(LLViewerObject* object, S32 te_index) - { - LLGLenum image_format = GL_RGB; - - LLViewerTexture* image = object->getTEImage(te_index); - if (image) image_format = image->getPrimaryFormat(); - return image_format; - } - } func2; - LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func2, image_format ); + bool identical_image_format = false; + LLSelectedTE::getImageFormat(image_format, identical_image_format); mIsAlpha = FALSE; switch (image_format) @@ -876,53 +799,27 @@ void LLPanelFace::updateUI() } // Diffuse Alpha Mode - struct alpha_get : public LLSelectedTEGetFunctor<U8> - { - U8 get(LLViewerObject* object, S32 te_index) - { - U8 ret = 1; - - LLMaterial* mat = object->getTE(te_index)->getMaterialParams().get(); + U8 alpha_mode = LLMaterial::DIFFUSE_ALPHA_MODE_NONE; + bool identical_alpha_mode = false; + LLSelectedTEMaterial::getDiffuseAlphaMode(alpha_mode, identical_alpha_mode); - if (mat) - { - ret = mat->getDiffuseAlphaMode(); - } - - return ret; - } - } alpha_get_func; - - U8 alpha_mode = 1; - LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &alpha_get_func, alpha_mode); - + LLCtrlSelectionInterface* combobox_alphamode = childGetSelectionInterface("combobox alphamode"); + if (combobox_alphamode) { - LLCtrlSelectionInterface* combobox_alphamode = - childGetSelectionInterface("combobox alphamode"); - - if (combobox_alphamode) - { - - if (transparency > 0.f) - { //it is invalid to have any alpha mode other than blend if transparency is greater than zero ... - alpha_mode = LLMaterial::DIFFUSE_ALPHA_MODE_BLEND; - } - - if (!mIsAlpha) - { // ... unless there is no alpha channel in the texture, in which case alpha mode MUST ebe none - alpha_mode = LLMaterial::DIFFUSE_ALPHA_MODE_NONE; - } + //it is invalid to have any alpha mode other than blend if transparency is greater than zero ... + alpha_mode = (transparency > 0.f) ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : alpha_mode; - - combobox_alphamode->selectNthItem(alpha_mode); - } - else - { - llwarns << "failed childGetSelectionInterface for 'combobox alphamode'" << llendl; - } + // ... unless there is no alpha channel in the texture, in which case alpha mode MUST ebe none + alpha_mode = mIsAlpha ? alpha_mode : LLMaterial::DIFFUSE_ALPHA_MODE_NONE; - updateAlphaControls(); + combobox_alphamode->selectNthItem(alpha_mode); + } + else + { + llwarns << "failed childGetSelectionInterface for 'combobox alphamode'" << llendl; } + + updateAlphaControls(); if(texture_ctrl && !texture_ctrl->isPickerShown()) { @@ -1010,34 +907,20 @@ void LLPanelFace::updateUI() // planar align bool align_planar = false; bool identical_planar_aligned = false; - bool is_planar = false; { LLCheckBoxCtrl* cb_planar_align = getChild<LLCheckBoxCtrl>("checkbox planar align"); align_planar = (cb_planar_align && cb_planar_align->get()); - struct f1 : public LLSelectedTEGetFunctor<bool> - { - bool get(LLViewerObject* object, S32 face) - { - return (object->getTE(face)->getTexGen() == LLTextureEntry::TEX_GEN_PLANAR); - } - } func; - - bool texgens_identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, is_planar ); - bool enabled = (editable && texgens_identical && is_planar); + + bool enabled = (editable && isIdenticalPlanarTexgen()); childSetValue("checkbox planar align", align_planar && enabled); childSetEnabled("checkbox planar align", enabled); if (align_planar && enabled) { - struct f2 : public LLSelectedTEGetFunctor<LLFace *> - { - LLFace* get(LLViewerObject* object, S32 te) - { - return (object->mDrawable) ? object->mDrawable->getFace(te): NULL; - } - } get_te_face_func; - LLFace* last_face; - LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&get_te_face_func, last_face); + LLFace* last_face = NULL; + bool identical_face = false; + LLSelectedTE::getFace(last_face, identical_face); + LLPanelFaceGetIsAlignedTEFunctor get_is_aligend_func(last_face); // this will determine if the texture param controls are tentative: identical_planar_aligned = LLSelectMgr::getInstance()->getSelection()->applyToTEs(&get_is_aligend_func); @@ -1052,386 +935,210 @@ void LLPanelFace::updateUI() bool identical_texgen = true; bool identical_planar_texgen = false; - { - struct f11 : public LLSelectedTEGetFunctor<LLTextureEntry::e_texgen> - { - LLTextureEntry::e_texgen get(LLViewerObject* object, S32 face) - { - return (LLTextureEntry::e_texgen)(object->getTE(face)->getTexGen()); - } - } func; - identical_texgen = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, selected_texgen ); + { + LLSelectedTE::getTexGen(selected_texgen, identical_texgen); identical_planar_texgen = (identical_texgen && (selected_texgen == LLTextureEntry::TEX_GEN_PLANAR)); } // Texture scale { - F32 scale_s = 1.f; - struct f2 : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - return object->getTE(face)->mScaleS; - } - } func; + bool identical_diff_scale_s = false; + bool identical_spec_scale_s = false; + bool identical_norm_scale_s = false; - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, scale_s ); identical = align_planar ? identical_planar_aligned : identical; - F32 scale_u = editable ? scale_s : 0; - scale_u *= identical_planar_texgen ? 2.0f : 1.0f; + F32 diff_scale_s = 1.f; + F32 spec_scale_s = 1.f; + F32 norm_scale_s = 1.f; - getChild<LLUICtrl>("TexScaleU")->setValue(scale_u); - getChild<LLUICtrl>("TexScaleU")->setTentative(LLSD((BOOL)(!identical))); - getChildView("TexScaleU")->setEnabled(editable); - - scale_s = 1.f; - struct f3 : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - F32 s = 1.f, t = 1.f; + LLSelectedTE::getScaleS( diff_scale_s, identical_diff_scale_s); + LLSelectedTEMaterial::getSpecularRepeatX( spec_scale_s, identical_spec_scale_s); + LLSelectedTEMaterial::getNormalRepeatX( norm_scale_s, identical_norm_scale_s); - LLMaterial* mat = object->getTE(face)->getMaterialParams().get(); - if (mat) - { - mat->getSpecularRepeat(s, t); - } - return s; - } - } shiny_func; + diff_scale_s = editable ? diff_scale_s : 1.0f; + diff_scale_s *= identical_planar_texgen ? 2.0f : 1.0f; - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &shiny_func, scale_s ); - identical = align_planar ? identical_planar_aligned : identical; - - F32 scale_s_value = editable ? scale_s : 0; - scale_s_value *= identical_planar_texgen ? 2.0f : 1.0f; + norm_scale_s = editable ? norm_scale_s : 1.0f; + norm_scale_s *= identical_planar_texgen ? 2.0f : 1.0f; - getChild<LLUICtrl>("shinyScaleU")->setValue(scale_s_value); - getChild<LLUICtrl>("shinyScaleU")->setTentative(LLSD((BOOL)(!identical))); - getChildView("shinyScaleU")->setEnabled(editable && specmap_id.notNull()); + spec_scale_s = editable ? spec_scale_s : 1.0f; + spec_scale_s *= identical_planar_texgen ? 2.0f : 1.0f; - scale_s = 1.f; - struct f4 : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - F32 s = 1.f, t = 1.f; + getChild<LLUICtrl>("TexScaleU")->setValue(diff_scale_s); + getChild<LLUICtrl>("shinyScaleU")->setValue(spec_scale_s); + getChild<LLUICtrl>("bumpyScaleU")->setValue(norm_scale_s); - LLMaterial* mat = object->getTE(face)->getMaterialParams().get(); - if (mat) - { - mat->getNormalRepeat(s, t); - } - return s; - } - } bump_func; - - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &bump_func, scale_s ); - identical = align_planar ? identical_planar_aligned : identical; + getChildView("TexScaleU")->setEnabled(editable); + getChildView("shinyScaleU")->setEnabled(editable && specmap_id.notNull()); + getChildView("bumpyScaleU")->setEnabled(editable && normmap_id.notNull()); - scale_s_value = editable ? scale_s : 0; - scale_s_value *= identical_planar_texgen ? 2.0f : 1.0f; + BOOL diff_scale_tentative = !(identical && identical_diff_scale_s); + BOOL norm_scale_tentative = !(identical && identical_norm_scale_s); + BOOL spec_scale_tentative = !(identical && identical_spec_scale_s); - getChild<LLUICtrl>("bumpyScaleU")->setValue(scale_s_value); - getChild<LLUICtrl>("bumpyScaleU")->setTentative(LLSD((BOOL)(!identical))); - getChildView("bumpyScaleU")->setEnabled(editable && normmap_id.notNull()); + getChild<LLUICtrl>("TexScaleU")->setTentative( LLSD(diff_scale_tentative)); + getChild<LLUICtrl>("shinyScaleU")->setTentative(LLSD(spec_scale_tentative)); + getChild<LLUICtrl>("bumpyScaleU")->setTentative(LLSD(norm_scale_tentative)); } { - F32 scale_t = 1.f; - struct f3 : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - return object->getTE(face)->mScaleT; - } - } func; - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, scale_t ); - identical = align_planar ? identical_planar_aligned : identical; + bool identical_diff_scale_t = false; + bool identical_spec_scale_t = false; + bool identical_norm_scale_t = false; - F32 scale_t_value = editable ? scale_t : 0; - scale_t_value *= identical_planar_texgen ? 2.0f : 1.0f; + F32 diff_scale_t = 1.f; + F32 spec_scale_t = 1.f; + F32 norm_scale_t = 1.f; - getChild<LLUICtrl>("TexScaleV")->setValue(scale_t_value); - getChild<LLUICtrl>("TexScaleV")->setTentative(LLSD((BOOL)(!identical))); - getChildView("TexScaleV")->setEnabled(editable); - - scale_t = 1.f; - struct f4 : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - F32 s = 1.f, t = 1.f; + LLSelectedTE::getScaleT(diff_scale_t, identical_diff_scale_t); + LLSelectedTEMaterial::getSpecularRepeatY(spec_scale_t, identical_spec_scale_t); + LLSelectedTEMaterial::getNormalRepeatY(norm_scale_t, identical_norm_scale_t); - LLMaterial* mat = object->getTE(face)->getMaterialParams().get(); - if (mat) - { - mat->getSpecularRepeat(s, t); - } - return t; - } - } shiny_func; - - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &shiny_func, scale_t ); - identical = align_planar ? identical_planar_aligned : identical; + diff_scale_t = editable ? diff_scale_t : 1.0f; + diff_scale_t *= identical_planar_texgen ? 2.0f : 1.0f; - scale_t_value = editable ? scale_t : 0; - scale_t_value *= identical_planar_texgen ? 2.0f : 1.0f; + norm_scale_t = editable ? norm_scale_t : 1.0f; + norm_scale_t *= identical_planar_texgen ? 2.0f : 1.0f; - getChild<LLUICtrl>("shinyScaleV")->setValue(scale_t_value); - getChild<LLUICtrl>("shinyScaleV")->setTentative(LLSD((BOOL)(!identical))); - getChildView("shinyScaleV")->setEnabled(editable && specmap_id.notNull()); + spec_scale_t = editable ? spec_scale_t : 1.0f; + spec_scale_t *= identical_planar_texgen ? 2.0f : 1.0f; - scale_t = 1.f; - struct f5 : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - F32 s = 1.f, t = 1.f; + BOOL diff_scale_tentative = !identical_diff_scale_t; + BOOL norm_scale_tentative = !identical_norm_scale_t; + BOOL spec_scale_tentative = !identical_spec_scale_t; - LLMaterial* mat = object->getTE(face)->getMaterialParams().get(); - if (mat) - { - mat->getNormalRepeat(s, t); - } - return t; - } - } bump_func; - - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &bump_func, scale_t ); - identical = align_planar ? identical_planar_aligned : identical; + getChildView("TexScaleV")->setEnabled(editable); + getChildView("shinyScaleV")->setEnabled(editable && specmap_id.notNull()); + getChildView("bumpyScaleV")->setEnabled(editable && normmap_id.notNull()); - scale_t_value = editable ? scale_t : 0.0f; - scale_t_value *= identical_planar_texgen ? 2.0f : 1.0f; + getChild<LLUICtrl>("TexScaleV")->setValue(diff_scale_t); + getChild<LLUICtrl>("shinyScaleV")->setValue(norm_scale_t); + getChild<LLUICtrl>("bumpyScaleV")->setValue(spec_scale_t); - getChild<LLUICtrl>("bumpyScaleV")->setValue(scale_t_value); - getChild<LLUICtrl>("bumpyScaleV")->setTentative(LLSD((BOOL)(!identical))); - getChildView("bumpyScaleV")->setEnabled(editable && normmap_id.notNull()); - + getChild<LLUICtrl>("TexScaleV")->setTentative(LLSD(diff_scale_tentative)); + getChild<LLUICtrl>("shinyScaleV")->setTentative(LLSD(norm_scale_tentative)); + getChild<LLUICtrl>("bumpyScaleV")->setTentative(LLSD(spec_scale_tentative)); } // Texture offset { - getChildView("tex offset")->setEnabled(editable); - F32 offset_s = 0.f; - struct f4 : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - return object->getTE(face)->mOffsetS; - } - } func; - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, offset_s ); - identical = align_planar ? identical_planar_aligned : identical; - getChild<LLUICtrl>("TexOffsetU")->setValue(editable ? offset_s : 0); - getChild<LLUICtrl>("TexOffsetU")->setTentative(!identical); - getChildView("TexOffsetU")->setEnabled(editable); + bool identical_diff_offset_s = false; + bool identical_norm_offset_s = false; + bool identical_spec_offset_s = false; - offset_s = 1.f; - struct f3 : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - F32 s = 0.f, t = 0.f; + F32 diff_offset_s = 0.0f; + F32 norm_offset_s = 0.0f; + F32 spec_offset_s = 0.0f; - LLMaterial* mat = object->getTE(face)->getMaterialParams().get(); - if (mat) - { - mat->getSpecularOffset(s, t); - } - return s; - } - } shiny_func; - - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &shiny_func, offset_s ); - identical = align_planar ? identical_planar_aligned : identical; - getChild<LLUICtrl>("shinyOffsetU")->setValue(editable ? offset_s : 0); - getChild<LLUICtrl>("shinyOffsetU")->setTentative(LLSD((BOOL)(!identical))); - getChildView("shinyOffsetU")->setEnabled(editable && specmap_id.notNull()); + LLSelectedTE::getOffsetS(diff_offset_s, identical_diff_offset_s); + LLSelectedTEMaterial::getNormalOffsetX(norm_offset_s, identical_norm_offset_s); + LLSelectedTEMaterial::getSpecularOffsetX(spec_offset_s, identical_spec_offset_s); - offset_s = 1.f; - struct f5 : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - F32 s = 0.f, t = 0.f; + BOOL diff_offset_u_tentative = !(align_planar ? identical_planar_aligned : identical_diff_offset_s); + BOOL norm_offset_u_tentative = !(align_planar ? identical_planar_aligned : identical_norm_offset_s); + BOOL spec_offset_u_tentative = !(align_planar ? identical_planar_aligned : identical_spec_offset_s); - LLMaterial* mat = object->getTE(face)->getMaterialParams().get(); - if (mat) - { - mat->getNormalOffset(s, t); - } - return s; - } - } bump_func; - - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &bump_func, offset_s ); - identical = align_planar ? identical_planar_aligned : identical; + getChild<LLUICtrl>("TexOffsetU")->setValue( editable ? diff_offset_s : 0.0f); + getChild<LLUICtrl>("bumpyOffsetU")->setValue(editable ? norm_offset_s : 0.0f); + getChild<LLUICtrl>("shinyOffsetU")->setValue(editable ? spec_offset_s : 0.0f); - getChild<LLUICtrl>("bumpyOffsetU")->setValue(editable ? offset_s : 0); - getChild<LLUICtrl>("bumpyOffsetU")->setTentative(LLSD((BOOL)(!identical))); + getChild<LLUICtrl>("TexOffsetU")->setTentative(LLSD(diff_offset_u_tentative)); + getChild<LLUICtrl>("shinyOffsetU")->setTentative(LLSD(norm_offset_u_tentative)); + getChild<LLUICtrl>("bumpyOffsetU")->setTentative(LLSD(spec_offset_u_tentative)); + + getChildView("TexOffsetU")->setEnabled(editable); + getChildView("shinyOffsetU")->setEnabled(editable && specmap_id.notNull()); getChildView("bumpyOffsetU")->setEnabled(editable && normmap_id.notNull()); } { - F32 offset_t = 0.f; - struct f5 : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - return object->getTE(face)->mOffsetT; - } - } func; - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, offset_t ); - identical = align_planar ? identical_planar_aligned : identical; - getChild<LLUICtrl>("TexOffsetV")->setValue(editable ? offset_t : 0); - getChild<LLUICtrl>("TexOffsetV")->setTentative(!identical); - getChildView("TexOffsetV")->setEnabled(editable); - - - offset_t = 1.f; - struct f3 : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - F32 s = 0.f, t = 0.f; + bool identical_diff_offset_t = false; + bool identical_norm_offset_t = false; + bool identical_spec_offset_t = false; - LLMaterial* mat = object->getTE(face)->getMaterialParams().get(); - if (mat) - { - mat->getSpecularOffset(s, t); - } - return t; - } - } shiny_func; + F32 diff_offset_t = 0.0f; + F32 norm_offset_t = 0.0f; + F32 spec_offset_t = 0.0f; + + LLSelectedTE::getOffsetT(diff_offset_t, identical_diff_offset_t); + LLSelectedTEMaterial::getNormalOffsetY(norm_offset_t, identical_norm_offset_t); + LLSelectedTEMaterial::getSpecularOffsetY(spec_offset_t, identical_spec_offset_t); - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &shiny_func, offset_t ); - identical = align_planar ? identical_planar_aligned : identical; - getChild<LLUICtrl>("shinyOffsetV")->setValue(editable ? offset_t : 0); - getChild<LLUICtrl>("shinyOffsetV")->setTentative(LLSD((BOOL)(!identical))); - getChildView("shinyOffsetV")->setEnabled(editable && specmap_id.notNull()); + BOOL diff_offset_v_tentative = !(align_planar ? identical_planar_aligned : identical_diff_offset_t); + BOOL norm_offset_v_tentative = !(align_planar ? identical_planar_aligned : identical_norm_offset_t); + BOOL spec_offset_v_tentative = !(align_planar ? identical_planar_aligned : identical_spec_offset_t); - offset_t = 1.f; - struct f4 : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - F32 s = 0.f, t = 0.f; + getChild<LLUICtrl>("TexOffsetV")->setValue( editable ? diff_offset_t : 0.0f); + getChild<LLUICtrl>("bumpyOffsetV")->setValue(editable ? norm_offset_t : 0.0f); + getChild<LLUICtrl>("shinyOffsetV")->setValue(editable ? spec_offset_t : 0.0f); - LLMaterial* mat = object->getTE(face)->getMaterialParams().get(); - if (mat) - { - mat->getNormalOffset(s, t); - } - return t; - } - } bump_func; - - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &bump_func, offset_t ); - identical = align_planar ? identical_planar_aligned : identical; + getChild<LLUICtrl>("TexOffsetV")->setTentative(LLSD(diff_offset_v_tentative)); + getChild<LLUICtrl>("shinyOffsetV")->setTentative(LLSD(norm_offset_v_tentative)); + getChild<LLUICtrl>("bumpyOffsetV")->setTentative(LLSD(spec_offset_v_tentative)); - getChild<LLUICtrl>("bumpyOffsetV")->setValue(editable ? offset_t : 0); - getChild<LLUICtrl>("bumpyOffsetV")->setTentative(LLSD((BOOL)(!identical))); + getChildView("TexOffsetV")->setEnabled(editable); + getChildView("shinyOffsetV")->setEnabled(editable && specmap_id.notNull()); getChildView("bumpyOffsetV")->setEnabled(editable && normmap_id.notNull()); } // Texture rotation { - F32 rotation = 0.f; - struct f6 : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - return object->getTE(face)->mRotation; - } - } func; - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, rotation ); - identical = align_planar ? identical_planar_aligned : identical; - getChild<LLUICtrl>("TexRot")->setValue(editable ? rotation * RAD_TO_DEG : 0); - getChild<LLUICtrl>("TexRot")->setTentative(!identical); - getChildView("TexRot")->setEnabled(editable); + bool identical_diff_rotation = false; + bool identical_norm_rotation = false; + bool identical_spec_rotation = false; + F32 diff_rotation = 0.f; + F32 norm_rotation = 0.f; + F32 spec_rotation = 0.f; - - rotation = 1.f; - struct f3 : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - F32 ret = 0.f; + LLSelectedTE::getRotation(diff_rotation,identical_diff_rotation); + LLSelectedTEMaterial::getSpecularRotation(spec_rotation,identical_spec_rotation); + LLSelectedTEMaterial::getNormalRotation(norm_rotation,identical_norm_rotation); - LLMaterial* mat = object->getTE(face)->getMaterialParams().get(); - if (mat) - { - ret = mat->getSpecularRotation(); - } - return ret; - } - } shiny_func; - - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &shiny_func, rotation ); - identical = align_planar ? identical_planar_aligned : identical; - getChild<LLUICtrl>("shinyRot")->setValue(editable ? rotation * RAD_TO_DEG : 0); - getChild<LLUICtrl>("shinyRot")->setTentative(LLSD((BOOL)(!identical))); - getChildView("shinyRot")->setEnabled(editable && specmap_id.notNull()); + BOOL diff_rot_tentative = !(align_planar ? identical_planar_aligned : identical_diff_rotation); + BOOL norm_rot_tentative = !(align_planar ? identical_planar_aligned : identical_norm_rotation); + BOOL spec_rot_tentative = !(align_planar ? identical_planar_aligned : identical_spec_rotation); - rotation = 1.f; - struct f4 : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - F32 ret = 0.f; - - LLMaterial* mat = object->getTE(face)->getMaterialParams().get(); - if (mat) - { - ret = mat->getNormalRotation(); - } - return ret; - } - } bump_func; - - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &bump_func, rotation ); - identical = align_planar ? identical_planar_aligned : identical; + F32 diff_rot_deg = diff_rotation * RAD_TO_DEG; + F32 norm_rot_deg = norm_rotation * RAD_TO_DEG; + F32 spec_rot_deg = spec_rotation * RAD_TO_DEG; - F32 normal_rot_deg = rotation * RAD_TO_DEG; - getChild<LLUICtrl>("bumpyRot")->setValue(editable ? normal_rot_deg : 0.0f); - getChild<LLUICtrl>("bumpyRot")->setTentative(LLSD((BOOL)(!identical))); + getChildView("TexRot")->setEnabled(editable); + getChildView("shinyRot")->setEnabled(editable && specmap_id.notNull()); getChildView("bumpyRot")->setEnabled(editable && normmap_id.notNull()); + + getChild<LLUICtrl>("TexRot")->setTentative(diff_rot_tentative); + getChild<LLUICtrl>("shinyRot")->setTentative(LLSD(norm_rot_tentative)); + getChild<LLUICtrl>("bumpyRot")->setTentative(LLSD(spec_rot_tentative)); + + getChild<LLUICtrl>("TexRot")->setValue( editable ? diff_rot_deg : 0.0f); + getChild<LLUICtrl>("shinyRot")->setValue(editable ? spec_rot_deg : 0.0f); + getChild<LLUICtrl>("bumpyRot")->setValue(editable ? norm_rot_deg : 0.0f); } { F32 glow = 0.f; - struct f8 : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - return object->getTE(face)->getGlow(); - } - } func; - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, glow ); - + bool identical_glow = false; + LLSelectedTE::getGlow(glow,identical_glow); getChild<LLUICtrl>("glow")->setValue(glow); + getChild<LLUICtrl>("glow")->setTentative(!identical_glow); getChildView("glow")->setEnabled(editable); - getChild<LLUICtrl>("glow")->setTentative(!identical); - getChildView("glow label")->setEnabled(editable); - + getChildView("glow label")->setEnabled(editable); } - - { - LLCtrlSelectionInterface* combobox_texgen = - childGetSelectionInterface("combobox texgen"); + LLCtrlSelectionInterface* combobox_texgen = childGetSelectionInterface("combobox texgen"); if (combobox_texgen) { - combobox_texgen->selectNthItem(((S32)selected_texgen) >> 1); // Maps from enum to combobox entry index + // Maps from enum to combobox entry index + combobox_texgen->selectNthItem(((S32)selected_texgen) >> 1); } else { llwarns << "failed childGetSelectionInterface for 'combobox texgen'" << llendl; } + getChildView("combobox texgen")->setEnabled(editable); getChild<LLUICtrl>("combobox texgen")->setTentative(!identical); getChildView("tex gen")->setEnabled(editable); @@ -1450,18 +1157,13 @@ void LLPanelFace::updateUI() { U8 fullbright_flag = 0; - struct f12 : public LLSelectedTEGetFunctor<U8> - { - U8 get(LLViewerObject* object, S32 face) - { - return object->getTE(face)->getFullbright(); - } - } func; - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, fullbright_flag ); + bool identical_fullbright = false; + + LLSelectedTE::getFullbright(fullbright_flag,identical_fullbright); getChild<LLUICtrl>("checkbox fullbright")->setValue((S32)(fullbright_flag != 0)); getChildView("checkbox fullbright")->setEnabled(editable); - getChild<LLUICtrl>("checkbox fullbright")->setTentative(!identical); + getChild<LLUICtrl>("checkbox fullbright")->setTentative(!identical_fullbright); } // Repeats per meter @@ -1470,72 +1172,20 @@ void LLPanelFace::updateUI() F32 repeats_norm = 1.f; F32 repeats_spec = 1.f; - struct f13 : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - U32 s_axis = VX; - U32 t_axis = VY; - // BUG: Only repeats along S axis - // BUG: Only works for boxes. - LLPrimitive::getTESTAxes(face, &s_axis, &t_axis); - F32 repeats_s = object->getTE(face)->mScaleS / object->getScale().mV[s_axis]; - F32 repeats_t = object->getTE(face)->mScaleT / object->getScale().mV[t_axis]; - return llmax(repeats_s, repeats_t); - } + bool identical_diff_repeats = false; + bool identical_norm_repeats = false; + bool identical_spec_repeats = false; - } func_diff; - bool identical_diff_repeats = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func_diff, repeats_diff ); - - struct f14 : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - LLMaterial* mat = object->getTE(face)->getMaterialParams().get(); - U32 s_axis = VX; - U32 t_axis = VY; - F32 repeats_s = 1.0f; - F32 repeats_t = 1.0f; - if (mat) - { - mat->getNormalRepeat(repeats_s, repeats_t); - repeats_s /= object->getScale().mV[s_axis]; - repeats_t /= object->getScale().mV[t_axis]; - } - return llmax(repeats_s, repeats_t); - } - - } func_norm; - BOOL identical_norm_repeats = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func_norm, repeats_norm ); - - struct f15 : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - LLMaterial* mat = object->getTE(face)->getMaterialParams().get(); - U32 s_axis = VX; - U32 t_axis = VY; - F32 repeats_s = 1.0f; - F32 repeats_t = 1.0f; - if (mat) - { - mat->getSpecularRepeat(repeats_s, repeats_t); - repeats_s /= object->getScale().mV[s_axis]; - repeats_t /= object->getScale().mV[t_axis]; - } - return llmax(repeats_s, repeats_t); - } - - } func_spec; - BOOL identical_spec_repeats = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func_spec, repeats_spec ); - + LLSelectedTE::getMaxDiffuseRepeats(repeats_diff, identical_diff_repeats); + LLSelectedTEMaterial::getMaxNormalRepeats(repeats_norm, identical_norm_repeats); + LLSelectedTEMaterial::getMaxSpecularRepeats(repeats_spec, identical_spec_repeats); LLComboBox* mComboTexGen = getChild<LLComboBox>("combobox texgen"); if (mComboTexGen) { S32 index = mComboTexGen ? mComboTexGen->getCurrentIndex() : 0; BOOL enabled = editable && (index != 1); - BOOL identical = true; + BOOL identical_repeats = true; F32 repeats = 1.0f; U32 material_type = (combobox_matmedia->getCurrentIndex() == MATMEDIA_MATERIAL) ? combobox_mattype->getCurrentIndex() : MATTYPE_DIFFUSE; @@ -1545,7 +1195,7 @@ void LLPanelFace::updateUI() case MATTYPE_DIFFUSE: { enabled = editable && !id.isNull(); - identical = identical_diff_repeats; + identical_repeats = identical_diff_repeats; repeats = repeats_diff; } break; @@ -1553,7 +1203,7 @@ void LLPanelFace::updateUI() case MATTYPE_SPECULAR: { enabled = (editable && ((shiny == SHINY_TEXTURE) && !specmap_id.isNull())); - identical = identical_spec_repeats; + identical_repeats = identical_spec_repeats; repeats = repeats_spec; } break; @@ -1561,30 +1211,24 @@ void LLPanelFace::updateUI() case MATTYPE_NORMAL: { enabled = (editable && ((bumpy == BUMPY_TEXTURE) && !normmap_id.isNull())); - identical = identical_norm_repeats; + identical_repeats = identical_norm_repeats; repeats = repeats_norm; } break; } + BOOL repeats_tentative = !identical_repeats; + getChildView("rptctrl")->setEnabled(identical_planar_texgen ? FALSE : enabled); getChild<LLUICtrl>("rptctrl")->setValue(editable ? repeats : 1.0f); - getChild<LLUICtrl>("rptctrl")->setTentative(!identical); + getChild<LLUICtrl>("rptctrl")->setTentative(LLSD(repeats_tentative)); } } // Materials { - struct f1 : public LLSelectedTEGetFunctor<LLMaterialPtr> - { - LLMaterialPtr get(LLViewerObject* object, S32 te_index) - { - return object->getTE(te_index)->getMaterialParams(); - } - } func; - LLMaterialPtr material; - identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, material ); + LLSelectedTEMaterial::getCurrent(material, identical); if (material && editable) { @@ -1616,19 +1260,7 @@ void LLPanelFace::updateUI() getChild<LLUICtrl>("maskcutoff")->setValue(material->getAlphaMaskCutoff()); updateAlphaControls(); - LLTextureEntry::e_texgen selected_texgen = LLTextureEntry::TEX_GEN_DEFAULT; - bool identical_texgen = true; - bool identical_planar_texgen = false; - - struct f44 : public LLSelectedTEGetFunctor<LLTextureEntry::e_texgen> - { - LLTextureEntry::e_texgen get(LLViewerObject* object, S32 face) - { - return (LLTextureEntry::e_texgen)(object->getTE(face)->getTexGen()); - } - } func; - identical_texgen = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, selected_texgen ); - identical_planar_texgen = (identical_texgen && (selected_texgen == LLTextureEntry::TEX_GEN_PLANAR)); + identical_planar_texgen = isIdenticalPlanarTexgen(); // Shiny (specular) F32 offset_x, offset_y, repeat_x, repeat_y, rot; @@ -1771,144 +1403,6 @@ void LLPanelFace::refresh() getState(); } -void LLPanelFace::updateMaterial() -{ // assign current state of UI to material definition for submit to sim - LL_DEBUGS("Materials") << "Entered." << LL_ENDL; - LLComboBox* comboAlphaMode = getChild<LLComboBox>("combobox alphamode"); - LLComboBox* comboBumpiness = getChild<LLComboBox>("combobox bumpiness"); - LLComboBox* comboShininess = getChild<LLComboBox>("combobox shininess"); - if (!comboAlphaMode || !comboBumpiness || !comboShininess) - { - return; - } - U32 alpha_mode = comboAlphaMode->getCurrentIndex(); - U32 bumpiness = comboBumpiness->getCurrentIndex(); - U32 shininess = comboShininess->getCurrentIndex(); - - LLTextureEntry::e_texgen selected_texgen = LLTextureEntry::TEX_GEN_DEFAULT; - struct f45 : public LLSelectedTEGetFunctor<LLTextureEntry::e_texgen> - { - LLTextureEntry::e_texgen get(LLViewerObject* object, S32 face) - { - return (LLTextureEntry::e_texgen)(object->getTE(face)->getTexGen()); - } - } func; - bool identical_texgen = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, selected_texgen ); - bool identical_planar_texgen = (identical_texgen && (selected_texgen == LLTextureEntry::TEX_GEN_PLANAR)); - - bool is_default_blend_mode = mIsAlpha ? (alpha_mode == LLMaterial::DIFFUSE_ALPHA_MODE_BLEND) - : (alpha_mode == LLMaterial::DIFFUSE_ALPHA_MODE_NONE); - - LLUUID norm_map_id = getChild<LLTextureCtrl>("bumpytexture control")->getImageAssetID(); - LLUUID spec_map_id = getChild<LLTextureCtrl>("shinytexture control")->getImageAssetID(); - - if ( !is_default_blend_mode - || !norm_map_id.isNull() - || !spec_map_id.isNull()) - { - // This should match getState() - struct f1 : public LLSelectedTEGetFunctor<LLMaterialPtr> - { - LLMaterialPtr get(LLViewerObject* object, S32 te_index) - { - return object->getTE(te_index)->getMaterialParams(); - } - } func; - LLMaterialPtr cur_material; - LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&func, cur_material); - - bool new_material = cur_material.isNull(); - - LLMaterialPtr material( (!new_material) ? new LLMaterial(cur_material->asLLSD()) : new LLMaterial()); - llassert_always(material); - - material->setDiffuseAlphaMode(getChild<LLComboBox>("combobox alphamode")->getCurrentIndex()); - material->setAlphaMaskCutoff((U8)(getChild<LLUICtrl>("maskcutoff")->getValue().asInteger())); - - if (!norm_map_id.isNull() && (bumpiness == BUMPY_TEXTURE)) - { - LL_DEBUGS("Materials") << "Setting bumpy texture, bumpiness = " << bumpiness << LL_ENDL; - material->setNormalID(norm_map_id); - - F32 bumpy_scale_u = getChild<LLUICtrl>("bumpyScaleU")->getValue().asReal(); - F32 bumpy_scale_v = getChild<LLUICtrl>("bumpyScaleV")->getValue().asReal(); - - if (identical_planar_texgen) - { - bumpy_scale_u *= 0.5f; - bumpy_scale_v *= 0.5f; - } - - material->setNormalOffset(getChild<LLUICtrl>("bumpyOffsetU")->getValue().asReal(), - getChild<LLUICtrl>("bumpyOffsetV")->getValue().asReal()); - material->setNormalRepeat(bumpy_scale_u, bumpy_scale_v); - F32 normal_rot_rads = getChild<LLUICtrl>("bumpyRot")->getValue().asReal()*DEG_TO_RAD; - material->setNormalRotation(normal_rot_rads); - } - else - { - LL_DEBUGS("Materials") << "Removing bumpy texture, bumpiness = " << bumpiness << LL_ENDL; - material->setNormalID(LLUUID()); - material->setNormalOffset(0.0f,0.0f); - material->setNormalRepeat(1.0f,1.0f); - material->setNormalRotation(0.0f); - } - - - - if (!spec_map_id.isNull() && (shininess == SHINY_TEXTURE)) - { - LL_DEBUGS("Materials") << "Setting shiny texture, shininess = " << shininess << LL_ENDL; - material->setSpecularID(spec_map_id); - material->setSpecularOffset(getChild<LLUICtrl>("shinyOffsetU")->getValue().asReal(), - getChild<LLUICtrl>("shinyOffsetV")->getValue().asReal()); - - F32 shiny_scale_u = getChild<LLUICtrl>("shinyScaleU")->getValue().asReal(); - F32 shiny_scale_v = getChild<LLUICtrl>("shinyScaleV")->getValue().asReal(); - - if (identical_planar_texgen) - { - shiny_scale_u *= 0.5f; - shiny_scale_v *= 0.5f; - } - - material->setSpecularRepeat(shiny_scale_u, shiny_scale_v); - material->setSpecularRotation(getChild<LLUICtrl>("shinyRot")->getValue().asReal()*DEG_TO_RAD); - - //override shininess to 0.2f if this is a new material - if (!new_material) - { - material->setSpecularLightColor(getChild<LLColorSwatchCtrl>("shinycolorswatch")->get()); - material->setSpecularLightExponent(getChild<LLUICtrl>("glossiness")->getValue().asInteger()); - material->setEnvironmentIntensity(getChild<LLUICtrl>("environment")->getValue().asInteger()); - } - } - else - { - LL_DEBUGS("Materials") << "Removing shiny texture, shininess = " << shininess << LL_ENDL; - material->setSpecularID(LLUUID()); - material->setSpecularOffset(0.0f,0.0f); - material->setSpecularRepeat(1.0f,1.0f); - material->setSpecularRotation(0.0f); - material->setSpecularLightColor(LLMaterial::DEFAULT_SPECULAR_LIGHT_COLOR); - material->setSpecularLightExponent(LLMaterial::DEFAULT_SPECULAR_LIGHT_EXPONENT); - material->setEnvironmentIntensity(0); - } - - LL_DEBUGS("Materials") << "Updating material: " << material->asLLSD() << LL_ENDL; - - LLSelectMgr::getInstance()->selectionSetMaterial( material ); - } - else - { - // The user has specified settings that don't need a material. - LL_DEBUGS("Materials") << "Resetting material entry" << LL_ENDL; - - // Delete existing material entry... - LLSelectMgr::getInstance()->selectionRemoveMaterial(); - } -} - // // Static functions // @@ -1927,7 +1421,7 @@ void LLPanelFace::onCommitColor(const LLSD& data) void LLPanelFace::onCommitShinyColor(const LLSD& data) { - updateMaterial(); + LLSelectedTEMaterial::setSpecularLightColor(this, getChild<LLColorSwatchCtrl>("shinycolorswatch")->get()); } void LLPanelFace::onCommitAlpha(const LLSD& data) @@ -1950,6 +1444,11 @@ void LLPanelFace::onSelectColor(const LLSD& data) void LLPanelFace::onCommitMaterialsMedia(LLUICtrl* ctrl, void* userdata) { LLPanelFace* self = (LLPanelFace*) userdata; + // Force to default states to side-step problems with menu contents + // and generally reflecting old state when switching tabs or objects + // + self->updateShinyControls(false,true); + self->updateBumpyControls(false,true); self->updateUI(); } @@ -2037,10 +1536,11 @@ void LLPanelFace::updateVisibility() void LLPanelFace::onCommitMaterialType(LLUICtrl* ctrl, void* userdata) { LLPanelFace* self = (LLPanelFace*) userdata; - // This is here to insure that we properly update shared UI elements - // like the texture ctrls for diffuse/norm/spec so that they are correct - // when switching modes - // + // Force to default states to side-step problems with menu contents + // and generally reflecting old state when switching tabs or objects + // + self->updateShinyControls(false,true); + self->updateBumpyControls(false,true); self->updateUI(); } @@ -2084,18 +1584,6 @@ void LLPanelFace::updateShinyControls(bool is_setting_texture, bool mess_with_sh if (!comboShiny->itemExists(USE_TEXTURE)) { comboShiny->add(USE_TEXTURE); - - // NORSPEC-94: Set default specular color to white - // - LLColorSwatchCtrl* mShinyColorSwatch = getChild<LLColorSwatchCtrl>("shinycolorswatch"); - if(mShinyColorSwatch) - { - LL_DEBUGS("Materials") << "Resetting specular color to default of white" << LL_ENDL; - mShinyColorSwatch->setOriginal(LLColor4::white); - mShinyColorSwatch->set(LLColor4::white, TRUE); - } - getChild<LLUICtrl>("glossiness")->setValue(LLMaterial::DEFAULT_SPECULAR_LIGHT_EXPONENT); - getChild<LLUICtrl>("environment")->setValue(0); } comboShiny->setSimple(USE_TEXTURE); } @@ -2103,8 +1591,6 @@ void LLPanelFace::updateShinyControls(bool is_setting_texture, bool mess_with_sh { if (comboShiny->itemExists(USE_TEXTURE)) { - // HACK: This depends on adding the "Use texture" - // item at the end of a list of known length. comboShiny->remove(SHINY_TEXTURE); } } @@ -2216,7 +1702,7 @@ void LLPanelFace::onCommitAlphaMode(LLUICtrl* ctrl, void* userdata) { LLPanelFace* self = (LLPanelFace*) userdata; self->updateAlphaControls(); - self->updateMaterial(); + LLSelectedTEMaterial::setDiffuseAlphaMode(self,self->getCurrentDiffuseAlphaMode()); } // static @@ -2268,18 +1754,8 @@ void LLPanelFace::onSelectTexture(const LLSD& data) sendTexture(); LLGLenum image_format; - struct f2 : public LLSelectedTEGetFunctor<LLGLenum> - { - LLGLenum get(LLViewerObject* object, S32 te_index) - { - LLGLenum image_format = GL_RGB; - - LLViewerTexture* image = object->getTEImage(te_index); - if (image) image_format = image->getPrimaryFormat(); - return image_format; - } - } func2; - LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func2, image_format ); + bool identical_image_format = false; + LLSelectedTE::getImageFormat(image_format, identical_image_format); LLCtrlSelectionInterface* combobox_alphamode = childGetSelectionInterface("combobox alphamode"); @@ -2306,8 +1782,7 @@ void LLPanelFace::onSelectTexture(const LLSD& data) combobox_alphamode->selectNthItem(alpha_mode); } - - updateMaterial(); + LLSelectedTEMaterial::setDiffuseAlphaMode(this, getCurrentDiffuseAlphaMode()); } void LLPanelFace::onCommitSpecularTexture( const LLSD& data ) @@ -2319,22 +1794,14 @@ void LLPanelFace::onCommitSpecularTexture( const LLSD& data ) void LLPanelFace::onCommitNormalTexture( const LLSD& data ) { LL_DEBUGS("Materials") << data << LL_ENDL; - sendBump(BUMPY_TEXTURE); + sendBump(getCurrentNormalMap().isNull() ? 0 : BUMPY_TEXTURE); } void LLPanelFace::onCancelSpecularTexture(const LLSD& data) { - - U8 shiny = 0; - struct get_shiny : public LLSelectedTEGetFunctor<U8> - { - U8 get(LLViewerObject* object, S32 face) - { - return (U8)(object->getTE(face)->getShiny()); - } - } func; - LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, shiny ); - + U8 shiny = 0; + bool identical_shiny = false; + LLSelectedTE::getShiny(shiny, identical_shiny); LLUUID spec_map_id = getChild<LLTextureCtrl>("shinytexture control")->getImageAssetID(); shiny = spec_map_id.isNull() ? shiny : SHINY_TEXTURE; sendShiny(shiny); @@ -2342,16 +1809,9 @@ void LLPanelFace::onCancelSpecularTexture(const LLSD& data) void LLPanelFace::onCancelNormalTexture(const LLSD& data) { - U8 bumpy = 0; - struct get_bumpy : public LLSelectedTEGetFunctor<U8> - { - U8 get(LLViewerObject* object, S32 face) - { - return (U8)(object->getTE(face)->getBumpmap()); - } - - } func; - LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, bumpy ); + U8 bumpy = 0; + bool identical_bumpy = false; + LLSelectedTE::getBumpmap(bumpy, identical_bumpy); sendBump(bumpy); } @@ -2368,10 +1828,126 @@ void LLPanelFace::onSelectNormalTexture(const LLSD& data) } //static -void LLPanelFace::onCommitMaterial(LLUICtrl* ctrl, void* userdata) +void LLPanelFace::onCommitMaterialBumpyOffsetX(LLUICtrl* ctrl, void* userdata) +{ + LLPanelFace* self = (LLPanelFace*) userdata; + llassert_always(self); + LLSelectedTEMaterial::setNormalOffsetX(self,self->getCurrentBumpyOffsetU()); +} + +//static +void LLPanelFace::onCommitMaterialBumpyOffsetY(LLUICtrl* ctrl, void* userdata) +{ + LLPanelFace* self = (LLPanelFace*) userdata; + llassert_always(self); + LLSelectedTEMaterial::setNormalOffsetY(self,self->getCurrentBumpyOffsetV()); +} + +//static +void LLPanelFace::onCommitMaterialShinyOffsetX(LLUICtrl* ctrl, void* userdata) +{ + LLPanelFace* self = (LLPanelFace*) userdata; + llassert_always(self); + LLSelectedTEMaterial::setSpecularOffsetX(self,self->getCurrentShinyOffsetU()); +} + +//static +void LLPanelFace::onCommitMaterialShinyOffsetY(LLUICtrl* ctrl, void* userdata) +{ + LLPanelFace* self = (LLPanelFace*) userdata; + llassert_always(self); + LLSelectedTEMaterial::setSpecularOffsetY(self,self->getCurrentShinyOffsetV()); +} + +//static +void LLPanelFace::onCommitMaterialBumpyScaleX(LLUICtrl* ctrl, void* userdata) +{ + LLPanelFace* self = (LLPanelFace*) userdata; + llassert_always(self); + F32 bumpy_scale_u = self->getCurrentBumpyScaleU(); + if (self->isIdenticalPlanarTexgen()) + { + bumpy_scale_u *= 0.5f; + } + LLSelectedTEMaterial::setNormalRepeatX(self,bumpy_scale_u); +} + +//static +void LLPanelFace::onCommitMaterialBumpyScaleY(LLUICtrl* ctrl, void* userdata) +{ + LLPanelFace* self = (LLPanelFace*) userdata; + llassert_always(self); + F32 bumpy_scale_v = self->getCurrentBumpyScaleV(); + if (self->isIdenticalPlanarTexgen()) + { + bumpy_scale_v *= 0.5f; + } + LLSelectedTEMaterial::setNormalRepeatY(self,bumpy_scale_v); +} + +//static +void LLPanelFace::onCommitMaterialShinyScaleX(LLUICtrl* ctrl, void* userdata) +{ + LLPanelFace* self = (LLPanelFace*) userdata; + llassert_always(self); + F32 shiny_scale_u = self->getCurrentShinyScaleU(); + if (self->isIdenticalPlanarTexgen()) + { + shiny_scale_u *= 0.5f; + } + LLSelectedTEMaterial::setSpecularRepeatX(self,shiny_scale_u); +} + +//static +void LLPanelFace::onCommitMaterialShinyScaleY(LLUICtrl* ctrl, void* userdata) +{ + LLPanelFace* self = (LLPanelFace*) userdata; + llassert_always(self); + F32 shiny_scale_v = self->getCurrentShinyScaleV(); + if (self->isIdenticalPlanarTexgen()) + { + shiny_scale_v *= 0.5f; + } + LLSelectedTEMaterial::setSpecularRepeatY(self,shiny_scale_v); +} + +//static +void LLPanelFace::onCommitMaterialBumpyRot(LLUICtrl* ctrl, void* userdata) +{ + LLPanelFace* self = (LLPanelFace*) userdata; + llassert_always(self); + LLSelectedTEMaterial::setNormalRotation(self,self->getCurrentBumpyRot()); +} + +//static +void LLPanelFace::onCommitMaterialShinyRot(LLUICtrl* ctrl, void* userdata) +{ + LLPanelFace* self = (LLPanelFace*) userdata; + llassert_always(self); + LLSelectedTEMaterial::setSpecularRotation(self,self->getCurrentShinyRot()); +} + +//static +void LLPanelFace::onCommitMaterialGloss(LLUICtrl* ctrl, void* userdata) +{ + LLPanelFace* self = (LLPanelFace*) userdata; + llassert_always(self); + LLSelectedTEMaterial::setSpecularLightExponent(self,self->getCurrentGlossiness()); +} + +//static +void LLPanelFace::onCommitMaterialEnv(LLUICtrl* ctrl, void* userdata) +{ + LLPanelFace* self = (LLPanelFace*) userdata; + llassert_always(self); + LLSelectedTEMaterial::setEnvironmentIntensity(self,self->getCurrentEnvIntensity()); +} + +//static +void LLPanelFace::onCommitMaterialMaskCutoff(LLUICtrl* ctrl, void* userdata) { LLPanelFace* self = (LLPanelFace*) userdata; - self->updateMaterial(); + LLSelectedTEMaterial::setAlphaMaskCutoff(self,self->getCurrentAlphaMaskCutoff()); } // static @@ -2387,44 +1963,25 @@ void LLPanelFace::onCommitRepeatsPerMeter(LLUICtrl* ctrl, void* userdata) { LLPanelFace* self = (LLPanelFace*) userdata; - LLUICtrl* repeats_ctrl = self->getChild<LLUICtrl>("rptctrl"); - - F32 repeats_per_meter = repeats_ctrl->getValue().asReal(); + LLUICtrl* repeats_ctrl = self->getChild<LLUICtrl>("rptctrl"); + LLComboBox* combo_matmedia = self->getChild<LLComboBox>("combobox matmedia"); + LLComboBox* combo_mattype = self->getChild<LLComboBox>("combobox mattype"); - LLComboBox* combo_mattype = self->getChild<LLComboBox>("combobox mattype"); + U32 materials_media = combo_matmedia->getCurrentIndex(); - F32 obj_scale_s = 1.0f; - F32 obj_scale_t = 1.0f; - - U32 material_type = combo_mattype->getCurrentIndex(); - struct f_objscale_s : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - U32 s_axis = VX; - U32 t_axis = VY; - LLPrimitive::getTESTAxes(face, &s_axis, &t_axis); - return object->getScale().mV[s_axis]; - } - - } scale_s_func; - - struct f_objscale_t : public LLSelectedTEGetFunctor<F32> - { - F32 get(LLViewerObject* object, S32 face) - { - U32 s_axis = VX; - U32 t_axis = VY; - LLPrimitive::getTESTAxes(face, &s_axis, &t_axis); - return object->getScale().mV[t_axis]; - } - - } scale_t_func; - - LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &scale_s_func, obj_scale_s ); - LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &scale_t_func, obj_scale_t ); - + U32 material_type = (materials_media == MATMEDIA_MATERIAL) ? combo_mattype->getCurrentIndex() : 0; + F32 repeats_per_meter = repeats_ctrl->getValue().asReal(); + + F32 obj_scale_s = 1.0f; + F32 obj_scale_t = 1.0f; + + bool identical_scale_s = false; + bool identical_scale_t = false; + + LLSelectedTE::getObjectScaleS(obj_scale_s, identical_scale_s); + LLSelectedTE::getObjectScaleS(obj_scale_t, identical_scale_t); + switch (material_type) { case MATTYPE_DIFFUSE: @@ -2437,9 +1994,12 @@ void LLPanelFace::onCommitRepeatsPerMeter(LLUICtrl* ctrl, void* userdata) { LLUICtrl* bumpy_scale_u = self->getChild<LLUICtrl>("bumpyScaleU"); LLUICtrl* bumpy_scale_v = self->getChild<LLUICtrl>("bumpyScaleV"); + bumpy_scale_u->setValue(obj_scale_s * repeats_per_meter); bumpy_scale_v->setValue(obj_scale_t * repeats_per_meter); - self->updateMaterial(); + + LLSelectedTEMaterial::setNormalRepeatX(self,obj_scale_s * repeats_per_meter); + LLSelectedTEMaterial::setNormalRepeatY(self,obj_scale_t * repeats_per_meter); } break; @@ -2447,9 +2007,12 @@ void LLPanelFace::onCommitRepeatsPerMeter(LLUICtrl* ctrl, void* userdata) { LLUICtrl* shiny_scale_u = self->getChild<LLUICtrl>("shinyScaleU"); LLUICtrl* shiny_scale_v = self->getChild<LLUICtrl>("shinyScaleV"); + shiny_scale_u->setValue(obj_scale_s * repeats_per_meter); shiny_scale_v->setValue(obj_scale_t * repeats_per_meter); - self->updateMaterial(); + + LLSelectedTEMaterial::setSpecularRepeatX(self,obj_scale_s * repeats_per_meter); + LLSelectedTEMaterial::setSpecularRepeatY(self,obj_scale_t * repeats_per_meter); } break; @@ -2580,3 +2143,180 @@ void LLPanelFace::onTextureSelectionChanged(LLInventoryItem* itemp) } } +bool LLPanelFace::isIdenticalPlanarTexgen() +{ + LLTextureEntry::e_texgen selected_texgen = LLTextureEntry::TEX_GEN_DEFAULT; + bool identical_texgen = false; + LLSelectedTE::getTexGen(selected_texgen, identical_texgen); + return (identical_texgen && (selected_texgen == LLTextureEntry::TEX_GEN_PLANAR)); +} + +void LLPanelFace::LLSelectedTE::getFace(LLFace*& face_to_return, bool& identical_face) +{ + struct LLSelectedTEGetFace : public LLSelectedTEGetFunctor<LLFace *> + { + LLFace* get(LLViewerObject* object, S32 te) + { + return (object->mDrawable) ? object->mDrawable->getFace(te): NULL; + } + } get_te_face_func; + identical_face = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&get_te_face_func, face_to_return); +} + +void LLPanelFace::LLSelectedTE::getImageFormat(LLGLenum& image_format_to_return, bool& identical_face) +{ + struct LLSelectedTEGetImageFormat : public LLSelectedTEGetFunctor<LLGLenum> + { + LLGLenum get(LLViewerObject* object, S32 te_index) + { + LLViewerTexture* image = object->getTEImage(te_index); + return image ? image->getPrimaryFormat() : GL_RGB; + } + } get_glenum; + identical_face = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&get_glenum, image_format_to_return); +} + +void LLPanelFace::LLSelectedTE::getTexId(LLUUID& id, bool& identical) +{ + struct LLSelectedTEGetTexId : public LLSelectedTEGetFunctor<LLUUID> + { + LLUUID get(LLViewerObject* object, S32 te_index) + { + LLUUID id; + LLViewerTexture* image = object->getTEImage(te_index); + if (image) + { + id = image->getID(); + } + + if (!id.isNull() && LLViewerMedia::textureHasMedia(id)) + { + LLTextureEntry *te = object->getTE(te_index); + if (te) + { + LLViewerTexture* tex = te->getID().notNull() ? gTextureList.findImage(te->getID()) : NULL; + if(!tex) + { + tex = LLViewerFetchedTexture::sDefaultImagep; + } + if (tex) + { + id = tex->getID(); + } + } + } + return id; + } + } func; + identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, id ); +} + +void LLPanelFace::LLSelectedTEMaterial::getCurrent(LLMaterialPtr& material_ptr, bool& identical_material) +{ + struct MaterialFunctor : public LLSelectedTEGetFunctor<LLMaterialPtr> + { + LLMaterialPtr get(LLViewerObject* object, S32 te_index) + { + return object->getTE(te_index)->getMaterialParams(); + } + } func; + identical_material = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, material_ptr); +} + +void LLPanelFace::LLSelectedTEMaterial::getMaxSpecularRepeats(F32& repeats, bool& identical) +{ + struct LLSelectedTEGetMaxSpecRepeats : public LLSelectedTEGetFunctor<F32> + { + F32 get(LLViewerObject* object, S32 face) + { + LLMaterial* mat = object->getTE(face)->getMaterialParams().get(); + U32 s_axis = VX; + U32 t_axis = VY; + F32 repeats_s = 1.0f; + F32 repeats_t = 1.0f; + if (mat) + { + mat->getSpecularRepeat(repeats_s, repeats_t); + repeats_s /= object->getScale().mV[s_axis]; + repeats_t /= object->getScale().mV[t_axis]; + } + return llmax(repeats_s, repeats_t); + } + + } max_spec_repeats_func; + identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &max_spec_repeats_func, repeats); +} + +void LLPanelFace::LLSelectedTEMaterial::getMaxNormalRepeats(F32& repeats, bool& identical) +{ + struct LLSelectedTEGetMaxNormRepeats : public LLSelectedTEGetFunctor<F32> + { + F32 get(LLViewerObject* object, S32 face) + { + LLMaterial* mat = object->getTE(face)->getMaterialParams().get(); + U32 s_axis = VX; + U32 t_axis = VY; + F32 repeats_s = 1.0f; + F32 repeats_t = 1.0f; + if (mat) + { + mat->getNormalRepeat(repeats_s, repeats_t); + repeats_s /= object->getScale().mV[s_axis]; + repeats_t /= object->getScale().mV[t_axis]; + } + return llmax(repeats_s, repeats_t); + } + + } max_norm_repeats_func; + identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &max_norm_repeats_func, repeats); +} + +void LLPanelFace::LLSelectedTE::getObjectScaleS(F32& scale_s, bool& identical) +{ + struct LLSelectedTEGetObjectScaleS : public LLSelectedTEGetFunctor<F32> + { + F32 get(LLViewerObject* object, S32 face) + { + U32 s_axis = VX; + U32 t_axis = VY; + LLPrimitive::getTESTAxes(face, &s_axis, &t_axis); + return object->getScale().mV[s_axis]; + } + + } scale_s_func; + identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &scale_s_func, scale_s ); +} + +void LLPanelFace::LLSelectedTE::getObjectScaleT(F32& scale_t, bool& identical) +{ + struct LLSelectedTEGetObjectScaleS : public LLSelectedTEGetFunctor<F32> + { + F32 get(LLViewerObject* object, S32 face) + { + U32 s_axis = VX; + U32 t_axis = VY; + LLPrimitive::getTESTAxes(face, &s_axis, &t_axis); + return object->getScale().mV[t_axis]; + } + + } scale_t_func; + identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &scale_t_func, scale_t ); +} + +void LLPanelFace::LLSelectedTE::getMaxDiffuseRepeats(F32& repeats, bool& identical) +{ + struct LLSelectedTEGetMaxDiffuseRepeats : public LLSelectedTEGetFunctor<F32> + { + F32 get(LLViewerObject* object, S32 face) + { + U32 s_axis = VX; + U32 t_axis = VY; + LLPrimitive::getTESTAxes(face, &s_axis, &t_axis); + F32 repeats_s = object->getTE(face)->mScaleS / object->getScale().mV[s_axis]; + F32 repeats_t = object->getTE(face)->mScaleT / object->getScale().mV[t_axis]; + return llmax(repeats_s, repeats_t); + } + + } max_diff_repeats_func; + identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &max_diff_repeats_func, repeats ); +}
\ No newline at end of file diff --git a/indra/newview/llpanelface.h b/indra/newview/llpanelface.h index f64564c9a0..84aba4dc89 100755 --- a/indra/newview/llpanelface.h +++ b/indra/newview/llpanelface.h @@ -30,6 +30,9 @@ #include "v4color.h" #include "llpanel.h" #include "llmaterial.h" +#include "llmaterialmgr.h" +#include "lltextureentry.h" +#include "llselectmgr.h" class LLButton; class LLCheckBoxCtrl; @@ -45,6 +48,47 @@ class LLViewerObject; class LLFloater; class LLMaterialID; +// Represents an edit for use in replicating the op across one or more materials in the selection set. +// +// The apply function optionally performs the edit which it implements +// as a functor taking Data that calls member func MaterialFunc taking SetValueType +// on an instance of the LLMaterial class. +// +// boost who? +// +template< + typename DataType, + typename SetValueType, + void (LLMaterial::*MaterialEditFunc)(SetValueType data) > +class LLMaterialEditFunctor +{ +public: + LLMaterialEditFunctor(const DataType& data) : _data(data) {} + virtual ~LLMaterialEditFunctor() {} + virtual void apply(LLMaterialPtr& material) { (material->*(MaterialEditFunc))(_data); } + DataType _data; +}; + +template< + typename DataType, + DataType (LLMaterial::*MaterialGetFunc)() > +class LLMaterialGetFunctor +{ +public: + LLMaterialGetFunctor() {} + virtual DataType get(LLMaterialPtr& material) { return (material->*(MaterialGetFunc)); } +}; + +template< + typename DataType, + DataType (LLTextureEntry::*TEGetFunc)() > +class LLTEGetFunctor +{ +public: + LLTEGetFunctor() {} + virtual DataType get(LLTextureEntry* entry) { return (entry*(TEGetFunc)); } +}; + class LLPanelFace : public LLPanel { public: @@ -93,10 +137,31 @@ protected: // void updateUI(); + // Convenience func to determine if all faces in selection have + // identical planar texgen settings during edits + // + bool isIdenticalPlanarTexgen(); + // Callback funcs for individual controls // static void onCommitTextureInfo( LLUICtrl* ctrl, void* userdata); - static void onCommitMaterial( LLUICtrl* ctrl, void* userdata); + + static void onCommitMaterialBumpyScaleX( LLUICtrl* ctrl, void* userdata); + static void onCommitMaterialBumpyScaleY( LLUICtrl* ctrl, void* userdata); + static void onCommitMaterialBumpyRot( LLUICtrl* ctrl, void* userdata); + static void onCommitMaterialBumpyOffsetX( LLUICtrl* ctrl, void* userdata); + static void onCommitMaterialBumpyOffsetY( LLUICtrl* ctrl, void* userdata); + + static void onCommitMaterialShinyScaleX( LLUICtrl* ctrl, void* userdata); + static void onCommitMaterialShinyScaleY( LLUICtrl* ctrl, void* userdata); + static void onCommitMaterialShinyRot( LLUICtrl* ctrl, void* userdata); + static void onCommitMaterialShinyOffsetX( LLUICtrl* ctrl, void* userdata); + static void onCommitMaterialShinyOffsetY( LLUICtrl* ctrl, void* userdata); + + static void onCommitMaterialGloss( LLUICtrl* ctrl, void* userdata); + static void onCommitMaterialEnv( LLUICtrl* ctrl, void* userdata); + static void onCommitMaterialMaskCutoff( LLUICtrl* ctrl, void* userdata); + static void onCommitMaterialsMedia( LLUICtrl* ctrl, void* userdata); static void onCommitMaterialType( LLUICtrl* ctrl, void* userdata); static void onCommitBump( LLUICtrl* ctrl, void* userdata); @@ -113,6 +178,29 @@ protected: private: + bool isAlpha() { return mIsAlpha; } + + // Convenience funcs to keep the visual flack to a minimum + // + LLUUID getCurrentNormalMap(); + LLUUID getCurrentSpecularMap(); + U32 getCurrentShininess(); + U32 getCurrentBumpiness(); + U8 getCurrentDiffuseAlphaMode(); + U8 getCurrentAlphaMaskCutoff(); + U8 getCurrentEnvIntensity(); + U8 getCurrentGlossiness(); + F32 getCurrentBumpyRot(); + F32 getCurrentBumpyScaleU(); + F32 getCurrentBumpyScaleV(); + F32 getCurrentBumpyOffsetU(); + F32 getCurrentBumpyOffsetV(); + F32 getCurrentShinyRot(); + F32 getCurrentShinyScaleU(); + F32 getCurrentShinyScaleV(); + F32 getCurrentShinyOffsetU(); + F32 getCurrentShinyOffsetV(); + // Update visibility of controls to match current UI mode // (e.g. materials vs media editing) // @@ -120,10 +208,126 @@ private: // void updateVisibility(); - // Make material reflect current state of UI (apply edit) + // Make material(s) reflect current state of UI (apply edit) // void updateMaterial(); + // Hey look everyone, a type-safe alternative to copy and paste! :) + // + + // Update material parameters by applying 'edit_func' to selected TEs + // + template< + typename DataType, + typename SetValueType, + void (LLMaterial::*MaterialEditFunc)(SetValueType data) > + static void edit(LLPanelFace* p, DataType data) + { + LLMaterialEditFunctor< DataType, SetValueType, MaterialEditFunc > edit(data); + struct LLSelectedTEEditMaterial : public LLSelectedTEMaterialFunctor + { + LLSelectedTEEditMaterial(LLPanelFace* panel, LLMaterialEditFunctor< DataType, SetValueType, MaterialEditFunc >* editp) : _panel(panel), _edit(editp) {} + virtual ~LLSelectedTEEditMaterial() {}; + virtual LLMaterialPtr apply(LLViewerObject* object, S32 face, LLTextureEntry* tep, LLMaterialPtr& current_material) + { + if (_edit) + { + LLMaterialPtr new_material(!current_material.isNull() ? new LLMaterial(current_material->asLLSD()) : new LLMaterial()); + llassert_always(new_material); + + // Determine correct alpha mode for current diffuse texture + // (i.e. does it have an alpha channel that makes alpha mode useful) + // + U8 default_alpha_mode = (_panel->isAlpha() ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : LLMaterial::DIFFUSE_ALPHA_MODE_NONE); + + // Default to matching expected state of UI + // + new_material->setDiffuseAlphaMode(current_material.isNull() ? default_alpha_mode : current_material->getDiffuseAlphaMode()); + + // Do "It"! + // + _edit->apply(new_material); + + U32 new_alpha_mode = new_material->getDiffuseAlphaMode(); + LLUUID new_normal_map_id = new_material->getNormalID(); + LLUUID new_spec_map_id = new_material->getSpecularID(); + + bool is_default_blend_mode = (new_alpha_mode == default_alpha_mode); + bool is_need_material = !is_default_blend_mode || !new_normal_map_id.isNull() || !new_spec_map_id.isNull(); + + if (!is_need_material) + { + LL_DEBUGS("Materials") << "Removing material from object " << object->getID() << " face " << face << LL_ENDL; + LLMaterialMgr::getInstance()->remove(object->getID(),face); + } + else + { + LL_DEBUGS("Materials") << "Putting material on object " << object->getID() << " face " << face << ", material: " << new_material->asLLSD() << LL_ENDL; + LLMaterialMgr::getInstance()->put(object->getID(),face,*new_material); + } + + object->setTEMaterialParams(face, new_material); + return new_material; + } + return NULL; + } + LLMaterialEditFunctor< DataType, SetValueType, MaterialEditFunc >* _edit; + LLPanelFace* _panel; + } editor(p, &edit); + LLSelectMgr::getInstance()->selectionSetMaterialParams(&editor); + } + + template< + typename DataType, + typename ReturnType, + ReturnType (LLMaterial::* const MaterialGetFunc)() const > + static void getTEMaterialValue(DataType& data_to_return, bool& identical,DataType default_value) + { + struct GetTEMaterialVal : public LLSelectedTEGetFunctor<DataType> + { + GetTEMaterialVal(DataType default_value) : _default(default_value) {} + virtual ~GetTEMaterialVal() {} + + DataType get(LLViewerObject* object, S32 face) + { + DataType ret = _default; + LLMaterialPtr material_ptr; + LLTextureEntry* tep = object ? object->getTE(face) : NULL; + if (tep) + { + material_ptr = object->getTE(face)->getMaterialParams(); + if (!material_ptr.isNull()) + { + ret = (material_ptr->*(MaterialGetFunc))(); + } + } + return ret; + } + DataType _default; + } GetFunc(default_value); + identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &GetFunc, data_to_return); + } + + template< + typename DataType, + typename ReturnType, // some kids just have to different... + ReturnType (LLTextureEntry::* const TEGetFunc)() const > + static void getTEValue(DataType& data_to_return, bool& identical, DataType default_value) + { + struct GetTEVal : public LLSelectedTEGetFunctor<DataType> + { + GetTEVal(DataType default_value) : _default(default_value) {} + virtual ~GetTEVal() {} + + DataType get(LLViewerObject* object, S32 face) { + LLTextureEntry* tep = object ? object->getTE(face) : NULL; + return tep ? ((tep->*(TEGetFunc))()) : _default; + } + DataType _default; + } GetTEValFunc(default_value); + identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &GetTEValFunc, data_to_return ); + } + // Update vis and enabling of specific subsets of controls based on material params // (e.g. hide the spec controls if no spec texture is applied) // @@ -152,6 +356,112 @@ private: */ bool mUpdateInFlight; bool mUpdatePending; + + #if defined(DEF_GET_MAT_STATE) + #undef DEF_GET_MAT_STATE + #endif + + #if defined(DEF_GET_TE_STATE) + #undef DEF_GET_TE_STATE + #endif + + #if defined(DEF_EDIT_MAT_STATE) + DEF_EDIT_MAT_STATE + #endif + + // Accessors for selected TE material state + // + #define DEF_GET_MAT_STATE(DataType,ReturnType,MaterialMemberFunc,DefaultValue) \ + static void MaterialMemberFunc(DataType& data, bool& identical) \ + { \ + getTEMaterialValue< DataType, ReturnType, &LLMaterial::MaterialMemberFunc >(data, identical,DefaultValue); \ + } + + // Mutators for selected TE material + // + #define DEF_EDIT_MAT_STATE(DataType,ReturnType,MaterialMemberFunc) \ + static void MaterialMemberFunc(LLPanelFace* p,DataType data) \ + { \ + edit< DataType, ReturnType, &LLMaterial::MaterialMemberFunc >(p,data); \ + } + + // Accessors for selected TE state proper (legacy settings etc) + // + #define DEF_GET_TE_STATE(DataType,ReturnType,TexEntryMemberFunc,DefaultValue) \ + static void TexEntryMemberFunc(DataType& data, bool& identical) \ + { \ + getTEValue< DataType, ReturnType, &LLTextureEntry::TexEntryMemberFunc >(data, identical,DefaultValue); \ + } + + class LLSelectedTEMaterial + { + public: + static void getCurrent(LLMaterialPtr& material_ptr, bool& identical_material); + static void getMaxSpecularRepeats(F32& repeats, bool& identical); + static void getMaxNormalRepeats(F32& repeats, bool& identical); + + DEF_GET_MAT_STATE(LLUUID,const LLUUID&,getNormalID,LLUUID::null) + DEF_GET_MAT_STATE(LLUUID,const LLUUID&,getSpecularID,LLUUID::null) + DEF_GET_MAT_STATE(U8,U8,getDiffuseAlphaMode,LLMaterial::DIFFUSE_ALPHA_MODE_NONE) + + DEF_GET_MAT_STATE(F32,F32,getSpecularRepeatX,1.0f) + DEF_GET_MAT_STATE(F32,F32,getSpecularRepeatY,1.0f) + DEF_GET_MAT_STATE(F32,F32,getSpecularOffsetX,0.0f) + DEF_GET_MAT_STATE(F32,F32,getSpecularOffsetY,0.0f) + DEF_GET_MAT_STATE(F32,F32,getSpecularRotation,0.0f) + + DEF_GET_MAT_STATE(F32,F32,getNormalRepeatX,1.0f) + DEF_GET_MAT_STATE(F32,F32,getNormalRepeatY,1.0f) + DEF_GET_MAT_STATE(F32,F32,getNormalOffsetX,0.0f) + DEF_GET_MAT_STATE(F32,F32,getNormalOffsetY,0.0f) + DEF_GET_MAT_STATE(F32,F32,getNormalRotation,0.0f) + + DEF_EDIT_MAT_STATE(U8,U8,setDiffuseAlphaMode); + DEF_EDIT_MAT_STATE(U8,U8,setAlphaMaskCutoff); + + DEF_EDIT_MAT_STATE(F32,F32,setNormalOffsetX); + DEF_EDIT_MAT_STATE(F32,F32,setNormalOffsetY); + DEF_EDIT_MAT_STATE(F32,F32,setNormalRepeatX); + DEF_EDIT_MAT_STATE(F32,F32,setNormalRepeatY); + DEF_EDIT_MAT_STATE(F32,F32,setNormalRotation); + + DEF_EDIT_MAT_STATE(F32,F32,setSpecularOffsetX); + DEF_EDIT_MAT_STATE(F32,F32,setSpecularOffsetY); + DEF_EDIT_MAT_STATE(F32,F32,setSpecularRepeatX); + DEF_EDIT_MAT_STATE(F32,F32,setSpecularRepeatY); + DEF_EDIT_MAT_STATE(F32,F32,setSpecularRotation); + + DEF_EDIT_MAT_STATE(U8,U8,setEnvironmentIntensity); + DEF_EDIT_MAT_STATE(U8,U8,setSpecularLightExponent); + + DEF_EDIT_MAT_STATE(LLUUID,const LLUUID&,setNormalID); + DEF_EDIT_MAT_STATE(LLUUID,const LLUUID&,setSpecularID); + DEF_EDIT_MAT_STATE(LLColor4U, const LLColor4U&,setSpecularLightColor); + }; + + class LLSelectedTE + { + public: + + static void getFace(LLFace*& face_to_return, bool& identical_face); + static void getImageFormat(LLGLenum& image_format_to_return, bool& identical_face); + static void getTexId(LLUUID& id, bool& identical); + static void getObjectScaleS(F32& scale_s, bool& identical); + static void getObjectScaleT(F32& scale_t, bool& identical); + static void getMaxDiffuseRepeats(F32& repeats, bool& identical); + + DEF_GET_TE_STATE(U8,U8,getBumpmap,0) + DEF_GET_TE_STATE(U8,U8,getShiny,0) + DEF_GET_TE_STATE(U8,U8,getFullbright,0) + DEF_GET_TE_STATE(F32,F32,getRotation,0.0f) + DEF_GET_TE_STATE(F32,F32,getOffsetS,0.0f) + DEF_GET_TE_STATE(F32,F32,getOffsetT,0.0f) + DEF_GET_TE_STATE(F32,F32,getScaleS,1.0f) + DEF_GET_TE_STATE(F32,F32,getScaleT,1.0f) + DEF_GET_TE_STATE(F32,F32,getGlow,0.0f) + DEF_GET_TE_STATE(LLTextureEntry::e_texgen,LLTextureEntry::e_texgen,getTexGen,LLTextureEntry::TEX_GEN_DEFAULT) + DEF_GET_TE_STATE(LLColor4,const LLColor4&,getColor,LLColor4::white) + }; }; #endif diff --git a/indra/newview/llselectmgr.cpp b/indra/newview/llselectmgr.cpp index 37c11bd027..0cbdbe16a3 100755 --- a/indra/newview/llselectmgr.cpp +++ b/indra/newview/llselectmgr.cpp @@ -2016,23 +2016,29 @@ void LLSelectMgr::selectionSetGlow(F32 glow) mSelectedObjects->applyToObjects( &func2 ); } -void LLSelectMgr::selectionSetMaterial(LLMaterialPtr material) +void LLSelectMgr::selectionSetMaterialParams(LLSelectedTEMaterialFunctor* material_func) { struct f1 : public LLSelectedTEFunctor { LLMaterialPtr mMaterial; - f1(LLMaterialPtr material) : mMaterial(material) {}; + f1(LLSelectedTEMaterialFunctor* material_func) : _material_func(material_func) {} + bool apply(LLViewerObject* object, S32 face) { - if (object->permModify()) + if (object && object->permModify() && _material_func) { - LL_DEBUGS("Materials") << "Putting material on object " << object->getID() << " face " << face << ", material: " << mMaterial->asLLSD() << LL_ENDL; - LLMaterialMgr::getInstance()->put(object->getID(),face,*mMaterial); - object->setTEMaterialParams(face,mMaterial); + LLTextureEntry* tep = object->getTE(face); + if (tep) + { + LLMaterialPtr current_material = tep->getMaterialParams(); + _material_func->apply(object, face, tep, current_material); + } } return true; } - } func1(material); + + LLSelectedTEMaterialFunctor* _material_func; + } func1(material_func); mSelectedObjects->applyToTEs( &func1 ); struct f2 : public LLSelectedObjectFunctor @@ -2531,7 +2537,8 @@ void LLSelectMgr::adjustTexturesByScale(BOOL send_to_sim, BOOL stretch) LLMaterialPtr p = new LLMaterial(orig->asLLSD()); p->setNormalRepeat(normal_scale_s, normal_scale_t); p->setSpecularRepeat(specular_scale_s, specular_scale_t); - selectionSetMaterial( p ); + + LLMaterialMgr::getInstance()->put(object->getID(), te_num, *p); } } else @@ -2553,10 +2560,12 @@ void LLSelectMgr::adjustTexturesByScale(BOOL send_to_sim, BOOL stretch) if (tep && !tep->getMaterialParams().isNull()) { LLMaterialPtr orig = tep->getMaterialParams(); + LLMaterialPtr p = new LLMaterial(orig->asLLSD()); p->setNormalRepeat(normal_scale_s, normal_scale_t); p->setSpecularRepeat(specular_scale_s, specular_scale_t); - selectionSetMaterial( p ); + + LLMaterialMgr::getInstance()->put(object->getID(), te_num, *p); } } send = send_to_sim; diff --git a/indra/newview/llselectmgr.h b/indra/newview/llselectmgr.h index f9b97cebdd..d4b736640c 100755 --- a/indra/newview/llselectmgr.h +++ b/indra/newview/llselectmgr.h @@ -85,6 +85,12 @@ struct LLSelectedTEFunctor virtual bool apply(LLViewerObject* object, S32 face) = 0; }; +struct LLSelectedTEMaterialFunctor +{ + virtual ~LLSelectedTEMaterialFunctor() {}; + virtual LLMaterialPtr apply(LLViewerObject* object, S32 face, LLTextureEntry* tep, LLMaterialPtr& current_material) = 0; +}; + template <typename T> struct LLSelectedTEGetFunctor { virtual ~LLSelectedTEGetFunctor() {}; @@ -549,7 +555,7 @@ public: void selectionSetClickAction(U8 action); void selectionSetIncludeInSearch(bool include_in_search); void selectionSetGlow(const F32 glow); - void selectionSetMaterial(LLMaterialPtr material); + void selectionSetMaterialParams(LLSelectedTEMaterialFunctor* material_func); void selectionRemoveMaterial(); void selectionSetObjectPermissions(U8 perm_field, BOOL set, U32 perm_mask, BOOL override = FALSE); diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index 9e2a0d74db..b9e0847935 100755 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -44,6 +44,18 @@ #if LL_DARWIN #include "OpenGL/OpenGL.h" + +// include spec exp clamp to fix older mac rendering artifacts +// +#define SINGLE_FP_PERMUTATION(shader) \ + if (gGLManager.mIsMobileGF) \ + { \ + shader.addPermutation("SINGLE_FP_ONLY","1"); \ + } + + +#else +#define SINGLE_FP_PERMUTATION(shader) #endif #ifdef LL_RELEASE_FOR_DOWNLOAD @@ -1292,14 +1304,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() bool has_skin = i & 0x10; gDeferredMaterialProgram[i].addPermutation("HAS_SKIN",has_skin ? "1" : "0"); - #if LL_DARWIN - // include spec exp clamp to fix older mac rendering artifacts - // - if (gGLManager.mIsMobileGF) - { - gDeferredMaterialProgram[i].addPermutation("UGLY_MAC_HACK","1"); - } - #endif + SINGLE_FP_PERMUTATION(gDeferredMaterialProgram[i]); if (has_skin) { @@ -1358,6 +1363,9 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; + + SINGLE_FP_PERMUTATION(gDeferredLightProgram); + success = gDeferredLightProgram.createShader(NULL, NULL); } @@ -1368,6 +1376,9 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredMultiLightProgram.mShaderFiles.push_back(make_pair("deferred/multiPointLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredMultiLightProgram.mShaderFiles.push_back(make_pair("deferred/multiPointLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredMultiLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; + + SINGLE_FP_PERMUTATION(gDeferredMultiLightProgram); + success = gDeferredMultiLightProgram.createShader(NULL, NULL); } @@ -1378,6 +1389,9 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/spotLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredSpotLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; + + SINGLE_FP_PERMUTATION(gDeferredSpotLightProgram); + success = gDeferredSpotLightProgram.createShader(NULL, NULL); } @@ -1388,6 +1402,9 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredMultiSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/multiPointLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredMultiSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/multiSpotLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredMultiSpotLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; + + SINGLE_FP_PERMUTATION(gDeferredMultiSpotLightProgram); + success = gDeferredMultiSpotLightProgram.createShader(NULL, NULL); } @@ -1414,6 +1431,9 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredSunProgram.mShaderFiles.push_back(make_pair(vertex, GL_VERTEX_SHADER_ARB)); gDeferredSunProgram.mShaderFiles.push_back(make_pair(fragment, GL_FRAGMENT_SHADER_ARB)); gDeferredSunProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; + + SINGLE_FP_PERMUTATION(gDeferredSunProgram); + success = gDeferredSunProgram.createShader(NULL, NULL); } @@ -1424,6 +1444,9 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredBlurLightProgram.mShaderFiles.push_back(make_pair("deferred/blurLightV.glsl", GL_VERTEX_SHADER_ARB)); gDeferredBlurLightProgram.mShaderFiles.push_back(make_pair("deferred/blurLightF.glsl", GL_FRAGMENT_SHADER_ARB)); gDeferredBlurLightProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; + + SINGLE_FP_PERMUTATION(gDeferredBlurLightProgram); + success = gDeferredBlurLightProgram.createShader(NULL, NULL); } @@ -1454,6 +1477,9 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredAlphaProgram.addPermutation("USE_VERTEX_COLOR", "1"); gDeferredAlphaProgram.addPermutation("HAS_SHADOW", mVertexShaderLevel[SHADER_DEFERRED] > 1 ? "1" : "0"); gDeferredAlphaProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; + + SINGLE_FP_PERMUTATION(gDeferredAlphaProgram); + success = gDeferredAlphaProgram.createShader(NULL, NULL); // Hack @@ -1570,6 +1596,8 @@ BOOL LLViewerShaderMgr::loadShadersDeferred() gDeferredSoftenProgram.mShaderLevel = mVertexShaderLevel[SHADER_DEFERRED]; + SINGLE_FP_PERMUTATION(gDeferredSoftenProgram); + if (gSavedSettings.getBOOL("RenderDeferredSSAO")) { //if using SSAO, take screen space light map into account as if shadows are enabled gDeferredSoftenProgram.mShaderLevel = llmax(gDeferredSoftenProgram.mShaderLevel, 2); |