three-gpu-pathtracer 0.0.2 → 0.0.3
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 +107 -44
- package/build/index.module.js +2077 -1141
- package/build/index.module.js.map +1 -1
- package/build/index.umd.cjs +1922 -984
- package/build/index.umd.cjs.map +1 -1
- package/package.json +60 -61
- package/src/core/DynamicPathTracingSceneGenerator.js +106 -105
- package/src/core/PathTracingRenderer.js +233 -140
- package/src/index.js +4 -2
- package/src/materials/AlphaDisplayMaterial.js +48 -0
- package/src/materials/BlendMaterial.js +67 -0
- package/src/materials/PhysicalPathTracingMaterial.js +287 -75
- package/src/shader/shaderEnvMapSampling.js +67 -0
- package/src/shader/shaderMaterialSampling.js +7 -0
- package/src/shader/shaderStructs.js +92 -42
- package/src/shader/shaderUtils.js +37 -0
- package/src/uniforms/EquirectHdrInfoUniform.js +263 -0
- package/src/uniforms/MaterialsTexture.js +173 -0
- package/src/uniforms/RenderTarget2DArray.js +80 -80
- package/src/utils/BlurredEnvMapGenerator.js +113 -0
- package/src/utils/GeometryPreparationUtils.js +194 -200
- package/src/uniforms/EquirectPdfUniform.js +0 -132
- package/src/uniforms/MaterialStructArrayUniform.js +0 -18
- package/src/uniforms/MaterialStructUniform.js +0 -114
package/package.json
CHANGED
|
@@ -1,61 +1,60 @@
|
|
|
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
|
-
"
|
|
33
|
-
"eslint": "^
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"xatlas-web": "^0.1.0"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
"build
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "three-gpu-pathtracer",
|
|
3
|
+
"version": "0.0.3",
|
|
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
|
+
"parcel": "^2.4.0",
|
|
35
|
+
"process": "^0.11.10",
|
|
36
|
+
"rollup": "^2.70.0",
|
|
37
|
+
"three": "^0.139.2"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"three": "^0.139.2",
|
|
41
|
+
"xatlas-web": "^0.1.0"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"start": "cd example && parcel serve ./*.html --dist-dir ./dev-bundle/ --no-cache --no-hmr",
|
|
45
|
+
"build-examples": "cd example && parcel build ./*.html --dist-dir ./bundle/ --public-url . --no-cache --no-content-hash",
|
|
46
|
+
"build": "rollup -c",
|
|
47
|
+
"lint": "eslint \"./src/**/*.{js,ts}\" \"./example/*.js\"",
|
|
48
|
+
"prepublishOnly": "npm run build"
|
|
49
|
+
},
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "git+https://github.com/gkjohnson/three-gpu-pathtracer.git"
|
|
53
|
+
},
|
|
54
|
+
"author": "Garrett Johnson <garrett.kjohnson@gmail.com>",
|
|
55
|
+
"license": "MIT",
|
|
56
|
+
"bugs": {
|
|
57
|
+
"url": "https://github.com/gkjohnson/three-gpu-pathtracer/issues"
|
|
58
|
+
},
|
|
59
|
+
"homepage": "https://github.com/gkjohnson/three-gpu-pathtracer#readme"
|
|
60
|
+
}
|
|
@@ -1,105 +1,106 @@
|
|
|
1
|
-
import { BufferGeometry } from 'three';
|
|
2
|
-
import { StaticGeometryGenerator, MeshBVH } from 'three-mesh-bvh';
|
|
3
|
-
import { setCommonAttributes, getGroupMaterialIndicesAttribute } from '../utils/GeometryPreparationUtils.js';
|
|
4
|
-
|
|
5
|
-
export class DynamicPathTracingSceneGenerator {
|
|
6
|
-
|
|
7
|
-
get initialized() {
|
|
8
|
-
|
|
9
|
-
return Boolean( this.bvh );
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
constructor( scene ) {
|
|
14
|
-
|
|
15
|
-
this.scene = scene;
|
|
16
|
-
this.bvh = null;
|
|
17
|
-
this.geometry = new BufferGeometry();
|
|
18
|
-
this.materials = null;
|
|
19
|
-
this.textures = null;
|
|
20
|
-
this.staticGeometryGenerator = new StaticGeometryGenerator( scene );
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
reset() {
|
|
25
|
-
|
|
26
|
-
this.
|
|
27
|
-
this.geometry
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
materials.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
staticGeometryGenerator.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
geometry.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
this.
|
|
79
|
-
this.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
1
|
+
import { BufferGeometry } from 'three';
|
|
2
|
+
import { StaticGeometryGenerator, MeshBVH } from 'three-mesh-bvh';
|
|
3
|
+
import { setCommonAttributes, getGroupMaterialIndicesAttribute } from '../utils/GeometryPreparationUtils.js';
|
|
4
|
+
|
|
5
|
+
export class DynamicPathTracingSceneGenerator {
|
|
6
|
+
|
|
7
|
+
get initialized() {
|
|
8
|
+
|
|
9
|
+
return Boolean( this.bvh );
|
|
10
|
+
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor( scene ) {
|
|
14
|
+
|
|
15
|
+
this.scene = scene;
|
|
16
|
+
this.bvh = null;
|
|
17
|
+
this.geometry = new BufferGeometry();
|
|
18
|
+
this.materials = null;
|
|
19
|
+
this.textures = null;
|
|
20
|
+
this.staticGeometryGenerator = new StaticGeometryGenerator( scene );
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
reset() {
|
|
25
|
+
|
|
26
|
+
this.bvh = null;
|
|
27
|
+
this.geometry.dispose();
|
|
28
|
+
this.geometry = new BufferGeometry();
|
|
29
|
+
this.materials = null;
|
|
30
|
+
this.textures = null;
|
|
31
|
+
this.staticGeometryGenerator = new StaticGeometryGenerator( this.scene );
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
dispose() {}
|
|
36
|
+
|
|
37
|
+
generate() {
|
|
38
|
+
|
|
39
|
+
const { scene, staticGeometryGenerator, geometry } = this;
|
|
40
|
+
if ( this.bvh === null ) {
|
|
41
|
+
|
|
42
|
+
const attributes = [ 'position', 'normal', 'tangent', 'uv' ];
|
|
43
|
+
scene.traverse( c => {
|
|
44
|
+
|
|
45
|
+
if ( c.isMesh ) {
|
|
46
|
+
|
|
47
|
+
const normalMapRequired = ! ! c.material.normalMap;
|
|
48
|
+
setCommonAttributes( c.geometry, { attributes, normalMapRequired } );
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
} );
|
|
53
|
+
|
|
54
|
+
const textureSet = new Set();
|
|
55
|
+
const materials = staticGeometryGenerator.getMaterials();
|
|
56
|
+
materials.forEach( material => {
|
|
57
|
+
|
|
58
|
+
for ( const key in material ) {
|
|
59
|
+
|
|
60
|
+
const value = material[ key ];
|
|
61
|
+
if ( value && value.isTexture ) {
|
|
62
|
+
|
|
63
|
+
textureSet.add( value );
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
} );
|
|
70
|
+
|
|
71
|
+
staticGeometryGenerator.attributes = attributes;
|
|
72
|
+
staticGeometryGenerator.generate( geometry );
|
|
73
|
+
|
|
74
|
+
const materialIndexAttribute = getGroupMaterialIndicesAttribute( geometry, materials, materials );
|
|
75
|
+
geometry.setAttribute( 'materialIndex', materialIndexAttribute );
|
|
76
|
+
geometry.clearGroups();
|
|
77
|
+
|
|
78
|
+
this.bvh = new MeshBVH( geometry );
|
|
79
|
+
this.materials = materials;
|
|
80
|
+
this.textures = Array.from( textureSet );
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
bvh: this.bvh,
|
|
84
|
+
materials: this.materials,
|
|
85
|
+
textures: this.textures,
|
|
86
|
+
scene,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
} else {
|
|
90
|
+
|
|
91
|
+
const { bvh } = this;
|
|
92
|
+
staticGeometryGenerator.generate( geometry );
|
|
93
|
+
bvh.refit();
|
|
94
|
+
return {
|
|
95
|
+
bvh: this.bvh,
|
|
96
|
+
materials: this.materials,
|
|
97
|
+
textures: this.textures,
|
|
98
|
+
scene,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
}
|