@woosh/meep-engine 2.165.0 → 2.165.2
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/README.md +137 -108
- package/build/bundle-worker-image-decoder.js +1 -1
- package/package.json +1 -1
- package/samples/generation/SampleGenerator0.js +3 -3
- package/samples/generation/filters/SampleGroundMoistureFilter.js +63 -56
- package/samples/generation/filters/SampleNoise20_0.js +6 -1
- package/samples/generation/themes/SampleTheme0.js +47 -47
- package/src/core/color/YCoCg/rgb_to_ycocg.d.ts +17 -0
- package/src/core/color/YCoCg/rgb_to_ycocg.d.ts.map +1 -0
- package/src/core/color/YCoCg/rgb_to_ycocg.js +20 -0
- package/src/core/color/YCoCg/ycocg_to_rgb.d.ts +14 -0
- package/src/core/color/YCoCg/ycocg_to_rgb.d.ts.map +1 -0
- package/src/core/color/YCoCg/ycocg_to_rgb.js +17 -0
- package/src/engine/REVIEW_2026_07_03.md +211 -0
- package/src/engine/animation/curve/actionProcessorOperations/curveActions.d.ts.map +1 -1
- package/src/engine/animation/curve/actionProcessorOperations/curveActions.js +3 -2
- package/src/engine/animation/curve/compression/sample_animation_curve_to_float_array.js +1 -1
- package/src/engine/animation/keyed2/AnimationTrackPlayback.d.ts.map +1 -1
- package/src/engine/animation/keyed2/AnimationTrackPlayback.js +3 -1
- package/src/engine/asset/loaders/image/png/filter/png_filter_unFilterNone.js +2 -2
- package/src/engine/asset/preloader/AssetPreloader.d.ts.map +1 -1
- package/src/engine/asset/preloader/AssetPreloader.js +6 -0
- package/src/engine/control/first-person/sensors/FirstPersonSensorsSystem.d.ts.map +1 -1
- package/src/engine/control/first-person/sensors/FirstPersonSensorsSystem.js +5 -2
- package/src/engine/ecs/Entity.js +1 -1
- package/src/engine/ecs/EntityComponentDataset.d.ts.map +1 -1
- package/src/engine/ecs/EntityComponentDataset.js +1 -0
- package/src/engine/ecs/EntityManager.d.ts.map +1 -1
- package/src/engine/ecs/EntityManager.js +12 -8
- package/src/engine/ecs/EntityObserver.js +1 -1
- package/src/engine/ecs/System.d.ts.map +1 -1
- package/src/engine/ecs/System.js +4 -0
- package/src/engine/ecs/animation/AnimationClip.js +1 -1
- package/src/engine/ecs/attachment/AttachmentSystem.js +2 -2
- package/src/engine/ecs/attachment/TransformAttachmentBinding.d.ts.map +1 -1
- package/src/engine/ecs/attachment/TransformAttachmentBinding.js +11 -0
- package/src/engine/ecs/fow/FogOfWar.js +2 -2
- package/src/engine/ecs/fow/shader/screenSpaceFogOfWarShader.d.ts.map +1 -1
- package/src/engine/ecs/fow/shader/screenSpaceFogOfWarShader.js +27 -9
- package/src/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +1 -1
- package/src/engine/ecs/gui/position/ViewportPosition.d.ts +3 -1
- package/src/engine/ecs/gui/position/ViewportPosition.d.ts.map +1 -1
- package/src/engine/ecs/gui/position/ViewportPosition.js +4 -1
- package/src/engine/ecs/storage/binary/BinarySerializationRegistry.d.ts +10 -0
- package/src/engine/ecs/storage/binary/BinarySerializationRegistry.d.ts.map +1 -1
- package/src/engine/ecs/storage/binary/BinarySerializationRegistry.js +43 -0
- package/src/engine/ecs/storage/binary/object-v2/BinaryObjectDeSerializer.d.ts +93 -0
- package/src/engine/ecs/storage/binary/object-v2/BinaryObjectDeSerializer.d.ts.map +1 -0
- package/src/engine/ecs/storage/binary/object-v2/BinaryObjectDeSerializer.js +315 -0
- package/src/engine/ecs/storage/binary/object-v2/BinaryObjectSerializer.d.ts +48 -0
- package/src/engine/ecs/storage/binary/object-v2/BinaryObjectSerializer.d.ts.map +1 -0
- package/src/engine/ecs/storage/binary/object-v2/BinaryObjectSerializer.js +331 -0
- package/src/engine/ecs/storage/binary/object-v2/DESIGN.md +199 -0
- package/src/engine/ecs/storage/binary/object-v2/ObjectBinaryFormat.d.ts +53 -0
- package/src/engine/ecs/storage/binary/object-v2/ObjectBinaryFormat.d.ts.map +1 -0
- package/src/engine/ecs/storage/binary/object-v2/ObjectBinaryFormat.js +57 -0
- package/src/engine/ecs/storage/binary/object-v2/ObjectSerializationAdapter.d.ts +53 -0
- package/src/engine/ecs/storage/binary/object-v2/ObjectSerializationAdapter.d.ts.map +1 -0
- package/src/engine/ecs/storage/binary/object-v2/ObjectSerializationAdapter.js +56 -0
- package/src/engine/ecs/storage/binary/object-v2/README.md +110 -0
- package/src/engine/ecs/storage/binary/object-v2/objectStringCodec.d.ts +13 -0
- package/src/engine/ecs/storage/binary/object-v2/objectStringCodec.d.ts.map +1 -0
- package/src/engine/ecs/storage/binary/object-v2/objectStringCodec.js +48 -0
- package/src/engine/ecs/storage/binary/object-v2/serializerTestHarness.d.ts +29 -0
- package/src/engine/ecs/storage/binary/object-v2/serializerTestHarness.d.ts.map +1 -0
- package/src/engine/ecs/storage/binary/object-v2/serializerTestHarness.js +44 -0
- package/src/engine/ecs/system_validate_class.d.ts.map +1 -1
- package/src/engine/ecs/system_validate_class.js +9 -2
- package/src/engine/graphics/camera/makeScreenScissorFrustum.d.ts.map +1 -1
- package/src/engine/graphics/camera/makeScreenScissorFrustum.js +11 -10
- package/src/engine/graphics/canvas/canvas2d_draw_linear_scale.d.ts.map +1 -1
- package/src/engine/graphics/canvas/canvas2d_draw_linear_scale.js +3 -1
- package/src/engine/graphics/ecs/animation/animator/graph/definition/serialization/readAnimationGraphDefinitionFromJSON.d.ts +1 -1
- package/src/engine/graphics/ecs/animation/animator/graph/definition/serialization/readAnimationGraphDefinitionFromJSON.d.ts.map +1 -1
- package/src/engine/graphics/ecs/animation/animator/graph/definition/serialization/readAnimationGraphDefinitionFromJSON.js +2 -2
- package/src/engine/graphics/ecs/animation/animator/graph/definition/serialization/writeAnimationGraphDefinitionToJSON.d.ts.map +1 -1
- package/src/engine/graphics/ecs/animation/animator/graph/definition/serialization/writeAnimationGraphDefinitionToJSON.js +2 -0
- package/src/engine/graphics/ecs/camera/Camera.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/Camera.js +4 -0
- package/src/engine/graphics/ecs/camera/auto_set_camera_clipping_planes.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/auto_set_camera_clipping_planes.js +7 -2
- package/src/engine/graphics/ecs/camera/set_camera_aspect_ratio.js +1 -1
- package/src/engine/graphics/ecs/highlight/system/ShadedGeometryHighlightSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/highlight/system/ShadedGeometryHighlightSystem.js +4 -1
- package/src/engine/graphics/ecs/light/binding/LightBinding.js +2 -2
- package/src/engine/graphics/ecs/mesh/MeshSystem.js +1 -1
- package/src/engine/graphics/ecs/mesh/SkeletonUtils.js +1 -1
- package/src/engine/graphics/ecs/mesh-v2/sg_hierarchy_compute_bounding_box_via_parent_entity.js +1 -1
- package/src/engine/graphics/ecs/water/WaterSystem.d.ts +6 -0
- package/src/engine/graphics/ecs/water/WaterSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/water/WaterSystem.js +12 -1
- package/src/engine/graphics/geometry/buffered/ensureGeometryBoundingSphere.js +1 -1
- package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_nearest.d.ts.map +1 -1
- package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_nearest.js +0 -15
- package/src/engine/graphics/geometry/instancing/InstancedMeshGroup.js +10 -10
- package/src/engine/graphics/geometry/optimization/merge/merge_geometry_hierarchy.js +1 -1
- package/src/engine/graphics/material/SplatMaterial.js +1 -1
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.d.ts.map +1 -1
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +3 -2
- package/src/engine/graphics/particles/particular/engine/emitter/ParticlePool.js +1 -1
- package/src/engine/graphics/particles/particular/group/ParticleGroup.d.ts.map +1 -1
- package/src/engine/graphics/particles/particular/group/ParticleGroup.js +3 -2
- package/src/engine/graphics/render/forward_plus/plugin/ForwardPlusRenderingPlugin.js +1 -1
- package/src/engine/graphics/sh3/gi/material/MaterialTransformer.d.ts +1 -8
- package/src/engine/graphics/sh3/gi/material/MaterialTransformer.d.ts.map +1 -1
- package/src/engine/graphics/sh3/gi/material/MaterialTransformer.js +2 -14
- package/src/engine/graphics/sh3/gi/material/ProbeResolutionStage.d.ts +9 -0
- package/src/engine/graphics/sh3/gi/material/ProbeResolutionStage.d.ts.map +1 -0
- package/src/engine/graphics/sh3/gi/material/ProbeResolutionStage.js +14 -0
- package/src/engine/graphics/sh3/lightmap/bake_lightmap_for_scene.d.ts.map +1 -1
- package/src/engine/graphics/sh3/lightmap/bake_lightmap_for_scene.js +4 -1
- package/src/engine/graphics/sh3/lpg/LightProbeGrid.d.ts +69 -0
- package/src/engine/graphics/sh3/lpg/LightProbeGrid.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/LightProbeGrid.js +173 -0
- package/src/engine/graphics/sh3/lpg/LightProbeGridBaker.d.ts +24 -0
- package/src/engine/graphics/sh3/lpg/LightProbeGridBaker.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/LightProbeGridBaker.js +88 -0
- package/src/engine/graphics/sh3/lpg/build_light_probe_grid_for_scene.d.ts +20 -0
- package/src/engine/graphics/sh3/lpg/build_light_probe_grid_for_scene.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/build_light_probe_grid_for_scene.js +79 -0
- package/src/engine/graphics/sh3/lpg/light_probe_grid_obtain_storage_cached.d.ts +11 -0
- package/src/engine/graphics/sh3/lpg/light_probe_grid_obtain_storage_cached.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/light_probe_grid_obtain_storage_cached.js +84 -0
- package/src/engine/graphics/sh3/lpg/light_probe_grid_textures.d.ts +29 -0
- package/src/engine/graphics/sh3/lpg/light_probe_grid_textures.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/light_probe_grid_textures.js +160 -0
- package/src/engine/graphics/sh3/lpg/material/LightProbeGridMaterialTransformer.d.ts +23 -0
- package/src/engine/graphics/sh3/lpg/material/LightProbeGridMaterialTransformer.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/LightProbeGridMaterialTransformer.js +228 -0
- package/src/engine/graphics/sh3/lpg/material/chunk_lpg_get_irradiance_at.d.ts +2 -0
- package/src/engine/graphics/sh3/lpg/material/chunk_lpg_get_irradiance_at.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/chunk_lpg_get_irradiance_at.js +24 -0
- package/src/engine/graphics/sh3/lpg/material/common.d.ts +3 -0
- package/src/engine/graphics/sh3/lpg/material/common.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/common.js +73 -0
- package/src/engine/graphics/sh3/lpg/material/space_fragment/build_fragment_shader.d.ts +6 -0
- package/src/engine/graphics/sh3/lpg/material/space_fragment/build_fragment_shader.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/space_fragment/build_fragment_shader.js +42 -0
- package/src/engine/graphics/sh3/lpg/material/space_fragment/build_vertex_shader.d.ts +6 -0
- package/src/engine/graphics/sh3/lpg/material/space_fragment/build_vertex_shader.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/space_fragment/build_vertex_shader.js +49 -0
- package/src/engine/graphics/sh3/lpg/material/space_fragment/space_fragment_transform_shader.d.ts +9 -0
- package/src/engine/graphics/sh3/lpg/material/space_fragment/space_fragment_transform_shader.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/space_fragment/space_fragment_transform_shader.js +12 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/build_fragment_shader.d.ts +6 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/build_fragment_shader.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/build_fragment_shader.js +30 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/build_vertex_shader.d.ts +6 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/build_vertex_shader.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/build_vertex_shader.js +41 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/preamble.frag.d.ts +3 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/preamble.frag.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/preamble.frag.js +15 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/preamble.vert.d.ts +3 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/preamble.vert.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/preamble.vert.js +9 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/space_vertex_transform_shader.d.ts +9 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/space_vertex_transform_shader.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/material/space_vertex/space_vertex_transform_shader.js +12 -0
- package/src/engine/graphics/sh3/lpg/serialization/LightProbeGridSerializationAdapter.d.ts +20 -0
- package/src/engine/graphics/sh3/lpg/serialization/LightProbeGridSerializationAdapter.d.ts.map +1 -0
- package/src/engine/graphics/sh3/lpg/serialization/LightProbeGridSerializationAdapter.js +59 -0
- package/src/engine/graphics/sh3/path_tracer/material/MaterialConverter.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/material/MaterialConverter.js +8 -0
- package/src/engine/graphics/sh3/prototypeLightProbeGrid.d.ts +2 -0
- package/src/engine/graphics/sh3/prototypeLightProbeGrid.d.ts.map +1 -0
- package/src/engine/graphics/sh3/prototypeLightProbeGrid.js +170 -0
- package/src/engine/graphics/texture/atlas/AtlasLookupTexture.js +1 -1
- package/src/engine/graphics/texture/atlas/CachingTextureAtlas.js +1 -1
- package/src/engine/graphics/texture/sampler/resize/sampler2d_scale_down_lanczos.js +1 -1
- package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.js +3 -3
- package/src/engine/graphics/util/build_max_height_pyramid.d.ts.map +1 -1
- package/src/engine/graphics/util/build_max_height_pyramid.js +5 -2
- package/src/engine/grid/transform2grid/Transform2GridPositionSystem.js +1 -1
- package/src/engine/input/ecs/components/InputBinding.d.ts +7 -1
- package/src/engine/input/ecs/components/InputBinding.d.ts.map +1 -1
- package/src/engine/input/ecs/components/InputBinding.js +8 -1
- package/src/engine/input/ecs/systems/InputControllerSystem.js +1 -1
- package/src/engine/intelligence/behavior/decorator/OverrideContextBehavior.d.ts +2 -1
- package/src/engine/intelligence/behavior/decorator/OverrideContextBehavior.d.ts.map +1 -1
- package/src/engine/intelligence/behavior/decorator/OverrideContextBehavior.js +6 -2
- package/src/engine/intelligence/behavior/selector/WeightedElement.js +1 -1
- package/src/engine/knowledge/database/StaticKnowledgeDatabase.d.ts.map +1 -1
- package/src/engine/knowledge/database/StaticKnowledgeDatabase.js +2 -4
- package/src/engine/logging/elastic/ElasticSearchLogger.d.ts +1 -2
- package/src/engine/logging/elastic/ElasticSearchLogger.d.ts.map +1 -1
- package/src/engine/logging/elastic/ElasticSearchLogger.js +14 -10
- package/src/engine/navigation/ecs/path_following/PathFollower.js +1 -1
- package/src/engine/navigation/grid/find_path_on_grid_astar.d.ts.map +1 -1
- package/src/engine/navigation/grid/find_path_on_grid_astar.js +5 -2
- package/src/engine/network/orchestrator/ServerAuthoritativeServer.d.ts +1 -1
- package/src/engine/network/orchestrator/ServerAuthoritativeServer.d.ts.map +1 -1
- package/src/engine/network/orchestrator/ServerAuthoritativeServer.js +17 -0
- package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
- package/src/engine/physics/fluid/ecs/FluidSystem.d.ts +3 -3
- package/src/engine/scene/SceneManager.d.ts.map +1 -1
- package/src/engine/scene/SceneManager.js +4 -2
- package/src/engine/simulation/Ticker.d.ts.map +1 -1
- package/src/engine/simulation/Ticker.js +9 -0
- package/src/engine/sound/ecs/emitter/SoundEmitterSystem.d.ts.map +1 -1
- package/src/engine/sound/ecs/emitter/SoundEmitterSystem.js +6 -1
- package/src/engine/sound/material/concrete/json/serializeSoundMaterialToJSON.js +1 -1
- package/src/generation/theme/ThemeEngine.d.ts +9 -0
- package/src/generation/theme/ThemeEngine.d.ts.map +1 -1
- package/src/generation/theme/ThemeEngine.js +37 -2
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClampToEdgeWrapping,
|
|
3
|
+
DataTexture3D,
|
|
4
|
+
HalfFloatType,
|
|
5
|
+
LinearFilter,
|
|
6
|
+
RGBAFormat,
|
|
7
|
+
UnsignedByteType
|
|
8
|
+
} from "three";
|
|
9
|
+
import { to_half_float_uint16 } from "../../../../core/binary/to_half_float_uint16.js";
|
|
10
|
+
import { clamp } from "../../../../core/math/clamp.js";
|
|
11
|
+
import { rgb_to_ycocg } from "../../../../core/color/YCoCg/rgb_to_ycocg.js";
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
YCoCg irradiance storage, after "Cross-Platform GI in Metro Exodus" (4A Games).
|
|
15
|
+
Luminance (Y) carries the HDR range and most of the perceptible detail, so it keeps half-float precision.
|
|
16
|
+
Chrominance (Co, Cg) is perceptually low-frequency and is dropped to 8-bit UNORM.
|
|
17
|
+
|
|
18
|
+
The 8-bit chroma is stored via a global affine map `stored = chroma * LPG_CHROMA_SCALE + 0.5` (decoded on the GPU
|
|
19
|
+
as `(stored - 0.5) / LPG_CHROMA_SCALE`). Because YCoCg is linear and this map is a global scale+bias, hardware
|
|
20
|
+
trilinear filtering of the three textures followed by reconstruction is exactly equivalent to filtering the
|
|
21
|
+
original RGB — the encoding does not disturb filtering.
|
|
22
|
+
|
|
23
|
+
Representable chroma range is +/- 0.5 / LPG_CHROMA_SCALE; chroma beyond it clips (a colored, very saturated probe
|
|
24
|
+
desaturates) while luminance, and therefore brightness, is preserved.
|
|
25
|
+
*/
|
|
26
|
+
export const LPG_CHROMA_SCALE = 0.25;
|
|
27
|
+
|
|
28
|
+
const LPG_CHROMA_BIAS = 0.5;
|
|
29
|
+
|
|
30
|
+
const __ycocg = new Float32Array(3);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Create the half-float luminance volume of a {@link LightProbeGrid}. Each texel holds the 4 SH2 Y coefficients in RGBA.
|
|
34
|
+
* @param {number} resolution_x
|
|
35
|
+
* @param {number} resolution_y
|
|
36
|
+
* @param {number} resolution_z
|
|
37
|
+
* @returns {DataTexture3D}
|
|
38
|
+
*/
|
|
39
|
+
export function make_light_probe_grid_luma_texture(resolution_x, resolution_y, resolution_z) {
|
|
40
|
+
|
|
41
|
+
const texture = new DataTexture3D(
|
|
42
|
+
new Uint16Array(resolution_x * resolution_y * resolution_z * 4),
|
|
43
|
+
resolution_x,
|
|
44
|
+
resolution_y,
|
|
45
|
+
resolution_z
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
texture.name = "Light Probe Grid SH2 Y";
|
|
49
|
+
|
|
50
|
+
texture.flipY = false;
|
|
51
|
+
texture.generateMipmaps = false;
|
|
52
|
+
texture.magFilter = LinearFilter;
|
|
53
|
+
texture.minFilter = LinearFilter;
|
|
54
|
+
|
|
55
|
+
texture.wrapS = ClampToEdgeWrapping;
|
|
56
|
+
texture.wrapT = ClampToEdgeWrapping;
|
|
57
|
+
texture.wrapR = ClampToEdgeWrapping;
|
|
58
|
+
|
|
59
|
+
texture.type = HalfFloatType;
|
|
60
|
+
texture.format = RGBAFormat;
|
|
61
|
+
texture.internalFormat = "RGBA16F";
|
|
62
|
+
|
|
63
|
+
texture.unpackAlignment = 4;
|
|
64
|
+
|
|
65
|
+
texture.needsUpdate = true;
|
|
66
|
+
|
|
67
|
+
return texture;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Create an 8-bit chrominance volume (one of Co / Cg) of a {@link LightProbeGrid}. Each texel holds the 4 SH2
|
|
72
|
+
* coefficients of that chroma channel in RGBA.
|
|
73
|
+
* @param {number} resolution_x
|
|
74
|
+
* @param {number} resolution_y
|
|
75
|
+
* @param {number} resolution_z
|
|
76
|
+
* @returns {DataTexture3D}
|
|
77
|
+
*/
|
|
78
|
+
export function make_light_probe_grid_chroma_texture(resolution_x, resolution_y, resolution_z) {
|
|
79
|
+
|
|
80
|
+
const texture = new DataTexture3D(
|
|
81
|
+
new Uint8Array(resolution_x * resolution_y * resolution_z * 4),
|
|
82
|
+
resolution_x,
|
|
83
|
+
resolution_y,
|
|
84
|
+
resolution_z
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
texture.name = "Light Probe Grid SH2 chroma";
|
|
88
|
+
|
|
89
|
+
texture.flipY = false;
|
|
90
|
+
texture.generateMipmaps = false;
|
|
91
|
+
texture.magFilter = LinearFilter;
|
|
92
|
+
texture.minFilter = LinearFilter;
|
|
93
|
+
|
|
94
|
+
texture.wrapS = ClampToEdgeWrapping;
|
|
95
|
+
texture.wrapT = ClampToEdgeWrapping;
|
|
96
|
+
texture.wrapR = ClampToEdgeWrapping;
|
|
97
|
+
|
|
98
|
+
texture.type = UnsignedByteType;
|
|
99
|
+
texture.format = RGBAFormat;
|
|
100
|
+
texture.internalFormat = "RGBA8";
|
|
101
|
+
|
|
102
|
+
texture.unpackAlignment = 4;
|
|
103
|
+
|
|
104
|
+
texture.needsUpdate = true;
|
|
105
|
+
|
|
106
|
+
return texture;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @param {number} chroma
|
|
111
|
+
* @returns {number} 8-bit UNORM byte
|
|
112
|
+
*/
|
|
113
|
+
function encode_chroma_byte(chroma) {
|
|
114
|
+
return clamp(Math.round((chroma * LPG_CHROMA_SCALE + LPG_CHROMA_BIAS) * 255), 0, 255);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Write probe data of a grid into the YCoCg textures created by {@link make_light_probe_grid_luma_texture} and
|
|
119
|
+
* {@link make_light_probe_grid_chroma_texture}. Texture dimensions must match the grid resolution.
|
|
120
|
+
* @param {LightProbeGrid} grid
|
|
121
|
+
* @param {DataTexture3D} texture_y luminance, half-float
|
|
122
|
+
* @param {DataTexture3D} texture_co chroma-orange, 8-bit
|
|
123
|
+
* @param {DataTexture3D} texture_cg chroma-green, 8-bit
|
|
124
|
+
*/
|
|
125
|
+
export function light_probe_grid_write_textures(grid, texture_y, texture_co, texture_cg) {
|
|
126
|
+
|
|
127
|
+
const harmonics = grid.harmonics;
|
|
128
|
+
const count = grid.count;
|
|
129
|
+
|
|
130
|
+
const data_y = texture_y.image.data;
|
|
131
|
+
const data_co = texture_co.image.data;
|
|
132
|
+
const data_cg = texture_cg.image.data;
|
|
133
|
+
|
|
134
|
+
for (let i = 0; i < count; i++) {
|
|
135
|
+
|
|
136
|
+
const source_offset = i * 12;
|
|
137
|
+
const target_offset = i * 4;
|
|
138
|
+
|
|
139
|
+
for (let coefficient = 0; coefficient < 4; coefficient++) {
|
|
140
|
+
|
|
141
|
+
const source_address = source_offset + coefficient * 3;
|
|
142
|
+
const target_address = target_offset + coefficient;
|
|
143
|
+
|
|
144
|
+
rgb_to_ycocg(
|
|
145
|
+
__ycocg, 0,
|
|
146
|
+
harmonics[source_address],
|
|
147
|
+
harmonics[source_address + 1],
|
|
148
|
+
harmonics[source_address + 2]
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
data_y[target_address] = to_half_float_uint16(__ycocg[0]);
|
|
152
|
+
data_co[target_address] = encode_chroma_byte(__ycocg[1]);
|
|
153
|
+
data_cg[target_address] = encode_chroma_byte(__ycocg[2]);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
texture_y.needsUpdate = true;
|
|
158
|
+
texture_co.needsUpdate = true;
|
|
159
|
+
texture_cg.needsUpdate = true;
|
|
160
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export class LightProbeGridMaterialTransformer extends AbstractMaterialTransformer {
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {LightProbeGrid} grid
|
|
5
|
+
* @param {number|ProbeResolutionStage} stage Vertex sampling is faster but less accurate, fragment is more expensive and precise
|
|
6
|
+
*/
|
|
7
|
+
constructor({ grid, stage, }: LightProbeGrid);
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param {number} v
|
|
11
|
+
*/
|
|
12
|
+
set intensity(arg: number);
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @return {number}
|
|
16
|
+
*/
|
|
17
|
+
get intensity(): number;
|
|
18
|
+
update(): void;
|
|
19
|
+
transform(source: any): any;
|
|
20
|
+
#private;
|
|
21
|
+
}
|
|
22
|
+
import { AbstractMaterialTransformer } from "../../../material/manager/AbstractMaterialTransformer.js";
|
|
23
|
+
//# sourceMappingURL=LightProbeGridMaterialTransformer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LightProbeGridMaterialTransformer.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/lpg/material/LightProbeGridMaterialTransformer.js"],"names":[],"mappings":"AAgBA;IA2FI;;;;OAIG;IACH,8CAYC;IAzBD;;;OAGG;IACH,2BAEC;IAdD;;;OAGG;IACH,wBAEC;IAiED,eA0CC;IAED,4BAoBC;;CACJ;4CAhO2C,0DAA0D"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { Vector3 } from "three";
|
|
2
|
+
import { assert } from "../../../../../core/assert.js";
|
|
3
|
+
import { composeCompile } from "../../../material/composeCompile.js";
|
|
4
|
+
import { AbstractMaterialTransformer } from "../../../material/manager/AbstractMaterialTransformer.js";
|
|
5
|
+
import { isLitMaterial } from "../../../render/forward_plus/plugin/isLitMaterial.js";
|
|
6
|
+
import { ProbeResolutionStage } from "../../gi/material/ProbeResolutionStage.js";
|
|
7
|
+
import {
|
|
8
|
+
light_probe_grid_write_textures,
|
|
9
|
+
make_light_probe_grid_chroma_texture,
|
|
10
|
+
make_light_probe_grid_luma_texture
|
|
11
|
+
} from "../light_probe_grid_textures.js";
|
|
12
|
+
import { space_fragment_transform_shader } from "./space_fragment/space_fragment_transform_shader.js";
|
|
13
|
+
import { space_vertex_transform_shader } from "./space_vertex/space_vertex_transform_shader.js";
|
|
14
|
+
|
|
15
|
+
const PROPERTY_TRANSFORMER_MARKER = '@light-probe-grid-material-transformer';
|
|
16
|
+
|
|
17
|
+
export class LightProbeGridMaterialTransformer extends AbstractMaterialTransformer {
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @type {LightProbeGrid}
|
|
22
|
+
*/
|
|
23
|
+
#grid;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @type {ProbeResolutionStage|number}
|
|
28
|
+
*/
|
|
29
|
+
#sampling_stage = ProbeResolutionStage.Fragment;
|
|
30
|
+
|
|
31
|
+
#textures = {
|
|
32
|
+
sh_y: make_light_probe_grid_luma_texture(1, 1, 1),
|
|
33
|
+
sh_co: make_light_probe_grid_chroma_texture(1, 1, 1),
|
|
34
|
+
sh_cg: make_light_probe_grid_chroma_texture(1, 1, 1)
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
#uniforms = {
|
|
38
|
+
lpg_t_sh_y: {
|
|
39
|
+
type: "t",
|
|
40
|
+
value: this.#textures.sh_y
|
|
41
|
+
},
|
|
42
|
+
lpg_t_sh_co: {
|
|
43
|
+
type: "t",
|
|
44
|
+
value: this.#textures.sh_co
|
|
45
|
+
},
|
|
46
|
+
lpg_t_sh_cg: {
|
|
47
|
+
type: "t",
|
|
48
|
+
value: this.#textures.sh_cg
|
|
49
|
+
},
|
|
50
|
+
lpg_v3_bounds_min: {
|
|
51
|
+
value: new Vector3()
|
|
52
|
+
},
|
|
53
|
+
lpg_v3_bounds_max: {
|
|
54
|
+
value: new Vector3()
|
|
55
|
+
},
|
|
56
|
+
lpg_v3_uvw_scale: {
|
|
57
|
+
value: new Vector3()
|
|
58
|
+
},
|
|
59
|
+
lpg_v3_uvw_offset: {
|
|
60
|
+
value: new Vector3()
|
|
61
|
+
},
|
|
62
|
+
lpg_f_intensity: {
|
|
63
|
+
value: 1
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
*
|
|
69
|
+
* @type {number}
|
|
70
|
+
*/
|
|
71
|
+
#uniform_version = -1;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
*
|
|
75
|
+
* @param {{uniforms, glslVersion, defines, vertexShader, fragmentShader}} shader
|
|
76
|
+
*/
|
|
77
|
+
#onBeforeCompile = (shader) => {
|
|
78
|
+
Object.assign(shader.uniforms, this.#uniforms);
|
|
79
|
+
|
|
80
|
+
switch (this.#sampling_stage) {
|
|
81
|
+
case ProbeResolutionStage.Vertex:
|
|
82
|
+
space_vertex_transform_shader(shader);
|
|
83
|
+
break;
|
|
84
|
+
case ProbeResolutionStage.Fragment:
|
|
85
|
+
space_fragment_transform_shader(shader);
|
|
86
|
+
break;
|
|
87
|
+
default:
|
|
88
|
+
throw new Error(`Unsupported resolution space ${this.#sampling_stage}`);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
*
|
|
94
|
+
* @return {number}
|
|
95
|
+
*/
|
|
96
|
+
get intensity() {
|
|
97
|
+
return this.#uniforms.lpg_f_intensity.value;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
*
|
|
102
|
+
* @param {number} v
|
|
103
|
+
*/
|
|
104
|
+
set intensity(v) {
|
|
105
|
+
this.#uniforms.lpg_f_intensity.value = v;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
*
|
|
110
|
+
* @param {LightProbeGrid} grid
|
|
111
|
+
* @param {number|ProbeResolutionStage} stage Vertex sampling is faster but less accurate, fragment is more expensive and precise
|
|
112
|
+
*/
|
|
113
|
+
constructor({
|
|
114
|
+
grid,
|
|
115
|
+
stage = ProbeResolutionStage.Vertex,
|
|
116
|
+
}) {
|
|
117
|
+
|
|
118
|
+
super();
|
|
119
|
+
|
|
120
|
+
assert.defined(grid, 'grid');
|
|
121
|
+
assert.enum(stage, ProbeResolutionStage, 'stage');
|
|
122
|
+
|
|
123
|
+
this.#grid = grid;
|
|
124
|
+
this.#sampling_stage = stage;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Re-create channel textures when the grid resolution changes.
|
|
129
|
+
* Uniform objects are shared by reference with every compiled shader, so re-assigning their values is
|
|
130
|
+
* picked up by all transformed materials.
|
|
131
|
+
* @param {number} resolution_x
|
|
132
|
+
* @param {number} resolution_y
|
|
133
|
+
* @param {number} resolution_z
|
|
134
|
+
*/
|
|
135
|
+
#ensure_texture_dimensions(resolution_x, resolution_y, resolution_z) {
|
|
136
|
+
const textures = this.#textures;
|
|
137
|
+
|
|
138
|
+
const image = textures.sh_y.image;
|
|
139
|
+
|
|
140
|
+
if (
|
|
141
|
+
image.width === resolution_x
|
|
142
|
+
&& image.height === resolution_y
|
|
143
|
+
&& image.depth === resolution_z
|
|
144
|
+
) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
textures.sh_y.dispose();
|
|
149
|
+
textures.sh_co.dispose();
|
|
150
|
+
textures.sh_cg.dispose();
|
|
151
|
+
|
|
152
|
+
textures.sh_y = make_light_probe_grid_luma_texture(resolution_x, resolution_y, resolution_z);
|
|
153
|
+
textures.sh_co = make_light_probe_grid_chroma_texture(resolution_x, resolution_y, resolution_z);
|
|
154
|
+
textures.sh_cg = make_light_probe_grid_chroma_texture(resolution_x, resolution_y, resolution_z);
|
|
155
|
+
|
|
156
|
+
const uniforms = this.#uniforms;
|
|
157
|
+
|
|
158
|
+
uniforms.lpg_t_sh_y.value = textures.sh_y;
|
|
159
|
+
uniforms.lpg_t_sh_co.value = textures.sh_co;
|
|
160
|
+
uniforms.lpg_t_sh_cg.value = textures.sh_cg;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
update() {
|
|
164
|
+
const grid = this.#grid;
|
|
165
|
+
|
|
166
|
+
if (this.#uniform_version === grid.version) {
|
|
167
|
+
// up to date
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (grid.count === 0) {
|
|
172
|
+
// nothing baked yet
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const resolution_x = grid.resolution_x;
|
|
177
|
+
const resolution_y = grid.resolution_y;
|
|
178
|
+
const resolution_z = grid.resolution_z;
|
|
179
|
+
|
|
180
|
+
this.#ensure_texture_dimensions(resolution_x, resolution_y, resolution_z);
|
|
181
|
+
|
|
182
|
+
const textures = this.#textures;
|
|
183
|
+
|
|
184
|
+
light_probe_grid_write_textures(grid, textures.sh_y, textures.sh_co, textures.sh_cg);
|
|
185
|
+
|
|
186
|
+
const uniforms = this.#uniforms;
|
|
187
|
+
|
|
188
|
+
const bounds = grid.bounds;
|
|
189
|
+
|
|
190
|
+
uniforms.lpg_v3_bounds_min.value.set(bounds.x0, bounds.y0, bounds.z0);
|
|
191
|
+
uniforms.lpg_v3_bounds_max.value.set(bounds.x1, bounds.y1, bounds.z1);
|
|
192
|
+
|
|
193
|
+
uniforms.lpg_v3_uvw_scale.value.set(
|
|
194
|
+
(resolution_x - 1) / resolution_x,
|
|
195
|
+
(resolution_y - 1) / resolution_y,
|
|
196
|
+
(resolution_z - 1) / resolution_z
|
|
197
|
+
);
|
|
198
|
+
uniforms.lpg_v3_uvw_offset.value.set(
|
|
199
|
+
0.5 / resolution_x,
|
|
200
|
+
0.5 / resolution_y,
|
|
201
|
+
0.5 / resolution_z
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
this.#uniform_version = grid.version;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
transform(source) {
|
|
208
|
+
if (source.hasOwnProperty(PROPERTY_TRANSFORMER_MARKER)) {
|
|
209
|
+
// already transformed
|
|
210
|
+
|
|
211
|
+
if (source[PROPERTY_TRANSFORMER_MARKER] !== this) {
|
|
212
|
+
throw new Error('The material is already transformed, but is associated with a different transformer instance');
|
|
213
|
+
} else {
|
|
214
|
+
return source;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (isLitMaterial(source)) {
|
|
220
|
+
|
|
221
|
+
source.onBeforeCompile = composeCompile(source.onBeforeCompile, this.#onBeforeCompile);
|
|
222
|
+
|
|
223
|
+
source[PROPERTY_TRANSFORMER_MARKER] = this;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return source;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export const chunk_lpg_get_irradiance_at: "\n#ifndef LPG_CHUNK_GET_IRRADIANCE_AT\n#define LPG_CHUNK_GET_IRRADIANCE_AT\n\nvec3 lpg_get_irradiance_at(in vec3 normal, in vec3 shCoefficients[4]) {\n // normal is assumed to have unit length\n\n // band 0\n vec3 result = shCoefficients[0] * 0.8862269254527579;\n\n // band 1\n result += shCoefficients[1] * 1.0233267079464885 * normal.y;\n result += shCoefficients[2] * 1.0233267079464885 * normal.z;\n result += shCoefficients[3] * 1.0233267079464885 * normal.x;\n\n return result;\n}\n\n#endif\n";
|
|
2
|
+
//# sourceMappingURL=chunk_lpg_get_irradiance_at.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk_lpg_get_irradiance_at.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/lpg/material/chunk_lpg_get_irradiance_at.js"],"names":[],"mappings":"AAIA,wjBAmBC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
// source: https://graphics.stanford.edu/papers/envmap/envmap.pdf
|
|
3
|
+
// first two bands of chunk_lpv_get_irradiance_at, constants include the cosine-lobe convolution
|
|
4
|
+
//language=GLSL
|
|
5
|
+
export const chunk_lpg_get_irradiance_at = `
|
|
6
|
+
#ifndef LPG_CHUNK_GET_IRRADIANCE_AT
|
|
7
|
+
#define LPG_CHUNK_GET_IRRADIANCE_AT
|
|
8
|
+
|
|
9
|
+
vec3 lpg_get_irradiance_at(in vec3 normal, in vec3 shCoefficients[4]) {
|
|
10
|
+
// normal is assumed to have unit length
|
|
11
|
+
|
|
12
|
+
// band 0
|
|
13
|
+
vec3 result = shCoefficients[0] * 0.8862269254527579;
|
|
14
|
+
|
|
15
|
+
// band 1
|
|
16
|
+
result += shCoefficients[1] * 1.0233267079464885 * normal.y;
|
|
17
|
+
result += shCoefficients[2] * 1.0233267079464885 * normal.z;
|
|
18
|
+
result += shCoefficients[3] * 1.0233267079464885 * normal.x;
|
|
19
|
+
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
#endif
|
|
24
|
+
`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/lpg/material/common.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { chunk_lpg_get_irradiance_at } from "./chunk_lpg_get_irradiance_at.js";
|
|
2
|
+
import { LPG_CHROMA_SCALE } from "../light_probe_grid_textures.js";
|
|
3
|
+
|
|
4
|
+
// decode multiplier for the 8-bit chroma textures (see light_probe_grid_textures.js)
|
|
5
|
+
const LPG_CHROMA_DECODE = 1 / LPG_CHROMA_SCALE;
|
|
6
|
+
|
|
7
|
+
// language=GLSL
|
|
8
|
+
export default `
|
|
9
|
+
#ifndef LPG_SHADER_CHUNK_COMMON
|
|
10
|
+
#define LPG_SHADER_CHUNK_COMMON
|
|
11
|
+
|
|
12
|
+
precision highp sampler3D;
|
|
13
|
+
|
|
14
|
+
uniform sampler3D lpg_t_sh_y;
|
|
15
|
+
uniform sampler3D lpg_t_sh_co;
|
|
16
|
+
uniform sampler3D lpg_t_sh_cg;
|
|
17
|
+
|
|
18
|
+
uniform vec3 lpg_v3_bounds_min;
|
|
19
|
+
uniform vec3 lpg_v3_bounds_max;
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
Probes sit on the bounds faces, texels do not: the first and the last probe layer of an axis with N layers map
|
|
23
|
+
to texel centers 0.5/N and 1 - 0.5/N. uvw = normalized * (N-1)/N + 0.5/N re-aligns hardware trilinear filtering
|
|
24
|
+
with the probe lattice; scale and offset are precomputed per-axis on the CPU.
|
|
25
|
+
*/
|
|
26
|
+
uniform vec3 lpg_v3_uvw_scale;
|
|
27
|
+
uniform vec3 lpg_v3_uvw_offset;
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
Irradiance is stored as YCoCg (Metro Exodus): half-float luminance + two 8-bit chroma volumes. The chroma
|
|
31
|
+
encoding stored = chroma * LPG_CHROMA_SCALE + 0.5 is a global scale+bias, so hardware trilinear filtering of all
|
|
32
|
+
three volumes stays exactly equivalent to filtering RGB; we simply decode after the fetch.
|
|
33
|
+
*/
|
|
34
|
+
const float lpg_chroma_decode = ${LPG_CHROMA_DECODE.toFixed(8)};
|
|
35
|
+
|
|
36
|
+
${ chunk_lpg_get_irradiance_at }
|
|
37
|
+
|
|
38
|
+
vec3 lpg_compute_uvw(in vec3 position) {
|
|
39
|
+
vec3 normalized = (position - lpg_v3_bounds_min) / (lpg_v3_bounds_max - lpg_v3_bounds_min);
|
|
40
|
+
|
|
41
|
+
return normalized * lpg_v3_uvw_scale + lpg_v3_uvw_offset;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
vec3[4] lpg_fetch_sh(in vec3 position) {
|
|
45
|
+
vec3 uvw = lpg_compute_uvw(position);
|
|
46
|
+
|
|
47
|
+
// positions outside the bounds clamp to the nearest edge probe
|
|
48
|
+
vec4 y = texture(lpg_t_sh_y, uvw);
|
|
49
|
+
vec4 co = (texture(lpg_t_sh_co, uvw) - 0.5) * lpg_chroma_decode;
|
|
50
|
+
vec4 cg = (texture(lpg_t_sh_cg, uvw) - 0.5) * lpg_chroma_decode;
|
|
51
|
+
|
|
52
|
+
// reconstruct RGB per coefficient: R = Y + Co - Cg, G = Y + Cg, B = Y - Co - Cg
|
|
53
|
+
vec4 r = y + co - cg;
|
|
54
|
+
vec4 g = y + cg;
|
|
55
|
+
vec4 b = y - co - cg;
|
|
56
|
+
|
|
57
|
+
return vec3[4](
|
|
58
|
+
vec3(r.x, g.x, b.x),
|
|
59
|
+
vec3(r.y, g.y, b.y),
|
|
60
|
+
vec3(r.z, g.z, b.z),
|
|
61
|
+
vec3(r.w, g.w, b.w)
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
vec3 lpg_sample_irradiance(in vec3 position, in vec3 normal) {
|
|
66
|
+
|
|
67
|
+
vec3[4] sh = lpg_fetch_sh(position);
|
|
68
|
+
|
|
69
|
+
return lpg_get_irradiance_at(normal, sh);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
#endif
|
|
73
|
+
`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build_fragment_shader.d.ts","sourceRoot":"","sources":["../../../../../../../../src/engine/graphics/sh3/lpg/material/space_fragment/build_fragment_shader.js"],"names":[],"mappings":"AA0BA;;;GAGG;AACH,8CAFW,MAAM,UAahB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { insert_after } from "../../../../../../core/primitives/strings/insert_after.js";
|
|
2
|
+
import PREAMBLE_COMMON from "../common.js";
|
|
3
|
+
|
|
4
|
+
//language=GLSL
|
|
5
|
+
const PREAMBLE = `
|
|
6
|
+
#ifndef LPG_SHADER_CHUNK_PREAMBLE_FRAGMENT
|
|
7
|
+
#define LPG_SHADER_CHUNK_PREAMBLE_FRAGMENT
|
|
8
|
+
|
|
9
|
+
varying vec3 lpg_v_world_position;
|
|
10
|
+
|
|
11
|
+
uniform float lpg_f_intensity;
|
|
12
|
+
|
|
13
|
+
#endif
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
//language=GLSL
|
|
17
|
+
const ACCUMULATION = `
|
|
18
|
+
{
|
|
19
|
+
|
|
20
|
+
vec3 lpg_world_normal = normalize( inverseTransformDirection( geometry.normal, viewMatrix ) );
|
|
21
|
+
|
|
22
|
+
irradiance += lpg_sample_irradiance( lpg_v_world_position, lpg_world_normal ) * lpg_f_intensity;
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @param {string} source
|
|
30
|
+
*/
|
|
31
|
+
export function build_fragment_shader(source) {
|
|
32
|
+
|
|
33
|
+
let result = PREAMBLE + PREAMBLE_COMMON + source;
|
|
34
|
+
|
|
35
|
+
result = insert_after(
|
|
36
|
+
result,
|
|
37
|
+
'#include <lights_fragment_begin>',
|
|
38
|
+
ACCUMULATION
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build_vertex_shader.d.ts","sourceRoot":"","sources":["../../../../../../../../src/engine/graphics/sh3/lpg/material/space_fragment/build_vertex_shader.js"],"names":[],"mappings":"AAiCA;;;GAGG;AACH,4CAFW,MAAM,UAahB"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { insert_after } from "../../../../../../core/primitives/strings/insert_after.js";
|
|
2
|
+
|
|
3
|
+
//language=GLSL
|
|
4
|
+
const PREAMBLE = `
|
|
5
|
+
#ifndef LPG_SHADER_CHUNK_PREAMBLE_VERTEX
|
|
6
|
+
#define LPG_SHADER_CHUNK_PREAMBLE_VERTEX
|
|
7
|
+
|
|
8
|
+
varying vec3 lpg_v_world_position;
|
|
9
|
+
|
|
10
|
+
#endif
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
World position is computed from the raw 'position' attribute rather than three's 'worldPosition' (only declared
|
|
15
|
+
when shadow maps / env maps / transmission are enabled) or 'transformed' (only declared once <begin_vertex> has
|
|
16
|
+
run). 'position' is present on every non-raw shader that exposes the <fog_vertex> anchor. Probe GI is
|
|
17
|
+
low-frequency, so skipping morph/skin displacement in the lookup position is inconsequential.
|
|
18
|
+
*/
|
|
19
|
+
//language=GLSL
|
|
20
|
+
const CAPTURE_WORLD_POSITION = `
|
|
21
|
+
{
|
|
22
|
+
vec4 lpg_world_position = vec4( position, 1.0 );
|
|
23
|
+
|
|
24
|
+
#ifdef USE_INSTANCING
|
|
25
|
+
lpg_world_position = instanceMatrix * lpg_world_position;
|
|
26
|
+
#endif
|
|
27
|
+
|
|
28
|
+
lpg_world_position = modelMatrix * lpg_world_position;
|
|
29
|
+
|
|
30
|
+
lpg_v_world_position = lpg_world_position.xyz;
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param {string} source
|
|
37
|
+
*/
|
|
38
|
+
export function build_vertex_shader(source) {
|
|
39
|
+
|
|
40
|
+
let result = PREAMBLE + source;
|
|
41
|
+
|
|
42
|
+
result = insert_after(
|
|
43
|
+
result,
|
|
44
|
+
'#include <fog_vertex>',
|
|
45
|
+
CAPTURE_WORLD_POSITION
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
return result;
|
|
49
|
+
}
|
package/src/engine/graphics/sh3/lpg/material/space_fragment/space_fragment_transform_shader.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Probe field is sampled per-fragment
|
|
3
|
+
* @param {{vertexShader, fragmentShader}} shader
|
|
4
|
+
*/
|
|
5
|
+
export function space_fragment_transform_shader(shader: {
|
|
6
|
+
vertexShader;
|
|
7
|
+
fragmentShader;
|
|
8
|
+
}): void;
|
|
9
|
+
//# sourceMappingURL=space_fragment_transform_shader.d.ts.map
|
package/src/engine/graphics/sh3/lpg/material/space_fragment/space_fragment_transform_shader.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"space_fragment_transform_shader.d.ts","sourceRoot":"","sources":["../../../../../../../../src/engine/graphics/sh3/lpg/material/space_fragment/space_fragment_transform_shader.js"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wDAFW;IAAC,YAAY,CAAC;IAAC,cAAc,CAAA;CAAC,QAMxC"}
|
package/src/engine/graphics/sh3/lpg/material/space_fragment/space_fragment_transform_shader.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { build_fragment_shader } from "./build_fragment_shader.js";
|
|
2
|
+
import { build_vertex_shader } from "./build_vertex_shader.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Probe field is sampled per-fragment
|
|
6
|
+
* @param {{vertexShader, fragmentShader}} shader
|
|
7
|
+
*/
|
|
8
|
+
export function space_fragment_transform_shader(shader) {
|
|
9
|
+
|
|
10
|
+
shader.vertexShader = build_vertex_shader(shader.vertexShader);
|
|
11
|
+
shader.fragmentShader = build_fragment_shader(shader.fragmentShader);
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build_fragment_shader.d.ts","sourceRoot":"","sources":["../../../../../../../../src/engine/graphics/sh3/lpg/material/space_vertex/build_fragment_shader.js"],"names":[],"mappings":"AAcA;;;GAGG;AACH,8CAFW,MAAM,UAahB"}
|