three-gpu-pathtracer 0.0.3 → 0.0.6
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/README.md +136 -15
- package/build/index.module.js +2706 -529
- package/build/index.module.js.map +1 -1
- package/build/index.umd.cjs +2713 -529
- package/build/index.umd.cjs.map +1 -1
- package/package.json +68 -60
- package/src/core/DynamicPathTracingSceneGenerator.js +24 -11
- package/src/core/PathTracingRenderer.js +22 -0
- package/src/core/PathTracingSceneGenerator.js +36 -20
- package/src/index.js +9 -1
- package/src/materials/PhysicalPathTracingMaterial.js +350 -60
- package/src/objects/EquirectCamera.js +13 -0
- package/src/{core → objects}/PhysicalCamera.js +0 -0
- package/src/objects/PhysicalSpotLight.js +14 -0
- package/src/objects/ShapedAreaLight.js +12 -0
- package/src/shader/shaderEnvMapSampling.js +59 -67
- package/src/shader/shaderGGXFunctions.js +3 -2
- package/src/shader/shaderIridescenceFunctions.js +130 -0
- package/src/shader/shaderLightSampling.js +231 -0
- package/src/shader/shaderMaterialSampling.js +259 -53
- package/src/shader/shaderSheenFunctions.js +98 -0
- package/src/shader/shaderStructs.js +307 -92
- package/src/shader/shaderUtils.js +122 -0
- package/src/uniforms/EquirectHdrInfoUniform.js +10 -14
- package/src/uniforms/IESProfilesTexture.js +100 -0
- package/src/uniforms/LightsInfoUniformStruct.js +162 -0
- package/src/uniforms/MaterialsTexture.js +266 -33
- package/src/uniforms/PhysicalCameraUniform.js +1 -1
- package/src/uniforms/RenderTarget2DArray.js +93 -80
- package/src/utils/GeometryPreparationUtils.js +1 -1
- package/src/utils/IESLoader.js +325 -0
- package/src/workers/PathTracingSceneWorker.js +3 -1
package/package.json
CHANGED
|
@@ -1,60 +1,68 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "three-gpu-pathtracer",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Path tracing renderer and utilities for three.js built on top of three-mesh-bvh.",
|
|
5
|
-
"module": "src/index.js",
|
|
6
|
-
"main": "build/index.umd.cjs",
|
|
7
|
-
"type": "module",
|
|
8
|
-
"sideEffects": false,
|
|
9
|
-
"files": [
|
|
10
|
-
"src/*",
|
|
11
|
-
"build/*"
|
|
12
|
-
],
|
|
13
|
-
"keywords": [
|
|
14
|
-
"webgl",
|
|
15
|
-
"threejs",
|
|
16
|
-
"performance",
|
|
17
|
-
"geometry",
|
|
18
|
-
"graphics",
|
|
19
|
-
"mesh",
|
|
20
|
-
"renderer",
|
|
21
|
-
"raytracing",
|
|
22
|
-
"bvh",
|
|
23
|
-
"three-js",
|
|
24
|
-
"path-tracing",
|
|
25
|
-
"three-mesh-bvh",
|
|
26
|
-
"rtx"
|
|
27
|
-
],
|
|
28
|
-
"dependencies": {
|
|
29
|
-
"three-mesh-bvh": "^0.5.10"
|
|
30
|
-
},
|
|
31
|
-
"devDependencies": {
|
|
32
|
-
"eslint": "^7.32.0",
|
|
33
|
-
"eslint-config-mdcs": "^5.0.0",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "three-gpu-pathtracer",
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"description": "Path tracing renderer and utilities for three.js built on top of three-mesh-bvh.",
|
|
5
|
+
"module": "src/index.js",
|
|
6
|
+
"main": "build/index.umd.cjs",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"files": [
|
|
10
|
+
"src/*",
|
|
11
|
+
"build/*"
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
|
+
"webgl",
|
|
15
|
+
"threejs",
|
|
16
|
+
"performance",
|
|
17
|
+
"geometry",
|
|
18
|
+
"graphics",
|
|
19
|
+
"mesh",
|
|
20
|
+
"renderer",
|
|
21
|
+
"raytracing",
|
|
22
|
+
"bvh",
|
|
23
|
+
"three-js",
|
|
24
|
+
"path-tracing",
|
|
25
|
+
"three-mesh-bvh",
|
|
26
|
+
"rtx"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"three-mesh-bvh": "^0.5.10"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"eslint": "^7.32.0",
|
|
33
|
+
"eslint-config-mdcs": "^5.0.0",
|
|
34
|
+
"node-fetch": "^3.2.9",
|
|
35
|
+
"parcel": "^2.4.0",
|
|
36
|
+
"pixelmatch": "^5.3.0",
|
|
37
|
+
"pngjs": "^6.0.0",
|
|
38
|
+
"process": "^0.11.10",
|
|
39
|
+
"puppeteer": "^15.4.0",
|
|
40
|
+
"rollup": "^2.70.0",
|
|
41
|
+
"simple-git": "^3.10.0",
|
|
42
|
+
"three": "^0.141.0",
|
|
43
|
+
"yargs": "^17.5.1"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"three": "^0.139.2",
|
|
47
|
+
"xatlas-web": "^0.1.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"start": "cd example && parcel serve ./*.html --dist-dir ./dev-bundle/ --no-cache --no-hmr",
|
|
51
|
+
"build-examples": "cd example && parcel build ./*.html --dist-dir ./bundle/ --public-url . --no-cache --no-content-hash",
|
|
52
|
+
"update-screenshots": "node ./scripts/push-screenshots.js",
|
|
53
|
+
"screenshot-diff": "node ./scripts/regression-test.js",
|
|
54
|
+
"build": "rollup -c",
|
|
55
|
+
"lint": "eslint \"./src/**/*.{js,ts}\" \"./example/*.js\"",
|
|
56
|
+
"prepublishOnly": "npm run build"
|
|
57
|
+
},
|
|
58
|
+
"repository": {
|
|
59
|
+
"type": "git",
|
|
60
|
+
"url": "git+https://github.com/gkjohnson/three-gpu-pathtracer.git"
|
|
61
|
+
},
|
|
62
|
+
"author": "Garrett Johnson <garrett.kjohnson@gmail.com>",
|
|
63
|
+
"license": "MIT",
|
|
64
|
+
"bugs": {
|
|
65
|
+
"url": "https://github.com/gkjohnson/three-gpu-pathtracer/issues"
|
|
66
|
+
},
|
|
67
|
+
"homepage": "https://github.com/gkjohnson/three-gpu-pathtracer#readme"
|
|
68
|
+
}
|
|
@@ -12,11 +12,12 @@ export class DynamicPathTracingSceneGenerator {
|
|
|
12
12
|
|
|
13
13
|
constructor( scene ) {
|
|
14
14
|
|
|
15
|
-
this.
|
|
15
|
+
this.objects = Array.isArray( scene ) ? scene : [ scene ];
|
|
16
16
|
this.bvh = null;
|
|
17
17
|
this.geometry = new BufferGeometry();
|
|
18
18
|
this.materials = null;
|
|
19
19
|
this.textures = null;
|
|
20
|
+
this.lights = [];
|
|
20
21
|
this.staticGeometryGenerator = new StaticGeometryGenerator( scene );
|
|
21
22
|
|
|
22
23
|
}
|
|
@@ -28,7 +29,8 @@ export class DynamicPathTracingSceneGenerator {
|
|
|
28
29
|
this.geometry = new BufferGeometry();
|
|
29
30
|
this.materials = null;
|
|
30
31
|
this.textures = null;
|
|
31
|
-
this.
|
|
32
|
+
this.lights = [];
|
|
33
|
+
this.staticGeometryGenerator = new StaticGeometryGenerator( this.objects );
|
|
32
34
|
|
|
33
35
|
}
|
|
34
36
|
|
|
@@ -36,20 +38,29 @@ export class DynamicPathTracingSceneGenerator {
|
|
|
36
38
|
|
|
37
39
|
generate() {
|
|
38
40
|
|
|
39
|
-
const {
|
|
41
|
+
const { objects, staticGeometryGenerator, geometry } = this;
|
|
40
42
|
if ( this.bvh === null ) {
|
|
41
43
|
|
|
42
44
|
const attributes = [ 'position', 'normal', 'tangent', 'uv' ];
|
|
43
|
-
scene.traverse( c => {
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
for ( let i = 0, l = objects.length; i < l; i ++ ) {
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
setCommonAttributes( c.geometry, { attributes, normalMapRequired } );
|
|
48
|
+
objects[ i ].traverse( c => {
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
if ( c.isMesh ) {
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
const normalMapRequired = ! ! c.material.normalMap;
|
|
53
|
+
setCommonAttributes( c.geometry, { attributes, normalMapRequired } );
|
|
54
|
+
|
|
55
|
+
} else if ( c.isRectAreaLight || c.isSpotLight ) {
|
|
56
|
+
|
|
57
|
+
this.lights.push( c );
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
} );
|
|
62
|
+
|
|
63
|
+
}
|
|
53
64
|
|
|
54
65
|
const textureSet = new Set();
|
|
55
66
|
const materials = staticGeometryGenerator.getMaterials();
|
|
@@ -80,10 +91,11 @@ export class DynamicPathTracingSceneGenerator {
|
|
|
80
91
|
this.textures = Array.from( textureSet );
|
|
81
92
|
|
|
82
93
|
return {
|
|
94
|
+
lights: this.lights,
|
|
83
95
|
bvh: this.bvh,
|
|
84
96
|
materials: this.materials,
|
|
85
97
|
textures: this.textures,
|
|
86
|
-
|
|
98
|
+
objects,
|
|
87
99
|
};
|
|
88
100
|
|
|
89
101
|
} else {
|
|
@@ -92,10 +104,11 @@ export class DynamicPathTracingSceneGenerator {
|
|
|
92
104
|
staticGeometryGenerator.generate( geometry );
|
|
93
105
|
bvh.refit();
|
|
94
106
|
return {
|
|
107
|
+
lights: this.lights,
|
|
95
108
|
bvh: this.bvh,
|
|
96
109
|
materials: this.materials,
|
|
97
110
|
textures: this.textures,
|
|
98
|
-
|
|
111
|
+
objects,
|
|
99
112
|
};
|
|
100
113
|
|
|
101
114
|
}
|
|
@@ -24,6 +24,7 @@ function* renderTask() {
|
|
|
24
24
|
|
|
25
25
|
blendMaterial.opacity = 1 / ( this.samples + 1 );
|
|
26
26
|
material.blending = NoBlending;
|
|
27
|
+
material.opacity = 1;
|
|
27
28
|
|
|
28
29
|
} else {
|
|
29
30
|
|
|
@@ -48,6 +49,27 @@ function* renderTask() {
|
|
|
48
49
|
material.cameraWorldMatrix.copy( camera.matrixWorld );
|
|
49
50
|
material.invProjectionMatrix.copy( camera.projectionMatrixInverse );
|
|
50
51
|
|
|
52
|
+
// Perspective camera (default)
|
|
53
|
+
let cameraType = 0;
|
|
54
|
+
|
|
55
|
+
// An orthographic projection matrix will always have the bottom right element == 1
|
|
56
|
+
// And a perspective projection matrix will always have the bottom right element == 0
|
|
57
|
+
if ( camera.projectionMatrix.elements[ 15 ] > 0 ) {
|
|
58
|
+
|
|
59
|
+
// Orthographic
|
|
60
|
+
cameraType = 1;
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if ( camera.isEquirectCamera ) {
|
|
65
|
+
|
|
66
|
+
// Equirectangular
|
|
67
|
+
cameraType = 2;
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
material.setDefine( 'CAMERA_TYPE', cameraType );
|
|
72
|
+
|
|
51
73
|
const ogRenderTarget = _renderer.getRenderTarget();
|
|
52
74
|
const ogAutoClear = _renderer.autoClear;
|
|
53
75
|
|
|
@@ -6,44 +6,60 @@ export class PathTracingSceneGenerator {
|
|
|
6
6
|
|
|
7
7
|
prepScene( scene ) {
|
|
8
8
|
|
|
9
|
+
scene = Array.isArray( scene ) ? scene : [ scene ];
|
|
10
|
+
|
|
9
11
|
const meshes = [];
|
|
10
|
-
|
|
12
|
+
const lights = [];
|
|
13
|
+
|
|
14
|
+
for ( let i = 0, l = scene.length; i < l; i ++ ) {
|
|
15
|
+
|
|
16
|
+
scene[ i ].traverse( c => {
|
|
17
|
+
|
|
18
|
+
if ( c.isSkinnedMesh || c.isMesh && c.morphTargetInfluences ) {
|
|
11
19
|
|
|
12
|
-
|
|
20
|
+
const generator = new StaticGeometryGenerator( c );
|
|
21
|
+
generator.applyWorldTransforms = false;
|
|
22
|
+
const mesh = new Mesh(
|
|
23
|
+
generator.generate(),
|
|
24
|
+
c.material,
|
|
25
|
+
);
|
|
26
|
+
mesh.matrixWorld.copy( c.matrixWorld );
|
|
27
|
+
mesh.matrix.copy( c.matrixWorld );
|
|
28
|
+
mesh.matrix.decompose( mesh.position, mesh.quaternion, mesh.scale );
|
|
29
|
+
meshes.push( mesh );
|
|
13
30
|
|
|
14
|
-
|
|
15
|
-
generator.applyWorldTransforms = false;
|
|
16
|
-
const mesh = new Mesh(
|
|
17
|
-
generator.generate(),
|
|
18
|
-
c.material,
|
|
19
|
-
);
|
|
20
|
-
mesh.matrixWorld.copy( c.matrixWorld );
|
|
21
|
-
mesh.matrix.copy( c.matrixWorld );
|
|
22
|
-
mesh.matrix.decompose( mesh.position, mesh.quaternion, mesh.scale );
|
|
23
|
-
meshes.push( mesh );
|
|
31
|
+
} else if ( c.isMesh ) {
|
|
24
32
|
|
|
25
|
-
|
|
33
|
+
meshes.push( c );
|
|
26
34
|
|
|
27
|
-
|
|
35
|
+
} else if ( c.isRectAreaLight || c.isSpotLight ) {
|
|
28
36
|
|
|
29
|
-
|
|
37
|
+
lights.push( c );
|
|
30
38
|
|
|
31
|
-
|
|
39
|
+
}
|
|
32
40
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
41
|
+
} );
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
...mergeMeshes( meshes, {
|
|
47
|
+
attributes: [ 'position', 'normal', 'tangent', 'uv' ],
|
|
48
|
+
} ),
|
|
49
|
+
lights,
|
|
50
|
+
};
|
|
36
51
|
|
|
37
52
|
}
|
|
38
53
|
|
|
39
54
|
generate( scene, options = {} ) {
|
|
40
55
|
|
|
41
|
-
const { materials, textures, geometry } = this.prepScene( scene );
|
|
56
|
+
const { materials, textures, geometry, lights } = this.prepScene( scene );
|
|
42
57
|
const bvhOptions = { strategy: SAH, ...options, maxLeafTris: 1 };
|
|
43
58
|
return {
|
|
44
59
|
scene,
|
|
45
60
|
materials,
|
|
46
61
|
textures,
|
|
62
|
+
lights,
|
|
47
63
|
bvh: new MeshBVH( geometry, bvhOptions ),
|
|
48
64
|
};
|
|
49
65
|
|
package/src/index.js
CHANGED
|
@@ -3,17 +3,25 @@ export * from './core/PathTracingRenderer.js';
|
|
|
3
3
|
export * from './core/PathTracingSceneGenerator.js';
|
|
4
4
|
export * from './core/DynamicPathTracingSceneGenerator.js';
|
|
5
5
|
export * from './core/MaterialReducer.js';
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
// objects
|
|
8
|
+
export * from './objects/PhysicalCamera.js';
|
|
9
|
+
export * from './objects/EquirectCamera.js';
|
|
10
|
+
export * from './objects/PhysicalSpotLight.js';
|
|
11
|
+
export * from './objects/ShapedAreaLight.js';
|
|
7
12
|
|
|
8
13
|
// uniforms
|
|
9
14
|
export * from './uniforms/MaterialsTexture.js';
|
|
10
15
|
export * from './uniforms/RenderTarget2DArray.js';
|
|
11
16
|
export * from './uniforms/EquirectHdrInfoUniform.js';
|
|
12
17
|
export * from './uniforms/PhysicalCameraUniform.js';
|
|
18
|
+
export * from './uniforms/LightsInfoUniformStruct.js';
|
|
19
|
+
export * from './uniforms/IESProfilesTexture.js';
|
|
13
20
|
|
|
14
21
|
// utils
|
|
15
22
|
export * from './utils/GeometryPreparationUtils.js';
|
|
16
23
|
export * from './utils/BlurredEnvMapGenerator.js';
|
|
24
|
+
export * from './utils/IESLoader.js';
|
|
17
25
|
|
|
18
26
|
// materials
|
|
19
27
|
export * from './materials/MaterialBase.js';
|