diff options
Diffstat (limited to 'indra/newview')
6 files changed, 193 insertions, 138 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index ad3a93128d..8ebf09e7da 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -34,6 +34,7 @@ uniform vec3 proj_p; //plane projection is emitting from (in screen space) uniform float proj_focus; // distance from plane to begin blurring uniform float proj_lod ; // (number of mips in proj map) uniform float proj_range; // range between near clip and far clip plane of projection +uniform float proj_ambiance; // light params uniform vec3 color; // light_color @@ -146,6 +147,18 @@ float getDepth(vec2 pos_screen) return depth; } +vec4 getTexture2DLodAmbient(vec2 tc, float lod) +{ + vec4 ret = texture2DLod(projectionMap, tc, lod); + ret.rgb = srgb_to_linear(ret.rgb); + + vec2 dist = tc-vec2(0.5); + float d = dot(dist,dist); + ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); + + return ret; +} + vec4 getTexture2DLodDiffuse(vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); @@ -160,8 +173,24 @@ vec4 getTexture2DLodDiffuse(vec2 tc, float lod) return ret; } -// Returns projected light in Linear +// lit This is set by the caller: if (nl > 0.0) { lit = attenuation * nl * noise; } // Uses: +// color Projected spotlight color +vec3 getProjectedLightAmbiance(float amb_da, float attenuation, float lit, float nl, float noise, vec2 projected_uv) +{ + vec4 amb_plcol = getTexture2DLodAmbient(projected_uv, proj_lod); + vec3 amb_rgb = amb_plcol.rgb * amb_plcol.a; + + amb_da += proj_ambiance; + amb_da += (nl*nl*0.5+0.5) * proj_ambiance; + amb_da *= attenuation * noise; + amb_da = min(amb_da, 1.0-lit); + + return (amb_da * color.rgb * amb_rgb); +} + +// Returns projected light in Linear +// Uses global spotlight color: // color // NOTE: projected.a will be pre-multiplied with projected.rgb vec3 getProjectedLightDiffuseColor(float light_distance, vec2 projected_uv) diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl index e6f2c9d02b..87c1ff5517 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl @@ -31,6 +31,7 @@ #define DEBUG_VERTEX 0 #define DEBUG_NORMAL_MAP 0 // Output packed normal map "as is" to diffuse #define DEBUG_NORMAL_OUT 0 // Output unpacked normal to diffuse +#define DEBUG_ORM 0 // Output Occlusion Roughness Metal "as is" to diffuse #define DEBUG_POSITION 0 uniform sampler2D diffuseMap; //always in sRGB space @@ -139,6 +140,9 @@ void main() #if DEBUG_NORMAL_OUT col.rgb = vary_normal; #endif +#if DEBUG_ORM + col.rgb = linear_to_srgb(spec); +#endif #if DEBUG_POSITION col.rgb = vary_position.xyz; #endif diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index b27b171122..399948459b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -106,6 +106,8 @@ void main() { float dist = lightDist / lightSize; float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff); + dist_atten *= dist_atten; + dist_atten *= 2.0; vec3 intensity = dist_atten * getLightIntensityPoint(lightColor, lightSize, lightDist); colorDiffuse += intensity * nl * BRDFLambertian (reflect0, reflect90, c_diff , specWeight, vh); colorSpec += intensity * nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh); diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index 371c9d88f4..fdbeb34116 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -29,29 +29,36 @@ /*[EXTRA_CODE_HERE]*/ #define DEBUG_PBR_LIGHT_TYPE 0 // Ouput gray if PBR multiSpot lights object +#define DEBUG_PBR_SPOT_ZERO 0 // Output zero for spotlight #define DEBUG_PBR_SPOT 0 #define DEBUG_PBR_SPOT_DIFFUSE 0 // PBR diffuse lit #define DEBUG_PBR_SPOT_SPECULAR 0 // PBR spec lit -#define DEBUG_SPOT_DIFFUSE 0 -#define DEBUG_SPOT_NL 0 // monochome area effected by light -#define DEBUG_SPOT_SPEC_POS 0 -#define DEBUG_SPOT_REFLECTION 0 +#define DEBUG_LIGHT_FRUSTUM 0 // If projected light effects a surface +#define DEBUG_AMBIANCE_COLOR 0 // calculated ambiance color +#define DEBUG_AMBIANCE_AOE 0 // area of effect using inverse ambiance color +#define DEBUG_AMBIANCE_FINAL 0 // light color * ambiance color +#define DEBUG_NOISE 0 // monochrome noise +#define DEBUG_SHADOW 0 // Show inverted shadow +#define DEBUG_SPOT_DIFFUSE 0 // dot(n,l) * dist_atten +#define DEBUG_SPOT_NL 0 // monochome area effected by light +#define DEBUG_SPOT_SPEC_POS 0 +#define DEBUG_SPOT_REFLECTION 0 // color: pos reflected along n #define DEBUG_PBR_LIGHT_H 0 // Half vector #define DEBUG_PBR_LIHGT_L 0 // Light vector -#define DEBUG_PBR_LIGHT_NH 0 // dot(n,h) -#define DEBUG_PBR_LIGHT_NL 0 // doh(n,l) -#define DEBUG_PBR_LIGHT_NV 0 // doh(n,v) -#define DEBUG_PBR_LIGHT_VH 0 // doh(v,h) +#define DEBUG_PBR_LIGHT_NH 0 // colorized dot(n,h) +#define DEBUG_PBR_LIGHT_NL 0 // colorized dot(n,l) +#define DEBUG_PBR_LIGHT_NV 0 // colorized dot(n,v) +#define DEBUG_PBR_LIGHT_VH 0 // colorized dot(v,h) #define DEBUG_PBR_LIGHT_DIFFUSE_COLOR 0 // non PBR spotlight #define DEBUG_PBR_LIGHT_SPECULAR_COLOR 0 // non PBR spotlight #define DEBUG_PBR_LIGHT_INTENSITY 0 // Light intensity #define DEBUG_PBR_LIGHT_INTENSITY_NL 0 // Light intensity * dot(n,l) -#define DEBUG_PBR_LIGHT_BRDF_DIFFUSE 0 +#define DEBUG_PBR_LIGHT_BRDF_DIFFUSE 0 // like "fullbright" if no "nl" factor #define DEBUG_PBR_LIGHT_BRDF_SPECULAR 0 #define DEBUG_PBR_LIGHT_BRDF_FINAL 0 // BRDF Diffuse + BRDF Specular -#define DEBUG_PBR_SHADOW 0 // Show inverted shadow + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; @@ -104,6 +111,7 @@ void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float bool clipProjectedLightVars(vec3 center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc ); vec3 getLightIntensitySpot(vec3 lightColor, float lightRange, float lightDistance, vec3 v); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); +vec3 getProjectedLightAmbiance(float amb_da, float attenuation, float lit, float nl, float noise, vec2 projected_uv); vec3 getProjectedLightDiffuseColor(float light_distance, vec2 projected_uv ); vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n); vec2 getScreenXY(vec4 clip); @@ -118,20 +126,6 @@ vec3 colorized_dot(float x) return vec3( 0, 0, 1 ); } -vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - - vec2 dist = tc-vec2(0.5); - - float d = dot(dist,dist); - - ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); - - return ret; -} - vec4 getPosition(vec2 pos_screen); void main() @@ -166,6 +160,12 @@ void main() vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff); + dist_atten *= dist_atten; + dist_atten *= 2.0; + if (dist_atten <= 0.0) + { + discard; + } lv = proj_origin-pos.xyz; vec3 h, l, v = -normalize(pos); @@ -177,6 +177,8 @@ void main() vec3 dlit = vec3(0, 0, 0); vec3 slit = vec3(0, 0, 0); + vec3 amb_rgb = vec3(0); + if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { vec3 colorDiffuse = vec3(0); @@ -185,47 +187,56 @@ void main() vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl float metal = packedORM.b; -// if (proj_tc.x > 0.0 && proj_tc.x < 1.0 -// && proj_tc.y > 0.0 && proj_tc.y < 1.0) - if (nl > 0.0) + // We need this additional test inside a light's frustum since a spotlight's ambiance can be applied + if (proj_tc.x > 0.0 && proj_tc.x < 1.0 + && proj_tc.y > 0.0 && proj_tc.y < 1.0) { - vec3 c_diff, reflect0, reflect90; - float alphaRough, specWeight; - initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); + float lit = 0.0; + float amb_da = 0.0; - dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); - slit = getProjectedLightSpecularColor( pos, n ); + if (nl > 0.0) + { + amb_da += (nl*0.5 + 0.5) * proj_ambiance; + lit = nl * dist_atten; - colorDiffuse = shadow * dist_atten * nl * (dlit*0.5 + BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh )); - colorSpec = shadow * dist_atten * nl * (slit + BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh )); + vec3 c_diff, reflect0, reflect90; + float alphaRough, specWeight; + initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); - #if DEBUG_PBR_SPOT_DIFFUSE - colorDiffuse = dlit.rgb; colorSpec = vec3(0); - #endif - #if DEBUG_PBR_SPOT_SPECULAR - colorDiffuse = vec3(0); colorSpec = slit.rgb; - #endif - #if DEBUG_PBR_SPOT - colorDiffuse = dlit; colorSpec = vec3(0); - colorDiffuse *= nl; - colorDiffuse *= shadow; - #endif + dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); + slit = getProjectedLightSpecularColor( pos, n ); + + colorDiffuse = shadow * lit * (dlit*0.5 + BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh )); + colorSpec = shadow * lit * (slit + BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh )); + + #if DEBUG_PBR_SPOT_DIFFUSE + colorDiffuse = dlit.rgb; colorSpec = vec3(0); + #endif + #if DEBUG_PBR_SPOT_SPECULAR + colorDiffuse = vec3(0); colorSpec = slit.rgb; + #endif + #if DEBUG_PBR_SPOT + colorDiffuse = dlit; colorSpec = vec3(0); + colorDiffuse *= nl; + colorDiffuse *= shadow; + #endif + } + + amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ); + colorDiffuse += diffuse.rgb * amb_rgb; - #if DEBUG_SPOT_SPEC_POS - colorDiffuse = pos + ref * dot(pdelta, proj_n)/ds; colorSpec = vec3(0); + #if DEBUG_AMBIANCE_FINAL + colorDiffuse = diffuse.rgb * amb_rgb; colorSpec = vec3(0); #endif - #if DEBUG_SPOT_REFLECTION - colorDiffuse = ref; colorSpec = vec3(0); + #if DEBUG_LIGHT_FRUSTUM + colorDiffuse = vec3(0,1,0); colorSpec = vec3(0); + #endif + #if DEBUG_NOISE + float noise = texture2D(noiseMap, tc/128.0).b; + colorDiffuse = vec3(noise); colorSpec = vec3(0); #endif - } - #if DEBUG_SPOT_DIFFUSE - colorDiffuse = vec3(nl * dist_atten); - #endif - #if DEBUG_SPOT_NL - colorDiffuse = vec3(nl); colorSpec = vec3(0); - #endif #if DEBUG_PBR_LIGHT_TYPE colorDiffuse = vec3(0.5); colorSpec = vec3(0); #endif @@ -284,22 +295,11 @@ void main() colorDiffuse = nl * BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh ); colorSpec = nl * BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh ); #endif - #if DEBUG_PBR_SHADOW - colorDiffuse = 1.0 - vec3(shadow); - colorSpec = vec3(0); - #endif final_color = colorDiffuse + colorSpec; } else { - dist_atten *= dist_atten; - dist_atten *= 2.0; - if (dist_atten <= 0.0) - { - discard; - } - float noise = texture2D(noiseMap, tc/128.0).b; if (proj_tc.z > 0.0 && proj_tc.x < 1.0 && @@ -307,7 +307,7 @@ void main() proj_tc.x > 0.0 && proj_tc.y > 0.0) { - float amb_da = proj_ambiance; + float amb_da = 0; float lit = 0.0; if (nl > 0.0) @@ -322,15 +322,8 @@ void main() amb_da += (nl*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; } - //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); - vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - - // use unshadowed for consistency between forward and deferred? - amb_da += (nl*nl*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; - amb_da *= dist_atten * noise; - amb_da = min(amb_da, 1.0-lit); - - final_color += amb_da*color.rgb*diffuse.rgb*amb_plcol.rgb*amb_plcol.a; + amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, noise, proj_tc.xy ); + final_color += diffuse.rgb * amb_rgb; } if (spec.a > 0.0) @@ -378,22 +371,55 @@ void main() } } } - #if DEBUG_SPOT_SPEC_POS - final_color = pos + ref * dot(pdelta, proj_n)/ds; - #endif #if DEBUG_SPOT_REFLECTION final_color = ref; #endif } +#if DEBUG_LIGHT_FRUSTUM + if (proj_tc.x > 0.0 && proj_tc.x < 1.0 + && proj_tc.y > 0.0 && proj_tc.y < 1.0) + { + final_color = vec3(0,0,1); + } +#endif + } + +#if DEBUG_AMBIANCE_AOE + if (proj_tc.x > 0.0 && proj_tc.x < 1.0 + && proj_tc.y > 0.0 && proj_tc.y < 1.0) + { + final_color = 1.0 - amb_rgb; + } +#endif +#if DEBUG_AMBIANCE_COLOR + if (proj_tc.x > 0.0 && proj_tc.x < 1.0 + && proj_tc.y > 0.0 && proj_tc.y < 1.0) + { + final_color = amb_rgb; + } +#endif +#if DEBUG_SHADOW + final_color = 1.0 - vec3(shadow); +#endif +#if DEBUG_SPOT_DIFFUSE + final_color = vec3(nl * dist_atten); +#endif #if DEBUG_SPOT_NL final_color =vec3(nl); #endif -#if DEBUG_SPOT_DIFFUSE - final_color = vec3(nl * dist_atten * noise); +#if DEBUG_SPOT_SPEC_POS + vec3 ref = reflect(normalize(pos), n); + vec3 pdelta = proj_p-pos; + float ds = dot(ref, proj_n); + final_color = pos + ref * dot(pdelta, proj_n)/ds; +#endif +#if DEBUG_SPOT_REFLECTION + final_color = reflect(normalize(pos), n); +#endif +#if DEBUG_SPOT_ZERO + final_color = vec3(0); #endif - - } //not sure why, but this line prevents MATBUG-194 final_color = max(final_color, vec3(0.0)); diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index b4640187c7..42d7407456 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -90,6 +90,8 @@ void main() float dist = lightDist / size; float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff); + dist_atten *= dist_atten; + dist_atten *= 2.0; if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR)) { @@ -129,9 +131,6 @@ void main() discard; } - dist_atten *= dist_atten; - dist_atten *= 2.0; - float noise = texture2D(noiseMap, tc/128.0).b; float lit = nl * dist_atten * noise; diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl index 3b028d9fae..d82baf0804 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl @@ -30,10 +30,11 @@ #define DEBUG_PBR_LIGHT_TYPE 0 #define DEBUG_PBR_SPOT 0 -#define DEBUG_PBR_NL 0 // monochome area effected by light #define DEBUG_PBR_SPOT_DIFFUSE 0 #define DEBUG_PBR_SPOT_SPECULAR 0 +#define DEBUG_SPOT_NL 0 // monochome area effected by light + #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; #else @@ -84,6 +85,7 @@ void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float bool clipProjectedLightVars(vec3 center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc ); vec3 getLightIntensitySpot(vec3 lightColor, float lightRange, float lightDistance, vec3 v); vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity); +vec3 getProjectedLightAmbiance(float amb_da, float attenuation, float lit, float nl, float noise, vec2 projected_uv); vec3 getProjectedLightDiffuseColor(float light_distance, vec2 projected_uv ); vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n); vec2 getScreenXY(vec4 clip_point); @@ -91,18 +93,6 @@ void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 vec3 srgb_to_linear(vec3 c); vec4 texture2DLodSpecular(vec2 tc, float lod); -vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) -{ - vec4 ret = texture2DLod(projectionMap, tc, lod); - ret.rgb = srgb_to_linear(ret.rgb); - - vec2 dist = tc-vec2(0.5); - float d = dot(dist,dist); - ret *= min(clamp((0.25-d)/0.25, 0.0, 1.0), 1.0); - - return ret; -} - vec4 getPosition(vec2 pos_screen); void main() @@ -137,6 +127,12 @@ void main() vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG() float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff); + dist_atten *= dist_atten; + dist_atten *= 2.0; + if (dist_atten <= 0.0) + { + discard; + } lv = proj_origin-pos.xyz; // NOTE: Re-using lv vec3 h, l, v = -normalize(pos); @@ -156,40 +152,46 @@ void main() vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl float metal = packedORM.b; -// if (proj_tc.x > 0.0 && proj_tc.x < 1.0 -// && proj_tc.y > 0.0 && proj_tc.y < 1.0) - if (nl > 0.0) + // We need this additional test inside a light's frustum since a spotlight's ambiance can be applied + if (proj_tc.x > 0.0 && proj_tc.x < 1.0 + && proj_tc.y > 0.0 && proj_tc.y < 1.0) { - vec3 c_diff, reflect0, reflect90; - float alphaRough, specWeight; - initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); + float lit = 0.0; + float amb_da = 0.0; + + if (nl > 0.0) + { + amb_da += (nl*0.5 + 0.5) * proj_ambiance; + lit = nl * dist_atten; + + vec3 c_diff, reflect0, reflect90; + float alphaRough, specWeight; + initMaterial( diffuse, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight ); - dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); - slit = getProjectedLightSpecularColor( pos, n ); + dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy ); + slit = getProjectedLightSpecularColor( pos, n ); - colorDiffuse = shadow * dist_atten * nl * (dlit*0.5 + BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh )); - colorSpec = shadow * dist_atten * nl * (slit + BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh )); + colorDiffuse = shadow * dist_atten * nl * (dlit*0.5 + BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh )); + colorSpec = shadow * dist_atten * nl * (slit + BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh )); #if DEBUG_PBR_SPOT_DIFFUSE - colorDiffuse = dlit.rgb; colorSpec = vec3(0); + colorDiffuse = dlit.rgb; colorSpec = vec3(0); #endif #if DEBUG_PBR_SPOT_SPECULAR - colorDiffuse = vec3(0); colorSpec = slit.rgb; + colorDiffuse = vec3(0); colorSpec = slit.rgb; #endif #if DEBUG_PBR_SPOT - colorDiffuse = dlit; colorSpec = vec3(0); - colorDiffuse *= nl; - colorDiffuse *= shadow; + colorDiffuse = dlit; colorSpec = vec3(0); + colorDiffuse *= nl; + colorDiffuse *= shadow; #endif + } + + vec3 amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, 1.0, proj_tc.xy ); + colorDiffuse += diffuse.rgb * amb_rgb; } - #if DEBUG_SPOT_DIFFUSE - colorDiffuse = vec3(nl * dist_atten); - #endif - #if DEBUG_PBR_NL - colorDiffuse = vec3(nl); colorSpec = vec3(0); - #endif #if DEBUG_PBR_LIGHT_TYPE colorDiffuse = vec3(0.5,0,0); colorSpec = vec3(0.0); #endif @@ -198,14 +200,6 @@ void main() } else { - dist_atten *= dist_atten; - dist_atten *= 2.0; - - if (dist_atten <= 0.0) - { - discard; - } - float noise = texture2D(noiseMap, tc/128.0).b; if (proj_tc.z > 0.0 && proj_tc.x < 1.0 && @@ -227,14 +221,8 @@ void main() amb_da += (nl*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; } - //float diff = clamp((proj_range-proj_focus)/proj_range, 0.0, 1.0); - vec4 amb_plcol = texture2DLodAmbient(projectionMap, proj_tc.xy, proj_lod); - - amb_da += (nl*nl*0.5+0.5) /* * (1.0-shadow) */ * proj_ambiance; - amb_da *= dist_atten * noise; - amb_da = min(amb_da, 1.0-lit); - - final_color += amb_da*color.rgb*diffuse.rgb*amb_plcol.rgb*amb_plcol.a; + vec3 amb_rgb = getProjectedLightAmbiance( amb_da, dist_atten, lit, nl, noise, proj_tc.xy ); + final_color += diffuse.rgb*amb_rgb; } if (spec.a > 0.0) @@ -284,6 +272,13 @@ void main() } } +#if DEBUG_SPOT_DIFFUSE + final_color = vec3(nl * dist_atten); +#endif +#if DEBUG_SPOT_NL + final_color = vec3(nl); +#endif + //not sure why, but this line prevents MATBUG-194 final_color = max(final_color, vec3(0.0)); |