Puppet: the glaze and the bisque's roughness are prefiltered by the pixel's normal spread (geometric specular antialiasing)
The shading normal's screen derivatives give a kernel (Tokuyoshi and Kaplanyan 2021, pixel variance 1/24, clamped at 0.18) that widens the bisque's roughness and the studio the glaze reads: each studio box is averaged over the lobe as a trapezoid that keeps its integral, and is the authored ramp at kernel 0. The unfiltered studio_box is replaced, not kept beside it. lodur:cut_spec:cut-bds-puppet-specaa.r1 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
28a69549db
commit
5a75043d63
2 changed files with 31 additions and 10 deletions
|
|
@ -27,6 +27,12 @@ render_mode cull_back;
|
|||
// it needs no radiance map and draws the same under gl_compatibility, whose clearcoat sees punctual lights only. The bevel's tilted
|
||||
// normal feeds it, so the chamfers glint. Where two facets meet in a concave crease the glaze pools: the albedo goes darker and cooler,
|
||||
// and warmer over a convex bevel. Every number comes from Look.Glaze.
|
||||
//
|
||||
// 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
|
||||
// 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;
|
||||
uniform float bevel_min = 0.0;
|
||||
|
|
@ -89,6 +95,12 @@ void fragment() {
|
|||
n = normalize(mix(n, normalize(vertex_normal), corner));
|
||||
}
|
||||
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.
|
||||
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);
|
||||
// The creases within 6 mm of an edge: concave tints the albedo cooler and darker, convex warmer.
|
||||
float convex = 0.0, concave = 0.0;
|
||||
for (int k = 0; k < 3; k++) {
|
||||
|
|
@ -101,13 +113,14 @@ 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.
|
||||
ROUGHNESS = show_normals ? 1.0 : roughness;
|
||||
// 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)));
|
||||
SPECULAR = show_normals ? 0.0 : specular;
|
||||
BACKLIGHT = show_normals ? vec3(0.0) : backlight;
|
||||
EMISSION = show_normals ? n * 0.5 + 0.5 : vec3(0.0);
|
||||
if (!show_normals && glaze > 0.0) {
|
||||
vec3 r = reflect(-VIEW, n);
|
||||
float f = 0.04 + 0.96 * pow(1.0 - clamp(dot(n, VIEW), 0.0, 1.0), 5.0);
|
||||
EMISSION += glaze * f * studio(r);
|
||||
EMISSION += glaze * f * studio(r, kernel);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// The studio the glaze reflects: a dark room, one large soft box (key), two tall strip lights (rims) and a dim floor. Look owns the
|
||||
// numbers and feeds the same ones to the punctual lights, so the lights and the reflections are one studio. The directions are the
|
||||
// directions the light comes from, in view space (the studio turns with the camera, as a photographer's lights do). Radiances are in the render's linear units and are meant to clip where the glaze catches them.
|
||||
// The studio is prefiltered: it takes the spread of the pixel's normal and returns the average over the directions the pixel reflects, so a highlight does not flicker as the camera moves.
|
||||
uniform vec3 studio_room = vec3(0.0);
|
||||
uniform vec3 studio_key_dir = vec3(0.0, 1.0, 0.0);
|
||||
uniform float studio_key_size = 0.0;
|
||||
|
|
@ -12,23 +13,30 @@ 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.
|
||||
float studio_box(vec3 d, vec3 c, vec2 half_size) {
|
||||
// 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.
|
||||
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));
|
||||
vec3 v = cross(c, u);
|
||||
float f = dot(d, c);
|
||||
if (f <= 0.0) return 0.0;
|
||||
vec2 q = vec2(dot(d, u), dot(d, v)) / f;
|
||||
vec2 e = smoothstep(half_size, half_size * 0.8, abs(q));
|
||||
vec2 q = abs(vec2(dot(d, u), dot(d, v)) / f);
|
||||
float stretch = 1.0 + dot(q, q);
|
||||
vec2 edge = 0.9 * half_size;
|
||||
vec2 w = max(sqrt(0.01 * half_size * half_size + 6.0 * a2 * stretch * stretch), vec2(1e-6));
|
||||
vec2 e = max(min(q + w, edge) - max(q - w, -edge), 0.0) / (2.0 * w);
|
||||
return e.x * e.y;
|
||||
}
|
||||
|
||||
vec3 studio(vec3 d) {
|
||||
vec3 studio(vec3 d, float a2) {
|
||||
vec3 c = studio_room;
|
||||
c += studio_key_radiance * studio_box(d, normalize(studio_key_dir), vec2(studio_key_size, studio_key_size * 0.7)) * vec3(1.0, 0.98, 0.95);
|
||||
c += studio_rim_radiance * studio_box(d, normalize(studio_rim_a), studio_rim_size) * studio_rim_tint;
|
||||
c += studio_rim_radiance * studio_box(d, normalize(studio_rim_b), studio_rim_size) * studio_rim_tint;
|
||||
c += studio_key_radiance * studio_box(d, normalize(studio_key_dir), vec2(studio_key_size, studio_key_size * 0.7), a2) * vec3(1.0, 0.98, 0.95);
|
||||
c += studio_rim_radiance * studio_box(d, normalize(studio_rim_a), studio_rim_size, a2) * studio_rim_tint;
|
||||
c += studio_rim_radiance * studio_box(d, normalize(studio_rim_b), studio_rim_size, a2) * studio_rim_tint;
|
||||
c += studio_floor * smoothstep(0.0, -0.3, d.y) * vec3(1.0);
|
||||
return c;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue