summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl')
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl135
1 files changed, 74 insertions, 61 deletions
diff --git a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl
index 680fcbfab3..a82581d1a1 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/spotLightF.glsl
@@ -28,6 +28,12 @@
/*[EXTRA_CODE_HERE]*/
+#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
+
#ifdef DEFINE_GL_FRAGCOLOR
out vec4 frag_color;
#else
@@ -42,7 +48,7 @@ uniform sampler2DRect emissiveRect; // PBR linear packed Occlusion, Roughness, M
uniform samplerCube environmentMap;
uniform sampler2DRect lightMap;
uniform sampler2D noiseMap;
-uniform sampler2D projectionMap;
+uniform sampler2D projectionMap; // rgba
uniform sampler2D lightFunc;
uniform mat4 proj_mat; //screen space to light space
@@ -75,40 +81,15 @@ uniform mat4 inv_proj;
vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh );
vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRoughness, float specWeight, float vh, float nl, float nv, float nh );
void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist);
+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 getProjectedLightDiffuseColor(float light_distance, vec2 projected_uv );
+vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n);
vec2 getScreenXY(vec4 clip_point);
void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight );
vec3 srgb_to_linear(vec3 c);
-
-vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod)
-{
- vec4 ret = texture2DLod(projectionMap, tc, lod);
- ret.rgb = srgb_to_linear(ret.rgb);
-
- vec2 dist = vec2(0.5) - abs(tc-vec2(0.5));
- float det = min(lod/(proj_lod*0.5), 1.0);
- float d = min(dist.x, dist.y);
- d *= min(1, d * (proj_lod - lod));
- float edge = 0.25*det;
- ret *= clamp(d/edge, 0.0, 1.0);
-
- return ret;
-}
-
-vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod)
-{
- vec4 ret = texture2DLod(projectionMap, tc, lod);
- ret.rgb = srgb_to_linear(ret.rgb);
-
- vec2 dist = vec2(0.5) - abs(tc-vec2(0.5));
- float det = min(lod/(proj_lod*0.5), 1.0);
- float d = min(dist.x, dist.y);
- float edge = 0.25*det;
- ret *= clamp(d/edge, 0.0, 1.0);
-
- return ret;
-}
+vec4 texture2DLodSpecular(vec2 tc, float lod);
vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod)
{
@@ -133,13 +114,13 @@ void main()
vec2 tc = getScreenXY(vary_fragcoord);
vec3 pos = getPosition(tc).xyz;
- vec3 lv = trans_center.xyz-pos.xyz;
- float dist = length(lv);
- if (dist >= size)
+ vec3 lv;
+ vec4 proj_tc;
+ float dist, l_dist;
+ if (clipProjectedLightVars(trans_center, pos, dist, l_dist, lv, proj_tc))
{
discard;
}
- dist /= size;
float shadow = 1.0;
@@ -155,27 +136,9 @@ void main()
vec3 n;
vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); // need `norm.w` for GET_GBUFFER_FLAG()
- float l_dist = -dot(lv, proj_n);
-
- vec4 proj_tc = (proj_mat * vec4(pos.xyz, 1.0));
- if (proj_tc.z < 0.0)
- {
- discard;
- }
-
- proj_tc.xyz /= proj_tc.w;
-
- float fa = falloff+1.0;
- float dist_atten = min(1.0-(dist-1.0*(1.0-fa))/fa, 1.0);
- dist_atten *= dist_atten;
- dist_atten *= 2.0;
-
- if (dist_atten <= 0.0)
- {
- discard;
- }
+ float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff);
- lv = proj_origin-pos.xyz;
+ lv = proj_origin-pos.xyz; // NOTE: Re-using lv
vec3 h, l, v = -normalize(pos);
float nh, nl, nv, vh, lightDist;
calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist);
@@ -183,6 +146,7 @@ void main()
vec3 diffuse = texture2DRect(diffuseRect, tc).rgb;
vec4 spec = texture2DRect(specularRect, tc);
vec3 dlit = vec3(0, 0, 0);
+ vec3 slit = vec3(0, 0, 0);
if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR))
{
@@ -190,11 +154,65 @@ void main()
vec3 colorSpec = vec3(0);
vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl
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)
+ {
+ 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 );
+
+// vec3 intensity = getLightIntensitySpot( color, size, lightDist, v );
+// colorDiffuse = shadow * dlit * nl;
+// colorSpec = shadow * slit * nl;
+
+// colorDiffuse *= BRDFLambertian ( reflect0, reflect90, c_diff , specWeight, vh );
+// colorSpec *= BRDFSpecularGGX( reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh );
+
+ colorDiffuse = shadow * dlit * nl * dist_atten;
+ colorSpec = shadow * slit * nl * dist_atten;
+
+ #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
+
+ }
+
+ #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
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 &&
@@ -209,12 +227,7 @@ void main()
{
lit = nl * dist_atten * noise;
- float diff = clamp((l_dist-proj_focus)/proj_range, 0.0, 1.0);
- float lod = diff * proj_lod;
-
- vec4 plcol = texture2DLodDiffuse(projectionMap, proj_tc.xy, lod);
-
- dlit = color.rgb * plcol.rgb * plcol.a;
+ dlit = getProjectedLightDiffuseColor( l_dist, proj_tc.xy );
final_color = dlit*lit*diffuse*shadow;
@@ -271,7 +284,7 @@ void main()
stc.x > 0.0 &&
stc.y > 0.0)
{
- final_color += color.rgb * texture2DLodSpecular(projectionMap, stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity;
+ final_color += color.rgb * texture2DLodSpecular(stc.xy, (1 - spec.a) * (proj_lod * 0.6)).rgb * shadow * envIntensity;
}
}
}