three-gpu-pathtracer 0.0.5 → 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.
Files changed (42) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +781 -728
  3. package/build/index.module.js +5223 -3956
  4. package/build/index.module.js.map +1 -1
  5. package/build/index.umd.cjs +5226 -3954
  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 +255 -255
  11. package/src/core/PathTracingSceneGenerator.js +68 -68
  12. package/src/index.js +33 -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/LambertPathTracingMaterial.js +285 -285
  17. package/src/materials/MaterialBase.js +56 -56
  18. package/src/materials/PhysicalPathTracingMaterial.js +922 -848
  19. package/src/{core → objects}/EquirectCamera.js +13 -13
  20. package/src/{core → objects}/PhysicalCamera.js +28 -28
  21. package/src/objects/PhysicalSpotLight.js +14 -0
  22. package/src/objects/ShapedAreaLight.js +12 -0
  23. package/src/shader/shaderEnvMapSampling.js +59 -59
  24. package/src/shader/shaderGGXFunctions.js +108 -108
  25. package/src/shader/shaderIridescenceFunctions.js +130 -0
  26. package/src/shader/shaderLightSampling.js +231 -87
  27. package/src/shader/shaderMaterialSampling.js +546 -501
  28. package/src/shader/shaderSheenFunctions.js +98 -0
  29. package/src/shader/shaderStructs.js +307 -191
  30. package/src/shader/shaderUtils.js +350 -287
  31. package/src/uniforms/EquirectHdrInfoUniform.js +259 -263
  32. package/src/uniforms/IESProfilesTexture.js +100 -0
  33. package/src/uniforms/LightsInfoUniformStruct.js +162 -0
  34. package/src/uniforms/MaterialsTexture.js +406 -319
  35. package/src/uniforms/PhysicalCameraUniform.js +36 -36
  36. package/src/uniforms/RenderTarget2DArray.js +93 -93
  37. package/src/utils/BlurredEnvMapGenerator.js +113 -113
  38. package/src/utils/GeometryPreparationUtils.js +194 -194
  39. package/src/utils/IESLoader.js +325 -0
  40. package/src/utils/UVUnwrapper.js +101 -101
  41. package/src/workers/PathTracingSceneWorker.js +42 -41
  42. package/src/uniforms/LightsTexture.js +0 -83
@@ -0,0 +1,162 @@
1
+ import { DataTexture, RGBAFormat, ClampToEdgeWrapping, FloatType, Vector3, Quaternion, Matrix4 } from 'three';
2
+
3
+ const LIGHT_PIXELS = 6;
4
+ const RECT_AREA_LIGHT = 0;
5
+ const CIRC_AREA_LIGHT = 1;
6
+ const SPOT_LIGHT = 2;
7
+ export class LightsInfoUniformStruct {
8
+
9
+ constructor() {
10
+
11
+ const tex = new DataTexture( new Float32Array( 4 ), 1, 1 );
12
+ tex.format = RGBAFormat;
13
+ tex.type = FloatType;
14
+ tex.wrapS = ClampToEdgeWrapping;
15
+ tex.wrapT = ClampToEdgeWrapping;
16
+ tex.generateMipmaps = false;
17
+
18
+ this.tex = tex;
19
+ this.count = 0;
20
+
21
+ }
22
+
23
+ updateFrom( lights, iesTextures = [] ) {
24
+
25
+ const tex = this.tex;
26
+ const pixelCount = Math.max( lights.length * LIGHT_PIXELS, 1 );
27
+ const dimension = Math.ceil( Math.sqrt( pixelCount ) );
28
+
29
+ if ( tex.image.width !== dimension ) {
30
+
31
+ tex.dispose();
32
+
33
+ tex.image.data = new Float32Array( dimension * dimension * 4 );
34
+ tex.image.width = dimension;
35
+ tex.image.height = dimension;
36
+
37
+ }
38
+
39
+ const floatArray = tex.image.data;
40
+
41
+ const u = new Vector3();
42
+ const v = new Vector3();
43
+ const m = new Matrix4();
44
+ const worldQuaternion = new Quaternion();
45
+ const eye = new Vector3();
46
+ const target = new Vector3();
47
+ const up = new Vector3();
48
+
49
+ for ( let i = 0, l = lights.length; i < l; i ++ ) {
50
+
51
+ const l = lights[ i ];
52
+
53
+ const baseIndex = i * LIGHT_PIXELS * 4;
54
+ let index = 0;
55
+
56
+ // sample 1
57
+ // position
58
+ l.getWorldPosition( v );
59
+ floatArray[ baseIndex + ( index ++ ) ] = v.x;
60
+ floatArray[ baseIndex + ( index ++ ) ] = v.y;
61
+ floatArray[ baseIndex + ( index ++ ) ] = v.z;
62
+
63
+ // type
64
+ let type = RECT_AREA_LIGHT;
65
+ if ( l.isRectAreaLight && l.isCircular ) type = CIRC_AREA_LIGHT;
66
+ else if ( l.isSpotLight ) type = SPOT_LIGHT;
67
+ floatArray[ baseIndex + ( index ++ ) ] = type;
68
+
69
+ // sample 2
70
+ // color
71
+ floatArray[ baseIndex + ( index ++ ) ] = l.color.r;
72
+ floatArray[ baseIndex + ( index ++ ) ] = l.color.g;
73
+ floatArray[ baseIndex + ( index ++ ) ] = l.color.b;
74
+
75
+ // intensity
76
+ floatArray[ baseIndex + ( index ++ ) ] = l.intensity;
77
+
78
+ l.getWorldQuaternion( worldQuaternion );
79
+
80
+ if ( l.isRectAreaLight ) {
81
+
82
+ // sample 3
83
+ // u vector
84
+ u.set( l.width, 0, 0 ).applyQuaternion( worldQuaternion );
85
+
86
+ floatArray[ baseIndex + ( index ++ ) ] = u.x;
87
+ floatArray[ baseIndex + ( index ++ ) ] = u.y;
88
+ floatArray[ baseIndex + ( index ++ ) ] = u.z;
89
+ index ++;
90
+
91
+ // sample 4
92
+ // v vector
93
+ v.set( 0, l.height, 0 ).applyQuaternion( worldQuaternion );
94
+
95
+ floatArray[ baseIndex + ( index ++ ) ] = v.x;
96
+ floatArray[ baseIndex + ( index ++ ) ] = v.y;
97
+ floatArray[ baseIndex + ( index ++ ) ] = v.z;
98
+
99
+ // area
100
+ floatArray[ baseIndex + ( index ++ ) ] = u.cross( v ).length() * ( l.isCircular ? ( Math.PI / 4.0 ) : 1.0 );
101
+
102
+ } else if ( l.isSpotLight ) {
103
+
104
+ const radius = l.radius;
105
+ eye.setFromMatrixPosition( l.matrixWorld );
106
+ target.setFromMatrixPosition( l.target.matrixWorld );
107
+ m.lookAt( eye, target, up );
108
+ worldQuaternion.setFromRotationMatrix( m );
109
+
110
+ // sample 3
111
+ // u vector
112
+ u.set( 1, 0, 0 ).applyQuaternion( worldQuaternion );
113
+
114
+ floatArray[ baseIndex + ( index ++ ) ] = u.x;
115
+ floatArray[ baseIndex + ( index ++ ) ] = u.y;
116
+ floatArray[ baseIndex + ( index ++ ) ] = u.z;
117
+ index ++;
118
+
119
+ // sample 4
120
+ // v vector
121
+ v.set( 0, 1, 0 ).applyQuaternion( worldQuaternion );
122
+
123
+ floatArray[ baseIndex + ( index ++ ) ] = v.x;
124
+ floatArray[ baseIndex + ( index ++ ) ] = v.y;
125
+ floatArray[ baseIndex + ( index ++ ) ] = v.z;
126
+
127
+ // area
128
+ floatArray[ baseIndex + ( index ++ ) ] = Math.PI * radius * radius;
129
+
130
+ // sample 5
131
+ // radius
132
+ floatArray[ baseIndex + ( index ++ ) ] = radius;
133
+
134
+ // near
135
+ floatArray[ baseIndex + ( index ++ ) ] = l.shadow.camera.near;
136
+
137
+ // decay
138
+ floatArray[ baseIndex + ( index ++ ) ] = l.decay;
139
+
140
+ // distance
141
+ floatArray[ baseIndex + ( index ++ ) ] = l.distance;
142
+
143
+ // sample 6
144
+ // coneCos
145
+ floatArray[ baseIndex + ( index ++ ) ] = Math.cos( l.angle );
146
+
147
+ // penumbraCos
148
+ floatArray[ baseIndex + ( index ++ ) ] = Math.cos( l.angle * ( 1 - l.penumbra ) );
149
+
150
+ // iesProfile
151
+ floatArray[ baseIndex + ( index ++ ) ] = iesTextures.indexOf( l.iesTexture );
152
+
153
+ }
154
+
155
+ }
156
+
157
+ tex.needsUpdate = true;
158
+ this.count = lights.length;
159
+
160
+ }
161
+
162
+ }