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,50 @@
|
|
|
1
|
+
export const renderStructsGLSL = /* glsl */`
|
|
2
|
+
|
|
3
|
+
struct Ray {
|
|
4
|
+
|
|
5
|
+
vec3 origin;
|
|
6
|
+
vec3 direction;
|
|
7
|
+
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
struct SurfaceHit {
|
|
11
|
+
|
|
12
|
+
uvec4 faceIndices;
|
|
13
|
+
vec3 barycoord;
|
|
14
|
+
vec3 faceNormal;
|
|
15
|
+
float side;
|
|
16
|
+
float dist;
|
|
17
|
+
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
struct RenderState {
|
|
21
|
+
|
|
22
|
+
bool firstRay;
|
|
23
|
+
bool transmissiveRay;
|
|
24
|
+
bool isShadowRay;
|
|
25
|
+
float accumulatedRoughness;
|
|
26
|
+
int transmissiveTraversals;
|
|
27
|
+
int traversals;
|
|
28
|
+
uint depth;
|
|
29
|
+
vec3 throughputColor;
|
|
30
|
+
Material fogMaterial;
|
|
31
|
+
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
RenderState initRenderState() {
|
|
35
|
+
|
|
36
|
+
RenderState result;
|
|
37
|
+
result.firstRay = true;
|
|
38
|
+
result.transmissiveRay = true;
|
|
39
|
+
result.isShadowRay = false;
|
|
40
|
+
result.accumulatedRoughness = 0.0;
|
|
41
|
+
result.transmissiveTraversals = 0;
|
|
42
|
+
result.traversals = 0;
|
|
43
|
+
result.throughputColor = vec3( 1.0 );
|
|
44
|
+
result.depth = 0u;
|
|
45
|
+
result.fogMaterial.fogVolume = false;
|
|
46
|
+
return result;
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
`;
|
|
@@ -1,54 +1,52 @@
|
|
|
1
|
-
export const traceSceneGLSL = /* glsl */`
|
|
2
|
-
|
|
3
|
-
#define NO_HIT 0
|
|
4
|
-
#define SURFACE_HIT 1
|
|
5
|
-
#define LIGHT_HIT 2
|
|
6
|
-
#define FOG_HIT 3
|
|
7
|
-
|
|
8
|
-
int traceScene(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
`;
|
|
1
|
+
export const traceSceneGLSL = /* glsl */`
|
|
2
|
+
|
|
3
|
+
#define NO_HIT 0
|
|
4
|
+
#define SURFACE_HIT 1
|
|
5
|
+
#define LIGHT_HIT 2
|
|
6
|
+
#define FOG_HIT 3
|
|
7
|
+
|
|
8
|
+
int traceScene(
|
|
9
|
+
|
|
10
|
+
Ray ray, BVH bvh, LightsInfo lights, Material fogMaterial,
|
|
11
|
+
out SurfaceHit surfaceHit, out LightRecord lightRec
|
|
12
|
+
|
|
13
|
+
) {
|
|
14
|
+
|
|
15
|
+
bool hit = bvhIntersectFirstHit( bvh, ray.origin, ray.direction, surfaceHit.faceIndices, surfaceHit.faceNormal, surfaceHit.barycoord, surfaceHit.side, surfaceHit.dist );
|
|
16
|
+
bool lightHit = lightsClosestHit( lights.tex, lights.count, ray.origin, ray.direction, lightRec );
|
|
17
|
+
|
|
18
|
+
#if FEATURE_FOG
|
|
19
|
+
|
|
20
|
+
if ( fogMaterial.fogVolume ) {
|
|
21
|
+
|
|
22
|
+
float particleDist = intersectFogVolume( fogMaterial, sobol( 1 ) );
|
|
23
|
+
if ( particleDist + 1e-4 < surfaceHit.dist && ( particleDist + 1e-4 < lightRec.dist || ! lightHit ) ) {
|
|
24
|
+
|
|
25
|
+
surfaceHit.side = 1.0;
|
|
26
|
+
surfaceHit.faceNormal = normalize( - ray.direction );
|
|
27
|
+
surfaceHit.dist = particleDist;
|
|
28
|
+
return FOG_HIT;
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#endif
|
|
35
|
+
|
|
36
|
+
if ( lightHit && ( lightRec.dist < surfaceHit.dist || ! hit ) ) {
|
|
37
|
+
|
|
38
|
+
return LIGHT_HIT;
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if ( hit ) {
|
|
43
|
+
|
|
44
|
+
return SURFACE_HIT;
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return NO_HIT;
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
`;
|
|
@@ -1,207 +1,207 @@
|
|
|
1
|
-
import { TangentSpaceNormalMap, Vector2 } from 'three';
|
|
2
|
-
import { MaterialBase } from '../MaterialBase.js';
|
|
3
|
-
import { MeshBVHUniformStruct, shaderStructs, shaderIntersectFunction } from 'three-mesh-bvh';
|
|
4
|
-
|
|
5
|
-
import { materialStructGLSL } from '../../shader/structs/materialStruct.glsl.js';
|
|
6
|
-
import { shapeSamplingGLSL } from '../../shader/sampling/shapeSampling.glsl.js';
|
|
7
|
-
import { pcgGLSL } from '../../shader/rand/pcg.glsl.js';
|
|
8
|
-
|
|
9
|
-
export class AmbientOcclusionMaterial extends MaterialBase {
|
|
10
|
-
|
|
11
|
-
get normalMap() {
|
|
12
|
-
|
|
13
|
-
return this.uniforms.normalMap.value;
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
set normalMap( v ) {
|
|
18
|
-
|
|
19
|
-
this.uniforms.normalMap.value = v;
|
|
20
|
-
this.setDefine( 'USE_NORMALMAP', v ? null : '' );
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
get normalMapType() {
|
|
25
|
-
|
|
26
|
-
return TangentSpaceNormalMap;
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
set normalMapType( v ) {
|
|
31
|
-
|
|
32
|
-
if ( v !== TangentSpaceNormalMap ) {
|
|
33
|
-
|
|
34
|
-
throw new Error( 'AmbientOcclusionMaterial: Only tangent space normal map are supported' );
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
constructor( parameters ) {
|
|
41
|
-
|
|
42
|
-
super( {
|
|
43
|
-
|
|
44
|
-
defines: {
|
|
45
|
-
SAMPLES: 10,
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
uniforms: {
|
|
49
|
-
bvh: { value: new MeshBVHUniformStruct() },
|
|
50
|
-
radius: { value: 1.0 },
|
|
51
|
-
seed: { value: 0 },
|
|
52
|
-
|
|
53
|
-
normalMap: { value: null },
|
|
54
|
-
normalScale: { value: new Vector2( 1, 1 ) },
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
vertexShader: /* glsl */`
|
|
58
|
-
|
|
59
|
-
varying vec3 vNorm;
|
|
60
|
-
varying vec3 vPos;
|
|
61
|
-
|
|
62
|
-
#if defined(USE_NORMALMAP) && defined(USE_TANGENT)
|
|
63
|
-
|
|
64
|
-
varying vec2 vUv;
|
|
65
|
-
varying vec4 vTan;
|
|
66
|
-
|
|
67
|
-
#endif
|
|
68
|
-
|
|
69
|
-
void main() {
|
|
70
|
-
|
|
71
|
-
vec4 mvPosition = vec4( position, 1.0 );
|
|
72
|
-
mvPosition = modelViewMatrix * mvPosition;
|
|
73
|
-
gl_Position = projectionMatrix * mvPosition;
|
|
74
|
-
|
|
75
|
-
mat3 modelNormalMatrix = transpose( inverse( mat3( modelMatrix ) ) );
|
|
76
|
-
vNorm = normalize( modelNormalMatrix * normal );
|
|
77
|
-
vPos = ( modelMatrix * vec4( position, 1.0 ) ).xyz;
|
|
78
|
-
|
|
79
|
-
#if defined( USE_NORMALMAP ) && defined( USE_TANGENT )
|
|
80
|
-
|
|
81
|
-
vUv = uv;
|
|
82
|
-
vTan = tangent;
|
|
83
|
-
|
|
84
|
-
#endif
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
`,
|
|
89
|
-
|
|
90
|
-
fragmentShader: /* glsl */`
|
|
91
|
-
#define RAY_OFFSET 1e-4
|
|
92
|
-
|
|
93
|
-
precision highp isampler2D;
|
|
94
|
-
precision highp usampler2D;
|
|
95
|
-
precision highp sampler2DArray;
|
|
96
|
-
#include <common>
|
|
97
|
-
#include <cube_uv_reflection_fragment>
|
|
98
|
-
|
|
99
|
-
// bvh
|
|
100
|
-
${ shaderStructs }
|
|
101
|
-
${ shaderIntersectFunction }
|
|
102
|
-
|
|
103
|
-
// uniform structs
|
|
104
|
-
${ materialStructGLSL }
|
|
105
|
-
|
|
106
|
-
// rand
|
|
107
|
-
${ pcgGLSL }
|
|
108
|
-
|
|
109
|
-
// common
|
|
110
|
-
${ shapeSamplingGLSL }
|
|
111
|
-
|
|
112
|
-
uniform BVH bvh;
|
|
113
|
-
uniform int seed;
|
|
114
|
-
uniform float radius;
|
|
115
|
-
|
|
116
|
-
varying vec3 vNorm;
|
|
117
|
-
varying vec3 vPos;
|
|
118
|
-
|
|
119
|
-
#if defined(USE_NORMALMAP) && defined(USE_TANGENT)
|
|
120
|
-
|
|
121
|
-
uniform sampler2D normalMap;
|
|
122
|
-
uniform vec2 normalScale;
|
|
123
|
-
varying vec2 vUv;
|
|
124
|
-
varying vec4 vTan;
|
|
125
|
-
|
|
126
|
-
#endif
|
|
127
|
-
|
|
128
|
-
void main() {
|
|
129
|
-
|
|
130
|
-
rng_initialize( gl_FragCoord.xy, seed );
|
|
131
|
-
|
|
132
|
-
// compute the flat face surface normal
|
|
133
|
-
vec3 fdx = vec3( dFdx( vPos.x ), dFdx( vPos.y ), dFdx( vPos.z ) );
|
|
134
|
-
vec3 fdy = vec3( dFdy( vPos.x ), dFdy( vPos.y ), dFdy( vPos.z ) );
|
|
135
|
-
vec3 faceNormal = normalize( cross( fdx, fdy ) );
|
|
136
|
-
|
|
137
|
-
// find the max component to scale the offset to account for floating point error
|
|
138
|
-
vec3 absPoint = abs( vPos );
|
|
139
|
-
float maxPoint = max( absPoint.x, max( absPoint.y, absPoint.z ) );
|
|
140
|
-
vec3 normal = vNorm;
|
|
141
|
-
|
|
142
|
-
#if defined( USE_NORMALMAP ) && defined( USE_TANGENT )
|
|
143
|
-
|
|
144
|
-
// some provided tangents can be malformed (0, 0, 0) causing the normal to be degenerate
|
|
145
|
-
// resulting in NaNs and slow path tracing.
|
|
146
|
-
if ( length( vTan.xyz ) > 0.0 ) {
|
|
147
|
-
|
|
148
|
-
vec2 uv = vUv;
|
|
149
|
-
vec3 tangent = normalize( vTan.xyz );
|
|
150
|
-
vec3 bitangent = normalize( cross( normal, tangent ) * vTan.w );
|
|
151
|
-
mat3 vTBN = mat3( tangent, bitangent, normal );
|
|
152
|
-
|
|
153
|
-
vec3 texNormal = texture2D( normalMap, uv ).xyz * 2.0 - 1.0;
|
|
154
|
-
texNormal.xy *= normalScale;
|
|
155
|
-
normal = vTBN * texNormal;
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
#endif
|
|
160
|
-
|
|
161
|
-
normal *= gl_FrontFacing ? 1.0 : - 1.0;
|
|
162
|
-
|
|
163
|
-
vec3 rayOrigin = vPos + faceNormal * ( maxPoint + 1.0 ) * RAY_OFFSET;
|
|
164
|
-
float accumulated = 0.0;
|
|
165
|
-
for ( int i = 0; i < SAMPLES; i ++ ) {
|
|
166
|
-
|
|
167
|
-
// sample the cosine weighted hemisphere and discard the sample if it's below
|
|
168
|
-
// the geometric surface
|
|
169
|
-
vec3 rayDirection = sampleHemisphere( normalize( normal ), rand4().xy );
|
|
170
|
-
|
|
171
|
-
// check if we hit the mesh and its within the specified radius
|
|
172
|
-
float side = 1.0;
|
|
173
|
-
float dist = 0.0;
|
|
174
|
-
vec3 barycoord = vec3( 0.0 );
|
|
175
|
-
vec3 outNormal = vec3( 0.0 );
|
|
176
|
-
uvec4 faceIndices = uvec4( 0u );
|
|
177
|
-
|
|
178
|
-
// if the ray is above the geometry surface, and it doesn't hit another surface within the specified radius then
|
|
179
|
-
// we consider it lit
|
|
180
|
-
if (
|
|
181
|
-
dot( rayDirection, faceNormal ) > 0.0 &&
|
|
182
|
-
(
|
|
183
|
-
! bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, outNormal, barycoord, side, dist ) ||
|
|
184
|
-
dist
|
|
185
|
-
)
|
|
186
|
-
) {
|
|
187
|
-
|
|
188
|
-
accumulated += 1.0;
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
gl_FragColor.rgb = vec3( accumulated / float( SAMPLES ) );
|
|
195
|
-
gl_FragColor.a = 1.0;
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
`
|
|
200
|
-
|
|
201
|
-
} );
|
|
202
|
-
|
|
203
|
-
this.setValues( parameters );
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
}
|
|
1
|
+
import { TangentSpaceNormalMap, Vector2 } from 'three';
|
|
2
|
+
import { MaterialBase } from '../MaterialBase.js';
|
|
3
|
+
import { MeshBVHUniformStruct, shaderStructs, shaderIntersectFunction } from 'three-mesh-bvh';
|
|
4
|
+
|
|
5
|
+
import { materialStructGLSL } from '../../shader/structs/materialStruct.glsl.js';
|
|
6
|
+
import { shapeSamplingGLSL } from '../../shader/sampling/shapeSampling.glsl.js';
|
|
7
|
+
import { pcgGLSL } from '../../shader/rand/pcg.glsl.js';
|
|
8
|
+
|
|
9
|
+
export class AmbientOcclusionMaterial extends MaterialBase {
|
|
10
|
+
|
|
11
|
+
get normalMap() {
|
|
12
|
+
|
|
13
|
+
return this.uniforms.normalMap.value;
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
set normalMap( v ) {
|
|
18
|
+
|
|
19
|
+
this.uniforms.normalMap.value = v;
|
|
20
|
+
this.setDefine( 'USE_NORMALMAP', v ? null : '' );
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get normalMapType() {
|
|
25
|
+
|
|
26
|
+
return TangentSpaceNormalMap;
|
|
27
|
+
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
set normalMapType( v ) {
|
|
31
|
+
|
|
32
|
+
if ( v !== TangentSpaceNormalMap ) {
|
|
33
|
+
|
|
34
|
+
throw new Error( 'AmbientOcclusionMaterial: Only tangent space normal map are supported' );
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
constructor( parameters ) {
|
|
41
|
+
|
|
42
|
+
super( {
|
|
43
|
+
|
|
44
|
+
defines: {
|
|
45
|
+
SAMPLES: 10,
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
uniforms: {
|
|
49
|
+
bvh: { value: new MeshBVHUniformStruct() },
|
|
50
|
+
radius: { value: 1.0 },
|
|
51
|
+
seed: { value: 0 },
|
|
52
|
+
|
|
53
|
+
normalMap: { value: null },
|
|
54
|
+
normalScale: { value: new Vector2( 1, 1 ) },
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
vertexShader: /* glsl */`
|
|
58
|
+
|
|
59
|
+
varying vec3 vNorm;
|
|
60
|
+
varying vec3 vPos;
|
|
61
|
+
|
|
62
|
+
#if defined(USE_NORMALMAP) && defined(USE_TANGENT)
|
|
63
|
+
|
|
64
|
+
varying vec2 vUv;
|
|
65
|
+
varying vec4 vTan;
|
|
66
|
+
|
|
67
|
+
#endif
|
|
68
|
+
|
|
69
|
+
void main() {
|
|
70
|
+
|
|
71
|
+
vec4 mvPosition = vec4( position, 1.0 );
|
|
72
|
+
mvPosition = modelViewMatrix * mvPosition;
|
|
73
|
+
gl_Position = projectionMatrix * mvPosition;
|
|
74
|
+
|
|
75
|
+
mat3 modelNormalMatrix = transpose( inverse( mat3( modelMatrix ) ) );
|
|
76
|
+
vNorm = normalize( modelNormalMatrix * normal );
|
|
77
|
+
vPos = ( modelMatrix * vec4( position, 1.0 ) ).xyz;
|
|
78
|
+
|
|
79
|
+
#if defined( USE_NORMALMAP ) && defined( USE_TANGENT )
|
|
80
|
+
|
|
81
|
+
vUv = uv;
|
|
82
|
+
vTan = tangent;
|
|
83
|
+
|
|
84
|
+
#endif
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
`,
|
|
89
|
+
|
|
90
|
+
fragmentShader: /* glsl */`
|
|
91
|
+
#define RAY_OFFSET 1e-4
|
|
92
|
+
|
|
93
|
+
precision highp isampler2D;
|
|
94
|
+
precision highp usampler2D;
|
|
95
|
+
precision highp sampler2DArray;
|
|
96
|
+
#include <common>
|
|
97
|
+
#include <cube_uv_reflection_fragment>
|
|
98
|
+
|
|
99
|
+
// bvh
|
|
100
|
+
${ shaderStructs }
|
|
101
|
+
${ shaderIntersectFunction }
|
|
102
|
+
|
|
103
|
+
// uniform structs
|
|
104
|
+
${ materialStructGLSL }
|
|
105
|
+
|
|
106
|
+
// rand
|
|
107
|
+
${ pcgGLSL }
|
|
108
|
+
|
|
109
|
+
// common
|
|
110
|
+
${ shapeSamplingGLSL }
|
|
111
|
+
|
|
112
|
+
uniform BVH bvh;
|
|
113
|
+
uniform int seed;
|
|
114
|
+
uniform float radius;
|
|
115
|
+
|
|
116
|
+
varying vec3 vNorm;
|
|
117
|
+
varying vec3 vPos;
|
|
118
|
+
|
|
119
|
+
#if defined(USE_NORMALMAP) && defined(USE_TANGENT)
|
|
120
|
+
|
|
121
|
+
uniform sampler2D normalMap;
|
|
122
|
+
uniform vec2 normalScale;
|
|
123
|
+
varying vec2 vUv;
|
|
124
|
+
varying vec4 vTan;
|
|
125
|
+
|
|
126
|
+
#endif
|
|
127
|
+
|
|
128
|
+
void main() {
|
|
129
|
+
|
|
130
|
+
rng_initialize( gl_FragCoord.xy, seed );
|
|
131
|
+
|
|
132
|
+
// compute the flat face surface normal
|
|
133
|
+
vec3 fdx = vec3( dFdx( vPos.x ), dFdx( vPos.y ), dFdx( vPos.z ) );
|
|
134
|
+
vec3 fdy = vec3( dFdy( vPos.x ), dFdy( vPos.y ), dFdy( vPos.z ) );
|
|
135
|
+
vec3 faceNormal = normalize( cross( fdx, fdy ) );
|
|
136
|
+
|
|
137
|
+
// find the max component to scale the offset to account for floating point error
|
|
138
|
+
vec3 absPoint = abs( vPos );
|
|
139
|
+
float maxPoint = max( absPoint.x, max( absPoint.y, absPoint.z ) );
|
|
140
|
+
vec3 normal = vNorm;
|
|
141
|
+
|
|
142
|
+
#if defined( USE_NORMALMAP ) && defined( USE_TANGENT )
|
|
143
|
+
|
|
144
|
+
// some provided tangents can be malformed (0, 0, 0) causing the normal to be degenerate
|
|
145
|
+
// resulting in NaNs and slow path tracing.
|
|
146
|
+
if ( length( vTan.xyz ) > 0.0 ) {
|
|
147
|
+
|
|
148
|
+
vec2 uv = vUv;
|
|
149
|
+
vec3 tangent = normalize( vTan.xyz );
|
|
150
|
+
vec3 bitangent = normalize( cross( normal, tangent ) * vTan.w );
|
|
151
|
+
mat3 vTBN = mat3( tangent, bitangent, normal );
|
|
152
|
+
|
|
153
|
+
vec3 texNormal = texture2D( normalMap, uv ).xyz * 2.0 - 1.0;
|
|
154
|
+
texNormal.xy *= normalScale;
|
|
155
|
+
normal = vTBN * texNormal;
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
#endif
|
|
160
|
+
|
|
161
|
+
normal *= gl_FrontFacing ? 1.0 : - 1.0;
|
|
162
|
+
|
|
163
|
+
vec3 rayOrigin = vPos + faceNormal * ( maxPoint + 1.0 ) * RAY_OFFSET;
|
|
164
|
+
float accumulated = 0.0;
|
|
165
|
+
for ( int i = 0; i < SAMPLES; i ++ ) {
|
|
166
|
+
|
|
167
|
+
// sample the cosine weighted hemisphere and discard the sample if it's below
|
|
168
|
+
// the geometric surface
|
|
169
|
+
vec3 rayDirection = sampleHemisphere( normalize( normal ), rand4().xy );
|
|
170
|
+
|
|
171
|
+
// check if we hit the mesh and its within the specified radius
|
|
172
|
+
float side = 1.0;
|
|
173
|
+
float dist = 0.0;
|
|
174
|
+
vec3 barycoord = vec3( 0.0 );
|
|
175
|
+
vec3 outNormal = vec3( 0.0 );
|
|
176
|
+
uvec4 faceIndices = uvec4( 0u );
|
|
177
|
+
|
|
178
|
+
// if the ray is above the geometry surface, and it doesn't hit another surface within the specified radius then
|
|
179
|
+
// we consider it lit
|
|
180
|
+
if (
|
|
181
|
+
dot( rayDirection, faceNormal ) > 0.0 &&
|
|
182
|
+
(
|
|
183
|
+
! bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, outNormal, barycoord, side, dist ) ||
|
|
184
|
+
dist >= radius
|
|
185
|
+
)
|
|
186
|
+
) {
|
|
187
|
+
|
|
188
|
+
accumulated += 1.0;
|
|
189
|
+
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
gl_FragColor.rgb = vec3( accumulated / float( SAMPLES ) );
|
|
195
|
+
gl_FragColor.a = 1.0;
|
|
196
|
+
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
`
|
|
200
|
+
|
|
201
|
+
} );
|
|
202
|
+
|
|
203
|
+
this.setValues( parameters );
|
|
204
|
+
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { Color, MeshStandardMaterial } from 'three';
|
|
2
|
-
|
|
3
|
-
export class FogVolumeMaterial extends MeshStandardMaterial {
|
|
4
|
-
|
|
5
|
-
constructor( params ) {
|
|
6
|
-
|
|
7
|
-
super( params );
|
|
8
|
-
|
|
9
|
-
this.isFogVolumeMaterial = true;
|
|
10
|
-
|
|
11
|
-
this.density = 0.015;
|
|
12
|
-
this.emissive = new Color();
|
|
13
|
-
this.emissiveIntensity = 0.0;
|
|
14
|
-
this.opacity = 0.15;
|
|
15
|
-
this.transparent = true;
|
|
16
|
-
this.roughness = 1.0;
|
|
17
|
-
this.metalness = 0.0;
|
|
18
|
-
|
|
19
|
-
this.setValues( params );
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
}
|
|
1
|
+
import { Color, MeshStandardMaterial } from 'three';
|
|
2
|
+
|
|
3
|
+
export class FogVolumeMaterial extends MeshStandardMaterial {
|
|
4
|
+
|
|
5
|
+
constructor( params ) {
|
|
6
|
+
|
|
7
|
+
super( params );
|
|
8
|
+
|
|
9
|
+
this.isFogVolumeMaterial = true;
|
|
10
|
+
|
|
11
|
+
this.density = 0.015;
|
|
12
|
+
this.emissive = new Color();
|
|
13
|
+
this.emissiveIntensity = 0.0;
|
|
14
|
+
this.opacity = 0.15;
|
|
15
|
+
this.transparent = true;
|
|
16
|
+
this.roughness = 1.0;
|
|
17
|
+
this.metalness = 0.0;
|
|
18
|
+
|
|
19
|
+
this.setValues( params );
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Camera } from 'three';
|
|
2
|
-
|
|
3
|
-
export class EquirectCamera extends Camera {
|
|
4
|
-
|
|
5
|
-
constructor() {
|
|
6
|
-
|
|
7
|
-
super();
|
|
8
|
-
|
|
9
|
-
this.isEquirectCamera = true;
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
}
|
|
1
|
+
import { Camera } from 'three';
|
|
2
|
+
|
|
3
|
+
export class EquirectCamera extends Camera {
|
|
4
|
+
|
|
5
|
+
constructor() {
|
|
6
|
+
|
|
7
|
+
super();
|
|
8
|
+
|
|
9
|
+
this.isEquirectCamera = true;
|
|
10
|
+
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
}
|