reze-engine 0.68.15 → 0.68.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/engine.d.ts +72 -2
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +114 -13
- package/dist/graph/registry.d.ts.map +1 -1
- package/dist/graph/registry.js +4 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/shaders/lights.d.ts +1 -1
- package/dist/shaders/lights.d.ts.map +1 -1
- package/dist/shaders/lights.js +89 -6
- package/dist/shaders/materials/common.d.ts.map +1 -1
- package/dist/shaders/materials/common.js +2 -1
- package/dist/shaders/materials/nodes.d.ts +1 -1
- package/dist/shaders/materials/nodes.d.ts.map +1 -1
- package/dist/shaders/materials/nodes.js +182 -13
- package/dist/shaders/passes/composite.d.ts.map +1 -1
- package/dist/shaders/passes/composite.js +59 -4
- package/package.json +1 -1
- package/src/engine.ts +140 -13
- package/src/graph/registry.ts +4 -1
- package/src/index.ts +2 -0
- package/src/shaders/lights.ts +89 -6
- package/src/shaders/materials/common.ts +2 -1
- package/src/shaders/materials/nodes.ts +182 -13
- package/src/shaders/passes/composite.ts +59 -4
|
@@ -1290,15 +1290,147 @@ fn pmx_sphere_map(base: vec3f, strength: f32, N: vec3f) -> vec3f {
|
|
|
1290
1290
|
// (_rzLampN, not the mapped N) and in the order rzLightsDiffuse sums it, so the
|
|
1291
1291
|
// epilogue's rzLightsDiffuseOnce is that function's exact answer without a
|
|
1292
1292
|
// second pass over the grid. See lights.ts.
|
|
1293
|
-
|
|
1293
|
+
//
|
|
1294
|
+
// Each highlight also comes out as Blender's Principled draws it (.p, and .q
|
|
1295
|
+
// weighted by its rise toward grazing, _rzGrazing), for a closure that asks
|
|
1296
|
+
// for it (urp_lit's fresnel): its reflectance is then f0·p + (1 − f0)·q per
|
|
1297
|
+
// lamp. URP's own
|
|
1298
|
+
// lobe is not that with a Fresnel added — its V·F shortcut,
|
|
1299
|
+
// 1/(max(0.1, L·H²)(4a + 2)), already rises at grazing, and Schlick on top of
|
|
1300
|
+
// it counted the rise twice (a third too bright in a glossy floor's
|
|
1301
|
+
// reflection of a strip).
|
|
1302
|
+
struct _RzLampPair { d: vec3f, s: vec3f, p: vec3f, q: vec3f };
|
|
1303
|
+
var<private> _rzLampPrincipled: vec3f = vec3f(0.0);
|
|
1304
|
+
var<private> _rzLampPrincipledGrazing: vec3f = vec3f(0.0);
|
|
1305
|
+
|
|
1306
|
+
/**
|
|
1307
|
+
* How far a Principled surface's reflectance rises from f0 toward 1 at this
|
|
1308
|
+
* pair of directions: the EXACT Fresnel of a dielectric at Principled's
|
|
1309
|
+
* default IOR 1.5 (f0 0.04), as Cycles evaluates it, put as
|
|
1310
|
+
* (F(L·H) − 0.04)/0.96 so f0 + (1 − f0)·this is that Fresnel. Schlick's
|
|
1311
|
+
* (1 − L·H)⁵ is a sixth low from 45° to 65°, a few percent high past 80°. For a metal (f0 its
|
|
1312
|
+
* colour) it stands in for Cycles' F82 tint, close where (1 − f0) is small.
|
|
1313
|
+
*/
|
|
1314
|
+
fn _rzGrazing(l: vec3f, v: vec3f) -> f32 {
|
|
1315
|
+
let c = clamp(dot(l, normalize(l + v)), 1e-4, 1.0);
|
|
1316
|
+
let g = sqrt(1.25 + c * c); // n² − 1 + c², n = 1.5
|
|
1317
|
+
let a = (g - c) / (g + c);
|
|
1318
|
+
let b = (c * (g + c) - 1.0) / (c * (g - c) + 1.0);
|
|
1319
|
+
let f = 0.5 * a * a * (1.0 + b * b);
|
|
1320
|
+
return saturate((f - 0.04) / 0.96);
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
/**
|
|
1324
|
+
* Cycles' microfacet lobe without its Fresnel: GGX's D and Smith's
|
|
1325
|
+
* height-correlated visibility, α = roughness², times π for this engine's
|
|
1326
|
+
* light units (LIGHT UNITS — URP's lobe carries the same π). Returns
|
|
1327
|
+
* π·D·V; the caller multiplies by N·L (or a tube's irradiance) and the
|
|
1328
|
+
* reflectance.
|
|
1329
|
+
*/
|
|
1330
|
+
fn _rzGgxSmith(N: vec3f, L: vec3f, V: vec3f, roughness: f32) -> f32 {
|
|
1331
|
+
let a = max(roughness * roughness, 6.1035156e-5);
|
|
1332
|
+
let a2 = a * a;
|
|
1333
|
+
let H = normalize(L + V);
|
|
1334
|
+
let NH = saturate(dot(N, H));
|
|
1335
|
+
let NL = saturate(dot(N, L));
|
|
1336
|
+
let NV = max(dot(N, V), 1e-4);
|
|
1337
|
+
let d = NH * NH * (a2 - 1.0) + 1.0;
|
|
1338
|
+
let vis = 0.5 / max(NL * sqrt(NV * NV * (1.0 - a2) + a2) + NV * sqrt(NL * NL * (1.0 - a2) + a2), 1e-5);
|
|
1339
|
+
return a2 / max(d * d, 1e-8) * vis;
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
/** One point of a tube's highlight, per unit of its length: (URP's lobe,
|
|
1343
|
+
* Principled's, Principled's grazing part), each × the strip's cosine there
|
|
1344
|
+
* (1 for a tube glowing every way), the surface's and 1/r². */
|
|
1345
|
+
fn _rzTubeSample(x: vec3f, p: vec3f, n: vec3f, v: vec3f, roughness: f32, facing: f32, aim: vec3f, bulb: f32) -> vec3f {
|
|
1346
|
+
let d = x - p;
|
|
1347
|
+
let rr = max(length(d), 1e-4);
|
|
1348
|
+
let l = d / rr;
|
|
1349
|
+
let ce = select(1.0, max(-dot(aim, l), 0.0), facing > 0.5);
|
|
1350
|
+
let cr = max(dot(n, l), 0.0);
|
|
1351
|
+
if (ce <= 0.0 || cr <= 0.0) { return vec3f(0.0); }
|
|
1352
|
+
let k = ce / max(rr * rr, bulb * bulb);
|
|
1353
|
+
let pp = _rzGgxSmith(n, l, v, roughness) * cr * k;
|
|
1354
|
+
return vec3f(bsdf_urp(n, l, v, cr, roughness) * k, pp, pp * _rzGrazing(l, v));
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
/**
|
|
1358
|
+
* A tube's diffuse and highlight (see _rzTubeIrradiance in lights.ts).
|
|
1359
|
+
*
|
|
1360
|
+
* THE HIGHLIGHT IS INTEGRATED ALONG IT: the lobe at each point of the strip,
|
|
1361
|
+
* with its cosine, the surface's and 1/r², by Gauss-Legendre over three pieces
|
|
1362
|
+
* split around where the reflected ray passes nearest the segment — 4 points
|
|
1363
|
+
* across the lobe's window there, 2 on either side. The window's half-width
|
|
1364
|
+
* is the lobe's own at that distance, 0.85·α·d/sin (the ray's angle to the
|
|
1365
|
+
* tube), plus the bulb. Against the exact integral over a 2 × 0.1 m strip
|
|
1366
|
+
* from twelve views it is within 5% at roughness 0.35 and 7% at 0.6 (a
|
|
1367
|
+
* quarter low at 0.15, where the lobe is narrower than the strip is wide).
|
|
1368
|
+
* Karis's representative point, the lobe's peak times the whole strip's
|
|
1369
|
+
* light, was 0.2 to 2 times it across one floor.
|
|
1370
|
+
*/
|
|
1371
|
+
fn _rzTubeOne(i: u32, p: vec3f, n: vec3f, v: vec3f, roughness: f32, c: vec3f, h: vec3f, reach: f32) -> _RzLampPair {
|
|
1372
|
+
var out = _RzLampPair(vec3f(0.0), vec3f(0.0), vec3f(0.0), vec3f(0.0));
|
|
1373
|
+
let q = _rzTubeNearest(p, c, h);
|
|
1374
|
+
let qd = length(q - p);
|
|
1375
|
+
if (qd >= reach) { return out; }
|
|
1376
|
+
let t = clamp(qd / max(reach, 1e-4), 0.0, 1.0);
|
|
1377
|
+
let t2 = t * t;
|
|
1378
|
+
let window = 1.0 - t2 * t2;
|
|
1379
|
+
let bulb = rzLightNear(i);
|
|
1380
|
+
let aim = rzLightAim(i);
|
|
1381
|
+
let facing = select(0.0, 1.0, dot(aim, aim) > 0.5);
|
|
1382
|
+
let col = rzLightColor(i) * (window * window);
|
|
1383
|
+
out.d = col * _rzTubeIrradiance(p, _rzLampN, c, h, aim, bulb);
|
|
1384
|
+
if (rzLightSpecular(i) <= 0.0 || _rzTubeIrradiance(p, n, c, h, aim, bulb) <= 0.0) { return out; }
|
|
1385
|
+
let r = reflect(-v, n);
|
|
1386
|
+
let L0 = c - h - p;
|
|
1387
|
+
let Ld = 2.0 * h;
|
|
1388
|
+
let lenD = max(length(Ld), 1e-6);
|
|
1389
|
+
let rLd = dot(r, Ld);
|
|
1390
|
+
let s0 = clamp((dot(r, L0) * rLd - dot(L0, Ld)) / max(dot(Ld, Ld) - rLd * rLd, 1e-8), 0.0, 1.0);
|
|
1391
|
+
let dr = length(L0 + Ld * s0);
|
|
1392
|
+
let sinT = sqrt(max(1.0 - (rLd / lenD) * (rLd / lenD), 1e-4));
|
|
1393
|
+
let a = max(roughness * roughness, 6.1035156e-5);
|
|
1394
|
+
let w = min(0.85 * a * dr / (lenD * sinT) + bulb / lenD, 1.0);
|
|
1395
|
+
let lo = max(s0 - w, 0.0);
|
|
1396
|
+
let hi = min(s0 + w, 1.0);
|
|
1397
|
+
let base = c - h;
|
|
1398
|
+
var acc = vec3f(0.0);
|
|
1399
|
+
// the two side pieces, 2 points each (±1/√3, weight 1)
|
|
1400
|
+
let g2 = 0.5773503;
|
|
1401
|
+
if (lo > 1e-6) {
|
|
1402
|
+
let m = lo * 0.5;
|
|
1403
|
+
acc = acc + (_rzTubeSample(base + Ld * (m - m * g2), p, n, v, roughness, facing, aim, bulb)
|
|
1404
|
+
+ _rzTubeSample(base + Ld * (m + m * g2), p, n, v, roughness, facing, aim, bulb)) * m;
|
|
1405
|
+
}
|
|
1406
|
+
if (hi < 1.0 - 1e-6) {
|
|
1407
|
+
let m = (1.0 - hi) * 0.5;
|
|
1408
|
+
let mid = hi + m;
|
|
1409
|
+
acc = acc + (_rzTubeSample(base + Ld * (mid - m * g2), p, n, v, roughness, facing, aim, bulb)
|
|
1410
|
+
+ _rzTubeSample(base + Ld * (mid + m * g2), p, n, v, roughness, facing, aim, bulb)) * m;
|
|
1411
|
+
}
|
|
1412
|
+
// the lobe's window, 4 points
|
|
1413
|
+
let m = (hi - lo) * 0.5;
|
|
1414
|
+
let mid = lo + m;
|
|
1415
|
+
acc = acc + (_rzTubeSample(base + Ld * (mid - m * 0.8611363), p, n, v, roughness, facing, aim, bulb) * 0.3478548
|
|
1416
|
+
+ _rzTubeSample(base + Ld * (mid - m * 0.3399810), p, n, v, roughness, facing, aim, bulb) * 0.6521452
|
|
1417
|
+
+ _rzTubeSample(base + Ld * (mid + m * 0.3399810), p, n, v, roughness, facing, aim, bulb) * 0.6521452
|
|
1418
|
+
+ _rzTubeSample(base + Ld * (mid + m * 0.8611363), p, n, v, roughness, facing, aim, bulb) * 0.3478548) * m;
|
|
1419
|
+
out.s = col * acc.x;
|
|
1420
|
+
out.p = col * acc.y;
|
|
1421
|
+
out.q = col * acc.z;
|
|
1422
|
+
return out;
|
|
1423
|
+
}
|
|
1294
1424
|
|
|
1295
1425
|
fn _rzLampOne(i: u32, p: vec3f, n: vec3f, v: vec3f, roughness: f32) -> _RzLampPair {
|
|
1296
|
-
var out = _RzLampPair(vec3f(0.0), vec3f(0.0));
|
|
1426
|
+
var out = _RzLampPair(vec3f(0.0), vec3f(0.0), vec3f(0.0), vec3f(0.0));
|
|
1297
1427
|
if (!_rzLightReaches(i)) { return out; }
|
|
1298
1428
|
let pr = _rzLightVec(i, 0u);
|
|
1299
1429
|
let d = pr.xyz - p;
|
|
1300
1430
|
let dist = length(d);
|
|
1301
|
-
|
|
1431
|
+
let h = rzLightTube(i);
|
|
1432
|
+
if (dist >= pr.w + length(h)) { return out; }
|
|
1433
|
+
if (dot(h, h) > 0.0) { return _rzTubeOne(i, p, n, v, roughness, pr.xyz, h, pr.w); }
|
|
1302
1434
|
let toLight = d / max(dist, 1e-4);
|
|
1303
1435
|
let ndlD = max(dot(_rzLampN, toLight), 0.0);
|
|
1304
1436
|
let ndl = dot(n, toLight);
|
|
@@ -1312,12 +1444,17 @@ fn _rzLampOne(i: u32, p: vec3f, n: vec3f, v: vec3f, roughness: f32) -> _RzLampPa
|
|
|
1312
1444
|
let aim = clamp((dot(-toLight, rzLightAim(i)) - cone.x) / max(cone.y - cone.x, 1e-4), 0.0, 1.0);
|
|
1313
1445
|
let c = rzLightColor(i) * rzLightCookie(i, toLight);
|
|
1314
1446
|
if (ndlD > 0.0) { out.d = c * (ndlD * falloff * aim * aim); }
|
|
1315
|
-
if (ndl > 0.0) {
|
|
1447
|
+
if (ndl > 0.0) {
|
|
1448
|
+
let k = falloff * aim * aim * rzLightSpecular(i);
|
|
1449
|
+
out.s = c * (bsdf_urp(n, toLight, v, ndl, roughness) * k);
|
|
1450
|
+
out.p = c * (_rzGgxSmith(n, toLight, v, roughness) * ndl * k);
|
|
1451
|
+
out.q = out.p * _rzGrazing(toLight, v);
|
|
1452
|
+
}
|
|
1316
1453
|
return out;
|
|
1317
1454
|
}
|
|
1318
1455
|
|
|
1319
1456
|
fn _rzLampWord(bits0: u32, base: u32, p: vec3f, n: vec3f, v: vec3f, roughness: f32) -> _RzLampPair {
|
|
1320
|
-
var acc = _RzLampPair(vec3f(0.0), vec3f(0.0));
|
|
1457
|
+
var acc = _RzLampPair(vec3f(0.0), vec3f(0.0), vec3f(0.0), vec3f(0.0));
|
|
1321
1458
|
var bits = bits0;
|
|
1322
1459
|
loop {
|
|
1323
1460
|
if (bits == 0u) { break; }
|
|
@@ -1326,6 +1463,8 @@ fn _rzLampWord(bits0: u32, base: u32, p: vec3f, n: vec3f, v: vec3f, roughness: f
|
|
|
1326
1463
|
let one = _rzLampOne(i, p, n, v, roughness);
|
|
1327
1464
|
acc.d = acc.d + one.d;
|
|
1328
1465
|
acc.s = acc.s + one.s;
|
|
1466
|
+
acc.p = acc.p + one.p;
|
|
1467
|
+
acc.q = acc.q + one.q;
|
|
1329
1468
|
}
|
|
1330
1469
|
return acc;
|
|
1331
1470
|
}
|
|
@@ -1333,6 +1472,8 @@ fn _rzLampWord(bits0: u32, base: u32, p: vec3f, n: vec3f, v: vec3f, roughness: f
|
|
|
1333
1472
|
fn rzLampsSpecular(p: vec3f, n: vec3f, v: vec3f, roughness: f32) -> vec3f {
|
|
1334
1473
|
var d = vec3f(0.0);
|
|
1335
1474
|
var s = vec3f(0.0);
|
|
1475
|
+
var pr = vec3f(0.0);
|
|
1476
|
+
var q = vec3f(0.0);
|
|
1336
1477
|
let count = rzLightCount();
|
|
1337
1478
|
let docs = _rzLightDocCount();
|
|
1338
1479
|
if (docs > 0u) {
|
|
@@ -1347,12 +1488,18 @@ fn rzLampsSpecular(p: vec3f, n: vec3f, v: vec3f, roughness: f32) -> vec3f {
|
|
|
1347
1488
|
let w7 = _rzLampWord(m.hi.w, 224u, p, n, v, roughness);
|
|
1348
1489
|
d = d + w0.d + w1.d + w2.d + w3.d + w4.d + w5.d + w6.d + w7.d;
|
|
1349
1490
|
s = s + w0.s + w1.s + w2.s + w3.s + w4.s + w5.s + w6.s + w7.s;
|
|
1491
|
+
pr = pr + w0.p + w1.p + w2.p + w3.p + w4.p + w5.p + w6.p + w7.p;
|
|
1492
|
+
q = q + w0.q + w1.q + w2.q + w3.q + w4.q + w5.q + w6.q + w7.q;
|
|
1350
1493
|
}
|
|
1351
1494
|
for (var i = docs; i < count; i = i + 1u) {
|
|
1352
1495
|
let one = _rzLampOne(i, p, n, v, roughness);
|
|
1353
1496
|
d = d + one.d;
|
|
1354
1497
|
s = s + one.s;
|
|
1498
|
+
pr = pr + one.p;
|
|
1499
|
+
q = q + one.q;
|
|
1355
1500
|
}
|
|
1501
|
+
_rzLampPrincipled = pr;
|
|
1502
|
+
_rzLampPrincipledGrazing = q;
|
|
1356
1503
|
// The first closure's walk speaks for the fragment; a second principled in
|
|
1357
1504
|
// the same graph shares p and the prelude normal, so its answer is the same.
|
|
1358
1505
|
if (!_rzLampDiffuseSet) {
|
|
@@ -1375,10 +1522,14 @@ fn rzLampsSpecular(p: vec3f, n: vec3f, v: vec3f, roughness: f32) -> vec3f {
|
|
|
1375
1522
|
// behind the surface gets neither term, as the game's step(N·L ≥ 0) has it.
|
|
1376
1523
|
|
|
1377
1524
|
fn _rzAddLightOne(i: u32, p: vec3f, n: vec3f, v: vec3f, e: f32) -> _RzLampPair {
|
|
1378
|
-
var out = _RzLampPair(vec3f(0.0), vec3f(0.0));
|
|
1525
|
+
var out = _RzLampPair(vec3f(0.0), vec3f(0.0), vec3f(0.0), vec3f(0.0));
|
|
1379
1526
|
if (!_rzLightReaches(i)) { return out; }
|
|
1380
1527
|
let pr = _rzLightVec(i, 0u);
|
|
1381
|
-
|
|
1528
|
+
// a tube is met at its nearest point here: a graph's Blinn-Phong glint has
|
|
1529
|
+
// no representative-point form
|
|
1530
|
+
let tube = rzLightTube(i);
|
|
1531
|
+
let at = select(pr.xyz, _rzTubeNearest(p, pr.xyz, tube), dot(tube, tube) > 0.0);
|
|
1532
|
+
let d = at - p;
|
|
1382
1533
|
let dist = length(d);
|
|
1383
1534
|
if (dist >= pr.w) { return out; }
|
|
1384
1535
|
let toLight = d / max(dist, 1e-4);
|
|
@@ -1398,7 +1549,7 @@ fn _rzAddLightOne(i: u32, p: vec3f, n: vec3f, v: vec3f, e: f32) -> _RzLampPair {
|
|
|
1398
1549
|
}
|
|
1399
1550
|
|
|
1400
1551
|
fn _rzAddLightWord(bits0: u32, base: u32, p: vec3f, n: vec3f, v: vec3f, e: f32) -> _RzLampPair {
|
|
1401
|
-
var acc = _RzLampPair(vec3f(0.0), vec3f(0.0));
|
|
1552
|
+
var acc = _RzLampPair(vec3f(0.0), vec3f(0.0), vec3f(0.0), vec3f(0.0));
|
|
1402
1553
|
var bits = bits0;
|
|
1403
1554
|
loop {
|
|
1404
1555
|
if (bits == 0u) { break; }
|
|
@@ -1412,7 +1563,7 @@ fn _rzAddLightWord(bits0: u32, base: u32, p: vec3f, n: vec3f, v: vec3f, e: f32)
|
|
|
1412
1563
|
}
|
|
1413
1564
|
|
|
1414
1565
|
fn rz_additional_lights(p: vec3f, n: vec3f, v: vec3f, e: f32) -> _RzLampPair {
|
|
1415
|
-
var acc = _RzLampPair(vec3f(0.0), vec3f(0.0));
|
|
1566
|
+
var acc = _RzLampPair(vec3f(0.0), vec3f(0.0), vec3f(0.0), vec3f(0.0));
|
|
1416
1567
|
let count = rzLightCount();
|
|
1417
1568
|
let docs = _rzLightDocCount();
|
|
1418
1569
|
if (docs > 0u) {
|
|
@@ -1472,7 +1623,8 @@ fn rz_box_project(d: vec3f, p: vec3f, bmin: vec3f, bmax: vec3f, c: vec3f) -> vec
|
|
|
1472
1623
|
/**
|
|
1473
1624
|
* The scene's reflection: the stage's own reflection probe where the engine
|
|
1474
1625
|
* captured one (Engine reflection probe — rendered from the stage's middle,
|
|
1475
|
-
* GGX-prefiltered, box-projected to the stage's bounds
|
|
1626
|
+
* GGX-prefiltered, box-projected to the stage's bounds, or a local probe's own
|
|
1627
|
+
* point and box, outside which the sky stands in), else the world's sky.
|
|
1476
1628
|
*
|
|
1477
1629
|
* ROUGHNESS PICKS THE MIP ON UNITY'S CURVE, r·(1.7 − 0.7r)·6 on a cube of
|
|
1478
1630
|
* seven levels (64² down to 1²) — URP's PerceptualRoughnessToMipmapLevel with
|
|
@@ -1481,6 +1633,9 @@ fn rz_box_project(d: vec3f, p: vec3f, bmin: vec3f, bmax: vec3f, c: vec3f) -> vec
|
|
|
1481
1633
|
fn rzProbeSpecular(dir: vec3f, wp: vec3f, roughness: f32) -> vec3f {
|
|
1482
1634
|
let r = clamp(roughness, 0.0, 1.0);
|
|
1483
1635
|
if (probe.boxMin.w < 0.5) { return rzWorldSpecularLod(dir, r, 1.0); }
|
|
1636
|
+
// A local probe (boxMax.w 1) holds only its box: past it, the sky.
|
|
1637
|
+
let outside = any(wp <= probe.boxMin.xyz) || any(wp >= probe.boxMax.xyz);
|
|
1638
|
+
if (probe.boxMax.w > 0.5 && outside) { return rzWorldSpecularLod(dir, r, 1.0); }
|
|
1484
1639
|
let levels = f32(textureNumLevels(probeCube) - 1u);
|
|
1485
1640
|
let lod = min(r * (1.7 - 0.7 * r) * 6.0, levels);
|
|
1486
1641
|
let d = rz_box_project(normalize(dir), wp, probe.boxMin.xyz, probe.boxMax.xyz, probe.center.xyz);
|
|
@@ -1507,9 +1662,15 @@ fn rzProbeSpecular(dir: vec3f, wp: vec3f, roughness: f32) -> vec3f {
|
|
|
1507
1662
|
* shaded here by THIS surface's albedo and the epilogue adds none; as a layer
|
|
1508
1663
|
* of a larger look it leaves them to the epilogue. The cast's shadow on a
|
|
1509
1664
|
* stage multiplies the lit part.
|
|
1665
|
+
*
|
|
1666
|
+
* fresnel 1 draws the direct highlights as Blender's Principled does: GGX
|
|
1667
|
+
* with Smith's visibility and Fresnel's reflectance (_rzGrazing),
|
|
1668
|
+
* per light — a dark dielectric seen at a grazing angle mirrors a lamp several
|
|
1669
|
+
* times as strongly as head on. 0 (the default, every Unity stage) is URP's
|
|
1670
|
+
* lobe and reflectance, term for term; between them it mixes.
|
|
1510
1671
|
*/
|
|
1511
1672
|
fn urp_lit(base: vec3f, metallic: f32, smoothness: f32, spec: f32, occlusion: f32, emission: vec3f, alpha: f32,
|
|
1512
|
-
N: vec3f, L: vec3f, V: vec3f, sun_rgb: vec3f, amb_rgb: vec3f, shadow: f32, wp: vec3f,
|
|
1673
|
+
fresnel: f32, N: vec3f, L: vec3f, V: vec3f, sun_rgb: vec3f, amb_rgb: vec3f, shadow: f32, wp: vec3f,
|
|
1513
1674
|
surface: bool) -> vec4f {
|
|
1514
1675
|
let m = clamp(metallic, 0.0, 1.0);
|
|
1515
1676
|
let sm = clamp(smoothness, 0.0, 1.0);
|
|
@@ -1530,8 +1691,16 @@ fn urp_lit(base: vec3f, metallic: f32, smoothness: f32, spec: f32, occlusion: f3
|
|
|
1530
1691
|
_rzLampDiffuseTaken = true;
|
|
1531
1692
|
}
|
|
1532
1693
|
let ao = clamp(occlusion, 0.0, 1.0);
|
|
1533
|
-
let
|
|
1534
|
-
|
|
1694
|
+
let urpSpec = specular * (bsdf_urp(N, L, V, NL, r) * sun_rgb * shadow + lampSpec);
|
|
1695
|
+
var directSpec = urpSpec;
|
|
1696
|
+
let fz = clamp(fresnel, 0.0, 1.0);
|
|
1697
|
+
if (fz > 0.0) {
|
|
1698
|
+
let sunP = _rzGgxSmith(N, L, V, r) * NL * sun_rgb * shadow;
|
|
1699
|
+
let principled = specular * (sunP + _rzLampPrincipled)
|
|
1700
|
+
+ (vec3f(1.0) - specular) * (sunP * _rzGrazing(L, V) + _rzLampPrincipledGrazing);
|
|
1701
|
+
directSpec = mix(urpSpec, principled, fz);
|
|
1702
|
+
}
|
|
1703
|
+
let direct = diffuse * (sun_rgb * (NL * shadow) + lampDiff) + directSpec;
|
|
1535
1704
|
let indirect = diffuse * amb_rgb * ao
|
|
1536
1705
|
+ rzProbeSpecular(reflect(-V, N), wp, r) * ao * urp_env_brdf(specular, r, sm, reflectivity, NV);
|
|
1537
1706
|
var lit = direct + indirect;
|
|
@@ -155,7 +155,8 @@ override APPLY_GAMMA: bool = true;
|
|
|
155
155
|
// scene's own LUT (setStageGrade) — see _rzGradeScene() below.
|
|
156
156
|
// viewU[10] = (camera world position, _) — refreshed with the basis above.
|
|
157
157
|
// viewU[11..14] = the cast's positions (effects; count in viewU[10].w).
|
|
158
|
-
// viewU[15] = (soft curve contrast,
|
|
158
|
+
// viewU[15] = (soft curve contrast, pixel filter weights for offsets 0, ±1, ±2)
|
|
159
|
+
// — 1, 0, 0 is no filter; see rzPixelFiltered.
|
|
159
160
|
// invGamma = 1/gamma precomputed on CPU — avoids a per-pixel divide.
|
|
160
161
|
@group(0) @binding(6) var bgEquirect: texture_2d<f32>;
|
|
161
162
|
// The scene pass's own MSAA depth buffer, bound depth-only. NOT an extra
|
|
@@ -211,6 +212,25 @@ fn rzFieldMerge(top: vec4f, bot: vec4f) -> vec4f {
|
|
|
211
212
|
return vec4f(top.rgb + bot.rgb * (1.0 - top.a), top.a + bot.a * (1.0 - top.a));
|
|
212
213
|
}
|
|
213
214
|
|
|
215
|
+
/** The scene's premultiplied HDR light and coverage through the pixel filter
|
|
216
|
+
* (Engine.setPixelFilter): separable weights viewU[15].yzw over offsets 0,
|
|
217
|
+
* ±1, ±2, the coverage filtered alongside so the sky still composites under
|
|
218
|
+
* it. Only called while a filter is on. */
|
|
219
|
+
fn rzPixelFiltered(coord: vec2<i32>) -> vec4f {
|
|
220
|
+
let sz = vec2<i32>(textureDimensions(hdrTex)) - vec2<i32>(1);
|
|
221
|
+
let w = array<f32, 3>(viewU[15].y, viewU[15].z, viewU[15].w);
|
|
222
|
+
let r = select(1, 2, w[2] > 0.0);
|
|
223
|
+
var acc = vec4f(0.0);
|
|
224
|
+
for (var dy = -r; dy <= r; dy++) {
|
|
225
|
+
for (var dx = -r; dx <= r; dx++) {
|
|
226
|
+
let p = clamp(coord + vec2<i32>(dx, dy), vec2<i32>(0), sz);
|
|
227
|
+
let k = w[abs(dx)] * w[abs(dy)];
|
|
228
|
+
acc += vec4f(textureLoad(hdrTex, p, 0).rgb, textureLoad(maskTex, p, 0).g) * k;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return acc;
|
|
232
|
+
}
|
|
233
|
+
|
|
214
234
|
fn linearDepth(coord: vec2<i32>) -> f32 {
|
|
215
235
|
let z = textureLoad(depthTex, coord, 0);
|
|
216
236
|
// projA and projB are m[10] and m[14] of whatever projection the camera built,
|
|
@@ -573,8 +593,14 @@ const COMPOSITE_BODY = /* wgsl */ `
|
|
|
573
593
|
|
|
574
594
|
@fragment fn fs(@builtin(position) fragCoord: vec4f) -> @location(0) vec4f {
|
|
575
595
|
let coord = vec2<i32>(fragCoord.xy);
|
|
576
|
-
|
|
577
|
-
|
|
596
|
+
var hdr = textureLoad(hdrTex, coord, 0);
|
|
597
|
+
var alpha = textureLoad(maskTex, coord, 0).g;
|
|
598
|
+
// A renderer's pixel filter, while one is set (viewU[15].y < 1).
|
|
599
|
+
if (viewU[15].y < 0.99999) {
|
|
600
|
+
let f = rzPixelFiltered(coord);
|
|
601
|
+
hdr = vec4f(f.rgb, hdr.a);
|
|
602
|
+
alpha = f.a;
|
|
603
|
+
}
|
|
578
604
|
let a = max(alpha, 1e-6);
|
|
579
605
|
let straight = hdr.rgb / a;
|
|
580
606
|
let fullSz = vec2f(textureDimensions(hdrTex));
|
|
@@ -639,6 +665,9 @@ const COMPOSITE_BODY = /* wgsl */ `
|
|
|
639
665
|
|
|
640
666
|
let exposed = sceneStraight * exp2(viewU[0].x);
|
|
641
667
|
var disp = max(viewTransform(exposed), vec3f(0.0));
|
|
668
|
+
// The scene as formed before any grade: what the sky's light-first
|
|
669
|
+
// composite below measures itself against.
|
|
670
|
+
var formed = disp;
|
|
642
671
|
// Grade the SCENE only, before the display gamma. Deliberately not applied to
|
|
643
672
|
// the background: it keeps a picked background color exactly as picked, and —
|
|
644
673
|
// load-bearing — leaves green-screen mode's key color unshifted so chroma
|
|
@@ -648,6 +677,7 @@ const COMPOSITE_BODY = /* wgsl */ `
|
|
|
648
677
|
}
|
|
649
678
|
if (APPLY_GAMMA) {
|
|
650
679
|
disp = pow(disp, vec3f(viewU[0].y));
|
|
680
|
+
formed = pow(formed, vec3f(viewU[0].y));
|
|
651
681
|
}
|
|
652
682
|
// ── Film grain, on the SCENE ONLY ─────────────────────────────────────────
|
|
653
683
|
//
|
|
@@ -670,6 +700,11 @@ const COMPOSITE_BODY = /* wgsl */ `
|
|
|
670
700
|
let bg = viewU[2];
|
|
671
701
|
var bgA = select(0.0, 1.0, bg.w > 0.5);
|
|
672
702
|
var bgPm = bg.rgb * bgA; // premultiplied accumulator
|
|
703
|
+
// Mode 3's sky as LIGHT (scene-linear, exposed) and as formed, for the
|
|
704
|
+
// light-first composite after the layers below.
|
|
705
|
+
var skyLin = vec3f(0.0);
|
|
706
|
+
var skyFormed = vec3f(0.0);
|
|
707
|
+
var skyIsLight = false;
|
|
673
708
|
// This pixel's world-space view ray, rebuilt from the camera basis — what the
|
|
674
709
|
// equirect samples by, and what both effect mounts navigate by. The dome sits
|
|
675
710
|
// at infinity (no parallax): PhotoDome-style, display-only. Hoisted out of the
|
|
@@ -690,11 +725,14 @@ const COMPOSITE_BODY = /* wgsl */ `
|
|
|
690
725
|
// like a sun instead of clipping at texture white. bg.x carries the
|
|
691
726
|
// world STRENGTH (the colour slot is dead in equirect modes). The
|
|
692
727
|
// scene's grade stays scene-only, the documented rule above.
|
|
693
|
-
|
|
728
|
+
skyLin = bgPm * bg.x * exp2(viewU[0].x);
|
|
729
|
+
var sky = max(viewTransform(skyLin), vec3f(0.0));
|
|
694
730
|
if (APPLY_GAMMA) {
|
|
695
731
|
sky = pow(sky, vec3f(viewU[0].y));
|
|
696
732
|
}
|
|
697
733
|
bgPm = sky;
|
|
734
|
+
skyFormed = sky;
|
|
735
|
+
skyIsLight = true;
|
|
698
736
|
}
|
|
699
737
|
}
|
|
700
738
|
BACKGROUND_CALL
|
|
@@ -703,6 +741,23 @@ const COMPOSITE_BODY = /* wgsl */ `
|
|
|
703
741
|
// expression, because the foreground mount composites onto it.
|
|
704
742
|
var outRgb = disp * sceneAlpha + bgPm * (1.0 - sceneAlpha);
|
|
705
743
|
var outA = sceneAlpha + bgA * (1.0 - sceneAlpha);
|
|
744
|
+
// OVER A SKY OF LIGHT, LIGHT FIRST. Mode 3's sky is radiance, so where the
|
|
745
|
+
// scene only partly covers it — an antialiased edge, an ember smaller than a
|
|
746
|
+
// pixel, a glow the pixel filter spread — the film sees the two lights
|
|
747
|
+
// summed, as a renderer's camera does: the scene's light plus the sky's
|
|
748
|
+
// through what the scene leaves uncovered, then formed. Formed apart and
|
|
749
|
+
// mixed after, as the display-space composite above does, a thin edge at
|
|
750
|
+
// twenty times white is clipped to white first and then faded by its
|
|
751
|
+
// coverage to a grey dot. The difference is added on top of the layered
|
|
752
|
+
// frame, so the background effects drawn over the sky and the scene's grade
|
|
753
|
+
// stay as they were; with neither it is the summed light exactly.
|
|
754
|
+
if (skyIsLight && sceneAlpha < 0.99999) {
|
|
755
|
+
var summed = max(viewTransform(exposed * sceneAlpha + skyLin * (1.0 - sceneAlpha)), vec3f(0.0));
|
|
756
|
+
if (APPLY_GAMMA) {
|
|
757
|
+
summed = pow(summed, vec3f(viewU[0].y));
|
|
758
|
+
}
|
|
759
|
+
outRgb += summed - (formed * sceneAlpha + skyFormed * (1.0 - sceneAlpha));
|
|
760
|
+
}
|
|
706
761
|
// Ribbons are NOT read here any more: they draw inside the scene pass, so
|
|
707
762
|
// they are already in disp — tone mapped, and bloomed, which they never
|
|
708
763
|
// were while this line existed. Sampling them here as well would draw them
|