diff --git a/client/puppet.gdshader b/client/puppet.gdshader index 48b3d57..e257bd7 100644 --- a/client/puppet.gdshader +++ b/client/puppet.gdshader @@ -30,8 +30,9 @@ render_mode cull_back; // // The highlights are prefiltered where they are decided (geometric specular antialiasing): the shading normal changes across a pixel // along the bevel's chamfers and at facet edges, so a point sample of the studio in the reflected direction flickers as the camera moves. -// The spread of the normal over the pixel, from its screen derivatives, widens both the bisque's roughness and the studio the glaze reads, -// so each pixel reflects the studio's average over the directions it covers. MSAA (project.godot) antialiases the silhouette and the +// The spread of the normal over the pixel, from its screen derivatives, widens the studio the glaze reads, so each pixel reflects the +// studio's average over the directions it covers. (The bisque's roughness is left as it is: widening it by the same spread changed no pixel +// at any framing, the bisque's specular being dim.) MSAA (project.godot) antialiases the silhouette and the // triangle edges, which this does not touch. uniform vec3 albedo : source_color = vec3(0.9, 0.9, 0.88); uniform float bevel_screen = 0.0; @@ -96,8 +97,9 @@ void fragment() { } NORMAL = n; // The pixel's normal spread as GGX alpha^2 (Tokuyoshi and Kaplanyan 2021, JCGT 10(2) 31-58, Listing 5) with the pixel filter's variance - // 1/24 (the variance of a box one pixel wide is 1/12; this is half of it, which measured no overblur) and the clamp of Kaplanyan et al. - // 2016 (HPG) at 0.18. Derivatives are taken here, after every branch has joined, in uniform control flow. + // 1/24 and the clamp of Kaplanyan et al. 2016 (HPG) at 0.18. 1/24 is half of a box one pixel wide's own variance (1/12) and an eighth of the + // paper's 1/(2 pi); RenderCheck's flicker check holds it from both sides: with 1/24 the highlights stop crawling, and at 1/12 or more they + // are blurred below the supersampled reference's brightness. Derivatives are taken here, after every branch has joined, in uniform control flow. const float PIXEL_VARIANCE = 1.0 / 24.0; const float MAX_SPREAD = 0.18; float kernel = min(2.0 * PIXEL_VARIANCE * (dot(dFdx(n), dFdx(n)) + dot(dFdy(n), dFdy(n))), MAX_SPREAD); @@ -113,8 +115,7 @@ void fragment() { a = mix(a, a * vec3(1.02, 0.99, 0.94), glaze_pool * convex); ALBEDO = show_normals ? vec3(0.0) : a; // RenderCheck's normal view is the emission alone: no light, however shiny the bisque, may add to it. - // Godot's alpha is roughness^2, so the kernel adds to roughness^4. - ROUGHNESS = show_normals ? 1.0 : sqrt(sqrt(min(roughness * roughness * roughness * roughness + kernel, 1.0))); + ROUGHNESS = show_normals ? 1.0 : roughness; SPECULAR = show_normals ? 0.0 : specular; BACKLIGHT = show_normals ? vec3(0.0) : backlight; EMISSION = show_normals ? n * 0.5 + 0.5 : vec3(0.0); diff --git a/client/studio.gdshaderinc b/client/studio.gdshaderinc index 15b6742..1c442d4 100644 --- a/client/studio.gdshaderinc +++ b/client/studio.gdshaderinc @@ -13,11 +13,13 @@ uniform vec3 studio_rim_tint = vec3(1.0); uniform float studio_rim_radiance = 0.0; uniform float studio_floor = 0.0; -// A rectangular emitter seen from the origin along c, w by h on the plane at unit distance, soft at its edge, prefiltered by the pixel's -// normal spread a2 (GGX alpha^2; the shader's kernel). A reflected direction that spreads by variance 2 a2 per axis spreads (1 + |q|^2) -// times wider on the plane at unit distance, so each axis of the box (half width 0.9 h) is averaged over a box kernel of half width w -// (variance w^2 / 3, the lobe's 2 a2 times that stretch squared, plus the authored edge's own (0.1 h)^2). That is a trapezoid, which keeps -// the box's integral at every width, where a wider smoothstep would add energy; at a2 = 0 it is the authored ramp from 0.8 h to h. +// A rectangular emitter seen from the origin along c, w by h on the plane at unit distance, prefiltered by the pixel's normal spread a2 +// (GGX alpha^2; the shader's kernel). A reflected direction that spreads by variance 2 a2 per axis spreads (1 + |q|^2) times wider on the +// plane at unit distance, so each axis of the box (half width 0.9 h) is averaged over a box kernel of half width w (variance w^2 / 3: the +// lobe's 2 a2 times that stretch squared, plus the authored edge's own (0.1 h)^2). The result is a trapezoid: a linear ramp from 0.8 h to h +// at a2 = 0 (the authored edge was a smoothstep over the same span, so the two differ by under a tenth of the box's level), widening as a2 +// grows. The box's integral over the reflected directions is kept to about 6% up to a2 = 0.05; at the 0.18 clamp about a third of it remains, +// where the filter has stopped following the lobe and the highlight dims rather than brightens. float studio_box(vec3 d, vec3 c, vec2 half_size, float a2) { vec3 up = abs(c.y) > 0.9 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0); vec3 u = normalize(cross(up, c));