rayzee 8.0.0 → 8.2.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.
- package/dist/rayzee.es.js +4413 -4411
- package/dist/rayzee.umd.js +80 -215
- package/package.json +2 -2
- package/src/Passes/OIDNDenoiser.js +196 -270
- package/src/PathTracerApp.js +73 -19
- package/src/Processor/GeometryExtractor.js +3 -1
- package/src/Processor/utils.js +8 -20
- package/src/Stages/Compositor.js +1 -0
- package/src/Stages/PathTracerStage.js +25 -0
- package/src/TSL/SortGlobalKernels.js +3 -4
- package/src/TSL/patches.js +22 -82
- package/src/managers/DenoisingManager.js +276 -58
- package/src/managers/VideoRenderManager.js +4 -0
- package/src/Processor/ToneMapWGSL.js +0 -162
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WGSL tone mapping, a transcription of ToneMapCPU.js.
|
|
3
|
-
*
|
|
4
|
-
* The two must stay identical: the same image is produced on the CPU by `toneMapToRGBA8`
|
|
5
|
-
* (renderToBuffer, upscaler) and on the GPU by this (the OIDN output pack). Order is part of
|
|
6
|
-
* the contract — exposure, saturation, clamp-negative, curve, sRGB OETF — and moving any step
|
|
7
|
-
* shifts every mid-tone.
|
|
8
|
-
*/
|
|
9
|
-
import {
|
|
10
|
-
NoToneMapping, LinearToneMapping, ReinhardToneMapping,
|
|
11
|
-
CineonToneMapping, ACESFilmicToneMapping, AgXToneMapping, NeutralToneMapping
|
|
12
|
-
} from 'three';
|
|
13
|
-
|
|
14
|
-
const SUPPORTED = new Set( [
|
|
15
|
-
NoToneMapping, LinearToneMapping, ReinhardToneMapping,
|
|
16
|
-
CineonToneMapping, ACESFilmicToneMapping, AgXToneMapping, NeutralToneMapping
|
|
17
|
-
] );
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Three.js ToneMapping constant → shader mode. Anything unsupported falls back to ACES,
|
|
21
|
-
* matching `TONE_MAP_FNS.get( x ) || TONE_MAP_FNS.get( ACESFilmicToneMapping )`.
|
|
22
|
-
* @param {number} toneMapping
|
|
23
|
-
* @returns {number}
|
|
24
|
-
*/
|
|
25
|
-
export function toneMapMode( toneMapping ) {
|
|
26
|
-
|
|
27
|
-
return SUPPORTED.has( toneMapping ) ? toneMapping : ACESFilmicToneMapping;
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Prelude defining `toneMapPixel( linear, gain, saturation, mode ) -> vec3f` (sRGB, [0,1]).
|
|
33
|
-
* Concatenate ahead of a kernel that wants it.
|
|
34
|
-
*/
|
|
35
|
-
export const TONE_MAP_WGSL = /* wgsl */`
|
|
36
|
-
fn tmSaturation( c: vec3f, saturation: f32 ) -> vec3f {
|
|
37
|
-
if ( saturation == 1.0 ) { return c; }
|
|
38
|
-
let luma = dot( c, vec3f( 0.2126, 0.7152, 0.0722 ) );
|
|
39
|
-
return vec3f( luma ) + ( c - vec3f( luma ) ) * saturation;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
fn tmSrgb1( c: f32 ) -> f32 {
|
|
43
|
-
if ( c <= 0.0031308 ) { return 12.92 * c; }
|
|
44
|
-
return 1.055 * pow( c, 1.0 / 2.4 ) - 0.055;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
fn tmSrgb( c: vec3f ) -> vec3f {
|
|
48
|
-
return vec3f( tmSrgb1( c.r ), tmSrgb1( c.g ), tmSrgb1( c.b ) );
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
fn tmReinhard( c: vec3f ) -> vec3f {
|
|
52
|
-
return clamp( c / ( c + vec3f( 1.0 ) ), vec3f( 0.0 ), vec3f( 1.0 ) );
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
fn tmCineon1( x: f32 ) -> f32 {
|
|
56
|
-
let c = max( x - 0.004, 0.0 );
|
|
57
|
-
return pow( ( c * ( 6.2 * c + 0.5 ) ) / ( c * ( 6.2 * c + 1.7 ) + 0.06 ), 2.2 );
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
fn tmCineon( c: vec3f ) -> vec3f {
|
|
61
|
-
return vec3f( tmCineon1( c.r ), tmCineon1( c.g ), tmCineon1( c.b ) );
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
fn tmAcesFit( c: f32 ) -> f32 {
|
|
65
|
-
return ( c * ( c + 0.0245786 ) - 0.000090537 ) / ( c * ( 0.983729 * c + 0.4329510 ) + 0.238081 );
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
fn tmAces( cIn: vec3f ) -> vec3f {
|
|
69
|
-
let c = cIn / 0.6;
|
|
70
|
-
var i = vec3f(
|
|
71
|
-
0.59719 * c.r + 0.35458 * c.g + 0.04823 * c.b,
|
|
72
|
-
0.07600 * c.r + 0.90834 * c.g + 0.01566 * c.b,
|
|
73
|
-
0.02840 * c.r + 0.13383 * c.g + 0.83777 * c.b
|
|
74
|
-
);
|
|
75
|
-
i = vec3f( tmAcesFit( i.r ), tmAcesFit( i.g ), tmAcesFit( i.b ) );
|
|
76
|
-
let o = vec3f(
|
|
77
|
-
1.60475 * i.r - 0.53108 * i.g - 0.07367 * i.b,
|
|
78
|
-
-0.10208 * i.r + 1.10813 * i.g - 0.00605 * i.b,
|
|
79
|
-
-0.00327 * i.r - 0.07276 * i.g + 1.07602 * i.b
|
|
80
|
-
);
|
|
81
|
-
return clamp( o, vec3f( 0.0 ), vec3f( 1.0 ) );
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
fn tmAgxApprox( x: f32 ) -> f32 {
|
|
85
|
-
let x2 = x * x;
|
|
86
|
-
let x4 = x2 * x2;
|
|
87
|
-
return 15.5 * x4 * x2 - 40.14 * x4 * x + 31.96 * x4 - 6.868 * x2 * x + 0.4298 * x2 + 0.1191 * x - 0.00232;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
fn tmAgx( r: vec3f ) -> vec3f {
|
|
91
|
-
let c = vec3f(
|
|
92
|
-
0.6274 * r.r + 0.3293 * r.g + 0.0433 * r.b,
|
|
93
|
-
0.0691 * r.r + 0.9195 * r.g + 0.0113 * r.b,
|
|
94
|
-
0.0164 * r.r + 0.0880 * r.g + 0.8956 * r.b
|
|
95
|
-
);
|
|
96
|
-
var a = vec3f(
|
|
97
|
-
0.856627153315983 * c.r + 0.0951212405381588 * c.g + 0.0482516061458583 * c.b,
|
|
98
|
-
0.137318972929847 * c.r + 0.761241990602591 * c.g + 0.101439036467562 * c.b,
|
|
99
|
-
0.11189821299995 * c.r + 0.0767994186031903 * c.g + 0.811302368396859 * c.b
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
let agxMinEv = -12.47393;
|
|
103
|
-
let agxMaxEv = 4.026069;
|
|
104
|
-
let range = agxMaxEv - agxMinEv;
|
|
105
|
-
a = clamp( ( log2( max( a, vec3f( 1e-10 ) ) ) - vec3f( agxMinEv ) ) / range, vec3f( 0.0 ), vec3f( 1.0 ) );
|
|
106
|
-
a = vec3f( tmAgxApprox( a.r ), tmAgxApprox( a.g ), tmAgxApprox( a.b ) );
|
|
107
|
-
|
|
108
|
-
var o = vec3f(
|
|
109
|
-
1.1271005818144368 * a.r - 0.11060664309660323 * a.g - 0.016493938717834573 * a.b,
|
|
110
|
-
-0.1413297634984383 * a.r + 1.157823702216272 * a.g - 0.016493938717834257 * a.b,
|
|
111
|
-
-0.14132976349843826 * a.r - 0.11060664309660294 * a.g + 1.2519364065950405 * a.b
|
|
112
|
-
);
|
|
113
|
-
o = pow( max( o, vec3f( 0.0 ) ), vec3f( 2.2 ) );
|
|
114
|
-
|
|
115
|
-
return clamp( vec3f(
|
|
116
|
-
1.6605 * o.r - 0.5876 * o.g - 0.0728 * o.b,
|
|
117
|
-
-0.1246 * o.r + 1.1329 * o.g - 0.0083 * o.b,
|
|
118
|
-
-0.0182 * o.r - 0.1006 * o.g + 1.1187 * o.b
|
|
119
|
-
), vec3f( 0.0 ), vec3f( 1.0 ) );
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
fn tmNeutral( cIn: vec3f ) -> vec3f {
|
|
123
|
-
let startCompression = 0.8 - 0.04;
|
|
124
|
-
let desaturation = 0.15;
|
|
125
|
-
|
|
126
|
-
let x = min( cIn.r, min( cIn.g, cIn.b ) );
|
|
127
|
-
var offset = 0.04;
|
|
128
|
-
if ( x < 0.08 ) { offset = x - 6.25 * x * x; }
|
|
129
|
-
|
|
130
|
-
var c = cIn - vec3f( offset );
|
|
131
|
-
let peak = max( c.r, max( c.g, c.b ) );
|
|
132
|
-
if ( peak < startCompression ) { return c; }
|
|
133
|
-
|
|
134
|
-
let d = 1.0 - startCompression;
|
|
135
|
-
let newPeak = 1.0 - d * d / ( peak + d - startCompression );
|
|
136
|
-
c = c * ( newPeak / peak );
|
|
137
|
-
let gFactor = 1.0 - 1.0 / ( desaturation * ( peak - newPeak ) + 1.0 );
|
|
138
|
-
|
|
139
|
-
return c + ( vec3f( newPeak ) - c ) * gFactor;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
fn tmCurve( cIn: vec3f, mode: u32 ) -> vec3f {
|
|
143
|
-
// Three.js clamps the fragment output before tone mapping ("force unsigned floats"), and
|
|
144
|
-
// AgX/Neutral mix negatives across channels rather than clipping them.
|
|
145
|
-
let c = max( cIn, vec3f( 0.0 ) );
|
|
146
|
-
switch mode {
|
|
147
|
-
case 0u, 1u: { return clamp( c, vec3f( 0.0 ), vec3f( 1.0 ) ); }
|
|
148
|
-
case 2u: { return tmReinhard( c ); }
|
|
149
|
-
case 3u: { return tmCineon( c ); }
|
|
150
|
-
case 6u: { return tmAgx( c ); }
|
|
151
|
-
case 7u: { return tmNeutral( c ); }
|
|
152
|
-
default: { return tmAces( c ); }
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
fn toneMapPixel( linear: vec3f, gain: f32, saturation: f32, mode: u32 ) -> vec3f {
|
|
157
|
-
var c = linear * gain;
|
|
158
|
-
c = tmSaturation( c, saturation );
|
|
159
|
-
c = tmCurve( c, mode );
|
|
160
|
-
return tmSrgb( c );
|
|
161
|
-
}
|
|
162
|
-
`;
|