@woosh/meep-engine 2.138.13 → 2.138.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/build/bundle-worker-image-decoder.js +1 -1
- package/package.json +1 -1
- package/samples/terrain/from_image_2.js +2 -10
- package/src/engine/asset/loaders/image/ImageDecoderWorker.js +1 -1
- package/src/engine/asset/loaders/image/ImageRGBADataLoader.d.ts.map +1 -1
- package/src/engine/asset/loaders/image/ImageRGBADataLoader.js +6 -1
- package/src/engine/asset/loaders/image/png/PNGReader.d.ts +1 -99
- package/src/engine/asset/loaders/image/png/PNGReader.d.ts.map +1 -1
- package/src/engine/asset/loaders/image/png/PNGReader.js +31 -420
- package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_iTXt.d.ts +12 -0
- package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_iTXt.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_iTXt.js +53 -0
- package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_zTXt.d.ts +10 -0
- package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_zTXt.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/png/chunk/png_chunk_decode_zTXt.js +42 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterAverage.d.ts +18 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterAverage.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterAverage.js +59 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterNone.d.ts +17 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterNone.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterNone.js +55 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterPaeth.d.ts +17 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterPaeth.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterPaeth.js +74 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterSub.d.ts +15 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterSub.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterSub.js +34 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterUp.d.ts +16 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterUp.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterUp.js +46 -0
- package/src/engine/asset/loaders/image/png/inflate.d.ts +7 -0
- package/src/engine/asset/loaders/image/png/inflate.d.ts.map +1 -0
- package/src/engine/asset/loaders/image/png/inflate.js +20 -0
- package/src/engine/ecs/terrain/ecs/Terrain.js +1 -1
- package/src/engine/ecs/terrain/ecs/splat/SplatMapping.d.ts.map +1 -1
- package/src/engine/ecs/terrain/ecs/splat/SplatMapping.js +32 -9
- package/src/engine/graphics/impostors/octahedral/prototypeBaker.js +202 -8
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderDepthV0.d.ts +10 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderDepthV0.d.ts.map +1 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderDepthV0.js +418 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderLitV0.d.ts +14 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderLitV0.d.ts.map +1 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderLitV0.js +757 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderNormalsV0.d.ts +13 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderNormalsV0.d.ts.map +1 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderNormalsV0.js +380 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderPerPixelV0.d.ts +6 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderPerPixelV0.d.ts.map +1 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderPerPixelV0.js +406 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderV0.d.ts.map +1 -1
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderV0.js +8 -1
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderViewportDepthV0.d.ts +14 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderViewportDepthV0.d.ts.map +1 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderViewportDepthV0.js +356 -0
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderWireframeV0.d.ts.map +1 -1
- package/src/engine/graphics/impostors/octahedral/shader/ImpostorShaderWireframeV0.js +4 -1
- package/src/engine/graphics/shaders/TerrainShader.js +2 -2
- package/src/engine/intelligence/mcts/MonteCarlo.d.ts +35 -4
- package/src/engine/intelligence/mcts/MonteCarlo.d.ts.map +1 -1
- package/src/engine/intelligence/mcts/MonteCarlo.js +101 -31
- package/src/engine/intelligence/mcts/StateNode.d.ts +47 -24
- package/src/engine/intelligence/mcts/StateNode.d.ts.map +1 -1
- package/src/engine/intelligence/mcts/StateNode.js +364 -316
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GLSL3,
|
|
3
|
+
NoBlending,
|
|
4
|
+
RawShaderMaterial,
|
|
5
|
+
Vector3
|
|
6
|
+
} from "three";
|
|
7
|
+
|
|
8
|
+
// Shadow-pass depth material that matches ImpostorShaderV0's surface so the
|
|
9
|
+
// shadow caster silhouette agrees with what the colour pass draws. We need
|
|
10
|
+
// the full TBN + per-frame xform machinery so that parallax in the fragment
|
|
11
|
+
// reproduces the same UV displacement as V0 — otherwise the alpha discard
|
|
12
|
+
// would cut a different silhouette than the visible card.
|
|
13
|
+
//
|
|
14
|
+
// We DO write gl_FragDepth here. Reason: the caster card orients toward
|
|
15
|
+
// the light (modelViewMatrix in the shadow pass is light_view * model),
|
|
16
|
+
// while the visible card orients toward the camera. The two cards
|
|
17
|
+
// intersect at the bounding-sphere centre plane but diverge — without
|
|
18
|
+
// per-pixel depth the caster's silhouette would be a thin disc at that
|
|
19
|
+
// plane and any visible fragment "below" the centre (in light space)
|
|
20
|
+
// would read as self-shadowed. Projecting the parallaxed surface point
|
|
21
|
+
// through MVP and writing it as gl_FragDepth fixes the silhouette: the
|
|
22
|
+
// shadow map records the actual depth of the impostor surface at each
|
|
23
|
+
// (light_x, light_y), matching what the visible card produces.
|
|
24
|
+
// Cost: this disables early-Z in the shadow pass, but shadow passes are
|
|
25
|
+
// usually fillrate-light and the geometry is just a card.
|
|
26
|
+
//
|
|
27
|
+
// Output is RGBA-packed depth — that's the format three.js's PCFShadowMap
|
|
28
|
+
// reads, and it's what the default MeshDepthMaterial would write here.
|
|
29
|
+
const shader_vx = `
|
|
30
|
+
|
|
31
|
+
in vec2 uv;
|
|
32
|
+
in vec3 position;
|
|
33
|
+
|
|
34
|
+
out vec2 vUv;
|
|
35
|
+
out vec3 vViewPos;
|
|
36
|
+
|
|
37
|
+
// Card position and normal in OBJECT space — the fragment shader uses
|
|
38
|
+
// these to project the parallaxed surface point through MVP for the
|
|
39
|
+
// gl_FragDepth write. Position interpolates between vertices; the
|
|
40
|
+
// normal is the same for every card vertex so we mark it flat.
|
|
41
|
+
out vec3 vCardPos_OS;
|
|
42
|
+
flat out vec3 vCardNormal_OS;
|
|
43
|
+
|
|
44
|
+
flat out vec2 vGridFloor;
|
|
45
|
+
flat out vec4 vWeights;
|
|
46
|
+
|
|
47
|
+
flat out vec3 vTangent;
|
|
48
|
+
flat out vec3 vBinormal;
|
|
49
|
+
flat out vec3 vNormal;
|
|
50
|
+
|
|
51
|
+
flat out vec4 vFrameXform00;
|
|
52
|
+
flat out vec4 vFrameXform10;
|
|
53
|
+
flat out vec4 vFrameXform01;
|
|
54
|
+
flat out vec4 vFrameXform11;
|
|
55
|
+
|
|
56
|
+
uniform mat4 modelViewMatrix;
|
|
57
|
+
uniform mat4 projectionMatrix;
|
|
58
|
+
|
|
59
|
+
uniform vec3 uOffset;
|
|
60
|
+
uniform float uRadius;
|
|
61
|
+
uniform float uFrames;
|
|
62
|
+
uniform bool uIsFullSphere;
|
|
63
|
+
|
|
64
|
+
vec2 VecToSphereOct(vec3 pivotToCamera)
|
|
65
|
+
{
|
|
66
|
+
vec3 octant = sign(pivotToCamera);
|
|
67
|
+
float sum = dot(pivotToCamera, octant);
|
|
68
|
+
vec3 octahedron = pivotToCamera / sum;
|
|
69
|
+
if (octahedron.y < 0.0) {
|
|
70
|
+
vec3 absolute = abs(octahedron);
|
|
71
|
+
octahedron.xz = octant.xz * vec2(1.0 - absolute.z, 1.0 - absolute.x);
|
|
72
|
+
}
|
|
73
|
+
return octahedron.xz;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
vec2 VecToHemiSphereOct(vec3 v)
|
|
77
|
+
{
|
|
78
|
+
v.y = max(v.y, 0.001);
|
|
79
|
+
v = normalize(v);
|
|
80
|
+
vec3 octant = sign(v);
|
|
81
|
+
float sum = dot(v, octant);
|
|
82
|
+
vec3 octahedron = v / sum;
|
|
83
|
+
return vec2(
|
|
84
|
+
octahedron.x + octahedron.z,
|
|
85
|
+
octahedron.z - octahedron.x
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
vec2 VectorToGrid(vec3 v)
|
|
90
|
+
{
|
|
91
|
+
return uIsFullSphere ? VecToSphereOct(v) : VecToHemiSphereOct(v);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
vec3 OctaSphereDec(vec2 coord)
|
|
95
|
+
{
|
|
96
|
+
coord = (coord - 0.5) * 2.0;
|
|
97
|
+
vec3 p = vec3(coord.x, 0.0, coord.y);
|
|
98
|
+
vec2 a = abs(p.xz);
|
|
99
|
+
p.y = 1.0 - a.x - a.y;
|
|
100
|
+
if (p.y < 0.0) {
|
|
101
|
+
p.xz = sign(p.xz) * vec2(1.0 - a.y, 1.0 - a.x);
|
|
102
|
+
}
|
|
103
|
+
return p;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
vec3 OctaHemiSphereDec(vec2 coord)
|
|
107
|
+
{
|
|
108
|
+
vec3 p = vec3(coord.x - coord.y, 0.0, -1.0 + coord.x + coord.y);
|
|
109
|
+
vec2 a = abs(p.xz);
|
|
110
|
+
p.y = 1.0 - a.x - a.y;
|
|
111
|
+
return p;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
vec3 GridToVector(vec2 coord)
|
|
115
|
+
{
|
|
116
|
+
return uIsFullSphere ? OctaSphereDec(coord) : OctaHemiSphereDec(coord);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
vec3 FrameToRay(vec2 frame, vec2 framesMinusOne)
|
|
120
|
+
{
|
|
121
|
+
vec2 f = clamp(frame / framesMinusOne, 0.0, 1.0);
|
|
122
|
+
return normalize(GridToVector(f));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
vec4 ComputeFrameXform(vec3 D_frame, vec3 tangent_OS, vec3 binormal_OS)
|
|
126
|
+
{
|
|
127
|
+
vec3 D = abs(D_frame.y) > 0.99999
|
|
128
|
+
? normalize(D_frame + vec3(0.0, 0.0, 0.0001))
|
|
129
|
+
: D_frame;
|
|
130
|
+
vec3 bake_right = normalize(cross(vec3(0.0, 1.0, 0.0), D));
|
|
131
|
+
vec3 bake_up = cross(D, bake_right);
|
|
132
|
+
return vec4(
|
|
133
|
+
dot(tangent_OS, bake_right),
|
|
134
|
+
dot(binormal_OS, bake_right),
|
|
135
|
+
dot(tangent_OS, bake_up),
|
|
136
|
+
dot(binormal_OS, bake_up)
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
vec4 BilinearWeights(vec2 frac_uv)
|
|
141
|
+
{
|
|
142
|
+
vec2 omuv = vec2(1.0) - frac_uv;
|
|
143
|
+
return vec4(
|
|
144
|
+
omuv.x * omuv.y,
|
|
145
|
+
frac_uv.x * omuv.y,
|
|
146
|
+
omuv.x * frac_uv.y,
|
|
147
|
+
frac_uv.x * frac_uv.y
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
void main() {
|
|
152
|
+
vUv = uv;
|
|
153
|
+
|
|
154
|
+
// For shadow casting, modelViewMatrix = light_view * model. The
|
|
155
|
+
// camera in object space is therefore the LIGHT's position in
|
|
156
|
+
// object space, so the impostor card naturally orients to face the
|
|
157
|
+
// light — exactly what we want for a shadow caster.
|
|
158
|
+
// For a directional light's ORTHOGRAPHIC shadow camera, three.js
|
|
159
|
+
// positions the shadow camera at the light entity's world
|
|
160
|
+
// position — which is independent of the light's actual ray
|
|
161
|
+
// direction. Using "cameraPos_OS - uOffset" would index the atlas
|
|
162
|
+
// by "direction to shadow camera position", which generally does
|
|
163
|
+
// NOT equal the parallel light-ray direction (in our scene the
|
|
164
|
+
// light sits at (30, 70, 30) but rays travel along (0.17, -1, 0.17),
|
|
165
|
+
// which puts the camera position on the +X,+Z side while the
|
|
166
|
+
// light arrives from -X,-Z — i.e. mirrored on X and Z). The
|
|
167
|
+
// receiver (lit shader) uses the actual light direction for its
|
|
168
|
+
// shadow coord, so we have to match it on the caster side too.
|
|
169
|
+
//
|
|
170
|
+
// Row 2 of modelViewMatrix encodes the camera's +Z axis in OS,
|
|
171
|
+
// which for a three.js camera is "away from the looking direction"
|
|
172
|
+
// — i.e. the direction OPPOSITE the way the light travels, which
|
|
173
|
+
// is what we want for atlas indexing (the bake's D_frame =
|
|
174
|
+
// direction-from-centre-to-bake-camera = -look-direction).
|
|
175
|
+
//
|
|
176
|
+
// NOTE: signs verified by empirical comparison with the receiver
|
|
177
|
+
// side, since the conventions interlock through three.js's
|
|
178
|
+
// matrix-to-uniform pipeline in ways that are easy to get wrong
|
|
179
|
+
// on paper. The negation below comes from the observation that
|
|
180
|
+
// the un-negated formula produced a shadow in the exact-opposite
|
|
181
|
+
// direction of what the truth mesh casts.
|
|
182
|
+
vec3 pivotToCameraRay = -normalize(vec3(
|
|
183
|
+
modelViewMatrix[0][2],
|
|
184
|
+
modelViewMatrix[1][2],
|
|
185
|
+
modelViewMatrix[2][2]
|
|
186
|
+
));
|
|
187
|
+
|
|
188
|
+
vec2 framesMinusOne = vec2(uFrames - 1.0);
|
|
189
|
+
vec2 octahedral_uv = clamp(VectorToGrid(pivotToCameraRay) * 0.5 + 0.5, 0.0, 1.0);
|
|
190
|
+
vec2 grid = octahedral_uv * framesMinusOne;
|
|
191
|
+
vec2 gridFloor = min(floor(grid), framesMinusOne - 1.0);
|
|
192
|
+
vec4 weights = BilinearWeights(grid - gridFloor);
|
|
193
|
+
|
|
194
|
+
vGridFloor = gridFloor;
|
|
195
|
+
vWeights = weights;
|
|
196
|
+
|
|
197
|
+
vec3 ray00 = FrameToRay(gridFloor + vec2(0.0, 0.0), framesMinusOne);
|
|
198
|
+
vec3 ray10 = FrameToRay(gridFloor + vec2(1.0, 0.0), framesMinusOne);
|
|
199
|
+
vec3 ray01 = FrameToRay(gridFloor + vec2(0.0, 1.0), framesMinusOne);
|
|
200
|
+
vec3 ray11 = FrameToRay(gridFloor + vec2(1.0, 1.0), framesMinusOne);
|
|
201
|
+
vec3 projectedRay = normalize(
|
|
202
|
+
ray00 * weights.x +
|
|
203
|
+
ray10 * weights.y +
|
|
204
|
+
ray01 * weights.z +
|
|
205
|
+
ray11 * weights.w
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
vec3 normal_OS = projectedRay;
|
|
209
|
+
vec3 up_OS = abs(normal_OS.y) > 0.999
|
|
210
|
+
? vec3(0.0, 0.0, -1.0)
|
|
211
|
+
: vec3(0.0, 1.0, 0.0);
|
|
212
|
+
vec3 tangent_OS = normalize(cross(up_OS, normal_OS));
|
|
213
|
+
vec3 binormal_OS = cross(normal_OS, tangent_OS);
|
|
214
|
+
|
|
215
|
+
float card_diameter = uRadius * 2.0;
|
|
216
|
+
vec3 pos_OS = uOffset
|
|
217
|
+
+ position.x * card_diameter * tangent_OS
|
|
218
|
+
+ position.y * card_diameter * binormal_OS;
|
|
219
|
+
|
|
220
|
+
vCardPos_OS = pos_OS;
|
|
221
|
+
vCardNormal_OS = normal_OS;
|
|
222
|
+
|
|
223
|
+
vec4 mvPosition = modelViewMatrix * vec4(pos_OS, 1.0);
|
|
224
|
+
vViewPos = mvPosition.xyz;
|
|
225
|
+
gl_Position = projectionMatrix * mvPosition;
|
|
226
|
+
|
|
227
|
+
mat3 m3 = mat3(modelViewMatrix);
|
|
228
|
+
vTangent = normalize(m3 * tangent_OS);
|
|
229
|
+
vBinormal = normalize(m3 * binormal_OS);
|
|
230
|
+
vNormal = normalize(m3 * normal_OS);
|
|
231
|
+
|
|
232
|
+
vFrameXform00 = ComputeFrameXform(ray00, tangent_OS, binormal_OS);
|
|
233
|
+
vFrameXform10 = ComputeFrameXform(ray10, tangent_OS, binormal_OS);
|
|
234
|
+
vFrameXform01 = ComputeFrameXform(ray01, tangent_OS, binormal_OS);
|
|
235
|
+
vFrameXform11 = ComputeFrameXform(ray11, tangent_OS, binormal_OS);
|
|
236
|
+
}
|
|
237
|
+
`;
|
|
238
|
+
const shader_fg = `
|
|
239
|
+
precision highp float;
|
|
240
|
+
precision highp int;
|
|
241
|
+
|
|
242
|
+
in vec2 vUv;
|
|
243
|
+
in vec3 vViewPos;
|
|
244
|
+
|
|
245
|
+
in vec3 vCardPos_OS;
|
|
246
|
+
flat in vec3 vCardNormal_OS;
|
|
247
|
+
|
|
248
|
+
flat in vec2 vGridFloor;
|
|
249
|
+
flat in vec4 vWeights;
|
|
250
|
+
|
|
251
|
+
flat in vec3 vTangent;
|
|
252
|
+
flat in vec3 vBinormal;
|
|
253
|
+
flat in vec3 vNormal;
|
|
254
|
+
|
|
255
|
+
flat in vec4 vFrameXform00;
|
|
256
|
+
flat in vec4 vFrameXform10;
|
|
257
|
+
flat in vec4 vFrameXform01;
|
|
258
|
+
flat in vec4 vFrameXform11;
|
|
259
|
+
|
|
260
|
+
out vec4 color_out;
|
|
261
|
+
|
|
262
|
+
// Needed in the fragment to re-project the parallax-shifted surface
|
|
263
|
+
// point. three.js's WebGLRenderer sets both unconditionally for any
|
|
264
|
+
// ShaderMaterial-derived material (RawShaderMaterial included).
|
|
265
|
+
uniform mat4 modelViewMatrix;
|
|
266
|
+
uniform mat4 projectionMatrix;
|
|
267
|
+
|
|
268
|
+
uniform sampler2D tBase;
|
|
269
|
+
uniform sampler2D tGeometry;
|
|
270
|
+
uniform float uFrames;
|
|
271
|
+
uniform float uRadius;
|
|
272
|
+
uniform float uDepthScale;
|
|
273
|
+
|
|
274
|
+
// Mirrors three.js's packing.glsl chunk so the shadow map reader (PCF
|
|
275
|
+
// sampler in shadowmap_pars_fragment) can unpack our output.
|
|
276
|
+
const float PackUpscale = 256.0 / 255.0;
|
|
277
|
+
const vec3 PackFactors = vec3(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0);
|
|
278
|
+
const float ShiftRight8 = 1.0 / 256.0;
|
|
279
|
+
|
|
280
|
+
vec4 packDepthToRGBA(const in float v) {
|
|
281
|
+
vec4 r = vec4(fract(v * PackFactors), v);
|
|
282
|
+
r.yzw -= r.xyz * ShiftRight8;
|
|
283
|
+
return r * PackUpscale;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
vec2 apply_frame_xform(vec2 card_uv, vec4 xform)
|
|
287
|
+
{
|
|
288
|
+
vec2 c = card_uv - 0.5;
|
|
289
|
+
return vec2(
|
|
290
|
+
xform.x * c.x + xform.y * c.y,
|
|
291
|
+
xform.z * c.x + xform.w * c.y
|
|
292
|
+
) + 0.5;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
vec4 blend_4_frames(
|
|
296
|
+
sampler2D tex, vec2 card_uv,
|
|
297
|
+
vec2 gridFloor, vec4 w,
|
|
298
|
+
vec4 x00, vec4 x10, vec4 x01, vec4 x11
|
|
299
|
+
) {
|
|
300
|
+
vec2 frame_size = vec2(1.0 / uFrames);
|
|
301
|
+
vec2 uv00 = clamp(apply_frame_xform(card_uv, x00), 0.0, 1.0);
|
|
302
|
+
vec2 uv10 = clamp(apply_frame_xform(card_uv, x10), 0.0, 1.0);
|
|
303
|
+
vec2 uv01 = clamp(apply_frame_xform(card_uv, x01), 0.0, 1.0);
|
|
304
|
+
vec2 uv11 = clamp(apply_frame_xform(card_uv, x11), 0.0, 1.0);
|
|
305
|
+
vec4 s00 = texture(tex, (gridFloor + vec2(0.0, 0.0) + uv00) * frame_size);
|
|
306
|
+
vec4 s10 = texture(tex, (gridFloor + vec2(1.0, 0.0) + uv10) * frame_size);
|
|
307
|
+
vec4 s01 = texture(tex, (gridFloor + vec2(0.0, 1.0) + uv01) * frame_size);
|
|
308
|
+
vec4 s11 = texture(tex, (gridFloor + vec2(1.0, 1.0) + uv11) * frame_size);
|
|
309
|
+
return s00 * w.x + s10 * w.y + s01 * w.z + s11 * w.w;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
void main() {
|
|
313
|
+
// Same parallax shift as V0 so the silhouette we test matches the
|
|
314
|
+
// visible silhouette — otherwise the shadow would clip a slightly
|
|
315
|
+
// different cutout than the colour pass.
|
|
316
|
+
vec3 view_dir_view = normalize(-vViewPos);
|
|
317
|
+
vec3 view_dir = vec3(
|
|
318
|
+
dot(vTangent, view_dir_view),
|
|
319
|
+
dot(vBinormal, view_dir_view),
|
|
320
|
+
dot(vNormal, view_dir_view)
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
vec2 base_uv = vUv;
|
|
324
|
+
float depth = blend_4_frames(
|
|
325
|
+
tGeometry, base_uv,
|
|
326
|
+
vGridFloor, vWeights,
|
|
327
|
+
vFrameXform00, vFrameXform10, vFrameXform01, vFrameXform11
|
|
328
|
+
).a;
|
|
329
|
+
base_uv += (view_dir.xy / view_dir.z) * (depth - 0.5) * uDepthScale;
|
|
330
|
+
base_uv = clamp(base_uv, 0.0, 1.0);
|
|
331
|
+
|
|
332
|
+
vec4 texel_color = blend_4_frames(
|
|
333
|
+
tBase, base_uv,
|
|
334
|
+
vGridFloor, vWeights,
|
|
335
|
+
vFrameXform00, vFrameXform10, vFrameXform01, vFrameXform11
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
if (texel_color.a <= 0.5) {
|
|
339
|
+
discard;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Re-sample depth at the parallax-shifted UV. We want the surface
|
|
343
|
+
// depth at the post-parallax location, not the un-shifted one.
|
|
344
|
+
// For a single-step parallax these usually round-trip to a
|
|
345
|
+
// similar value, but the second sample keeps us self-consistent
|
|
346
|
+
// when the parallax shift is non-trivial.
|
|
347
|
+
float surface_depth = blend_4_frames(
|
|
348
|
+
tGeometry, base_uv,
|
|
349
|
+
vGridFloor, vWeights,
|
|
350
|
+
vFrameXform00, vFrameXform10, vFrameXform01, vFrameXform11
|
|
351
|
+
).a;
|
|
352
|
+
|
|
353
|
+
// Convention from BakeShaderStandard: depth=1 at the bounding
|
|
354
|
+
// sphere's near plane (front, +radius along bake camera), 0.5 at
|
|
355
|
+
// the centre (= the card plane), 0 at the far plane (-radius).
|
|
356
|
+
// So (depth - 0.5) is the signed height along the card normal in
|
|
357
|
+
// half-bounding-sphere units; multiply by 2*radius to get
|
|
358
|
+
// object-space height.
|
|
359
|
+
float height_OS = (surface_depth - 0.5) * 2.0 * uRadius;
|
|
360
|
+
|
|
361
|
+
vec3 surface_OS = vCardPos_OS + height_OS * vCardNormal_OS;
|
|
362
|
+
vec4 surface_clip = projectionMatrix * modelViewMatrix * vec4(surface_OS, 1.0);
|
|
363
|
+
float surface_ndc_z = surface_clip.z / surface_clip.w;
|
|
364
|
+
|
|
365
|
+
// gl_FragCoord.z / gl_FragDepth are in [0, 1] (assuming default
|
|
366
|
+
// depth range). Map NDC z (-1..+1) to that range, then clamp so
|
|
367
|
+
// out-of-frustum surface points don't write garbage into the
|
|
368
|
+
// shadow map.
|
|
369
|
+
gl_FragDepth = clamp(surface_ndc_z * 0.5 + 0.5, 0.0, 1.0);
|
|
370
|
+
|
|
371
|
+
color_out = packDepthToRGBA(gl_FragDepth);
|
|
372
|
+
}
|
|
373
|
+
`;
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Depth-pass companion to ImpostorShaderV0. Use this as
|
|
377
|
+
* ShadedGeometry.depth_material so the impostor casts a shadow whose
|
|
378
|
+
* silhouette matches the visible card.
|
|
379
|
+
*/
|
|
380
|
+
export class ImpostorShaderDepthV0 extends RawShaderMaterial {
|
|
381
|
+
constructor() {
|
|
382
|
+
super({
|
|
383
|
+
fragmentShader: shader_fg,
|
|
384
|
+
vertexShader: shader_vx,
|
|
385
|
+
uniforms: {
|
|
386
|
+
tBase: {
|
|
387
|
+
value: null
|
|
388
|
+
},
|
|
389
|
+
tGeometry: {
|
|
390
|
+
value: null
|
|
391
|
+
},
|
|
392
|
+
tMaterial: {
|
|
393
|
+
value: null
|
|
394
|
+
},
|
|
395
|
+
uFrames: {
|
|
396
|
+
value: 0
|
|
397
|
+
},
|
|
398
|
+
uRadius: {
|
|
399
|
+
value: 0
|
|
400
|
+
},
|
|
401
|
+
uOffset: {
|
|
402
|
+
value: new Vector3(0, 0, 0)
|
|
403
|
+
},
|
|
404
|
+
uIsFullSphere: {
|
|
405
|
+
value: false
|
|
406
|
+
},
|
|
407
|
+
uDepthScale: {
|
|
408
|
+
value: 0.5
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
glslVersion: GLSL3
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
// Shadow pass writes a single RGBA depth value per fragment — no
|
|
415
|
+
// need for blending.
|
|
416
|
+
this.blending = NoBlending;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PBR-lit impostor material — applies three.js's standard (physical)
|
|
3
|
+
* lighting model to a baked impostor atlas. Casts/receives shadows like
|
|
4
|
+
* any MeshStandardMaterial-backed mesh.
|
|
5
|
+
*
|
|
6
|
+
* Same uniform names as ImpostorShaderV0 (tBase / tGeometry / tMaterial /
|
|
7
|
+
* uFrames / uRadius / uOffset / uIsFullSphere / uDepthScale) plus the
|
|
8
|
+
* standard PBR knobs (diffuse / emissive / roughness / metalness / opacity).
|
|
9
|
+
*/
|
|
10
|
+
export class ImpostorShaderLitV0 extends ShaderMaterial {
|
|
11
|
+
constructor();
|
|
12
|
+
}
|
|
13
|
+
import { ShaderMaterial } from "three";
|
|
14
|
+
//# sourceMappingURL=ImpostorShaderLitV0.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImpostorShaderLitV0.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/impostors/octahedral/shader/ImpostorShaderLitV0.js"],"names":[],"mappings":"AA4sBA;;;;;;;;GAQG;AACH;IACI,cA6BC;CACJ;+BA9uBM,OAAO"}
|