diff options
8 files changed, 331 insertions, 146 deletions
| diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index 4df74b762a..ad3a93128d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -25,12 +25,27 @@  uniform sampler2DRect   normalMap;  uniform sampler2DRect   depthMap; +uniform sampler2D projectionMap; // rgba + +// projected lighted params +uniform mat4 proj_mat; //screen space to light space projector +uniform vec3 proj_n; // projector normal +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 + +// light params +uniform vec3 color; // light_color +uniform float size; // light_size  uniform mat4 inv_proj;  uniform vec2 screen_res;  const float M_PI = 3.14159265; +vec3 srgb_to_linear(vec3 cs); +  // In:  //   lv  unnormalized surface to light vector  //   n   normal of the surface @@ -52,6 +67,33 @@ void calcHalfVectors(vec3 lv, vec3 n, vec3 v,      lightDist = length(lv);  } +// In: +//   light_center +//   pos +// Out: +//   dist +//   l_dist +//   lv +//   proj_tc  Projector Textue Coordinates +bool clipProjectedLightVars(vec3 light_center, vec3 pos, out float dist, out float l_dist, out vec3 lv, out vec4 proj_tc ) +{ +    lv = light_center - pos.xyz; +    dist = length(lv); +    bool clipped = (dist >= size); +    if ( !clipped ) +    { +        dist /= size; + +        l_dist = -dot(lv, proj_n); +        vec4 projected_point = (proj_mat * vec4(pos.xyz, 1.0)); +        clipped = (projected_point.z < 0.0); +        projected_point.xyz /= projected_point.w; +        proj_tc = projected_point; +    } + +    return clipped; +} +  vec2 getScreenCoordinate(vec2 screenpos)  {      vec2 sc = screenpos.xy * 2.0; @@ -104,6 +146,80 @@ float getDepth(vec2 pos_screen)      return depth;  } +vec4 getTexture2DLodDiffuse(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; +} + +// Returns projected light in Linear +// Uses: +//  color +// NOTE: projected.a will be pre-multiplied with projected.rgb +vec3 getProjectedLightDiffuseColor(float light_distance, vec2 projected_uv) +{ +    float diff = clamp((light_distance - proj_focus)/proj_range, 0.0, 1.0); +    float lod = diff * proj_lod; +    vec4 plcol = getTexture2DLodDiffuse(projected_uv.xy, lod); + +    return color.rgb * plcol.rgb * plcol.a; +} + +vec4 texture2DLodSpecular(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)); // BUG? extra factor compared to diffuse causes N repeats +    float edge = 0.25*det; +    ret *= clamp(d/edge, 0.0, 1.0); + +    return ret; +} + +// See: clipProjectedLightVars() +vec3 getProjectedLightSpecularColor(vec3 pos, vec3 n ) +{ +    vec3 slit = vec3(0); +    vec3 ref = reflect(normalize(pos), n); + +    //project from point pos in direction ref to plane proj_p, proj_n +    vec3 pdelta = proj_p-pos; +    float l_dist = length(pdelta); +    float ds = dot(ref, proj_n); +    if (ds < 0.0) +    { +        vec3 pfinal = pos + ref * dot(pdelta, proj_n)/ds; +        vec4 stc = (proj_mat * vec4(pfinal.xyz, 1.0)); +        if (stc.z > 0.0) +        { +            stc /= stc.w; +            slit = getProjectedLightDiffuseColor( l_dist, stc.xy ); // NOTE: Using diffuse due to texture2DLodSpecular() has extra: d *= min(1, d * (proj_lod - lod)); +        } +    } +    return slit; // specular light +} + +vec3 getProjectedLightSpecularColor(float light_distance, vec2 projected_uv) +{ +    float diff = clamp((light_distance - proj_focus)/proj_range, 0.0, 1.0); +    float lod = diff * proj_lod; +    vec4 plcol = getTexture2DLodDiffuse(projected_uv.xy, lod); // NOTE: Using diffuse due to texture2DLodSpecular() has extra: d *= min(1, d * (proj_lod - lod)); + +    return color.rgb * plcol.rgb * plcol.a; +} +  vec4 getPosition(vec2 pos_screen)  {      float depth = getDepth(pos_screen); @@ -174,7 +290,7 @@ vec2 getGGX( vec2 brdfPoint )  float getLightAttenuationPointSpot(float range, float distance)  {  #if 1 -    return range; +    return distance;  #else      float range2 = pow(range, 2.0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl index 5072f16988..e6f2c9d02b 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl @@ -25,6 +25,8 @@  /*[EXTRA_CODE_HERE]*/ +#define DEBUG_PBR_LIGHT_TYPE 0 // Output Diffuse=0.75, Emissive=0, ORM=0,0,0 +  #define DEBUG_BASIC         0  #define DEBUG_VERTEX        0  #define DEBUG_NORMAL_MAP    0 // Output packed normal map "as is" to diffuse @@ -120,7 +122,11 @@ void main()      emissive *= texture2D(emissiveMap, vary_texcoord0.xy).rgb;  #endif - +#if DEBUG_PBR_LIGHT_TYPE +    col.rgb  = vec3(0.75); +    emissive = vec3(0); +    spec.rgb = vec3(0); +#endif  #if DEBUG_BASIC      col.rgb = vec3( 1, 0, 1 );  #endif diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl index 513b748f5f..699a9c0276 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiPointLightF.glsl @@ -27,6 +27,8 @@  /*[EXTRA_CODE_HERE]*/ +#define DEBUG_PBR_LIGHT_TYPE      0 +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_color;  #else @@ -95,17 +97,24 @@ void main()          for (int light_idx = 0; light_idx < LIGHT_COUNT; ++light_idx)          {              vec3  lightColor = light_col[ light_idx ].rgb; +            float falloff    = light_col[ light_idx ].a;              float lightSize  = light    [ light_idx ].w;              vec3  lv         =(light    [ light_idx ].xyz - pos);              calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist);              if (nl > 0.0 || nv > 0.0)              { -                vec3 intensity = getLightIntensityPoint(lightColor, lightSize, lightDist); +                float dist = lightDist / lightSize; +                float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff); +                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);              }          } + +  #if DEBUG_PBR_LIGHT_TYPE +        colorDiffuse = vec3(0,0.5,0); colorSpec = vec3(0); +  #endif          final_color = colorDiffuse + colorSpec;      }      else diff --git a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl index b86402b031..20309d9673 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/multiSpotLightF.glsl @@ -28,6 +28,16 @@  /*[EXTRA_CODE_HERE]*/ +#define DEBUG_PBR_LIGHT_TYPE         0 // Ouput gray if PBR multiSpot lights object +#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 +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_color;  #else @@ -42,7 +52,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 @@ -76,48 +86,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);  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 cs); - -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)  { @@ -144,14 +121,13 @@ void main()      vec2 tc          = getScreenXY(vary_fragcoord);      vec3 pos         = getPosition(tc).xyz; -    vec3 lv = center.xyz-pos.xyz; -    float dist = length(lv); - -    if (dist >= size) +    vec3 lv; +    vec4 proj_tc; +    float dist, l_dist; +    if (clipProjectedLightVars(center, pos, dist, l_dist, lv, proj_tc))      {          discard;      } -    dist /= size;      float shadow = 1.0; @@ -167,24 +143,7 @@ void main()      vec3 n;      vec4 norm = getNormalEnvIntensityFlags(tc, n, envIntensity); -    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;      vec3  h, l, v = -normalize(pos); @@ -194,6 +153,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))      { @@ -201,11 +161,68 @@ 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 * dist_atten; +            colorSpec    = shadow * slit * nl * dist_atten; + +//          colorDiffuse *= BRDFLambertian ( reflect0, reflect90, c_diff    , specWeight, vh ); +//          colorSpec    *= 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 + +  #if DEBUG_SPOT_SPEC_POS +            colorDiffuse = pos + ref * dot(pdelta, proj_n)/ds; colorSpec = vec3(0); +  #endif +  #if DEBUG_SPOT_REFLECTION +            colorDiffuse = ref; 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          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 && @@ -220,13 +237,8 @@ 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;                  // unshadowed for consistency between forward and deferred? @@ -244,7 +256,6 @@ void main()              final_color += amb_da*color.rgb*diffuse.rgb*amb_plcol.rgb*amb_plcol.a;          } -          if (spec.a > 0.0)          {              dlit *= min(nl*6.0, 1.0) * dist_atten; @@ -286,11 +297,25 @@ 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;                      }                  }              } +  #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_SPOT_NL +    final_color =vec3(nl); +#endif +#if DEBUG_SPOT_DIFFUSE +    final_color = vec3(nl * dist_atten * noise); +#endif +      }      //not sure why, but this line prevents MATBUG-194 diff --git a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl index 8886abb7d1..defd577266 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/pointLightF.glsl @@ -27,6 +27,8 @@  /*[EXTRA_CODE_HERE]*/ +#define DEBUG_PBR_LIGHT_TYPE         0 +  #ifdef DEFINE_GL_FRAGCOLOR  out vec4 frag_color;  #else @@ -86,6 +88,9 @@ void main()      float nh, nl, nv, vh, lightDist;      calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); +    float dist = lightDist / size; +    float dist_atten = 1.0 - (dist + falloff)/(1.0 + falloff); +      if (GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR))      {          vec3 colorDiffuse  = vec3(0); @@ -99,11 +104,15 @@ void main()          if (nl > 0.0 || nv > 0.0)          { -            vec3 intensity = getLightIntensityPoint(color, size, lightDist); +            vec3 intensity = dist_atten * getLightIntensityPoint(color, size, lightDist);              colorDiffuse += intensity * nl * BRDFLambertian (reflect0, reflect90, c_diff    , specWeight, vh);              colorSpec    += intensity * nl * BRDFSpecularGGX(reflect0, reflect90, alphaRough, specWeight, vh, nl, nv, nh);          } +#if DEBUG_PBR_LIGHT_TYPE +        colorDiffuse = vec3(0,0,0.5); colorSpec = vec3(0); +#endif +          final_color = colorDiffuse + colorSpec;      }      else @@ -120,8 +129,6 @@ void main()              discard;          } -        float fa = falloff+1.0; -        float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0);          dist_atten *= dist_atten;          dist_atten *= 2.0; diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 59076d9760..c2a3e472d0 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -27,6 +27,7 @@  #define PBR_USE_GGX_EMS_HACK       0  #define PBR_USE_IRRADIANCE_HACK    1 +#define DEBUG_PBR_LIGHT_TYPE       0 // Output no global light to make it easier to see pointLight and spotLight  #define DEBUG_PBR_PACKORM0         0 // Rough=0, Metal=0  #define DEBUG_PBR_PACKORM1         0 // Rough=1, Metal=1  #define DEBUG_PBR_TANGENT1         1 // Tangent = 1,0,0 @@ -54,6 +55,8 @@  #define DEBUG_PBR_DOT_NV           0 // Output: grayscale dot(Normal   ,Vertex2Camera)  #define DEBUG_PBR_BRDF_UV          0 // Output: red green BRDF UV         (GGX input)  #define DEBUG_PBR_BRDF_SCALE_BIAS  0 // Output: red green BRDF Scale Bias (GGX output) +#define DEBUG_PBR_BRDF_SCALE_ONLY  0 // Output: grayscale BRDF Scale +#define DEBUG_PBR_BRDF_BIAS_ONLY   0 // Output: grayscale BRDER Bias  #define DEBUG_PBR_FRESNEL          0 // Output: roughness dependent fresnel  #define DEBUG_PBR_KSPEC            0 // Output: K spec  #define DEBUG_PBR_REFLECTION_DIR   0 // Output: reflection dir @@ -66,7 +69,7 @@  #define DEBUG_PBR_IRRADIANCE_RAW   0 // Output: Diffuse Irradiance pre-mix  #define DEBUG_PBR_IRRADIANCE       0 // Output: Diffuse Irradiance  #define DEBUG_PBR_FSS_ESS_LAMBERT  0 // Output: FssEssLambert -#define DEBUG_PBR_EMS              0 // Output: Ems +#define DEBUG_PBR_EMS              0 // Output: Ems = (1 - BRDF Scale + BRDF Bias)  #define DEBUG_PBR_AVG              0 // Output: Avg  #define DEBUG_PBR_FMS_EMS          0 // Output: FmsEms  #define DEBUG_PBR_DIFFUSE_K        0 // Output: diffuse FssEssLambert + FmsEms @@ -178,8 +181,7 @@ void main()      da                = pow(da, light_gamma);      vec4 diffuse     = texture2DRect(diffuseRect, tc); -    vec4 spec        = texture2DRect(specularRect, vary_fragcoord.xy); - +    vec4 spec        = texture2DRect(specularRect, vary_fragcoord.xy); // NOTE: PBR sRGB Emissive  #if defined(HAS_SUN_SHADOW) || defined(HAS_SSAO)      vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; @@ -306,10 +308,7 @@ void main()          // Reference: getIBLRadianceLambertian          vec3  FssEssLambert = specWeight * kSpec * vScaleBias.x + vScaleBias.y; // NOTE: Very similar to FssEssRadiance but with extra specWeight term -        float Ems           = (1.0 - vScaleBias.x + vScaleBias.y); -#if PBR_USE_GGX_EMS_HACK -              Ems           = alphaRough; // With GGX approximation Ems = 0 so use substitute -#endif +        float Ems           = 1.0 - (vScaleBias.x + vScaleBias.y);          vec3  avg           = specWeight * (reflect0 + (1.0 - reflect0) / 21.0);          vec3  AvgEms        = avg * Ems;          vec3  FmsEms        = AvgEms * FssEssLambert / (1.0 - AvgEms); @@ -390,6 +389,12 @@ void main()      #if DEBUG_PBR_DIFFUSE_C          color.rgb = c_diff;      #endif +    #if DEBUG_PBR_BRDF_SCALE_ONLY +        color.rgb = vec3(vScaleBias.x); +    #endif +    #if DEBUG_PBR_BRDF_BIAS_ONLY +        color.rgb = vec3(vScaleBias.y); +    #endif      #if DEBUG_PBR_DIFFUSE_K          color.rgb = kDiffuse;      #endif @@ -478,6 +483,9 @@ void main()      #if DEBUG_PBR_SUN_CONTRIB          color.rgb = sun_contrib;      #endif +    #if DEBUG_PBR_LIGHT_TYPE +        color.rgb = vec3(0); +    #endif          frag_color.rgb = color.rgb; // PBR is done in linear      }  else 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;                      }                  }              } diff --git a/indra/newview/skins/default/xui/en/floater_material_editor.xml b/indra/newview/skins/default/xui/en/floater_material_editor.xml index 7d532ecd7b..74adc86126 100644 --- a/indra/newview/skins/default/xui/en/floater_material_editor.xml +++ b/indra/newview/skins/default/xui/en/floater_material_editor.xml @@ -245,7 +245,7 @@               layout="topleft"               left_delta="0"               top_pad="5" -             max_val="100" +             max_val="1"               name="metalness factor"              width="64"               /> @@ -270,7 +270,8 @@                 layout="topleft"                 left_delta="0"                 top_pad="5" -               max_val="100" +                +               max_val="1"                 name="roughness factor"                width="64"               /> | 
