summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl')
-rw-r--r--indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl97
1 files changed, 34 insertions, 63 deletions
diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
index 1a7e11a1cd..6dd140bff3 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl
@@ -89,34 +89,21 @@ vec4 applyWaterFogView(vec3 pos, vec4 color);
#endif
// PBR interface
-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);
-void initMaterial( vec3 diffuse, vec3 packedORM,
- out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight );
-// perform PBR image based lighting according to GLTF spec
-// all parameters are in linear space
-void pbrIbl(out vec3 colorDiffuse, // diffuse color output
- out vec3 colorSpec, // specular color output,
+vec3 pbrIbl(vec3 diffuseColor,
+ vec3 specularColor,
vec3 radiance, // radiance map sample
vec3 irradiance, // irradiance map sample
float ao, // ambient occlusion factor
- float nv,
- float perceptualRough, // roughness factor
- float gloss, // 1.0 - roughness factor
- vec3 reflect0,
- vec3 c_diff);
-
-void pbrDirectionalLight(inout vec3 colorDiffuse,
- inout vec3 colorSpec,
- vec3 sunlit,
- float scol,
- vec3 reflect0,
- vec3 reflect90,
- vec3 c_diff,
- float alphaRough,
- float vh,
- float nl,
- float nv,
- float nh);
+ float nv, // normal dot view vector
+ float perceptualRoughness);
+
+vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor,
+ float perceptualRoughness,
+ float metallic,
+ vec3 n, // normal
+ vec3 v, // surface point to camera
+ vec3 l); //surface point to light
+
void main()
{
@@ -160,51 +147,34 @@ void main()
bool hasPBR = GET_GBUFFER_FLAG(GBUFFER_FLAG_HAS_PBR);
if (hasPBR)
{
- // 5.22.2. material.pbrMetallicRoughness.baseColorTexture
- // The first three components (RGB) MUST be encoded with the sRGB transfer function.
- //
- // 5.19.7. material.emissiveTexture
- // This texture contains RGB components encoded with the sRGB transfer function.
- //
- // 5.22.5. material.pbrMetallicRoughness.metallicRoughnessTexture
- // These values MUST be encoded with a linear transfer function.
-
- vec3 colorDiffuse = vec3(0);
- vec3 colorEmissive = spec.rgb; // PBR sRGB Emissive. See: pbropaqueF.glsl
- vec3 colorSpec = vec3(0);
-
- vec3 packedORM = texture2DRect(emissiveRect, tc).rgb; // PBR linear packed Occlusion, Roughness, Metal. See: pbropaqueF.glsl
- float IOR = 1.5; // default Index Of Refraction 1.5 (dielectrics)
- float ao = packedORM.r;
- float metal = packedORM.b;
- vec3 v = -normalize(pos.xyz);
- vec3 n = norm.xyz;
-
- vec3 h, l;
- float nh, nl, nv, vh, lightDist;
- calcHalfVectors(light_dir, n, v, h, l, nh, nl, nv, vh, lightDist);
-
- float perceptualRough = packedORM.g; // NOTE: do NOT clamp here to be consistent with Blender, Blender is wrong and Substance is right
-
- vec3 c_diff, reflect0, reflect90;
- float alphaRough, specWeight;
- initMaterial( diffuse.rgb, packedORM, alphaRough, c_diff, reflect0, reflect90, specWeight );
+ vec3 orm = texture2DRect(emissiveRect, tc).rgb; //orm is packed into "emissiveRect" to keep the data in linear color space
+ float perceptualRoughness = orm.g;
+ float metallic = orm.b;
+ float ao = orm.r * ambocc;
- float gloss = 1.0 - perceptualRough;
+ vec3 colorEmissive = texture2DRect(specularRect, tc).rgb; //specularRect is sRGB sampler, result is in linear space
+
+ // PBR IBL
+ float gloss = 1.0 - perceptualRoughness;
vec3 irradiance = vec3(0);
vec3 radiance = vec3(0);
sampleReflectionProbes(irradiance, radiance, legacyenv, pos.xyz, norm.xyz, gloss, 0.0);
- irradiance = max(amblit,irradiance) * ambocc;
+ irradiance = max(srgb_to_linear(amblit),irradiance) * ambocc*4.0;
- pbrIbl(colorDiffuse, colorSpec, radiance, irradiance, ao, nv, perceptualRough, gloss, reflect0, c_diff);
+ vec3 f0 = vec3(0.04);
+ vec3 baseColor = diffuse.rgb;
- // Add in sun/moon punctual light
- if (nl > 0.0 || nv > 0.0)
- {
- pbrDirectionalLight(colorDiffuse, colorSpec, srgb_to_linear(sunlit), scol, reflect0, reflect90, c_diff, alphaRough, vh, nl, nv, nh);
- }
+ vec3 diffuseColor = baseColor.rgb*(vec3(1.0)-f0);
+ diffuseColor *= 1.0 - metallic;
+
+ vec3 specularColor = mix(f0, baseColor.rgb, metallic);
- color.rgb = colorDiffuse + colorEmissive + colorSpec;
+ vec3 v = -normalize(pos.xyz);
+ float NdotV = clamp(abs(dot(norm.xyz, v)), 0.001, 1.0);
+
+ color.rgb += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness);
+ color.rgb += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm.xyz, v, normalize(light_dir)) * sunlit*8.0 * scol;
+ color.rgb += colorEmissive;
color = linear_to_srgb(color);
color *= atten.r;
@@ -212,6 +182,7 @@ void main()
color = scaleSoftClipFrag(color);
color = srgb_to_linear(color);
+
frag_color.rgb = color.rgb; //output linear since local lights will be added to this shader's results
}
else