rayzee 6.5.0 → 7.0.0

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.
Files changed (51) hide show
  1. package/README.md +24 -5
  2. package/dist/rayzee.es.js +7554 -7014
  3. package/dist/rayzee.es.js.map +1 -1
  4. package/dist/rayzee.umd.js +157 -236
  5. package/dist/rayzee.umd.js.map +1 -1
  6. package/package.json +1 -1
  7. package/src/EngineDefaults.js +12 -9
  8. package/src/PathTracerApp.js +118 -26
  9. package/src/Pipeline/PipelineContext.js +1 -2
  10. package/src/Pipeline/RenderPipeline.js +1 -1
  11. package/src/Pipeline/RenderStage.js +1 -1
  12. package/src/Processor/CameraOptimizer.js +0 -5
  13. package/src/Processor/GeometryExtractor.js +6 -0
  14. package/src/Processor/KernelManager.js +277 -0
  15. package/src/Processor/PackedRayBuffer.js +265 -0
  16. package/src/Processor/QueueManager.js +173 -0
  17. package/src/Processor/SceneProcessor.js +1 -0
  18. package/src/Processor/ShaderBuilder.js +11 -317
  19. package/src/Processor/StorageTexturePool.js +29 -15
  20. package/src/Processor/VRAMTracker.js +169 -0
  21. package/src/Processor/utils.js +11 -110
  22. package/src/RenderSettings.js +0 -3
  23. package/src/Stages/ASVGF.js +76 -20
  24. package/src/Stages/BilateralFilter.js +34 -10
  25. package/src/Stages/EdgeFilter.js +2 -3
  26. package/src/Stages/MotionVector.js +16 -9
  27. package/src/Stages/NormalDepth.js +17 -5
  28. package/src/Stages/PathTracer.js +671 -1456
  29. package/src/Stages/PathTracerStage.js +1451 -0
  30. package/src/Stages/SSRC.js +32 -15
  31. package/src/Stages/Variance.js +35 -12
  32. package/src/TSL/CompactKernel.js +110 -0
  33. package/src/TSL/DebugKernel.js +98 -0
  34. package/src/TSL/Environment.js +13 -11
  35. package/src/TSL/ExtendKernel.js +75 -0
  36. package/src/TSL/FinalWriteKernel.js +121 -0
  37. package/src/TSL/GenerateKernel.js +109 -0
  38. package/src/TSL/LightsSampling.js +2 -2
  39. package/src/TSL/PathTracerCore.js +43 -1039
  40. package/src/TSL/ShadeKernel.js +873 -0
  41. package/src/TSL/patches.js +81 -4
  42. package/src/index.js +3 -0
  43. package/src/managers/CameraManager.js +1 -1
  44. package/src/managers/DenoisingManager.js +40 -75
  45. package/src/managers/EnvironmentManager.js +30 -39
  46. package/src/managers/OverlayManager.js +7 -22
  47. package/src/managers/UniformManager.js +0 -3
  48. package/src/managers/helpers/TileHelper.js +2 -2
  49. package/src/Stages/AdaptiveSampling.js +0 -483
  50. package/src/TSL/PathTracer.js +0 -384
  51. package/src/managers/TileManager.js +0 -298
@@ -0,0 +1,109 @@
1
+ /**
2
+ * GenerateKernel.js — wavefront primary ray generation (16×16, 2D screen-space dispatch).
3
+ */
4
+
5
+ import {
6
+ Fn, float, vec2, vec3, vec4, int, uint,
7
+ If, select,
8
+ localId, workgroupId,
9
+ } from 'three/tsl';
10
+
11
+ import {
12
+ getDecorrelatedSeed,
13
+ pcgHash,
14
+ getStratifiedSample,
15
+ } from './Random.js';
16
+
17
+ import { generateRayFromCamera } from './BVHTraversal.js';
18
+ import { Ray } from './Struct.js';
19
+ import { RAY_FLAG } from '../Processor/QueueManager.js';
20
+ import {
21
+ writeRayOriginMeta, writeRayDirFlags, writeRayThroughputPdf,
22
+ writeRayRadiance, writeGBuffer,
23
+ writeMediumStack,
24
+ } from '../Processor/PackedRayBuffer.js';
25
+
26
+ const WG_SIZE = 16;
27
+
28
+ export function buildGenerateKernel( params ) {
29
+
30
+ const {
31
+ rayBufferRW, rngBufferRW, gBufferRW,
32
+ resolution, frame,
33
+ cameraWorldMatrix, cameraProjectionMatrixInverse,
34
+ enableDOF, focalLength, aperture, focusDistance, sceneScale, apertureScale, anamorphicRatio,
35
+ renderWidth, renderHeight,
36
+ // Multi-sample: S primary rays/pixel/frame; S>1 dispatch covers h*S rows, ray lands in slot subSample*(w*h) + pixelIndex.
37
+ samplesPerPass = 1,
38
+ transmissiveBounces, // per-ray refraction budget (megakernel parity: PathTracerCore.js:606)
39
+ transparentBackground, // alpha inits to 1 here (megakernel parity: PathTracerCore.js:554) — env-escape-without-opaque zeroes it in Shade
40
+ } = params;
41
+
42
+ const S = samplesPerPass | 0;
43
+
44
+ const computeFn = Fn( () => {
45
+
46
+ const gx = int( workgroupId.x ).mul( WG_SIZE ).add( int( localId.x ) );
47
+ const gyRaw = int( workgroupId.y ).mul( WG_SIZE ).add( int( localId.y ) );
48
+
49
+ const subSample = S > 1 ? gyRaw.div( renderHeight ).toVar() : int( 0 );
50
+ const gy = S > 1 ? gyRaw.sub( subSample.mul( renderHeight ) ).toVar() : gyRaw;
51
+ const yBound = S > 1 ? renderHeight.mul( int( S ) ) : renderHeight;
52
+
53
+ If( gx.lessThan( renderWidth ).and( gyRaw.lessThan( yBound ) ), () => {
54
+
55
+ const pixelCoord = vec2( float( gx ).add( 0.5 ), float( gy ).add( 0.5 ) );
56
+ const pixelIndex = gy.mul( int( resolution.x ) ).add( gx );
57
+ // maxRaysPerSample = w*h, derived from the resolution uniform (NOT baked) so resize never changes the WGSL.
58
+ const rayID = S > 1
59
+ ? uint( pixelIndex ).add( uint( subSample ).mul( uint( resolution.x ).mul( uint( resolution.y ) ) ) )
60
+ : uint( pixelIndex );
61
+
62
+ const screenPosition = pixelCoord.div( resolution ).mul( 2.0 ).sub( 1.0 ).toVar();
63
+ screenPosition.y.assign( screenPosition.y.negate() );
64
+
65
+ const baseSeed = getDecorrelatedSeed( { pixelCoord, rayIndex: subSample, frame } ).toVar();
66
+ const seed = pcgHash( { state: baseSeed } ).toVar();
67
+
68
+ const stratifiedJitter = getStratifiedSample( pixelCoord, subSample, int( S ), seed, resolution, frame ).toVar();
69
+
70
+ const jitterScale = vec2( 2.0 ).div( resolution );
71
+ const jitter = stratifiedJitter.sub( 0.5 ).mul( jitterScale );
72
+ const jitteredScreenPosition = screenPosition.add( jitter );
73
+
74
+ const ray = Ray.wrap( generateRayFromCamera(
75
+ jitteredScreenPosition, seed,
76
+ cameraWorldMatrix, cameraProjectionMatrixInverse,
77
+ enableDOF, focalLength, aperture, focusDistance, sceneScale, apertureScale, anamorphicRatio,
78
+ ) );
79
+
80
+ writeRayOriginMeta( rayBufferRW, rayID, ray.origin, int( 0 ), int( 0 ) );
81
+ writeRayDirFlags( rayBufferRW, rayID, ray.direction, uint( RAY_FLAG.ACTIVE ) );
82
+ // pdf inits to 0 = prevBouncePdf (megakernel parity PathTracerCore.js:556). The bounce>0 env/emissive
83
+ // MIS gate skips until an opaque scatter writes a real combinedPdf; free bounces preserve it.
84
+ writeRayThroughputPdf( rayBufferRW, rayID, vec4( 1.0, 1.0, 1.0, 0.0 ).xyz, float( 0.0 ) );
85
+ // Alpha inits to 1 in transparent-bg mode (megakernel parity: PathTracerCore.js:554). Shade zeroes
86
+ // it only on env-escape-without-opaque; a ray that dies inside geometry (e.g. SSS walk termination)
87
+ // keeps alpha 1 → solid. Non-transparent mode is inert (FinalWrite forces alpha 1).
88
+ writeRayRadiance( rayBufferRW, rayID, vec4( vec3( 0.0 ), select( transparentBackground, float( 1.0 ), float( 0.0 ) ) ) );
89
+
90
+ If( subSample.equal( int( 0 ) ), () => {
91
+
92
+ // default: normal +Z, depth 1 (far), black albedo (background/miss)
93
+ writeGBuffer( gBufferRW, uint( pixelIndex ), vec3( 0.0, 0.0, 1.0 ), float( 1.0 ), vec3( 0.0 ) );
94
+
95
+ } );
96
+
97
+ writeMediumStack( rayBufferRW, rayID, uint( 0 ), uint( transmissiveBounces ), float( 1.0 ), float( 1.0 ), float( 1.0 ) );
98
+
99
+ rngBufferRW.element( rayID ).assign( seed );
100
+
101
+ } );
102
+
103
+ } );
104
+
105
+ return computeFn;
106
+
107
+ }
108
+
109
+ export { WG_SIZE as GENERATE_WG_SIZE };
@@ -704,7 +704,7 @@ export const calculateDirectLightingUnified = Fn( ( [
704
704
  materialBuffer,
705
705
  // Environment resources
706
706
  envTexture, environmentIntensity, envMatrix,
707
- envCDFBuffer,
707
+ envCDFTexture,
708
708
  envTotalSum, envCompensationDelta, envResolution,
709
709
  enableEnvironmentLight,
710
710
  ] ) => {
@@ -969,7 +969,7 @@ export const calculateDirectLightingUnified = Fn( ( [
969
969
 
970
970
  // Sample direction + PDF + color from importance-sampled environment
971
971
  const envSampleResult = sampleEquirectProbability(
972
- envTexture, envCDFBuffer,
972
+ envTexture, envCDFTexture,
973
973
  envMatrix, environmentIntensity, envTotalSum, envCompensationDelta, envResolution, envRandom, envColor
974
974
  ).toVar();
975
975