summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class1
diff options
context:
space:
mode:
authorBrad Payne (Vir Linden) <vir@lindenlab.com>2022-09-01 15:12:14 +0100
committerBrad Payne (Vir Linden) <vir@lindenlab.com>2022-09-01 15:12:14 +0100
commit3c3442cbbc38beff1ab82ffcc7f81390c7979361 (patch)
treeb2e60cc8818e372706a2c3463ca2a2f255066b79 /indra/newview/app_settings/shaders/class1
parent2c692f635da67990f842f20adf3b42d870d42fdf (diff)
parentce685a12b9acc888a39c336c91ae6272db74ce91 (diff)
Merge branch 'DRTVWR-559' of https://bitbucket.org/lindenlab/viewer into DRTVWR-559
Diffstat (limited to 'indra/newview/app_settings/shaders/class1')
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl116
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/materialV.glsl2
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl15
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl7
4 files changed, 122 insertions, 18 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..68a57d12f0 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
@@ -43,9 +44,21 @@ uniform mat4 inv_proj;
uniform vec2 screen_res;
const float M_PI = 3.14159265;
+const float ONE_OVER_PI = 0.3183098861;
vec3 srgb_to_linear(vec3 cs);
+float calcLegacyDistanceAttenuation(float distance, float falloff)
+{
+ float dist_atten = 1.0 - clamp((distance + falloff)/(1.0 + falloff), 0.0, 1.0);
+ dist_atten *= dist_atten;
+
+ // Tweak falloff slightly to match pre-EEP attenuation
+ // NOTE: this magic number also shows up in a great many other places, search for dist_atten *= to audit
+ dist_atten *= 2.0;
+ return dist_atten;
+}
+
// In:
// lv unnormalized surface to light vector
// n normal of the surface
@@ -146,6 +159,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 +185,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)
@@ -251,8 +292,41 @@ vec2 getScreenXY(vec4 clip)
return screen;
}
+// Color utils
+
+vec3 colorize_dot(float x)
+{
+ if (x > 0.0) return vec3( 0, x, 0 );
+ if (x < 0.0) return vec3(-x, 0, 0 );
+ return vec3( 0, 0, 1 );
+}
+
+vec3 hue_to_rgb(float hue)
+{
+ if (hue > 1.0) return vec3(0.5);
+ vec3 rgb = abs(hue * 6. - vec3(3, 2, 4)) * vec3(1, -1, -1) + vec3(-1, 2, 2);
+ return clamp(rgb, 0.0, 1.0);
+}
+
// PBR Utils
+// ior Index of Refraction, normally 1.5
+// returns reflect0
+float calcF0(float ior)
+{
+ float f0 = (1.0 - ior) / (1.0 + ior);
+ return f0 * f0;
+}
+
+vec3 fresnel(float vh, vec3 f0, vec3 f90 )
+{
+ float x = 1.0 - abs(vh);
+ float x2 = x*x;
+ float x5 = x2*x2*x;
+ vec3 fr = f0 + (f90 - f0)*x5;
+ return fr;
+}
+
vec3 fresnelSchlick( vec3 reflect0, vec3 reflect90, float vh)
{
return reflect0 + (reflect90 - reflect0) * pow(clamp(1.0 - vh, 0.0, 1.0), 5.0);
@@ -330,42 +404,68 @@ float D_GGX( float nh, float alphaRough )
}
// NOTE: This is different from the GGX texture
+// See:
+// Real Time Rendering, 4th Edition
+// Page 341
+// Equation 9.43
+// Also see:
+// https://google.github.io/filament/Filament.md.html#materialsystem/specularbrdf/geometricshadowing(specularg)
+// 4.4.2 Geometric Shadowing (specular G)
float V_GGX( float nl, float nv, float alphaRough )
{
+#if 1
+ // Note: When roughness is zero, has discontuinity in the bottom hemisphere
float rough2 = alphaRough * alphaRough;
float ggxv = nl * sqrt(nv * nv * (1.0 - rough2) + rough2);
float ggxl = nv * sqrt(nl * nl * (1.0 - rough2) + rough2);
+
float ggx = ggxv + ggxl;
if (ggx > 0.0)
{
return 0.5 / ggx;
}
return 0.0;
+#else
+ // See: smithVisibility_GGXCorrelated, V_SmithCorrelated, etc.
+ float rough2 = alphaRough * alphaRough;
+ float ggxv = nl * sqrt(nv * (nv - rough2 * nv) + rough2);
+ float ggxl = nv * sqrt(nl * (nl - rough2 * nl) + rough2);
+ return 0.5 / (ggxv + ggxl);
+#endif
+
}
+// NOTE: Assumes a hard-coded IOR = 1.5
void initMaterial( vec3 diffuse, vec3 packedORM, out float alphaRough, out vec3 c_diff, out vec3 reflect0, out vec3 reflect90, out float specWeight )
{
float metal = packedORM.b;
- c_diff = mix(diffuse.rgb, vec3(0), metal);
+ c_diff = mix(diffuse, vec3(0), metal);
float IOR = 1.5; // default Index Of Refraction 1.5 (dielectrics)
reflect0 = vec3(0.04); // -> incidence reflectance 0.04
- reflect0 = mix( reflect0, diffuse.rgb, metal); // reflect at 0 degrees
+// reflect0 = vec3(calcF0(IOR));
+ reflect0 = mix(reflect0, diffuse, metal); // reflect at 0 degrees
reflect90 = vec3(1); // reflect at 90 degrees
specWeight = 1.0;
- float perceptualRough = packedORM.g;
+ // When roughness is zero blender shows a tiny specular
+ float perceptualRough = max(packedORM.g, 0.1);
alphaRough = perceptualRough * perceptualRough;
}
+vec3 BRDFDiffuse(vec3 color)
+{
+ return color * ONE_OVER_PI;
+}
+
vec3 BRDFLambertian( vec3 reflect0, vec3 reflect90, vec3 c_diff, float specWeight, float vh )
{
- return (1.0 - specWeight * fresnelSchlick( reflect0, reflect90, vh)) * (c_diff / M_PI);
+ return (1.0 - specWeight * fresnelSchlick( reflect0, reflect90, vh)) * BRDFDiffuse(c_diff);
}
vec3 BRDFSpecularGGX( vec3 reflect0, vec3 reflect90, float alphaRough, float specWeight, float vh, float nl, float nv, float nh )
{
- vec3 fresnel = fresnelSchlick( reflect0, reflect90, vh );
- float vis = V_GGX( nl, nv, alphaRough );
- float d = D_GGX( nh, alphaRough );
+ vec3 fresnel = fresnelSchlick( reflect0, reflect90, vh ); // Fresnel
+ float vis = V_GGX( nl, nv, alphaRough ); // Visibility
+ float d = D_GGX( nh, alphaRough ); // Distribution
return specWeight * fresnel * vis * d;
}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl
index 7e29ada205..a1cab87092 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl
@@ -1,5 +1,5 @@
/**
- * @file bumpV.glsl
+ * @file materialV.glsl
*
* $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl
index e6f2c9d02b..b5c38bba04 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
@@ -103,15 +104,16 @@ void main()
tnorm = normalize(tnorm.xyz);
norm.xyz = normalize(tnorm.xyz);
+
// RGB = Occlusion, Roughness, Metal
- // default values
- // occlusion ?
- // roughness 1.0
- // metal 1.0
+ // default values, see LLViewerTexture::sDefaultPBRORMImagep
+ // occlusion 1.0
+ // roughness 0.0
+ // metal 0.0
#ifdef HAS_SPECULAR_MAP
vec3 spec = texture2D(specularMap, vary_texcoord2.xy).rgb;
#else
- vec3 spec = vec3(1,1,1);
+ vec3 spec = vec3(1,0,0);
#endif
spec.g *= roughnessFactor;
@@ -139,6 +141,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/class1/deferred/pbropaqueV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl
index 82338069a8..a2606ed771 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl
@@ -78,24 +78,23 @@ VARYING vec2 vary_texcoord0;
void main()
{
- vec4 pos4 = vec4(position,1.0);
#ifdef HAS_SKIN
mat4 mat = getObjectSkinnedTransform();
mat = modelview_matrix * mat;
- vec3 pos = (mat*pos4).xyz;
+ vec3 pos = (mat*vec4(position.xyz,1.0)).xyz;
#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
vary_position = pos;
#endif
- gl_Position = projection_matrix*pos4;
+ gl_Position = projection_matrix*vec4(pos,1.0);
#else
//transform vertex
+ gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
- gl_Position = modelview_projection_matrix * pos4;
#endif
vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;