three-gpu-pathtracer 0.0.2 → 0.0.5
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 +728 -597
- package/build/index.module.js +3585 -1739
- package/build/index.module.js.map +1 -1
- package/build/index.umd.cjs +3589 -1739
- package/build/index.umd.cjs.map +1 -1
- package/package.json +60 -61
- package/src/core/DynamicPathTracingSceneGenerator.js +17 -11
- package/src/core/EquirectCamera.js +13 -0
- package/src/core/MaterialReducer.js +256 -256
- package/src/core/PathTracingRenderer.js +143 -28
- package/src/core/PathTracingSceneGenerator.js +68 -52
- package/src/core/PhysicalCamera.js +28 -28
- package/src/index.js +26 -23
- package/src/materials/AlphaDisplayMaterial.js +48 -0
- package/src/materials/AmbientOcclusionMaterial.js +197 -197
- package/src/materials/BlendMaterial.js +67 -0
- package/src/materials/LambertPathTracingMaterial.js +285 -285
- package/src/materials/MaterialBase.js +56 -56
- package/src/materials/PhysicalPathTracingMaterial.js +848 -420
- package/src/shader/shaderEnvMapSampling.js +59 -0
- package/src/shader/shaderGGXFunctions.js +108 -107
- package/src/shader/shaderLightSampling.js +87 -0
- package/src/shader/shaderMaterialSampling.js +501 -333
- package/src/shader/shaderStructs.js +191 -42
- package/src/shader/shaderUtils.js +287 -191
- package/src/uniforms/EquirectHdrInfoUniform.js +263 -0
- package/src/uniforms/LightsTexture.js +83 -0
- package/src/uniforms/MaterialsTexture.js +319 -0
- package/src/uniforms/PhysicalCameraUniform.js +36 -36
- package/src/uniforms/RenderTarget2DArray.js +93 -80
- package/src/utils/BlurredEnvMapGenerator.js +113 -0
- package/src/utils/GeometryPreparationUtils.js +2 -8
- package/src/utils/UVUnwrapper.js +101 -101
- package/src/workers/PathTracingSceneWorker.js +41 -40
- package/src/uniforms/EquirectPdfUniform.js +0 -132
- package/src/uniforms/MaterialStructArrayUniform.js +0 -18
- package/src/uniforms/MaterialStructUniform.js +0 -114
|
@@ -1,42 +1,191 @@
|
|
|
1
|
-
export const shaderMaterialStructs = /* glsl */ `
|
|
2
|
-
|
|
3
|
-
struct PhysicalCamera {
|
|
4
|
-
|
|
5
|
-
float focusDistance;
|
|
6
|
-
float anamorphicRatio;
|
|
7
|
-
float bokehSize;
|
|
8
|
-
int apertureBlades;
|
|
9
|
-
float apertureRotation;
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
struct
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
1
|
+
export const shaderMaterialStructs = /* glsl */ `
|
|
2
|
+
|
|
3
|
+
struct PhysicalCamera {
|
|
4
|
+
|
|
5
|
+
float focusDistance;
|
|
6
|
+
float anamorphicRatio;
|
|
7
|
+
float bokehSize;
|
|
8
|
+
int apertureBlades;
|
|
9
|
+
float apertureRotation;
|
|
10
|
+
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
struct EquirectHdrInfo {
|
|
14
|
+
|
|
15
|
+
sampler2D marginalWeights;
|
|
16
|
+
sampler2D conditionalWeights;
|
|
17
|
+
sampler2D map;
|
|
18
|
+
sampler2D totalSum;
|
|
19
|
+
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
struct Material {
|
|
23
|
+
|
|
24
|
+
vec3 color;
|
|
25
|
+
int map;
|
|
26
|
+
|
|
27
|
+
float metalness;
|
|
28
|
+
int metalnessMap;
|
|
29
|
+
|
|
30
|
+
float roughness;
|
|
31
|
+
int roughnessMap;
|
|
32
|
+
|
|
33
|
+
float ior;
|
|
34
|
+
float transmission;
|
|
35
|
+
int transmissionMap;
|
|
36
|
+
|
|
37
|
+
float emissiveIntensity;
|
|
38
|
+
vec3 emissive;
|
|
39
|
+
int emissiveMap;
|
|
40
|
+
|
|
41
|
+
int normalMap;
|
|
42
|
+
vec2 normalScale;
|
|
43
|
+
|
|
44
|
+
float clearcoat;
|
|
45
|
+
int clearcoatMap;
|
|
46
|
+
int clearcoatNormalMap;
|
|
47
|
+
vec2 clearcoatNormalScale;
|
|
48
|
+
float clearcoatRoughness;
|
|
49
|
+
int clearcoatRoughnessMap;
|
|
50
|
+
|
|
51
|
+
int alphaMap;
|
|
52
|
+
|
|
53
|
+
bool castShadow;
|
|
54
|
+
float opacity;
|
|
55
|
+
float alphaTest;
|
|
56
|
+
|
|
57
|
+
float side;
|
|
58
|
+
bool matte;
|
|
59
|
+
|
|
60
|
+
mat3 mapTransform;
|
|
61
|
+
mat3 metalnessMapTransform;
|
|
62
|
+
mat3 roughnessMapTransform;
|
|
63
|
+
mat3 transmissionMapTransform;
|
|
64
|
+
mat3 emissiveMapTransform;
|
|
65
|
+
mat3 normalMapTransform;
|
|
66
|
+
mat3 clearcoatMapTransform;
|
|
67
|
+
mat3 clearcoatNormalMapTransform;
|
|
68
|
+
mat3 clearcoatRoughnessMapTransform;
|
|
69
|
+
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
mat3 readTextureTransform( sampler2D tex, uint index ) {
|
|
73
|
+
|
|
74
|
+
mat3 textureTransform;
|
|
75
|
+
|
|
76
|
+
vec4 row1 = texelFetch1D( tex, index );
|
|
77
|
+
vec4 row2 = texelFetch1D( tex, index + 1u );
|
|
78
|
+
|
|
79
|
+
textureTransform[0] = vec3(row1.r, row2.r, 0.0);
|
|
80
|
+
textureTransform[1] = vec3(row1.g, row2.g, 0.0);
|
|
81
|
+
textureTransform[2] = vec3(row1.b, row2.b, 1.0);
|
|
82
|
+
|
|
83
|
+
return textureTransform;
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
Material readMaterialInfo( sampler2D tex, uint index ) {
|
|
88
|
+
|
|
89
|
+
uint i = index * 26u;
|
|
90
|
+
|
|
91
|
+
vec4 s0 = texelFetch1D( tex, i + 0u );
|
|
92
|
+
vec4 s1 = texelFetch1D( tex, i + 1u );
|
|
93
|
+
vec4 s2 = texelFetch1D( tex, i + 2u );
|
|
94
|
+
vec4 s3 = texelFetch1D( tex, i + 3u );
|
|
95
|
+
vec4 s4 = texelFetch1D( tex, i + 4u );
|
|
96
|
+
vec4 s5 = texelFetch1D( tex, i + 5u );
|
|
97
|
+
vec4 s6 = texelFetch1D( tex, i + 6u );
|
|
98
|
+
vec4 s7 = texelFetch1D( tex, i + 7u );
|
|
99
|
+
|
|
100
|
+
Material m;
|
|
101
|
+
m.color = s0.rgb;
|
|
102
|
+
m.map = int( round( s0.a ) );
|
|
103
|
+
|
|
104
|
+
m.metalness = s1.r;
|
|
105
|
+
m.metalnessMap = int( round( s1.g ) );
|
|
106
|
+
m.roughness = s1.b;
|
|
107
|
+
m.roughnessMap = int( round( s1.a ) );
|
|
108
|
+
|
|
109
|
+
m.ior = s2.r;
|
|
110
|
+
m.transmission = s2.g;
|
|
111
|
+
m.transmissionMap = int( round( s2.b ) );
|
|
112
|
+
m.emissiveIntensity = s2.a;
|
|
113
|
+
|
|
114
|
+
m.emissive = s3.rgb;
|
|
115
|
+
m.emissiveMap = int( round( s3.a ) );
|
|
116
|
+
|
|
117
|
+
m.normalMap = int( round( s4.r ) );
|
|
118
|
+
m.normalScale = s4.gb;
|
|
119
|
+
|
|
120
|
+
m.clearcoat = s4.a;
|
|
121
|
+
m.clearcoatMap = int( round( s5.r ) );
|
|
122
|
+
m.clearcoatRoughness = s5.g;
|
|
123
|
+
m.clearcoatRoughnessMap = int( round( s5.b ) );
|
|
124
|
+
m.clearcoatNormalMap = int( round( s5.a ) );
|
|
125
|
+
m.clearcoatNormalScale = s6.rg;
|
|
126
|
+
|
|
127
|
+
m.alphaMap = int( round( s6.b ) );
|
|
128
|
+
|
|
129
|
+
m.opacity = s6.a;
|
|
130
|
+
m.alphaTest = s7.r;
|
|
131
|
+
m.side = s7.g;
|
|
132
|
+
m.matte = bool( s7.b );
|
|
133
|
+
|
|
134
|
+
m.castShadow = ! bool( s7.a );
|
|
135
|
+
|
|
136
|
+
uint firstTextureTransformIdx = i + 8u;
|
|
137
|
+
|
|
138
|
+
m.mapTransform = m.map == - 1 ? mat3( 0 ) : readTextureTransform( tex, firstTextureTransformIdx);
|
|
139
|
+
m.metalnessMapTransform = m.metalnessMap == - 1 ? mat3( 0 ) : readTextureTransform( tex, firstTextureTransformIdx + 2u );
|
|
140
|
+
m.roughnessMapTransform = m.roughnessMap == - 1 ? mat3( 0 ) : readTextureTransform( tex, firstTextureTransformIdx + 4u );
|
|
141
|
+
m.transmissionMapTransform = m.transmissionMap == - 1 ? mat3( 0 ) : readTextureTransform( tex, firstTextureTransformIdx + 6u );
|
|
142
|
+
m.emissiveMapTransform = m.emissiveMap == - 1 ? mat3( 0 ) : readTextureTransform( tex, firstTextureTransformIdx + 8u );
|
|
143
|
+
m.normalMapTransform = m.normalMap == - 1 ? mat3( 0 ) : readTextureTransform( tex, firstTextureTransformIdx + 10u );
|
|
144
|
+
m.clearcoatMapTransform = m.clearcoatMap == - 1 ? mat3( 0 ) : readTextureTransform( tex, firstTextureTransformIdx + 12u );
|
|
145
|
+
m.clearcoatNormalMapTransform = m.clearcoatNormalMap == - 1 ? mat3( 0 ) : readTextureTransform( tex, firstTextureTransformIdx + 14u );
|
|
146
|
+
m.clearcoatRoughnessMapTransform = m.clearcoatRoughnessMap == - 1 ? mat3( 0 ) : readTextureTransform( tex, firstTextureTransformIdx + 16u );
|
|
147
|
+
|
|
148
|
+
return m;
|
|
149
|
+
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
`;
|
|
153
|
+
|
|
154
|
+
export const shaderLightStruct = /* glsl */ `
|
|
155
|
+
struct Light {
|
|
156
|
+
|
|
157
|
+
vec3 position;
|
|
158
|
+
|
|
159
|
+
vec3 color;
|
|
160
|
+
float intensity;
|
|
161
|
+
|
|
162
|
+
vec3 u;
|
|
163
|
+
vec3 v;
|
|
164
|
+
float area;
|
|
165
|
+
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
Light readLightInfo( sampler2D tex, uint index ) {
|
|
169
|
+
|
|
170
|
+
uint i = index * 4u;
|
|
171
|
+
|
|
172
|
+
vec4 s0 = texelFetch1D( tex, i + 0u );
|
|
173
|
+
vec4 s1 = texelFetch1D( tex, i + 1u );
|
|
174
|
+
vec4 s2 = texelFetch1D( tex, i + 2u );
|
|
175
|
+
vec4 s3 = texelFetch1D( tex, i + 3u );
|
|
176
|
+
|
|
177
|
+
Light l;
|
|
178
|
+
l.position = s0.rgb;
|
|
179
|
+
|
|
180
|
+
l.color = s1.rgb;
|
|
181
|
+
l.intensity = s1.a;
|
|
182
|
+
|
|
183
|
+
l.u = s2.rgb;
|
|
184
|
+
l.v = s3.rgb;
|
|
185
|
+
l.area = s3.a;
|
|
186
|
+
|
|
187
|
+
return l;
|
|
188
|
+
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
`;
|