@gnsx/three 0.184.10 → 0.184.11
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.
|
@@ -7,9 +7,14 @@ import {
|
|
|
7
7
|
} from 'three';
|
|
8
8
|
import { NodeMaterial } from 'three/webgpu';
|
|
9
9
|
import {
|
|
10
|
+
abs,
|
|
10
11
|
cubeTexture,
|
|
11
12
|
Fn,
|
|
12
|
-
|
|
13
|
+
max,
|
|
14
|
+
normalLocal,
|
|
15
|
+
positionLocal,
|
|
16
|
+
select,
|
|
17
|
+
vec3,
|
|
13
18
|
vec4
|
|
14
19
|
} from 'three/tsl';
|
|
15
20
|
|
|
@@ -17,7 +22,41 @@ function createNodeMaterial( texture ) {
|
|
|
17
22
|
|
|
18
23
|
const fragmentNode = Fn( () => {
|
|
19
24
|
|
|
20
|
-
|
|
25
|
+
// Get local position and normal
|
|
26
|
+
const localPos = positionLocal;
|
|
27
|
+
const localNormal = normalLocal;
|
|
28
|
+
|
|
29
|
+
// Get absolute normal components to determine dominant axis
|
|
30
|
+
const absNormal = abs( localNormal );
|
|
31
|
+
const maxComp = max( max( absNormal.x, absNormal.y ), absNormal.z );
|
|
32
|
+
|
|
33
|
+
// Determine which face we're on and compute sample direction
|
|
34
|
+
const isX = maxComp.equal( absNormal.x );
|
|
35
|
+
const isY = maxComp.equal( absNormal.y ).and( isX.not() );
|
|
36
|
+
|
|
37
|
+
// Match LightProbeGrid / WebGL cubemap face conventions (see LightProbeGrid.js SH projection).
|
|
38
|
+
const xPositive = localNormal.x.greaterThan( 0.0 );
|
|
39
|
+
const xDir = select( xPositive,
|
|
40
|
+
vec3( 1.0, localPos.y, localPos.z.negate() ).normalize(),
|
|
41
|
+
vec3( - 1.0, localPos.y, localPos.z ).normalize()
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const yPositive = localNormal.y.greaterThan( 0.0 );
|
|
45
|
+
const yDir = select( yPositive,
|
|
46
|
+
vec3( localPos.x, 1.0, localPos.z.negate() ).normalize(),
|
|
47
|
+
vec3( localPos.x, - 1.0, localPos.z ).normalize()
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const zPositive = localNormal.z.greaterThan( 0.0 );
|
|
51
|
+
const zDir = select( zPositive,
|
|
52
|
+
vec3( localPos.x, localPos.y, 1.0 ).normalize(),
|
|
53
|
+
vec3( localPos.x, localPos.y, - 1.0 ).normalize()
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
// Select the appropriate direction based on which axis is dominant
|
|
57
|
+
const sampleDir = select( isX, xDir, select( isY, yDir, zDir ) );
|
|
58
|
+
|
|
59
|
+
return vec4( cubeTexture( texture, sampleDir ).rgb, 1.0 );
|
|
21
60
|
|
|
22
61
|
} )();
|
|
23
62
|
|
|
@@ -40,11 +79,13 @@ function createShaderMaterial( texture ) {
|
|
|
40
79
|
|
|
41
80
|
vertexShader: /* glsl */`
|
|
42
81
|
|
|
43
|
-
varying vec3
|
|
82
|
+
varying vec3 vLocalPosition;
|
|
83
|
+
varying vec3 vNormal;
|
|
44
84
|
|
|
45
85
|
void main() {
|
|
46
86
|
|
|
47
|
-
|
|
87
|
+
vLocalPosition = position;
|
|
88
|
+
vNormal = normal;
|
|
48
89
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
49
90
|
|
|
50
91
|
}
|
|
@@ -57,12 +98,56 @@ function createShaderMaterial( texture ) {
|
|
|
57
98
|
|
|
58
99
|
uniform samplerCube cubeTexture;
|
|
59
100
|
|
|
60
|
-
varying vec3
|
|
101
|
+
varying vec3 vLocalPosition;
|
|
102
|
+
varying vec3 vNormal;
|
|
61
103
|
|
|
62
104
|
void main() {
|
|
105
|
+
// Get the dominant axis from the normal to determine which face we're on
|
|
106
|
+
vec3 absNormal = abs( vNormal );
|
|
107
|
+
float maxComp = max( max( absNormal.x, absNormal.y ), absNormal.z );
|
|
108
|
+
|
|
109
|
+
vec3 sampleDir;
|
|
110
|
+
|
|
111
|
+
// Match LightProbeGrid / WebGL cubemap face conventions (see LightProbeGrid.js SH projection).
|
|
112
|
+
if ( maxComp == absNormal.x ) {
|
|
113
|
+
|
|
114
|
+
if ( vNormal.x > 0.0 ) {
|
|
115
|
+
|
|
116
|
+
sampleDir = normalize( vec3( 1.0, vLocalPosition.y, -vLocalPosition.z ) );
|
|
117
|
+
|
|
118
|
+
} else {
|
|
119
|
+
|
|
120
|
+
sampleDir = normalize( vec3( -1.0, vLocalPosition.y, vLocalPosition.z ) );
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
} else if ( maxComp == absNormal.y ) {
|
|
125
|
+
|
|
126
|
+
if ( vNormal.y > 0.0 ) {
|
|
127
|
+
|
|
128
|
+
sampleDir = normalize( vec3( vLocalPosition.x, 1.0, -vLocalPosition.z ) );
|
|
129
|
+
|
|
130
|
+
} else {
|
|
131
|
+
|
|
132
|
+
sampleDir = normalize( vec3( vLocalPosition.x, -1.0, vLocalPosition.z ) );
|
|
133
|
+
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
} else {
|
|
137
|
+
|
|
138
|
+
if ( vNormal.z > 0.0 ) {
|
|
139
|
+
|
|
140
|
+
sampleDir = normalize( vec3( vLocalPosition.x, vLocalPosition.y, 1.0 ) );
|
|
141
|
+
|
|
142
|
+
} else {
|
|
143
|
+
|
|
144
|
+
sampleDir = normalize( vec3( vLocalPosition.x, vLocalPosition.y, -1.0 ) );
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
}
|
|
63
149
|
|
|
64
|
-
vec3
|
|
65
|
-
vec3 color = textureCube( cubeTexture, direction ).rgb;
|
|
150
|
+
vec3 color = textureCube( cubeTexture, sampleDir ).rgb;
|
|
66
151
|
|
|
67
152
|
gl_FragColor = vec4( color, 1.0 );
|
|
68
153
|
|
|
@@ -238,7 +238,11 @@ class LightProbeGrid extends Object3D {
|
|
|
238
238
|
*/
|
|
239
239
|
getProbePosition( ix, iy, iz, target ) {
|
|
240
240
|
|
|
241
|
-
const pos = this.position;
|
|
241
|
+
// const pos = this.position;
|
|
242
|
+
// WITH_GENESYS
|
|
243
|
+
const pos = _position;
|
|
244
|
+
this.getWorldPosition( pos );
|
|
245
|
+
// !WITH_GENESYS
|
|
242
246
|
const res = this.resolution;
|
|
243
247
|
const w = this.width, h = this.height, d = this.depth;
|
|
244
248
|
|
|
@@ -257,8 +261,15 @@ class LightProbeGrid extends Object3D {
|
|
|
257
261
|
*/
|
|
258
262
|
updateBoundingBox() {
|
|
259
263
|
|
|
264
|
+
// WITH_GENESYS
|
|
265
|
+
this.getWorldPosition( _position );
|
|
266
|
+
_size.set( this.width, this.height, this.depth );
|
|
267
|
+
this.boundingBox.setFromCenterAndSize( _position, _size );
|
|
268
|
+
// !WITH_GENESYS
|
|
269
|
+
/*
|
|
260
270
|
_size.set( this.width, this.height, this.depth );
|
|
261
271
|
this.boundingBox.setFromCenterAndSize( this.position, _size );
|
|
272
|
+
*/
|
|
262
273
|
|
|
263
274
|
}
|
|
264
275
|
|