@bornengine/engine 0.4.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/LICENSE +21 -0
- package/README.md +231 -0
- package/native/android/Cargo.lock +1848 -0
- package/native/android/Cargo.toml +24 -0
- package/native/android/src/lib.rs +702 -0
- package/native/ios/Cargo.lock +1690 -0
- package/native/ios/Cargo.toml +32 -0
- package/native/ios/src/lib.rs +1267 -0
- package/native/linux/Cargo.lock +3279 -0
- package/native/linux/Cargo.toml +29 -0
- package/native/linux/src/lib.rs +1331 -0
- package/native/macos/Cargo.lock +3310 -0
- package/native/macos/Cargo.toml +46 -0
- package/native/macos/src/lib.rs +1302 -0
- package/native/shared/Cargo.lock +1899 -0
- package/native/shared/Cargo.toml +62 -0
- package/native/shared/assets/default_font.ttf +0 -0
- package/native/shared/build.rs +270 -0
- package/native/shared/shaders/common/clouds.wgsl +122 -0
- package/native/shared/shaders/common/fog.wgsl +16 -0
- package/native/shared/shaders/common/foliage_wind.wgsl +98 -0
- package/native/shared/shaders/common/imposter.wgsl +112 -0
- package/native/shared/shaders/common/pbr.wgsl +186 -0
- package/native/shared/shaders/common/shadows.wgsl +186 -0
- package/native/shared/shaders/common/sky.wgsl +8 -0
- package/native/shared/shaders/common/tonemap.wgsl +25 -0
- package/native/shared/shaders/impulse_field.wgsl +57 -0
- package/native/shared/shaders/material_abi.wgsl +383 -0
- package/native/shared/shaders/materials/test_minimal.wgsl +42 -0
- package/native/shared/src/anim_mixer.rs +61 -0
- package/native/shared/src/attach.rs +263 -0
- package/native/shared/src/audio/decode.rs +123 -0
- package/native/shared/src/audio/mod.rs +863 -0
- package/native/shared/src/audio/render.rs +892 -0
- package/native/shared/src/audio/spsc.rs +156 -0
- package/native/shared/src/audio/stream.rs +226 -0
- package/native/shared/src/custom_shaders.rs +104 -0
- package/native/shared/src/decals.rs +245 -0
- package/native/shared/src/drs.rs +211 -0
- package/native/shared/src/engine.rs +261 -0
- package/native/shared/src/ffi.rs +116 -0
- package/native/shared/src/ffi_core/assets.rs +388 -0
- package/native/shared/src/ffi_core/audio_ffi.rs +184 -0
- package/native/shared/src/ffi_core/draw.rs +334 -0
- package/native/shared/src/ffi_core/game_loop.rs +577 -0
- package/native/shared/src/ffi_core/input.rs +234 -0
- package/native/shared/src/ffi_core/mod.rs +127 -0
- package/native/shared/src/ffi_core/models.rs +1154 -0
- package/native/shared/src/ffi_core/ragdoll_ffi.rs +261 -0
- package/native/shared/src/ffi_core/scene.rs +626 -0
- package/native/shared/src/ffi_core/vfx.rs +212 -0
- package/native/shared/src/ffi_core/visual.rs +691 -0
- package/native/shared/src/frame_callbacks.rs +122 -0
- package/native/shared/src/geometry.rs +236 -0
- package/native/shared/src/handles.rs +182 -0
- package/native/shared/src/input.rs +448 -0
- package/native/shared/src/jolt_sys.rs +822 -0
- package/native/shared/src/lib.rs +55 -0
- package/native/shared/src/models.rs +1093 -0
- package/native/shared/src/models_gltf.rs +1280 -0
- package/native/shared/src/particles.rs +391 -0
- package/native/shared/src/physics_jolt.rs +1908 -0
- package/native/shared/src/picking.rs +298 -0
- package/native/shared/src/postfx.rs +345 -0
- package/native/shared/src/profiler.rs +492 -0
- package/native/shared/src/ragdoll.rs +474 -0
- package/native/shared/src/renderer/atmosphere_lut.rs +573 -0
- package/native/shared/src/renderer/brdf_lut.rs +154 -0
- package/native/shared/src/renderer/draw2d.rs +143 -0
- package/native/shared/src/renderer/formats.rs +822 -0
- package/native/shared/src/renderer/froxel.rs +421 -0
- package/native/shared/src/renderer/gi_bake.rs +653 -0
- package/native/shared/src/renderer/graph.rs +462 -0
- package/native/shared/src/renderer/hiz.rs +269 -0
- package/native/shared/src/renderer/hot_reload.rs +390 -0
- package/native/shared/src/renderer/impulse_field.rs +456 -0
- package/native/shared/src/renderer/lighting.rs +154 -0
- package/native/shared/src/renderer/material_instancing.rs +171 -0
- package/native/shared/src/renderer/material_pipeline.rs +700 -0
- package/native/shared/src/renderer/material_system.rs +1996 -0
- package/native/shared/src/renderer/material_system_tests.rs +601 -0
- package/native/shared/src/renderer/material_system_wasm.rs +41 -0
- package/native/shared/src/renderer/mod.rs +12556 -0
- package/native/shared/src/renderer/model_draw.rs +641 -0
- package/native/shared/src/renderer/occlusion.rs +429 -0
- package/native/shared/src/renderer/planar_pass.rs +593 -0
- package/native/shared/src/renderer/planar_reflection.rs +499 -0
- package/native/shared/src/renderer/post_pass.rs +249 -0
- package/native/shared/src/renderer/postfx_chain.rs +728 -0
- package/native/shared/src/renderer/pt_pass.rs +577 -0
- package/native/shared/src/renderer/scene_pass.rs +607 -0
- package/native/shared/src/renderer/shader_include.rs +205 -0
- package/native/shared/src/renderer/shader_library.rs +135 -0
- package/native/shared/src/renderer/shaders/ao.rs +570 -0
- package/native/shared/src/renderer/shaders/core.rs +1243 -0
- package/native/shared/src/renderer/shaders/env.rs +907 -0
- package/native/shared/src/renderer/shaders/gi.rs +810 -0
- package/native/shared/src/renderer/shaders/mod.rs +19 -0
- package/native/shared/src/renderer/shaders/post.rs +1558 -0
- package/native/shared/src/renderer/shaders/pt.rs +1859 -0
- package/native/shared/src/renderer/shaders/ssgi.rs +1586 -0
- package/native/shared/src/renderer/shadow_pass.rs +731 -0
- package/native/shared/src/renderer/ssgi_pass.rs +392 -0
- package/native/shared/src/renderer/ssr_pass.rs +188 -0
- package/native/shared/src/renderer/texture_store.rs +473 -0
- package/native/shared/src/renderer/transient.rs +591 -0
- package/native/shared/src/renderer/types.rs +941 -0
- package/native/shared/src/renderer/util.rs +152 -0
- package/native/shared/src/scene.rs +1362 -0
- package/native/shared/src/sdf_cache.rs +274 -0
- package/native/shared/src/shadows.rs +1036 -0
- package/native/shared/src/staging.rs +102 -0
- package/native/shared/src/string_header.rs +266 -0
- package/native/shared/src/text_renderer.rs +502 -0
- package/native/shared/src/textures.rs +197 -0
- package/native/tvos/Cargo.lock +1693 -0
- package/native/tvos/Cargo.toml +36 -0
- package/native/tvos/metal-patched/Cargo.toml +178 -0
- package/native/tvos/metal-patched/LICENSE-APACHE +201 -0
- package/native/tvos/metal-patched/LICENSE-MIT +25 -0
- package/native/tvos/metal-patched/src/acceleration_structure.rs +667 -0
- package/native/tvos/metal-patched/src/acceleration_structure_pass.rs +108 -0
- package/native/tvos/metal-patched/src/argument.rs +366 -0
- package/native/tvos/metal-patched/src/blitpass.rs +102 -0
- package/native/tvos/metal-patched/src/buffer.rs +71 -0
- package/native/tvos/metal-patched/src/capturedescriptor.rs +76 -0
- package/native/tvos/metal-patched/src/capturemanager.rs +113 -0
- package/native/tvos/metal-patched/src/commandbuffer.rs +192 -0
- package/native/tvos/metal-patched/src/commandqueue.rs +44 -0
- package/native/tvos/metal-patched/src/computepass.rs +107 -0
- package/native/tvos/metal-patched/src/constants.rs +152 -0
- package/native/tvos/metal-patched/src/counters.rs +119 -0
- package/native/tvos/metal-patched/src/depthstencil.rs +190 -0
- package/native/tvos/metal-patched/src/device.rs +2134 -0
- package/native/tvos/metal-patched/src/drawable.rs +39 -0
- package/native/tvos/metal-patched/src/encoder.rs +2041 -0
- package/native/tvos/metal-patched/src/heap.rs +281 -0
- package/native/tvos/metal-patched/src/indirect_encoder.rs +344 -0
- package/native/tvos/metal-patched/src/lib.rs +657 -0
- package/native/tvos/metal-patched/src/library.rs +902 -0
- package/native/tvos/metal-patched/src/mps.rs +575 -0
- package/native/tvos/metal-patched/src/pipeline/compute.rs +475 -0
- package/native/tvos/metal-patched/src/pipeline/mod.rs +71 -0
- package/native/tvos/metal-patched/src/pipeline/render.rs +762 -0
- package/native/tvos/metal-patched/src/renderpass.rs +443 -0
- package/native/tvos/metal-patched/src/resource.rs +182 -0
- package/native/tvos/metal-patched/src/sampler.rs +165 -0
- package/native/tvos/metal-patched/src/sync.rs +178 -0
- package/native/tvos/metal-patched/src/texture.rs +352 -0
- package/native/tvos/metal-patched/src/types.rs +90 -0
- package/native/tvos/metal-patched/src/vertexdescriptor.rs +250 -0
- package/native/tvos/src/audio_backend.rs +197 -0
- package/native/tvos/src/lib.rs +1891 -0
- package/native/visionos/Cargo.lock +1693 -0
- package/native/visionos/Cargo.toml +40 -0
- package/native/visionos/src/audio_backend.rs +197 -0
- package/native/visionos/src/lib.rs +1887 -0
- package/native/watchos/Cargo.lock +16 -0
- package/native/watchos/Cargo.toml +19 -0
- package/native/watchos/shaders/bloom_postfx.metal +99 -0
- package/native/watchos/src/BloomWatchApp.swift +1267 -0
- package/native/watchos/src/BloomWatchAudio.swift +179 -0
- package/native/watchos/src/audio.rs +55 -0
- package/native/watchos/src/draw_list.rs +229 -0
- package/native/watchos/src/ffi_stubs.rs +915 -0
- package/native/watchos/src/ffi_stubs_manual.rs +35 -0
- package/native/watchos/src/lib.rs +1124 -0
- package/native/watchos/src/models.rs +746 -0
- package/native/watchos/src/postfx.rs +95 -0
- package/native/watchos/src/scene.rs +534 -0
- package/native/watchos/src/textures.rs +184 -0
- package/native/web/Cargo.lock +1657 -0
- package/native/web/Cargo.toml +43 -0
- package/native/web/bloom_glue.js +695 -0
- package/native/web/build.sh +131 -0
- package/native/web/index.html +35 -0
- package/native/web/jolt_bridge.js +1519 -0
- package/native/web/src/input_ffi.rs +286 -0
- package/native/web/src/lib.rs +1796 -0
- package/native/web/src/material_ffi.rs +710 -0
- package/native/web/src/parity_ffi.rs +343 -0
- package/native/web/src/physics_ffi.rs +643 -0
- package/native/web/src/ragdoll_ffi.rs +250 -0
- package/native/web/src/render_settings.rs +98 -0
- package/native/windows/Cargo.lock +1815 -0
- package/native/windows/Cargo.toml +68 -0
- package/native/windows/src/lib.rs +1486 -0
- package/package.json +4279 -0
- package/src/audio/index.ts +315 -0
- package/src/core/colors.ts +63 -0
- package/src/core/index.ts +1206 -0
- package/src/core/keys.ts +63 -0
- package/src/core/types.ts +104 -0
- package/src/index.ts +171 -0
- package/src/math/index.ts +516 -0
- package/src/mobile/index.ts +294 -0
- package/src/models/index.ts +1258 -0
- package/src/physics/index.ts +1134 -0
- package/src/scene/index.ts +698 -0
- package/src/shapes/index.ts +120 -0
- package/src/text/index.ts +48 -0
- package/src/textures/index.ts +187 -0
- package/src/vfx/index.ts +191 -0
- package/src/world/index.ts +24 -0
- package/src/world/loader.ts +423 -0
- package/src/world/prefab.ts +217 -0
- package/src/world/render.ts +172 -0
- package/src/world/saver.ts +108 -0
- package/src/world/serialize.ts +301 -0
- package/src/world/terrain.ts +355 -0
- package/src/world/types.ts +160 -0
- package/src/world/validate.ts +319 -0
- package/src/world/version.ts +114 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
//! EN-001 instance-buffer creation/destruction, including the
|
|
2
|
+
//! spatial tiling that lets the dispatcher frustum-cull instanced
|
|
3
|
+
//! draws per tile. Split from material_system.rs (2000-line file
|
|
4
|
+
//! policy).
|
|
5
|
+
|
|
6
|
+
use super::material_system::{MaterialSystem, InstanceBuffer, InstanceTile};
|
|
7
|
+
|
|
8
|
+
impl MaterialSystem {
|
|
9
|
+
/// EN-001 — create a persistent instance buffer from CPU-side
|
|
10
|
+
/// floats. The data layout matches `InstanceData3D` (9 floats per
|
|
11
|
+
/// instance: pos.xyz, rot_y, scale, tint.rgba); this method pads
|
|
12
|
+
/// each instance to 12 floats at upload time so the GPU side gets
|
|
13
|
+
/// the correct 48-byte stride. Returns a 1-based handle to use
|
|
14
|
+
/// with `submit_draw_instanced`. Pair with `destroy_instance_buffer`
|
|
15
|
+
/// when the buffer's no longer needed.
|
|
16
|
+
pub fn create_instance_buffer(
|
|
17
|
+
&mut self,
|
|
18
|
+
device: &wgpu::Device,
|
|
19
|
+
queue: &wgpu::Queue,
|
|
20
|
+
raw: &[f32],
|
|
21
|
+
instance_count: u32,
|
|
22
|
+
) -> u32 {
|
|
23
|
+
let count = (instance_count as usize).min(raw.len() / 9);
|
|
24
|
+
|
|
25
|
+
// Spatial tiling: reorder instances into an XZ grid so each tile
|
|
26
|
+
// is a contiguous range the dispatcher can frustum-cull as a
|
|
27
|
+
// unit. Reordering is invisible to opaque/cutout draws (depth
|
|
28
|
+
// tested) and the per-instance attributes travel with the
|
|
29
|
+
// instance, so @builtin(instance_index) consumers stay
|
|
30
|
+
// consistent with their data. Small buffers stay untiled.
|
|
31
|
+
const TILE_TARGET: usize = 128;
|
|
32
|
+
const TILE_MIN_COUNT: usize = 512;
|
|
33
|
+
let mut order: Vec<usize> = (0..count).collect();
|
|
34
|
+
let mut tiles: Vec<InstanceTile> = Vec::new();
|
|
35
|
+
if count >= TILE_MIN_COUNT {
|
|
36
|
+
let mut xz_min = [f32::MAX; 2];
|
|
37
|
+
let mut xz_max = [f32::MIN; 2];
|
|
38
|
+
for i in 0..count {
|
|
39
|
+
let p = &raw[i * 9..i * 9 + 3];
|
|
40
|
+
if p[0] < xz_min[0] { xz_min[0] = p[0]; }
|
|
41
|
+
if p[0] > xz_max[0] { xz_max[0] = p[0]; }
|
|
42
|
+
if p[2] < xz_min[1] { xz_min[1] = p[2]; }
|
|
43
|
+
if p[2] > xz_max[1] { xz_max[1] = p[2]; }
|
|
44
|
+
}
|
|
45
|
+
let grid = ((count as f32 / TILE_TARGET as f32).sqrt().ceil() as usize).max(1);
|
|
46
|
+
let ext_x = (xz_max[0] - xz_min[0]).max(1e-3);
|
|
47
|
+
let ext_z = (xz_max[1] - xz_min[1]).max(1e-3);
|
|
48
|
+
let cell_of = |i: usize| -> usize {
|
|
49
|
+
let p = &raw[i * 9..i * 9 + 3];
|
|
50
|
+
let cx = (((p[0] - xz_min[0]) / ext_x * grid as f32) as usize).min(grid - 1);
|
|
51
|
+
let cz = (((p[2] - xz_min[1]) / ext_z * grid as f32) as usize).min(grid - 1);
|
|
52
|
+
cz * grid + cx
|
|
53
|
+
};
|
|
54
|
+
order.sort_by_key(|&i| cell_of(i));
|
|
55
|
+
// Emit one tile per non-empty cell (contiguous after the sort).
|
|
56
|
+
let mut start = 0usize;
|
|
57
|
+
while start < count {
|
|
58
|
+
let cell = cell_of(order[start]);
|
|
59
|
+
let mut end = start + 1;
|
|
60
|
+
while end < count && cell_of(order[end]) == cell { end += 1; }
|
|
61
|
+
let mut pmin = [f32::MAX; 3];
|
|
62
|
+
let mut pmax = [f32::MIN; 3];
|
|
63
|
+
let mut max_scale = 0.0f32;
|
|
64
|
+
for &i in &order[start..end] {
|
|
65
|
+
let inst = &raw[i * 9..i * 9 + 9];
|
|
66
|
+
for a in 0..3 {
|
|
67
|
+
if inst[a] < pmin[a] { pmin[a] = inst[a]; }
|
|
68
|
+
if inst[a] > pmax[a] { pmax[a] = inst[a]; }
|
|
69
|
+
}
|
|
70
|
+
if inst[4].abs() > max_scale { max_scale = inst[4].abs(); }
|
|
71
|
+
}
|
|
72
|
+
tiles.push(InstanceTile {
|
|
73
|
+
first: start as u32,
|
|
74
|
+
count: (end - start) as u32,
|
|
75
|
+
pmin,
|
|
76
|
+
pmax,
|
|
77
|
+
max_scale,
|
|
78
|
+
});
|
|
79
|
+
start = end;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let mut packed: Vec<f32> = Vec::with_capacity(count * 12);
|
|
84
|
+
for &i in order.iter() {
|
|
85
|
+
let off = i * 9;
|
|
86
|
+
packed.extend_from_slice(&raw[off..off + 3]); // pos.xyz
|
|
87
|
+
packed.push(raw[off + 3]); // rot_y
|
|
88
|
+
packed.push(raw[off + 4]); // scale
|
|
89
|
+
packed.extend_from_slice(&raw[off + 5..off + 9]); // tint.rgba
|
|
90
|
+
packed.extend_from_slice(&[0.0, 0.0, 0.0]); // pad to 48 bytes
|
|
91
|
+
}
|
|
92
|
+
let size = (packed.len() * std::mem::size_of::<f32>()) as u64;
|
|
93
|
+
// Empty buffers can't be created (size 0 is invalid in wgpu).
|
|
94
|
+
// Reserve at least one stride so the BG/binding remains valid.
|
|
95
|
+
let buffer_size = size.max(48);
|
|
96
|
+
let buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
|
97
|
+
label: Some("material_instance_buffer"),
|
|
98
|
+
size: buffer_size,
|
|
99
|
+
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
|
100
|
+
mapped_at_creation: false,
|
|
101
|
+
});
|
|
102
|
+
if !packed.is_empty() {
|
|
103
|
+
queue.write_buffer(&buffer, 0, bytemuck::cast_slice(&packed));
|
|
104
|
+
}
|
|
105
|
+
self.instance_buffers.push(Some(InstanceBuffer {
|
|
106
|
+
buffer,
|
|
107
|
+
count: count as u32,
|
|
108
|
+
tiles,
|
|
109
|
+
}));
|
|
110
|
+
self.instance_buffers.len() as u32
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/// EN-026 — a *dynamic* instance buffer: fixed capacity, rewritten every
|
|
114
|
+
/// frame, never tiled.
|
|
115
|
+
///
|
|
116
|
+
/// The static path above reorders instances into XZ tiles so the
|
|
117
|
+
/// dispatcher can frustum-cull them, which is right for a 20k-blade grass
|
|
118
|
+
/// field that never moves and wrong for particles, which move every frame
|
|
119
|
+
/// and would have to be re-tiled (a sort) each time. Here the caller
|
|
120
|
+
/// simply writes the live prefix of the buffer and draws that many
|
|
121
|
+
/// instances.
|
|
122
|
+
pub fn create_dynamic_instance_buffer(
|
|
123
|
+
&mut self,
|
|
124
|
+
device: &wgpu::Device,
|
|
125
|
+
capacity: u32,
|
|
126
|
+
) -> u32 {
|
|
127
|
+
let size = (capacity.max(1) as u64) * 48;
|
|
128
|
+
let buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
|
129
|
+
label: Some("dynamic_instance_buffer"),
|
|
130
|
+
size,
|
|
131
|
+
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
|
132
|
+
mapped_at_creation: false,
|
|
133
|
+
});
|
|
134
|
+
self.instance_buffers.push(Some(InstanceBuffer {
|
|
135
|
+
buffer,
|
|
136
|
+
count: capacity,
|
|
137
|
+
tiles: Vec::new(),
|
|
138
|
+
}));
|
|
139
|
+
self.instance_buffers.len() as u32
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/// EN-026 — overwrite the first `count` instances of a dynamic buffer.
|
|
143
|
+
/// `packed` is already at the 12-float GPU stride (pos.xyz, rot_y, scale,
|
|
144
|
+
/// tint.rgba, extra.xyz), so this is a straight memcpy into GPU memory
|
|
145
|
+
/// with no per-instance work on the CPU.
|
|
146
|
+
pub fn update_instance_buffer(
|
|
147
|
+
&mut self,
|
|
148
|
+
queue: &wgpu::Queue,
|
|
149
|
+
handle: u32,
|
|
150
|
+
packed: &[f32],
|
|
151
|
+
count: u32,
|
|
152
|
+
) {
|
|
153
|
+
if handle == 0 || count == 0 { return; }
|
|
154
|
+
let idx = handle as usize - 1;
|
|
155
|
+
let Some(Some(ib)) = self.instance_buffers.get(idx) else { return };
|
|
156
|
+
let n = (count as usize).min(packed.len() / 12);
|
|
157
|
+
if n == 0 { return; }
|
|
158
|
+
queue.write_buffer(&ib.buffer, 0, bytemuck::cast_slice(&packed[..n * 12]));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/// EN-001 — drop an instance buffer slot. The slot is left as
|
|
162
|
+
/// `None` so previously-issued handles never alias a future
|
|
163
|
+
/// allocation. No-op for `handle == 0` or out-of-range handles.
|
|
164
|
+
pub fn destroy_instance_buffer(&mut self, handle: u32) {
|
|
165
|
+
if handle == 0 { return; }
|
|
166
|
+
let idx = handle as usize - 1;
|
|
167
|
+
if idx < self.instance_buffers.len() {
|
|
168
|
+
self.instance_buffers[idx] = None;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|