three-gpu-pathtracer 0.0.5 → 0.0.7

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.
Files changed (44) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +815 -728
  3. package/build/index.module.js +5474 -3706
  4. package/build/index.module.js.map +1 -1
  5. package/build/index.umd.cjs +5479 -3704
  6. package/build/index.umd.cjs.map +1 -1
  7. package/package.json +68 -60
  8. package/src/core/DynamicPathTracingSceneGenerator.js +119 -111
  9. package/src/core/MaterialReducer.js +256 -256
  10. package/src/core/PathTracingRenderer.js +270 -255
  11. package/src/core/PathTracingSceneGenerator.js +4 -3
  12. package/src/index.js +35 -26
  13. package/src/materials/AlphaDisplayMaterial.js +48 -48
  14. package/src/materials/AmbientOcclusionMaterial.js +197 -197
  15. package/src/materials/BlendMaterial.js +67 -67
  16. package/src/materials/DenoiseMaterial.js +142 -0
  17. package/src/materials/GraphMaterial.js +243 -0
  18. package/src/materials/LambertPathTracingMaterial.js +285 -285
  19. package/src/materials/MaterialBase.js +56 -56
  20. package/src/materials/PhysicalPathTracingMaterial.js +970 -848
  21. package/src/{core → objects}/EquirectCamera.js +13 -13
  22. package/src/{core → objects}/PhysicalCamera.js +28 -28
  23. package/src/objects/PhysicalSpotLight.js +14 -0
  24. package/src/objects/ShapedAreaLight.js +12 -0
  25. package/src/shader/shaderEnvMapSampling.js +59 -59
  26. package/src/shader/shaderGGXFunctions.js +100 -108
  27. package/src/shader/shaderIridescenceFunctions.js +130 -0
  28. package/src/shader/shaderLightSampling.js +231 -87
  29. package/src/shader/shaderMaterialSampling.js +542 -501
  30. package/src/shader/shaderSheenFunctions.js +98 -0
  31. package/src/shader/shaderStructs.js +321 -191
  32. package/src/shader/shaderUtils.js +364 -287
  33. package/src/uniforms/EquirectHdrInfoUniform.js +259 -263
  34. package/src/uniforms/IESProfilesTexture.js +100 -0
  35. package/src/uniforms/LightsInfoUniformStruct.js +162 -0
  36. package/src/uniforms/MaterialsTexture.js +426 -319
  37. package/src/uniforms/PhysicalCameraUniform.js +36 -36
  38. package/src/uniforms/RenderTarget2DArray.js +93 -93
  39. package/src/utils/BlurredEnvMapGenerator.js +113 -113
  40. package/src/utils/GeometryPreparationUtils.js +21 -1
  41. package/src/utils/IESLoader.js +325 -0
  42. package/src/utils/UVUnwrapper.js +101 -101
  43. package/src/workers/PathTracingSceneWorker.js +42 -41
  44. package/src/uniforms/LightsTexture.js +0 -83
@@ -0,0 +1,142 @@
1
+ import { NoBlending } from 'three';
2
+ import { MaterialBase } from './MaterialBase.js';
3
+
4
+ export class DenoiseMaterial extends MaterialBase {
5
+
6
+ constructor( parameters ) {
7
+
8
+ super( {
9
+
10
+ blending: NoBlending,
11
+
12
+ transparent: false,
13
+
14
+ depthWrite: false,
15
+
16
+ depthTest: false,
17
+
18
+ defines: {
19
+
20
+ USE_SLIDER: 0,
21
+
22
+ },
23
+
24
+ uniforms: {
25
+
26
+ sigma: { value: 5.0 },
27
+ threshold: { value: 0.03 },
28
+ kSigma: { value: 1.0 },
29
+
30
+ map: { value: null },
31
+
32
+ },
33
+
34
+ vertexShader: /* glsl */`
35
+
36
+ varying vec2 vUv;
37
+
38
+ void main() {
39
+
40
+ vUv = uv;
41
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
42
+
43
+ }
44
+
45
+ `,
46
+
47
+ fragmentShader: /* glsl */`
48
+
49
+ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
50
+ // Copyright (c) 2018-2019 Michele Morrone
51
+ // All rights reserved.
52
+ //
53
+ // https://michelemorrone.eu - https://BrutPitt.com
54
+ //
55
+ // me@michelemorrone.eu - brutpitt@gmail.com
56
+ // twitter: @BrutPitt - github: BrutPitt
57
+ //
58
+ // https://github.com/BrutPitt/glslSmartDeNoise/
59
+ //
60
+ // This software is distributed under the terms of the BSD 2-Clause license
61
+ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62
+
63
+ uniform sampler2D map;
64
+
65
+ uniform float sigma;
66
+ uniform float threshold;
67
+ uniform float kSigma;
68
+
69
+ varying vec2 vUv;
70
+
71
+ #define INV_SQRT_OF_2PI 0.39894228040143267793994605993439
72
+ #define INV_PI 0.31830988618379067153776752674503
73
+
74
+ // Parameters:
75
+ // sampler2D tex - sampler image / texture
76
+ // vec2 uv - actual fragment coord
77
+ // float sigma > 0 - sigma Standard Deviation
78
+ // float kSigma >= 0 - sigma coefficient
79
+ // kSigma * sigma --> radius of the circular kernel
80
+ // float threshold - edge sharpening threshold
81
+ vec4 smartDeNoise( sampler2D tex, vec2 uv, float sigma, float kSigma, float threshold ) {
82
+
83
+ float radius = round( kSigma * sigma );
84
+ float radQ = radius * radius;
85
+
86
+ float invSigmaQx2 = 0.5 / ( sigma * sigma );
87
+ float invSigmaQx2PI = INV_PI * invSigmaQx2;
88
+
89
+ float invThresholdSqx2 = 0.5 / ( threshold * threshold );
90
+ float invThresholdSqrt2PI = INV_SQRT_OF_2PI / threshold;
91
+
92
+ vec4 centrPx = texture2D( tex, uv );
93
+ centrPx.rgb *= centrPx.a;
94
+
95
+ float zBuff = 0.0;
96
+ vec4 aBuff = vec4( 0.0 );
97
+ vec2 size = vec2( textureSize( tex, 0 ) );
98
+
99
+ vec2 d;
100
+ for ( d.x = - radius; d.x <= radius; d.x ++ ) {
101
+
102
+ float pt = sqrt( radQ - d.x * d.x );
103
+
104
+ for ( d.y = - pt; d.y <= pt; d.y ++ ) {
105
+
106
+ float blurFactor = exp( - dot( d, d ) * invSigmaQx2 ) * invSigmaQx2PI;
107
+
108
+ vec4 walkPx = texture2D( tex, uv + d / size );
109
+ walkPx.rgb *= walkPx.a;
110
+
111
+ vec4 dC = walkPx - centrPx;
112
+ float deltaFactor = exp( - dot( dC.rgba, dC.rgba ) * invThresholdSqx2 ) * invThresholdSqrt2PI * blurFactor;
113
+
114
+ zBuff += deltaFactor;
115
+ aBuff += deltaFactor * walkPx;
116
+
117
+ }
118
+
119
+ }
120
+
121
+ return aBuff / zBuff;
122
+
123
+ }
124
+
125
+ void main() {
126
+
127
+ gl_FragColor = smartDeNoise( map, vec2( vUv.x, vUv.y ), sigma, kSigma, threshold );
128
+ #include <tonemapping_fragment>
129
+ #include <encodings_fragment>
130
+ #include <premultiplied_alpha_fragment>
131
+
132
+ }
133
+
134
+ `
135
+
136
+ } );
137
+
138
+ this.setValues( parameters );
139
+
140
+ }
141
+
142
+ }
@@ -0,0 +1,243 @@
1
+ import { NoBlending, Color, Vector2, Vector4 } from 'three';
2
+ import { MaterialBase } from './MaterialBase.js';
3
+
4
+ export class GraphMaterial extends MaterialBase {
5
+
6
+ get graphFunctionSnippet() {
7
+
8
+ return this._graphFunctionSnippet;
9
+
10
+ }
11
+
12
+ set graphFunctionSnippet( v ) {
13
+
14
+ this._graphFunctionSnippet = v;
15
+
16
+ }
17
+
18
+ constructor( parameters ) {
19
+
20
+ super( {
21
+
22
+ blending: NoBlending,
23
+
24
+ transparent: false,
25
+
26
+ depthWrite: false,
27
+
28
+ depthTest: false,
29
+
30
+ defines: {
31
+
32
+ USE_SLIDER: 0,
33
+
34
+ },
35
+
36
+ uniforms: {
37
+
38
+ dim: { value: true },
39
+ thickness: { value: 1 },
40
+ graphCount: { value: 4 },
41
+ graphDisplay: { value: new Vector4( 1.0, 1.0, 1.0, 1.0 ) },
42
+ overlay: { value: true },
43
+ xRange: { value: new Vector2( - 2.0, 2.0 ) },
44
+ yRange: { value: new Vector2( - 2.0, 2.0 ) },
45
+ colors: { value: [
46
+ new Color( 0xe91e63 ).convertSRGBToLinear(),
47
+ new Color( 0x4caf50 ).convertSRGBToLinear(),
48
+ new Color( 0x03a9f4 ).convertSRGBToLinear(),
49
+ new Color( 0xffc107 ).convertSRGBToLinear(),
50
+ ] },
51
+
52
+ },
53
+
54
+ vertexShader: /* glsl */`
55
+
56
+ varying vec2 vUv;
57
+
58
+ void main() {
59
+
60
+ vUv = uv;
61
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
62
+
63
+ }
64
+
65
+ `,
66
+
67
+ fragmentShader: /* glsl */`
68
+ varying vec2 vUv;
69
+ uniform bool overlay;
70
+ uniform bool dim;
71
+ uniform bvec4 graphDisplay;
72
+ uniform float graphCount;
73
+ uniform float thickness;
74
+ uniform vec2 xRange;
75
+ uniform vec2 yRange;
76
+ uniform vec3 colors[ 4 ];
77
+
78
+ __FUNCTION_CONTENT__
79
+
80
+ float map( float _min, float _max, float v ) {
81
+
82
+ float len = _max - _min;
83
+ return _min + len * v;
84
+
85
+ }
86
+
87
+ vec3 getBackground( vec2 point, float steepness ) {
88
+
89
+ vec2 pw = fwidth( point );
90
+ vec2 halfWidth = pw * 0.5;
91
+
92
+ // x, y axes
93
+ vec2 distToZero = smoothstep(
94
+ - halfWidth * 0.5,
95
+ halfWidth * 0.5,
96
+ abs( point.xy ) - pw
97
+ );
98
+
99
+ // 1 unit markers
100
+ vec2 temp;
101
+ vec2 modAxis = abs( modf( point + vec2( 0.5 ), temp ) ) - 0.5;
102
+ vec2 distToAxis = smoothstep(
103
+ - halfWidth,
104
+ halfWidth,
105
+ abs( modAxis.xy ) - pw * 0.5
106
+ );
107
+
108
+ // if we're at a chart boundary then remove the artifacts
109
+ if ( abs( pw.y ) > steepness * 0.5 ) {
110
+
111
+ distToZero.y = 1.0;
112
+ distToAxis.y = 1.0;
113
+
114
+ }
115
+
116
+ // mix colors into a background color
117
+ float axisIntensity = 1.0 - min( distToZero.x, distToZero.y );
118
+ float markerIntensity = 1.0 - min( distToAxis.x, distToAxis.y );
119
+
120
+ vec3 markerColor = mix( vec3( 0.005 ), vec3( 0.05 ), markerIntensity );
121
+ vec3 backgroundColor = mix( markerColor, vec3( 0.2 ), axisIntensity );
122
+ return backgroundColor;
123
+
124
+ }
125
+
126
+ void main() {
127
+
128
+ // from uniforms
129
+ float sectionCount = overlay ? 1.0 : graphCount;
130
+ float yWidth = abs( yRange.y - yRange.x );
131
+
132
+ // separate into sections
133
+ float _section;
134
+ float sectionY = modf( sectionCount * vUv.y, _section );
135
+ int section = int( sectionCount - _section - 1.0 );
136
+
137
+ // get the current point
138
+ vec2 point = vec2(
139
+ map( xRange.x, xRange.y, vUv.x ),
140
+ map( yRange.x, yRange.y, sectionY )
141
+ );
142
+
143
+ // get the results
144
+ vec4 result = graphFunction( point.x );
145
+ vec4 delta = result - vec4( point.y );
146
+ vec4 halfDdf = fwidth( delta ) * 0.5;
147
+ if ( fwidth( point.y ) > yWidth * 0.5 ) {
148
+
149
+ halfDdf = vec4( 0.0 );
150
+
151
+ }
152
+
153
+ // graph display intensity
154
+ vec4 graph = smoothstep( - halfDdf, halfDdf, abs( delta ) - thickness * halfDdf );
155
+
156
+ // initialize the background
157
+ gl_FragColor.rgb = getBackground( point, yWidth );
158
+ gl_FragColor.a = 1.0;
159
+
160
+ if ( dim && ( point.x < 0.0 || point.y < 0.0 ) ) {
161
+
162
+ graph = mix(
163
+ vec4( 1.0 ),
164
+ graph,
165
+ 0.05
166
+ );
167
+
168
+ }
169
+
170
+ // color the charts
171
+ if ( sectionCount > 1.0 ) {
172
+
173
+ if ( graphDisplay[ section ] ) {
174
+
175
+ gl_FragColor.rgb = mix(
176
+ colors[ section ],
177
+ gl_FragColor.rgb,
178
+ graph[ section ]
179
+ );
180
+
181
+ }
182
+
183
+ } else {
184
+
185
+ for ( int i = 0; i < int( graphCount ); i ++ ) {
186
+
187
+ if ( graphDisplay[ i ] ) {
188
+
189
+ gl_FragColor.rgb = mix(
190
+ colors[ i ],
191
+ gl_FragColor.rgb,
192
+ graph[ i ]
193
+ );
194
+
195
+ }
196
+
197
+ }
198
+
199
+ }
200
+
201
+ #include <encodings_fragment>
202
+
203
+ }
204
+
205
+ `
206
+
207
+ } );
208
+
209
+
210
+ this._graphFunctionSnippet = /* glsl */`
211
+ vec4 graphFunctionSnippet( float x ) {
212
+
213
+ return vec4(
214
+ sin( x * 3.1415926535 ),
215
+ cos( x ),
216
+ 0.0,
217
+ 0.0
218
+ );
219
+
220
+ }
221
+ `;
222
+
223
+ this.setValues( parameters );
224
+
225
+ }
226
+
227
+ onBeforeCompile( shader ) {
228
+
229
+ shader.fragmentShader = shader.fragmentShader.replace(
230
+ '__FUNCTION_CONTENT__',
231
+ this._graphFunctionSnippet,
232
+ );
233
+ return shader;
234
+
235
+ }
236
+
237
+ customProgramCacheKey() {
238
+
239
+ return this._graphFunctionSnippet;
240
+
241
+ }
242
+
243
+ }