three-gpu-pathtracer 0.0.14 → 0.0.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/LICENSE +21 -21
- package/README.md +1004 -981
- package/build/index.module.js +7413 -6902
- package/build/index.module.js.map +1 -1
- package/build/index.umd.cjs +7446 -6933
- package/build/index.umd.cjs.map +1 -1
- package/package.json +73 -73
- package/src/core/DynamicPathTracingSceneGenerator.js +119 -119
- package/src/core/MaterialReducer.js +256 -256
- package/src/core/PathTracingRenderer.js +346 -346
- package/src/core/PathTracingSceneGenerator.js +69 -69
- package/src/core/QuiltPathTracingRenderer.js +223 -223
- package/src/detectors/CompatibilityDetector.js +38 -0
- package/src/detectors/MaterialCompileDetector.js +50 -0
- package/src/detectors/PrecisionDetector.js +85 -0
- package/src/detectors/PrecisionMaterial.js +160 -0
- package/src/index.js +40 -36
- package/src/materials/MaterialBase.js +56 -56
- package/src/materials/debug/GraphMaterial.js +243 -243
- package/src/materials/fullscreen/AlphaDisplayMaterial.js +50 -48
- package/src/materials/fullscreen/BlendMaterial.js +67 -67
- package/src/materials/fullscreen/DenoiseMaterial.js +142 -142
- package/src/materials/fullscreen/GradientMapMaterial.js +82 -0
- package/src/materials/pathtracing/LambertPathTracingMaterial.js +296 -296
- package/src/materials/pathtracing/PhysicalPathTracingMaterial.js +118 -196
- package/src/materials/pathtracing/glsl/attenuateHit.glsl.js +177 -179
- package/src/materials/pathtracing/glsl/cameraUtils.glsl.js +84 -81
- package/src/materials/pathtracing/glsl/directLightContribution.glsl.js +93 -0
- package/src/materials/pathtracing/glsl/getSurfaceRecord.glsl.js +323 -317
- package/src/materials/pathtracing/glsl/renderStructs.glsl.js +50 -0
- package/src/materials/pathtracing/glsl/traceScene.glsl.js +52 -54
- package/src/materials/surface/AmbientOcclusionMaterial.js +207 -207
- package/src/materials/surface/FogVolumeMaterial.js +23 -23
- package/src/objects/EquirectCamera.js +13 -13
- package/src/objects/PhysicalCamera.js +42 -28
- package/src/objects/PhysicalSpotLight.js +25 -14
- package/src/objects/ShapedAreaLight.js +22 -12
- package/src/shader/bsdf/bsdfSampling.glsl.js +499 -490
- package/src/shader/bsdf/fog.glsl.js +22 -23
- package/src/shader/bsdf/ggx.glsl.js +102 -102
- package/src/shader/bsdf/iridescence.glsl.js +135 -135
- package/src/shader/bsdf/sheen.glsl.js +98 -98
- package/src/shader/common/arraySamplerTexelFetch.glsl.js +25 -25
- package/src/shader/common/bvhAnyHit.glsl.js +76 -76
- package/src/shader/common/fresnel.glsl.js +98 -98
- package/src/shader/common/intersectShapes.glsl.js +62 -62
- package/src/shader/common/math.glsl.js +81 -81
- package/src/shader/common/utils.glsl.js +116 -116
- package/src/shader/rand/pcg.glsl.js +57 -57
- package/src/shader/rand/sobol.glsl.js +256 -256
- package/src/shader/sampling/equirectSampling.glsl.js +62 -62
- package/src/shader/sampling/lightSampling.glsl.js +223 -223
- package/src/shader/sampling/shapeSampling.glsl.js +86 -86
- package/src/shader/structs/cameraStruct.glsl.js +13 -13
- package/src/shader/structs/equirectStruct.glsl.js +13 -14
- package/src/shader/structs/fogMaterialBvh.glsl.js +62 -62
- package/src/shader/structs/lightsStruct.glsl.js +78 -78
- package/src/shader/structs/materialStruct.glsl.js +207 -207
- package/src/textures/GradientEquirectTexture.js +35 -35
- package/src/textures/ProceduralEquirectTexture.js +75 -75
- package/src/uniforms/AttributesTextureArray.js +35 -35
- package/src/uniforms/EquirectHdrInfoUniform.js +269 -277
- package/src/uniforms/FloatAttributeTextureArray.js +169 -169
- package/src/uniforms/IESProfilesTexture.js +100 -100
- package/src/uniforms/LightsInfoUniformStruct.js +212 -212
- package/src/uniforms/MaterialsTexture.js +503 -503
- package/src/uniforms/PhysicalCameraUniform.js +36 -36
- package/src/uniforms/RenderTarget2DArray.js +97 -97
- package/src/uniforms/utils.js +30 -30
- package/src/utils/BlurredEnvMapGenerator.js +116 -116
- package/src/utils/GeometryPreparationUtils.js +214 -214
- package/src/utils/IESLoader.js +325 -325
- package/src/utils/SobolNumberMapGenerator.js +80 -80
- package/src/utils/UVUnwrapper.js +101 -101
- package/src/utils/macroify.js +9 -9
- package/src/workers/PathTracingSceneWorker.js +42 -42
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { WebGLRenderTarget } from 'three';
|
|
2
|
+
import { FullScreenQuad } from 'three/examples/jsm/postprocessing/Pass.js';
|
|
3
|
+
import { PrecisionMaterial } from './PrecisionMaterial.js';
|
|
4
|
+
|
|
5
|
+
// see https://github.com/gkjohnson/webgl-precision
|
|
6
|
+
// Returns whether the platform can use highp precision consistently in structs
|
|
7
|
+
export class PrecisionDetector {
|
|
8
|
+
|
|
9
|
+
constructor( renderer ) {
|
|
10
|
+
|
|
11
|
+
this._renderer = renderer;
|
|
12
|
+
this._result = null;
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
detect() {
|
|
17
|
+
|
|
18
|
+
if ( this._result ) {
|
|
19
|
+
|
|
20
|
+
return this._result;
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const renderer = this._renderer;
|
|
25
|
+
const material = new PrecisionMaterial();
|
|
26
|
+
const quad = new FullScreenQuad( material );
|
|
27
|
+
const target = new WebGLRenderTarget( 1, 1 );
|
|
28
|
+
const ogTarget = renderer.getRenderTarget();
|
|
29
|
+
|
|
30
|
+
const detail = {
|
|
31
|
+
'int': extractResult( 'int' ),
|
|
32
|
+
'uint': extractResult( 'uint' ),
|
|
33
|
+
'float': extractResult( 'float' ),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const message = doesPass( 'int', detail.int ) || doesPass( 'uint', detail.uint ) || doesPass( 'float', detail.float );
|
|
37
|
+
this._result = {
|
|
38
|
+
detail,
|
|
39
|
+
message,
|
|
40
|
+
pass: ! Boolean( message ),
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
renderer.setRenderTarget( ogTarget );
|
|
44
|
+
quad.dispose();
|
|
45
|
+
target.dispose();
|
|
46
|
+
material.dispose();
|
|
47
|
+
return this._result;
|
|
48
|
+
|
|
49
|
+
function doesPass( type, info ) {
|
|
50
|
+
|
|
51
|
+
if ( info.vertex === info.vertexStruct && info.fragment === info.fragmentStruct ) {
|
|
52
|
+
|
|
53
|
+
return '';
|
|
54
|
+
|
|
55
|
+
} else {
|
|
56
|
+
|
|
57
|
+
return `Type "${ type }" cannot correctly provide highp precision in structs.`;
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function extractResult( mode ) {
|
|
64
|
+
|
|
65
|
+
material.mode = mode;
|
|
66
|
+
renderer.setRenderTarget( target );
|
|
67
|
+
quad.render( renderer );
|
|
68
|
+
|
|
69
|
+
const readBuffer = new Uint8Array( 4 );
|
|
70
|
+
renderer.readRenderTargetPixels( target, 0, 0, 1, 1, readBuffer );
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
|
|
74
|
+
vertex: readBuffer[ 0 ],
|
|
75
|
+
vertexStruct: readBuffer[ 1 ],
|
|
76
|
+
fragment: readBuffer[ 2 ],
|
|
77
|
+
fragmentStruct: readBuffer[ 3 ],
|
|
78
|
+
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { MaterialBase } from '../materials/MaterialBase.js';
|
|
2
|
+
|
|
3
|
+
const computePrecisionFunction = /* glsl */`
|
|
4
|
+
precision highp float;
|
|
5
|
+
precision highp int;
|
|
6
|
+
struct FloatStruct {
|
|
7
|
+
highp float value;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
struct IntStruct {
|
|
11
|
+
highp int value;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
struct UintStruct {
|
|
15
|
+
highp uint value;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
vec2 computePrecision() {
|
|
19
|
+
|
|
20
|
+
#if MODE == 0 // float
|
|
21
|
+
|
|
22
|
+
float exponent = 0.0;
|
|
23
|
+
float value = 1.5;
|
|
24
|
+
while ( value > 1.0 ) {
|
|
25
|
+
|
|
26
|
+
exponent ++;
|
|
27
|
+
value = 1.0 + pow( 2.0, - exponent ) / 2.0;
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
float structExponent = 0.0;
|
|
32
|
+
FloatStruct str;
|
|
33
|
+
str.value = 1.5;
|
|
34
|
+
while ( str.value > 1.0 ) {
|
|
35
|
+
|
|
36
|
+
structExponent ++;
|
|
37
|
+
str.value = 1.0 + pow( 2.0, - structExponent ) / 2.0;
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return vec2( exponent, structExponent );
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
#elif MODE == 1 // int
|
|
45
|
+
|
|
46
|
+
int bits = 0;
|
|
47
|
+
int value = 1;
|
|
48
|
+
while ( value > 0 ) {
|
|
49
|
+
|
|
50
|
+
value = value << 1;
|
|
51
|
+
value = value | 1;
|
|
52
|
+
bits ++;
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
int structBits = 0;
|
|
57
|
+
IntStruct str;
|
|
58
|
+
str.value = 1;
|
|
59
|
+
while ( str.value > 0 ) {
|
|
60
|
+
|
|
61
|
+
str.value = str.value << 1;
|
|
62
|
+
str.value = str.value | 1;
|
|
63
|
+
structBits ++;
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return vec2( bits, structBits );
|
|
68
|
+
|
|
69
|
+
#else // uint
|
|
70
|
+
|
|
71
|
+
int bits = 0;
|
|
72
|
+
uint value = 1u;
|
|
73
|
+
while ( value > 0u ) {
|
|
74
|
+
|
|
75
|
+
value = value << 1u;
|
|
76
|
+
bits ++;
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
int structBits = 0;
|
|
81
|
+
UintStruct str;
|
|
82
|
+
str.value = 1u;
|
|
83
|
+
while( str.value > 0u ) {
|
|
84
|
+
|
|
85
|
+
str.value = str.value << 1u;
|
|
86
|
+
structBits ++;
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return vec2( bits, structBits );
|
|
91
|
+
|
|
92
|
+
#endif
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
`;
|
|
98
|
+
|
|
99
|
+
export class PrecisionMaterial extends MaterialBase {
|
|
100
|
+
|
|
101
|
+
set mode( v ) {
|
|
102
|
+
|
|
103
|
+
this._mode = v;
|
|
104
|
+
|
|
105
|
+
switch ( v.toLowerCase() ) {
|
|
106
|
+
|
|
107
|
+
case 'float':
|
|
108
|
+
this.setDefine( 'MODE', 0 );
|
|
109
|
+
break;
|
|
110
|
+
case 'int':
|
|
111
|
+
this.setDefine( 'MODE', 1 );
|
|
112
|
+
break;
|
|
113
|
+
case 'uint':
|
|
114
|
+
this.setDefine( 'MODE', 2 );
|
|
115
|
+
break;
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
constructor() {
|
|
122
|
+
|
|
123
|
+
super( {
|
|
124
|
+
|
|
125
|
+
vertexShader: /* glsl */`
|
|
126
|
+
|
|
127
|
+
${ computePrecisionFunction }
|
|
128
|
+
|
|
129
|
+
varying vec2 vPrecision;
|
|
130
|
+
void main() {
|
|
131
|
+
|
|
132
|
+
vec4 mvPosition = vec4( position, 1.0 );
|
|
133
|
+
mvPosition = modelViewMatrix * mvPosition;
|
|
134
|
+
gl_Position = projectionMatrix * mvPosition;
|
|
135
|
+
|
|
136
|
+
vPrecision = computePrecision();
|
|
137
|
+
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
`,
|
|
141
|
+
|
|
142
|
+
fragmentShader: /* glsl */`
|
|
143
|
+
|
|
144
|
+
${ computePrecisionFunction }
|
|
145
|
+
|
|
146
|
+
varying vec2 vPrecision;
|
|
147
|
+
void main( void ) {
|
|
148
|
+
|
|
149
|
+
vec2 fPrecision = computePrecision();
|
|
150
|
+
gl_FragColor = vec4( vPrecision, fPrecision ) / 255.0;
|
|
151
|
+
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
`,
|
|
155
|
+
|
|
156
|
+
} );
|
|
157
|
+
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,36 +1,40 @@
|
|
|
1
|
-
// core
|
|
2
|
-
export * from './core/PathTracingRenderer.js';
|
|
3
|
-
export * from './core/QuiltPathTracingRenderer.js';
|
|
4
|
-
export * from './core/PathTracingSceneGenerator.js';
|
|
5
|
-
export * from './core/DynamicPathTracingSceneGenerator.js';
|
|
6
|
-
export * from './core/MaterialReducer.js';
|
|
7
|
-
|
|
8
|
-
// objects
|
|
9
|
-
export * from './objects/PhysicalCamera.js';
|
|
10
|
-
export * from './objects/EquirectCamera.js';
|
|
11
|
-
export * from './objects/PhysicalSpotLight.js';
|
|
12
|
-
export * from './objects/ShapedAreaLight.js';
|
|
13
|
-
|
|
14
|
-
// textures
|
|
15
|
-
export * from './textures/ProceduralEquirectTexture.js';
|
|
16
|
-
export * from './textures/GradientEquirectTexture.js';
|
|
17
|
-
|
|
18
|
-
// uniforms
|
|
19
|
-
export * from './uniforms/MaterialsTexture.js';
|
|
20
|
-
export * from './uniforms/RenderTarget2DArray.js';
|
|
21
|
-
export * from './uniforms/EquirectHdrInfoUniform.js';
|
|
22
|
-
export * from './uniforms/PhysicalCameraUniform.js';
|
|
23
|
-
export * from './uniforms/LightsInfoUniformStruct.js';
|
|
24
|
-
export * from './uniforms/IESProfilesTexture.js';
|
|
25
|
-
|
|
26
|
-
// utils
|
|
27
|
-
export * from './utils/GeometryPreparationUtils.js';
|
|
28
|
-
export * from './utils/BlurredEnvMapGenerator.js';
|
|
29
|
-
export * from './utils/IESLoader.js';
|
|
30
|
-
|
|
31
|
-
// materials
|
|
32
|
-
export * from './materials/fullscreen/DenoiseMaterial.js';
|
|
33
|
-
export * from './materials/
|
|
34
|
-
export * from './materials/
|
|
35
|
-
export * from './materials/
|
|
36
|
-
export * from './materials/
|
|
1
|
+
// core
|
|
2
|
+
export * from './core/PathTracingRenderer.js';
|
|
3
|
+
export * from './core/QuiltPathTracingRenderer.js';
|
|
4
|
+
export * from './core/PathTracingSceneGenerator.js';
|
|
5
|
+
export * from './core/DynamicPathTracingSceneGenerator.js';
|
|
6
|
+
export * from './core/MaterialReducer.js';
|
|
7
|
+
|
|
8
|
+
// objects
|
|
9
|
+
export * from './objects/PhysicalCamera.js';
|
|
10
|
+
export * from './objects/EquirectCamera.js';
|
|
11
|
+
export * from './objects/PhysicalSpotLight.js';
|
|
12
|
+
export * from './objects/ShapedAreaLight.js';
|
|
13
|
+
|
|
14
|
+
// textures
|
|
15
|
+
export * from './textures/ProceduralEquirectTexture.js';
|
|
16
|
+
export * from './textures/GradientEquirectTexture.js';
|
|
17
|
+
|
|
18
|
+
// uniforms
|
|
19
|
+
export * from './uniforms/MaterialsTexture.js';
|
|
20
|
+
export * from './uniforms/RenderTarget2DArray.js';
|
|
21
|
+
export * from './uniforms/EquirectHdrInfoUniform.js';
|
|
22
|
+
export * from './uniforms/PhysicalCameraUniform.js';
|
|
23
|
+
export * from './uniforms/LightsInfoUniformStruct.js';
|
|
24
|
+
export * from './uniforms/IESProfilesTexture.js';
|
|
25
|
+
|
|
26
|
+
// utils
|
|
27
|
+
export * from './utils/GeometryPreparationUtils.js';
|
|
28
|
+
export * from './utils/BlurredEnvMapGenerator.js';
|
|
29
|
+
export * from './utils/IESLoader.js';
|
|
30
|
+
|
|
31
|
+
// materials
|
|
32
|
+
export * from './materials/fullscreen/DenoiseMaterial.js';
|
|
33
|
+
export * from './materials/fullscreen/GradientMapMaterial.js';
|
|
34
|
+
export * from './materials/debug/GraphMaterial.js';
|
|
35
|
+
export * from './materials/MaterialBase.js';
|
|
36
|
+
export * from './materials/pathtracing/PhysicalPathTracingMaterial.js';
|
|
37
|
+
export * from './materials/surface/FogVolumeMaterial.js';
|
|
38
|
+
|
|
39
|
+
// detectors
|
|
40
|
+
export * from './detectors/CompatibilityDetector.js';
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { ShaderMaterial } from 'three';
|
|
2
|
-
|
|
3
|
-
export class MaterialBase extends ShaderMaterial {
|
|
4
|
-
|
|
5
|
-
constructor( shader ) {
|
|
6
|
-
|
|
7
|
-
super( shader );
|
|
8
|
-
|
|
9
|
-
for ( const key in this.uniforms ) {
|
|
10
|
-
|
|
11
|
-
Object.defineProperty( this, key, {
|
|
12
|
-
|
|
13
|
-
get() {
|
|
14
|
-
|
|
15
|
-
return this.uniforms[ key ].value;
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
set( v ) {
|
|
20
|
-
|
|
21
|
-
this.uniforms[ key ].value = v;
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
} );
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// sets the given named define value and sets "needsUpdate" to true if it's different
|
|
32
|
-
setDefine( name, value = undefined ) {
|
|
33
|
-
|
|
34
|
-
if ( value === undefined || value === null ) {
|
|
35
|
-
|
|
36
|
-
if ( name in this.defines ) {
|
|
37
|
-
|
|
38
|
-
delete this.defines[ name ];
|
|
39
|
-
this.needsUpdate = true;
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
} else {
|
|
44
|
-
|
|
45
|
-
if ( this.defines[ name ] !== value ) {
|
|
46
|
-
|
|
47
|
-
this.defines[ name ] = value;
|
|
48
|
-
this.needsUpdate = true;
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
}
|
|
1
|
+
import { ShaderMaterial } from 'three';
|
|
2
|
+
|
|
3
|
+
export class MaterialBase extends ShaderMaterial {
|
|
4
|
+
|
|
5
|
+
constructor( shader ) {
|
|
6
|
+
|
|
7
|
+
super( shader );
|
|
8
|
+
|
|
9
|
+
for ( const key in this.uniforms ) {
|
|
10
|
+
|
|
11
|
+
Object.defineProperty( this, key, {
|
|
12
|
+
|
|
13
|
+
get() {
|
|
14
|
+
|
|
15
|
+
return this.uniforms[ key ].value;
|
|
16
|
+
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
set( v ) {
|
|
20
|
+
|
|
21
|
+
this.uniforms[ key ].value = v;
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
} );
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// sets the given named define value and sets "needsUpdate" to true if it's different
|
|
32
|
+
setDefine( name, value = undefined ) {
|
|
33
|
+
|
|
34
|
+
if ( value === undefined || value === null ) {
|
|
35
|
+
|
|
36
|
+
if ( name in this.defines ) {
|
|
37
|
+
|
|
38
|
+
delete this.defines[ name ];
|
|
39
|
+
this.needsUpdate = true;
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
} else {
|
|
44
|
+
|
|
45
|
+
if ( this.defines[ name ] !== value ) {
|
|
46
|
+
|
|
47
|
+
this.defines[ name ] = value;
|
|
48
|
+
this.needsUpdate = true;
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
}
|