@tinypoly/gpu-renderer 0.2.1 → 0.2.2
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/frameLayout.d.ts.map +1 -1
- package/dist/frameLayout.js +2 -0
- package/dist/frameLayout.js.map +1 -1
- package/dist/grass.d.ts +106 -0
- package/dist/grass.d.ts.map +1 -0
- package/dist/grass.js +350 -0
- package/dist/grass.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/materialLayout.d.ts +6 -0
- package/dist/materialLayout.d.ts.map +1 -1
- package/dist/materialLayout.js +2 -0
- package/dist/materialLayout.js.map +1 -1
- package/dist/pathTracePass.d.ts +2 -2
- package/dist/pathTracePass.d.ts.map +1 -1
- package/dist/pathTracePass.js +11 -9
- package/dist/pathTracePass.js.map +1 -1
- package/dist/renderer.d.ts.map +1 -1
- package/dist/renderer.js +14 -3
- package/dist/renderer.js.map +1 -1
- package/dist/shaderProgram.d.ts.map +1 -1
- package/dist/shaderProgram.js +10 -1
- package/dist/shaderProgram.js.map +1 -1
- package/dist/subsurface.d.ts +2 -0
- package/dist/subsurface.d.ts.map +1 -1
- package/dist/subsurface.js +3 -2
- package/dist/subsurface.js.map +1 -1
- package/dist/wgsl/bsdf.wgsl.d.ts +1 -1
- package/dist/wgsl/bsdf.wgsl.d.ts.map +1 -1
- package/dist/wgsl/bsdf.wgsl.js +39 -3
- package/dist/wgsl/bsdf.wgsl.js.map +1 -1
- package/dist/wgsl/grass.wgsl.d.ts +14 -0
- package/dist/wgsl/grass.wgsl.d.ts.map +1 -0
- package/dist/wgsl/grass.wgsl.js +456 -0
- package/dist/wgsl/grass.wgsl.js.map +1 -0
- package/dist/wgsl/lights.wgsl.d.ts +1 -1
- package/dist/wgsl/lights.wgsl.d.ts.map +1 -1
- package/dist/wgsl/lights.wgsl.js +5 -0
- package/dist/wgsl/lights.wgsl.js.map +1 -1
- package/dist/wgsl/pathTrace.wgsl.d.ts +1 -1
- package/dist/wgsl/pathTrace.wgsl.d.ts.map +1 -1
- package/dist/wgsl/pathTrace.wgsl.js +34 -5
- package/dist/wgsl/pathTrace.wgsl.js.map +1 -1
- package/dist/wgsl/surface.wgsl.d.ts +1 -1
- package/dist/wgsl/surface.wgsl.d.ts.map +1 -1
- package/dist/wgsl/surface.wgsl.js +2 -0
- package/dist/wgsl/surface.wgsl.js.map +1 -1
- package/package.json +2 -2
- package/src/frameLayout.ts +2 -0
- package/src/grass.ts +523 -0
- package/src/index.ts +2 -0
- package/src/materialLayout.ts +7 -0
- package/src/pathTracePass.ts +11 -9
- package/src/renderer.ts +21 -6
- package/src/shaderProgram.ts +11 -1
- package/src/subsurface.ts +3 -2
- package/src/wgsl/bsdf.wgsl.ts +39 -3
- package/src/wgsl/grass.wgsl.ts +456 -0
- package/src/wgsl/lights.wgsl.ts +5 -0
- package/src/wgsl/pathTrace.wgsl.ts +34 -5
- package/src/wgsl/surface.wgsl.ts +2 -0
package/src/wgsl/lights.wgsl.ts
CHANGED
|
@@ -660,6 +660,11 @@ fn lightTransmittance(position: vec3<f32>, chosen: LightSample, rng: ptr<functio
|
|
|
660
660
|
return vec3<f32>(1.0);
|
|
661
661
|
}
|
|
662
662
|
|
|
663
|
+
// A blade of grass on the way blocks the light.
|
|
664
|
+
if (GRASS && chosen.occlude && traceGrass(position, chosen.direction, chosen.distance).found) {
|
|
665
|
+
return vec3<f32>(0.0);
|
|
666
|
+
}
|
|
667
|
+
|
|
663
668
|
if (chosen.occlude) {
|
|
664
669
|
// Most blockers are plainly opaque, and for those any triangle on the way settles it: the search stops at the
|
|
665
670
|
// first one found instead of looking for the closest. Anything that lets light through goes the long way below.
|
|
@@ -132,7 +132,8 @@ fn emissionWeight(hit: Hit, direction: vec3<f32>, bsdfPdf: f32, lightsOwnDirect:
|
|
|
132
132
|
* volume, a toon ramp read all round, a clearcoat that may face what its base turns from, and transmission.
|
|
133
133
|
*/
|
|
134
134
|
fn treeNormal(surface: Surface) -> vec3<f32> {
|
|
135
|
-
if (surface.kind == KIND_VOLUME || surface.kind == KIND_TOON || surface.clearcoat > 0.0 || surface.transmission > 0.0
|
|
135
|
+
if (surface.kind == KIND_VOLUME || surface.kind == KIND_TOON || surface.clearcoat > 0.0 || surface.transmission > 0.0
|
|
136
|
+
|| (GRASS && any(surface.translucent > vec3<f32>(0.0)))) {
|
|
136
137
|
return vec3<f32>(0.0);
|
|
137
138
|
}
|
|
138
139
|
|
|
@@ -171,7 +172,14 @@ fn directLight(
|
|
|
171
172
|
let toon = surface.kind == KIND_TOON;
|
|
172
173
|
// Three's shadow map leaves a toon mesh's own far side unshadowed; tracing through the mesh would not.
|
|
173
174
|
let skip = select(NO_MATERIAL, surface.material, toon && dot(surface.normal, chosen.direction) < 0.1);
|
|
174
|
-
|
|
175
|
+
var shadowFrom = position;
|
|
176
|
+
|
|
177
|
+
// Light from behind a translucent surface is looked for from its far side, past the surface itself.
|
|
178
|
+
if (GRASS && any(surface.translucent > vec3<f32>(0.0)) && dot(chosen.direction, surface.facing) < 0.0) {
|
|
179
|
+
shadowFrom = position - (surface.normal + surface.facing) * RAY_EPSILON;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
let through = lightTransmittance(shadowFrom, chosen, rng, skip, medium);
|
|
175
183
|
|
|
176
184
|
if (all(through <= vec3<f32>(0.0))) {
|
|
177
185
|
return vec3<f32>(0.0);
|
|
@@ -457,7 +465,20 @@ fn traceRadiance(
|
|
|
457
465
|
}
|
|
458
466
|
|
|
459
467
|
for (var step = 0u; step < MAX_STEPS + MAX_WALK; step = step + 1u) {
|
|
460
|
-
|
|
468
|
+
var hit = traceScene(origin, direction, limit);
|
|
469
|
+
// A blade of grass in front of whatever the ray hit. A walk inside a material never meets one.
|
|
470
|
+
var grass: GrassHit;
|
|
471
|
+
|
|
472
|
+
if (GRASS && !(SUBSURFACE_WALK && inMedium)) {
|
|
473
|
+
grass = traceGrass(origin, direction, hit.distance);
|
|
474
|
+
|
|
475
|
+
if (grass.found) {
|
|
476
|
+
hit.distance = grass.distance;
|
|
477
|
+
hit.triangle = GRASS_TRIANGLE;
|
|
478
|
+
hit.u = 0.0;
|
|
479
|
+
hit.v = 0.0;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
461
482
|
|
|
462
483
|
// A step of the walk inside a material that ends in the medium: the light scatters there, keeping each colour's
|
|
463
484
|
// share of it. It needs three numbers, which a plain hash gives for a fraction of what the sequence costs.
|
|
@@ -570,7 +591,7 @@ fn traceRadiance(
|
|
|
570
591
|
let point = origin + direction * travel;
|
|
571
592
|
var m = 0u;
|
|
572
593
|
|
|
573
|
-
if (!scattering) {
|
|
594
|
+
if (!scattering && !(GRASS && grass.found)) {
|
|
574
595
|
m = materialIndexOf(hit.triangle);
|
|
575
596
|
}
|
|
576
597
|
|
|
@@ -582,6 +603,8 @@ fn traceRadiance(
|
|
|
582
603
|
direction = -surface.normal;
|
|
583
604
|
} else if (VOLUMES && scattering) {
|
|
584
605
|
surface = volumePoint(direction, volumeAlbedo, volumeG);
|
|
606
|
+
} else if (GRASS && grass.found) {
|
|
607
|
+
surface = grassSurface(grass, direction);
|
|
585
608
|
} else {
|
|
586
609
|
|
|
587
610
|
// A volume's boundary is not a surface: the ray goes in or out, and the medium is what it meets.
|
|
@@ -730,7 +753,8 @@ fn traceRadiance(
|
|
|
730
753
|
if (primary) {
|
|
731
754
|
alpha = 1.0;
|
|
732
755
|
|
|
733
|
-
if (!scattering && !
|
|
756
|
+
if (!scattering && !(GRASS && grass.found) && !fogged && afterMaterial == NO_MATERIAL
|
|
757
|
+
&& materials[m].afterProgram != NO_PROGRAM) {
|
|
734
758
|
afterMaterial = m;
|
|
735
759
|
afterTriangle = hit.triangle;
|
|
736
760
|
afterBary = bary;
|
|
@@ -893,6 +917,11 @@ fn traceRadiance(
|
|
|
893
917
|
escapeIntensity = surface.envMapIntensity;
|
|
894
918
|
next = scattered.direction;
|
|
895
919
|
nextOrigin = position;
|
|
920
|
+
|
|
921
|
+
// Through a translucent surface, the path carries on from its far side.
|
|
922
|
+
if (GRASS && dot(next, surface.facing) < 0.0 && any(surface.translucent > vec3<f32>(0.0))) {
|
|
923
|
+
nextOrigin = point - surface.facing * RAY_EPSILON;
|
|
924
|
+
}
|
|
896
925
|
primary = false;
|
|
897
926
|
straight = false;
|
|
898
927
|
bounce = bounce + 1u;
|
package/src/wgsl/surface.wgsl.ts
CHANGED
|
@@ -64,6 +64,8 @@ struct Surface {
|
|
|
64
64
|
material: u32,
|
|
65
65
|
// Share of the diffuse layer that scatters inside the material instead of at its surface.
|
|
66
66
|
subsurface: f32,
|
|
67
|
+
// What a translucent surface lets through to its far side, diffusely: grass blades. Zero for everything else.
|
|
68
|
+
translucent: vec3<f32>,
|
|
67
69
|
};
|
|
68
70
|
|
|
69
71
|
/** Barycentric weights of the two trailing vertices, for a point drawn uniformly over a triangle's area. */
|