@multiplekex/shallot 0.1.0 → 0.1.1
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/package.json +8 -23
- package/src/standard/compute/index.ts +36 -0
- package/src/standard/render/camera.ts +1 -1
- package/dist/core/builder.d.ts +0 -25
- package/dist/core/builder.d.ts.map +0 -1
- package/dist/core/builder.js +0 -88
- package/dist/core/builder.js.map +0 -1
- package/dist/core/component.d.ts +0 -29
- package/dist/core/component.d.ts.map +0 -1
- package/dist/core/component.js +0 -36
- package/dist/core/component.js.map +0 -1
- package/dist/core/index.d.ts +0 -13
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/math.d.ts +0 -32
- package/dist/core/math.d.ts.map +0 -1
- package/dist/core/math.js +0 -39
- package/dist/core/math.js.map +0 -1
- package/dist/core/relation.d.ts +0 -16
- package/dist/core/relation.d.ts.map +0 -1
- package/dist/core/relation.js +0 -32
- package/dist/core/relation.js.map +0 -1
- package/dist/core/resource.d.ts +0 -9
- package/dist/core/resource.d.ts.map +0 -1
- package/dist/core/resource.js +0 -12
- package/dist/core/resource.js.map +0 -1
- package/dist/core/runtime.d.ts +0 -13
- package/dist/core/runtime.d.ts.map +0 -1
- package/dist/core/runtime.js +0 -118
- package/dist/core/runtime.js.map +0 -1
- package/dist/core/scheduler.d.ts +0 -47
- package/dist/core/scheduler.d.ts.map +0 -1
- package/dist/core/scheduler.js +0 -138
- package/dist/core/scheduler.js.map +0 -1
- package/dist/core/state.d.ts +0 -62
- package/dist/core/state.d.ts.map +0 -1
- package/dist/core/state.js +0 -185
- package/dist/core/state.js.map +0 -1
- package/dist/core/strings.d.ts +0 -3
- package/dist/core/strings.d.ts.map +0 -1
- package/dist/core/strings.js +0 -11
- package/dist/core/strings.js.map +0 -1
- package/dist/core/types.d.ts +0 -33
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/xml.d.ts +0 -42
- package/dist/core/xml.d.ts.map +0 -1
- package/dist/core/xml.js +0 -349
- package/dist/core/xml.js.map +0 -1
- package/dist/extras/arrows/index.d.ts +0 -33
- package/dist/extras/arrows/index.d.ts.map +0 -1
- package/dist/extras/arrows/index.js +0 -288
- package/dist/extras/arrows/index.js.map +0 -1
- package/dist/extras/index.d.ts +0 -5
- package/dist/extras/index.d.ts.map +0 -1
- package/dist/extras/index.js +0 -31
- package/dist/extras/index.js.map +0 -1
- package/dist/extras/lines/index.d.ts +0 -36
- package/dist/extras/lines/index.d.ts.map +0 -1
- package/dist/extras/lines/index.js +0 -288
- package/dist/extras/lines/index.js.map +0 -1
- package/dist/extras/orbit/index.d.ts +0 -20
- package/dist/extras/orbit/index.d.ts.map +0 -1
- package/dist/extras/orbit/index.js +0 -93
- package/dist/extras/orbit/index.js.map +0 -1
- package/dist/extras/text/index.d.ts +0 -64
- package/dist/extras/text/index.d.ts.map +0 -1
- package/dist/extras/text/index.js +0 -423
- package/dist/extras/text/index.js.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -187
- package/dist/index.js.map +0 -1
- package/dist/rust/transforms/pkg/shallot_transforms.js +0 -107
- package/dist/rust/transforms/pkg/shallot_transforms.js.map +0 -1
- package/dist/standard/compute/graph.d.ts +0 -37
- package/dist/standard/compute/graph.d.ts.map +0 -1
- package/dist/standard/compute/graph.js +0 -85
- package/dist/standard/compute/graph.js.map +0 -1
- package/dist/standard/compute/index.d.ts +0 -21
- package/dist/standard/compute/index.d.ts.map +0 -1
- package/dist/standard/compute/index.js +0 -81
- package/dist/standard/compute/index.js.map +0 -1
- package/dist/standard/defaults.d.ts +0 -3
- package/dist/standard/defaults.d.ts.map +0 -1
- package/dist/standard/defaults.js +0 -18
- package/dist/standard/defaults.js.map +0 -1
- package/dist/standard/index.d.ts +0 -8
- package/dist/standard/index.d.ts.map +0 -1
- package/dist/standard/input/index.d.ts +0 -5
- package/dist/standard/input/index.d.ts.map +0 -1
- package/dist/standard/input/index.js +0 -70
- package/dist/standard/input/index.js.map +0 -1
- package/dist/standard/loading/index.d.ts +0 -7
- package/dist/standard/loading/index.d.ts.map +0 -1
- package/dist/standard/loading/index.js +0 -91
- package/dist/standard/loading/index.js.map +0 -1
- package/dist/standard/render/camera.d.ts +0 -36
- package/dist/standard/render/camera.d.ts.map +0 -1
- package/dist/standard/render/camera.js +0 -71
- package/dist/standard/render/camera.js.map +0 -1
- package/dist/standard/render/forward.d.ts +0 -30
- package/dist/standard/render/forward.d.ts.map +0 -1
- package/dist/standard/render/forward.js +0 -158
- package/dist/standard/render/forward.js.map +0 -1
- package/dist/standard/render/index.d.ts +0 -22
- package/dist/standard/render/index.d.ts.map +0 -1
- package/dist/standard/render/index.js +0 -153
- package/dist/standard/render/index.js.map +0 -1
- package/dist/standard/render/light.d.ts +0 -25
- package/dist/standard/render/light.d.ts.map +0 -1
- package/dist/standard/render/light.js +0 -48
- package/dist/standard/render/light.js.map +0 -1
- package/dist/standard/render/mesh/box.d.ts +0 -3
- package/dist/standard/render/mesh/box.d.ts.map +0 -1
- package/dist/standard/render/mesh/box.js +0 -190
- package/dist/standard/render/mesh/box.js.map +0 -1
- package/dist/standard/render/mesh/index.d.ts +0 -52
- package/dist/standard/render/mesh/index.d.ts.map +0 -1
- package/dist/standard/render/mesh/index.js +0 -158
- package/dist/standard/render/mesh/index.js.map +0 -1
- package/dist/standard/render/mesh/plane.d.ts +0 -3
- package/dist/standard/render/mesh/plane.d.ts.map +0 -1
- package/dist/standard/render/mesh/plane.js +0 -33
- package/dist/standard/render/mesh/plane.js.map +0 -1
- package/dist/standard/render/mesh/sphere.d.ts +0 -3
- package/dist/standard/render/mesh/sphere.d.ts.map +0 -1
- package/dist/standard/render/mesh/sphere.js +0 -25
- package/dist/standard/render/mesh/sphere.js.map +0 -1
- package/dist/standard/render/postprocess.d.ts +0 -11
- package/dist/standard/render/postprocess.d.ts.map +0 -1
- package/dist/standard/render/postprocess.js +0 -190
- package/dist/standard/render/postprocess.js.map +0 -1
- package/dist/standard/render/scene.d.ts +0 -8
- package/dist/standard/render/scene.d.ts.map +0 -1
- package/dist/standard/render/scene.js +0 -67
- package/dist/standard/render/scene.js.map +0 -1
- package/dist/standard/transforms/index.d.ts +0 -27
- package/dist/standard/transforms/index.d.ts.map +0 -1
- package/dist/standard/transforms/index.js +0 -122
- package/dist/standard/transforms/index.js.map +0 -1
- package/dist/standard/transforms/wasm.d.ts +0 -17
- package/dist/standard/transforms/wasm.d.ts.map +0 -1
- package/dist/standard/transforms/wasm.js +0 -31
- package/dist/standard/transforms/wasm.js.map +0 -1
- package/dist/standard/tween/easing.d.ts +0 -5
- package/dist/standard/tween/easing.d.ts.map +0 -1
- package/dist/standard/tween/easing.js +0 -80
- package/dist/standard/tween/easing.js.map +0 -1
- package/dist/standard/tween/index.d.ts +0 -4
- package/dist/standard/tween/index.d.ts.map +0 -1
- package/dist/standard/tween/sequence.d.ts +0 -20
- package/dist/standard/tween/sequence.d.ts.map +0 -1
- package/dist/standard/tween/sequence.js +0 -95
- package/dist/standard/tween/sequence.js.map +0 -1
- package/dist/standard/tween/tween.d.ts +0 -28
- package/dist/standard/tween/tween.d.ts.map +0 -1
- package/dist/standard/tween/tween.js +0 -136
- package/dist/standard/tween/tween.js.map +0 -1
- package/src/vite-env.d.ts +0 -6
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { setTraits as a } from "../../core/component.js";
|
|
2
|
-
import { WorldTransform as m } from "../transforms/index.js";
|
|
3
|
-
import { clearColor as n } from "./forward.js";
|
|
4
|
-
import { perspective as p, invert as d, multiply as g } from "./scene.js";
|
|
5
|
-
const C = {
|
|
6
|
-
Raster: 0,
|
|
7
|
-
Raytracing: 1
|
|
8
|
-
}, v = {
|
|
9
|
-
Color: 0,
|
|
10
|
-
Depth: 1,
|
|
11
|
-
Normal: 2,
|
|
12
|
-
Material: 3,
|
|
13
|
-
Hit: 4
|
|
14
|
-
}, e = {
|
|
15
|
-
fov: [],
|
|
16
|
-
near: [],
|
|
17
|
-
far: [],
|
|
18
|
-
active: [],
|
|
19
|
-
clearColor: [],
|
|
20
|
-
renderMode: [],
|
|
21
|
-
debugMode: []
|
|
22
|
-
};
|
|
23
|
-
a(e, {
|
|
24
|
-
defaults: () => ({
|
|
25
|
-
fov: 60,
|
|
26
|
-
near: 0.1,
|
|
27
|
-
far: 1e3,
|
|
28
|
-
active: 1,
|
|
29
|
-
clearColor: 1710618,
|
|
30
|
-
renderMode: C.Raster,
|
|
31
|
-
debugMode: v.Color
|
|
32
|
-
})
|
|
33
|
-
});
|
|
34
|
-
const M = {
|
|
35
|
-
exposure: []
|
|
36
|
-
};
|
|
37
|
-
a(M, {
|
|
38
|
-
defaults: () => ({ exposure: 1 })
|
|
39
|
-
});
|
|
40
|
-
const T = {}, b = {
|
|
41
|
-
strength: [],
|
|
42
|
-
inner: [],
|
|
43
|
-
outer: []
|
|
44
|
-
};
|
|
45
|
-
a(b, {
|
|
46
|
-
defaults: () => ({ strength: 0.5, inner: 0.4, outer: 0.8 })
|
|
47
|
-
});
|
|
48
|
-
function w(r) {
|
|
49
|
-
return {
|
|
50
|
-
r: (r >> 16 & 255) / 255,
|
|
51
|
-
g: (r >> 8 & 255) / 255,
|
|
52
|
-
b: (r & 255) / 255
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function j(r, s, o, u) {
|
|
56
|
-
const t = w(e.clearColor[o]);
|
|
57
|
-
n.r = t.r, n.g = t.g, n.b = t.b;
|
|
58
|
-
const c = p(e.fov[o], u, e.near[o], e.far[o]), l = m.data.subarray(o * 16, o * 16 + 16), f = d(l), i = g(c, f);
|
|
59
|
-
r.queue.writeBuffer(s, 0, i), r.queue.writeBuffer(s, 64, l);
|
|
60
|
-
}
|
|
61
|
-
export {
|
|
62
|
-
e as Camera,
|
|
63
|
-
v as DebugMode,
|
|
64
|
-
T as FXAA,
|
|
65
|
-
C as RenderMode,
|
|
66
|
-
M as Tonemap,
|
|
67
|
-
b as Vignette,
|
|
68
|
-
w as unpackColor,
|
|
69
|
-
j as uploadCamera
|
|
70
|
-
};
|
|
71
|
-
//# sourceMappingURL=camera.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"camera.js","sources":["../../../src/standard/render/camera.ts"],"sourcesContent":["import { setTraits } from \"../../core/component\";\nimport { WorldTransform } from \"../transforms\";\nimport { clearColor } from \"./forward\";\nimport { perspective, multiply, invert } from \"./scene\";\n\nexport const RenderMode = {\n Raster: 0,\n Raytracing: 1,\n} as const;\n\nexport const DebugMode = {\n Color: 0,\n Depth: 1,\n Normal: 2,\n Material: 3,\n Hit: 4,\n} as const;\n\nexport const Camera = {\n fov: [] as number[],\n near: [] as number[],\n far: [] as number[],\n active: [] as number[],\n clearColor: [] as number[],\n renderMode: [] as number[],\n debugMode: [] as number[],\n};\n\nsetTraits(Camera, {\n defaults: () => ({\n fov: 60,\n near: 0.1,\n far: 1000,\n active: 1,\n clearColor: 0x1a1a1a,\n renderMode: RenderMode.Raster,\n debugMode: DebugMode.Color,\n }),\n});\n\nexport const Tonemap = {\n exposure: [] as number[],\n};\n\nsetTraits(Tonemap, {\n defaults: () => ({ exposure: 1.0 }),\n});\n\nexport const FXAA = {};\n\nexport const Vignette = {\n strength: [] as number[],\n inner: [] as number[],\n outer: [] as number[],\n};\n\nsetTraits(Vignette, {\n defaults: () => ({ strength: 0.5, inner: 0.4, outer: 0.8 }),\n});\n\nexport function unpackColor(packed: number): { r: number; g: number; b: number } {\n return {\n r: ((packed >> 16) & 0xff) / 255,\n g: ((packed >> 8) & 0xff) / 255,\n b: (packed & 0xff) / 255,\n };\n}\n\nexport function uploadCamera(\n device: GPUDevice,\n buffer: GPUBuffer,\n eid: number,\n aspect: number\n): void {\n const color = unpackColor(Camera.clearColor[eid]);\n clearColor.r = color.r;\n clearColor.g = color.g;\n clearColor.b = color.b;\n\n const proj = perspective(Camera.fov[eid], aspect, Camera.near[eid], Camera.far[eid]);\n const world = WorldTransform.data.subarray(eid * 16, eid * 16 + 16);\n const view = invert(world);\n const viewProj = multiply(proj, view);\n\n device.queue.writeBuffer(buffer, 0, viewProj as Float32Array<ArrayBuffer>);\n device.queue.writeBuffer(buffer, 64, world);\n}\n"],"names":["RenderMode","DebugMode","Camera","setTraits","Tonemap","FXAA","Vignette","unpackColor","packed","uploadCamera","device","buffer","eid","aspect","color","clearColor","proj","perspective","world","WorldTransform","view","invert","viewProj","multiply"],"mappings":";;;;AAKO,MAAMA,IAAa;AAAA,EACtB,QAAQ;AAAA,EACR,YAAY;AAChB,GAEaC,IAAY;AAAA,EACrB,OAAO;AAAA,EACP,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,KAAK;AACT,GAEaC,IAAS;AAAA,EAClB,KAAK,CAAA;AAAA,EACL,MAAM,CAAA;AAAA,EACN,KAAK,CAAA;AAAA,EACL,QAAQ,CAAA;AAAA,EACR,YAAY,CAAA;AAAA,EACZ,YAAY,CAAA;AAAA,EACZ,WAAW,CAAA;AACf;AAEAC,EAAUD,GAAQ;AAAA,EACd,UAAU,OAAO;AAAA,IACb,KAAK;AAAA,IACL,MAAM;AAAA,IACN,KAAK;AAAA,IACL,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,YAAYF,EAAW;AAAA,IACvB,WAAWC,EAAU;AAAA,EAAA;AAE7B,CAAC;AAEM,MAAMG,IAAU;AAAA,EACnB,UAAU,CAAA;AACd;AAEAD,EAAUC,GAAS;AAAA,EACf,UAAU,OAAO,EAAE,UAAU,EAAA;AACjC,CAAC;AAEM,MAAMC,IAAO,CAAA,GAEPC,IAAW;AAAA,EACpB,UAAU,CAAA;AAAA,EACV,OAAO,CAAA;AAAA,EACP,OAAO,CAAA;AACX;AAEAH,EAAUG,GAAU;AAAA,EAChB,UAAU,OAAO,EAAE,UAAU,KAAK,OAAO,KAAK,OAAO,IAAA;AACzD,CAAC;AAEM,SAASC,EAAYC,GAAqD;AAC7E,SAAO;AAAA,IACH,IAAKA,KAAU,KAAM,OAAQ;AAAA,IAC7B,IAAKA,KAAU,IAAK,OAAQ;AAAA,IAC5B,IAAIA,IAAS,OAAQ;AAAA,EAAA;AAE7B;AAEO,SAASC,EACZC,GACAC,GACAC,GACAC,GACI;AACJ,QAAMC,IAAQP,EAAYL,EAAO,WAAWU,CAAG,CAAC;AAChD,EAAAG,EAAW,IAAID,EAAM,GACrBC,EAAW,IAAID,EAAM,GACrBC,EAAW,IAAID,EAAM;AAErB,QAAME,IAAOC,EAAYf,EAAO,IAAIU,CAAG,GAAGC,GAAQX,EAAO,KAAKU,CAAG,GAAGV,EAAO,IAAIU,CAAG,CAAC,GAC7EM,IAAQC,EAAe,KAAK,SAASP,IAAM,IAAIA,IAAM,KAAK,EAAE,GAC5DQ,IAAOC,EAAOH,CAAK,GACnBI,IAAWC,EAASP,GAAMI,CAAI;AAEpC,EAAAV,EAAO,MAAM,YAAYC,GAAQ,GAAGW,CAAqC,GACzEZ,EAAO,MAAM,YAAYC,GAAQ,IAAIO,CAAK;AAC9C;"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ComputeNode } from '../compute';
|
|
2
|
-
import { ShapeBatch } from './mesh';
|
|
3
|
-
export declare const INDIRECT_SIZE = 20;
|
|
4
|
-
export interface IndirectArgs {
|
|
5
|
-
indexCount: number;
|
|
6
|
-
instanceCount: number;
|
|
7
|
-
firstIndex: number;
|
|
8
|
-
baseVertex: number;
|
|
9
|
-
firstInstance: number;
|
|
10
|
-
}
|
|
11
|
-
export declare function createIndirectBuffer(device: GPUDevice, slotCount: number): GPUBuffer;
|
|
12
|
-
export declare function writeIndirect(device: GPUDevice, buffer: GPUBuffer, slot: number, args: IndirectArgs): void;
|
|
13
|
-
export declare const litShader = "\nstruct VertexInput {\n @location(0) position: vec3<f32>,\n @location(1) normal: vec3<f32>,\n @builtin(instance_index) instance: u32,\n}\n\nstruct VertexOutput {\n @builtin(position) position: vec4<f32>,\n @location(0) color: vec4<f32>,\n @location(1) worldNormal: vec3<f32>,\n}\n\nstruct Scene {\n viewProj: mat4x4<f32>,\n cameraWorld: mat4x4<f32>,\n ambientColor: vec4<f32>,\n sunDirection: vec4<f32>,\n sunColor: vec4<f32>,\n}\n\n@group(0) @binding(0) var<uniform> scene: Scene;\n@group(0) @binding(1) var<storage, read> entityIds: array<u32>;\n@group(0) @binding(2) var<storage, read> matrices: array<mat4x4<f32>>;\n@group(0) @binding(3) var<storage, read> colors: array<vec4<f32>>;\n@group(0) @binding(4) var<storage, read> sizes: array<vec4<f32>>;\n\n@vertex\nfn vs(input: VertexInput) -> VertexOutput {\n let eid = entityIds[input.instance];\n let world = matrices[eid];\n let scaledPos = input.position * sizes[eid].xyz;\n let worldPos = world * vec4<f32>(scaledPos, 1.0);\n let worldNormal = normalize((world * vec4<f32>(input.normal, 0.0)).xyz);\n\n var output: VertexOutput;\n output.position = scene.viewProj * worldPos;\n output.color = colors[eid];\n output.worldNormal = worldNormal;\n return output;\n}\n\n@fragment\nfn fs(input: VertexOutput) -> @location(0) vec4<f32> {\n let normal = normalize(input.worldNormal);\n let NdotL = max(dot(normal, -scene.sunDirection.xyz), 0.0);\n\n let ambient = scene.ambientColor.rgb * scene.ambientColor.a;\n let diffuse = scene.sunColor.rgb * NdotL;\n let lighting = ambient + diffuse;\n\n return vec4<f32>(input.color.rgb * lighting, input.color.a);\n}\n";
|
|
14
|
-
export declare function createForwardPipeline(device: GPUDevice, format: GPUTextureFormat): GPURenderPipeline;
|
|
15
|
-
export declare const clearColor: {
|
|
16
|
-
r: number;
|
|
17
|
-
g: number;
|
|
18
|
-
b: number;
|
|
19
|
-
a: number;
|
|
20
|
-
};
|
|
21
|
-
export interface ForwardConfig {
|
|
22
|
-
scene: GPUBuffer;
|
|
23
|
-
matrices: GPUBuffer;
|
|
24
|
-
colors: GPUBuffer;
|
|
25
|
-
sizes: GPUBuffer;
|
|
26
|
-
indirect: GPUBuffer;
|
|
27
|
-
batches: Map<number, ShapeBatch>;
|
|
28
|
-
}
|
|
29
|
-
export declare function createForwardNode(config: ForwardConfig): ComputeNode;
|
|
30
|
-
//# sourceMappingURL=forward.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"forward.d.ts","sourceRoot":"","sources":["../../../src/standard/render/forward.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAoB,MAAM,YAAY,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAGzC,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC,MAAM,WAAW,YAAY;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,CAUpF;AAED,wBAAgB,aAAa,CACzB,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,YAAY,GACnB,IAAI,CAYN;AAED,eAAO,MAAM,SAAS,gqDAqDrB,CAAC;AAEF,wBAAgB,qBAAqB,CACjC,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,gBAAgB,GACzB,iBAAiB,CAiCnB;AAED,eAAO,MAAM,UAAU;;;;;CAAmC,CAAC;AAE3D,MAAM,WAAW,aAAa;IAC1B,KAAK,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CACpC;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,GAAG,WAAW,CA8DpE"}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { DEPTH_FORMAT as p } from "./scene.js";
|
|
2
|
-
const d = 20;
|
|
3
|
-
function w(e, t) {
|
|
4
|
-
return e.createBuffer({
|
|
5
|
-
label: "indirect",
|
|
6
|
-
size: t * d,
|
|
7
|
-
usage: GPUBufferUsage.INDIRECT | GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
function x(e, t, n, r) {
|
|
11
|
-
const s = n * d, u = new ArrayBuffer(d), o = new DataView(u);
|
|
12
|
-
o.setUint32(0, r.indexCount, !0), o.setUint32(4, r.instanceCount, !0), o.setUint32(8, r.firstIndex, !0), o.setInt32(12, r.baseVertex, !0), o.setUint32(16, r.firstInstance, !0), e.queue.writeBuffer(t, s, u);
|
|
13
|
-
}
|
|
14
|
-
const b = (
|
|
15
|
-
/* wgsl */
|
|
16
|
-
`
|
|
17
|
-
struct VertexInput {
|
|
18
|
-
@location(0) position: vec3<f32>,
|
|
19
|
-
@location(1) normal: vec3<f32>,
|
|
20
|
-
@builtin(instance_index) instance: u32,
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
struct VertexOutput {
|
|
24
|
-
@builtin(position) position: vec4<f32>,
|
|
25
|
-
@location(0) color: vec4<f32>,
|
|
26
|
-
@location(1) worldNormal: vec3<f32>,
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
struct Scene {
|
|
30
|
-
viewProj: mat4x4<f32>,
|
|
31
|
-
cameraWorld: mat4x4<f32>,
|
|
32
|
-
ambientColor: vec4<f32>,
|
|
33
|
-
sunDirection: vec4<f32>,
|
|
34
|
-
sunColor: vec4<f32>,
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
@group(0) @binding(0) var<uniform> scene: Scene;
|
|
38
|
-
@group(0) @binding(1) var<storage, read> entityIds: array<u32>;
|
|
39
|
-
@group(0) @binding(2) var<storage, read> matrices: array<mat4x4<f32>>;
|
|
40
|
-
@group(0) @binding(3) var<storage, read> colors: array<vec4<f32>>;
|
|
41
|
-
@group(0) @binding(4) var<storage, read> sizes: array<vec4<f32>>;
|
|
42
|
-
|
|
43
|
-
@vertex
|
|
44
|
-
fn vs(input: VertexInput) -> VertexOutput {
|
|
45
|
-
let eid = entityIds[input.instance];
|
|
46
|
-
let world = matrices[eid];
|
|
47
|
-
let scaledPos = input.position * sizes[eid].xyz;
|
|
48
|
-
let worldPos = world * vec4<f32>(scaledPos, 1.0);
|
|
49
|
-
let worldNormal = normalize((world * vec4<f32>(input.normal, 0.0)).xyz);
|
|
50
|
-
|
|
51
|
-
var output: VertexOutput;
|
|
52
|
-
output.position = scene.viewProj * worldPos;
|
|
53
|
-
output.color = colors[eid];
|
|
54
|
-
output.worldNormal = worldNormal;
|
|
55
|
-
return output;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
@fragment
|
|
59
|
-
fn fs(input: VertexOutput) -> @location(0) vec4<f32> {
|
|
60
|
-
let normal = normalize(input.worldNormal);
|
|
61
|
-
let NdotL = max(dot(normal, -scene.sunDirection.xyz), 0.0);
|
|
62
|
-
|
|
63
|
-
let ambient = scene.ambientColor.rgb * scene.ambientColor.a;
|
|
64
|
-
let diffuse = scene.sunColor.rgb * NdotL;
|
|
65
|
-
let lighting = ambient + diffuse;
|
|
66
|
-
|
|
67
|
-
return vec4<f32>(input.color.rgb * lighting, input.color.a);
|
|
68
|
-
}
|
|
69
|
-
`
|
|
70
|
-
);
|
|
71
|
-
function m(e, t) {
|
|
72
|
-
const n = e.createShaderModule({ code: b });
|
|
73
|
-
return e.createRenderPipeline({
|
|
74
|
-
layout: "auto",
|
|
75
|
-
vertex: {
|
|
76
|
-
module: n,
|
|
77
|
-
entryPoint: "vs",
|
|
78
|
-
buffers: [
|
|
79
|
-
{
|
|
80
|
-
arrayStride: 24,
|
|
81
|
-
attributes: [
|
|
82
|
-
{ shaderLocation: 0, offset: 0, format: "float32x3" },
|
|
83
|
-
{ shaderLocation: 1, offset: 12, format: "float32x3" }
|
|
84
|
-
]
|
|
85
|
-
}
|
|
86
|
-
]
|
|
87
|
-
},
|
|
88
|
-
fragment: {
|
|
89
|
-
module: n,
|
|
90
|
-
entryPoint: "fs",
|
|
91
|
-
targets: [{ format: t }]
|
|
92
|
-
},
|
|
93
|
-
primitive: {
|
|
94
|
-
topology: "triangle-list",
|
|
95
|
-
cullMode: "back"
|
|
96
|
-
},
|
|
97
|
-
depthStencil: {
|
|
98
|
-
format: p,
|
|
99
|
-
depthWriteEnabled: !0,
|
|
100
|
-
depthCompare: "less"
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
const g = { r: 0.1, g: 0.1, b: 0.1, a: 1 };
|
|
105
|
-
function h(e) {
|
|
106
|
-
let t = null;
|
|
107
|
-
const n = /* @__PURE__ */ new Map();
|
|
108
|
-
return {
|
|
109
|
-
id: "forward",
|
|
110
|
-
inputs: [],
|
|
111
|
-
outputs: [{ id: "scene", access: "write" }],
|
|
112
|
-
execute(r) {
|
|
113
|
-
const { device: s, encoder: u, format: o } = r, l = r.getTextureView("scene") ?? r.canvasView, f = r.getTextureView("depth");
|
|
114
|
-
t || (t = m(s, o));
|
|
115
|
-
const i = u.beginRenderPass({
|
|
116
|
-
colorAttachments: [
|
|
117
|
-
{
|
|
118
|
-
view: l,
|
|
119
|
-
clearValue: g,
|
|
120
|
-
loadOp: "clear",
|
|
121
|
-
storeOp: "store"
|
|
122
|
-
}
|
|
123
|
-
],
|
|
124
|
-
depthStencilAttachment: {
|
|
125
|
-
view: f,
|
|
126
|
-
depthClearValue: 1,
|
|
127
|
-
depthLoadOp: "clear",
|
|
128
|
-
depthStoreOp: "store"
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
i.setPipeline(t);
|
|
132
|
-
for (const a of e.batches.values()) {
|
|
133
|
-
let c = n.get(a.index);
|
|
134
|
-
c || (c = s.createBindGroup({
|
|
135
|
-
layout: t.getBindGroupLayout(0),
|
|
136
|
-
entries: [
|
|
137
|
-
{ binding: 0, resource: { buffer: e.scene } },
|
|
138
|
-
{ binding: 1, resource: { buffer: a.entityIds } },
|
|
139
|
-
{ binding: 2, resource: { buffer: e.matrices } },
|
|
140
|
-
{ binding: 3, resource: { buffer: e.colors } },
|
|
141
|
-
{ binding: 4, resource: { buffer: e.sizes } }
|
|
142
|
-
]
|
|
143
|
-
}), n.set(a.index, c)), i.setBindGroup(0, c), i.setVertexBuffer(0, a.buffers.vertex), i.setIndexBuffer(a.buffers.index, "uint16"), i.drawIndexedIndirect(e.indirect, a.index * d);
|
|
144
|
-
}
|
|
145
|
-
i.end();
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
export {
|
|
150
|
-
d as INDIRECT_SIZE,
|
|
151
|
-
g as clearColor,
|
|
152
|
-
h as createForwardNode,
|
|
153
|
-
m as createForwardPipeline,
|
|
154
|
-
w as createIndirectBuffer,
|
|
155
|
-
b as litShader,
|
|
156
|
-
x as writeIndirect
|
|
157
|
-
};
|
|
158
|
-
//# sourceMappingURL=forward.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"forward.js","sources":["../../../src/standard/render/forward.ts"],"sourcesContent":["import type { ComputeNode, ExecutionContext } from \"../compute\";\nimport type { ShapeBatch } from \"./mesh\";\nimport { DEPTH_FORMAT } from \"./scene\";\n\nexport const INDIRECT_SIZE = 20;\n\nexport interface IndirectArgs {\n indexCount: number;\n instanceCount: number;\n firstIndex: number;\n baseVertex: number;\n firstInstance: number;\n}\n\nexport function createIndirectBuffer(device: GPUDevice, slotCount: number): GPUBuffer {\n return device.createBuffer({\n label: \"indirect\",\n size: slotCount * INDIRECT_SIZE,\n usage:\n GPUBufferUsage.INDIRECT |\n GPUBufferUsage.STORAGE |\n GPUBufferUsage.COPY_DST |\n GPUBufferUsage.COPY_SRC,\n });\n}\n\nexport function writeIndirect(\n device: GPUDevice,\n buffer: GPUBuffer,\n slot: number,\n args: IndirectArgs\n): void {\n const offset = slot * INDIRECT_SIZE;\n const data = new ArrayBuffer(INDIRECT_SIZE);\n const view = new DataView(data);\n\n view.setUint32(0, args.indexCount, true);\n view.setUint32(4, args.instanceCount, true);\n view.setUint32(8, args.firstIndex, true);\n view.setInt32(12, args.baseVertex, true);\n view.setUint32(16, args.firstInstance, true);\n\n device.queue.writeBuffer(buffer, offset, data);\n}\n\nexport const litShader = /* wgsl */ `\nstruct VertexInput {\n @location(0) position: vec3<f32>,\n @location(1) normal: vec3<f32>,\n @builtin(instance_index) instance: u32,\n}\n\nstruct VertexOutput {\n @builtin(position) position: vec4<f32>,\n @location(0) color: vec4<f32>,\n @location(1) worldNormal: vec3<f32>,\n}\n\nstruct Scene {\n viewProj: mat4x4<f32>,\n cameraWorld: mat4x4<f32>,\n ambientColor: vec4<f32>,\n sunDirection: vec4<f32>,\n sunColor: vec4<f32>,\n}\n\n@group(0) @binding(0) var<uniform> scene: Scene;\n@group(0) @binding(1) var<storage, read> entityIds: array<u32>;\n@group(0) @binding(2) var<storage, read> matrices: array<mat4x4<f32>>;\n@group(0) @binding(3) var<storage, read> colors: array<vec4<f32>>;\n@group(0) @binding(4) var<storage, read> sizes: array<vec4<f32>>;\n\n@vertex\nfn vs(input: VertexInput) -> VertexOutput {\n let eid = entityIds[input.instance];\n let world = matrices[eid];\n let scaledPos = input.position * sizes[eid].xyz;\n let worldPos = world * vec4<f32>(scaledPos, 1.0);\n let worldNormal = normalize((world * vec4<f32>(input.normal, 0.0)).xyz);\n\n var output: VertexOutput;\n output.position = scene.viewProj * worldPos;\n output.color = colors[eid];\n output.worldNormal = worldNormal;\n return output;\n}\n\n@fragment\nfn fs(input: VertexOutput) -> @location(0) vec4<f32> {\n let normal = normalize(input.worldNormal);\n let NdotL = max(dot(normal, -scene.sunDirection.xyz), 0.0);\n\n let ambient = scene.ambientColor.rgb * scene.ambientColor.a;\n let diffuse = scene.sunColor.rgb * NdotL;\n let lighting = ambient + diffuse;\n\n return vec4<f32>(input.color.rgb * lighting, input.color.a);\n}\n`;\n\nexport function createForwardPipeline(\n device: GPUDevice,\n format: GPUTextureFormat\n): GPURenderPipeline {\n const module = device.createShaderModule({ code: litShader });\n\n return device.createRenderPipeline({\n layout: \"auto\",\n vertex: {\n module,\n entryPoint: \"vs\",\n buffers: [\n {\n arrayStride: 24,\n attributes: [\n { shaderLocation: 0, offset: 0, format: \"float32x3\" as const },\n { shaderLocation: 1, offset: 12, format: \"float32x3\" as const },\n ],\n },\n ],\n },\n fragment: {\n module,\n entryPoint: \"fs\",\n targets: [{ format }],\n },\n primitive: {\n topology: \"triangle-list\",\n cullMode: \"back\",\n },\n depthStencil: {\n format: DEPTH_FORMAT,\n depthWriteEnabled: true,\n depthCompare: \"less\",\n },\n });\n}\n\nexport const clearColor = { r: 0.1, g: 0.1, b: 0.1, a: 1 };\n\nexport interface ForwardConfig {\n scene: GPUBuffer;\n matrices: GPUBuffer;\n colors: GPUBuffer;\n sizes: GPUBuffer;\n indirect: GPUBuffer;\n batches: Map<number, ShapeBatch>;\n}\n\nexport function createForwardNode(config: ForwardConfig): ComputeNode {\n let pipeline: GPURenderPipeline | null = null;\n const bindGroups = new Map<number, GPUBindGroup>();\n\n return {\n id: \"forward\",\n inputs: [],\n outputs: [{ id: \"scene\", access: \"write\" }],\n\n execute(ctx: ExecutionContext) {\n const { device, encoder, format } = ctx;\n const targetView = ctx.getTextureView(\"scene\") ?? ctx.canvasView;\n const depthView = ctx.getTextureView(\"depth\")!;\n\n if (!pipeline) {\n pipeline = createForwardPipeline(device, format);\n }\n\n const pass = encoder.beginRenderPass({\n colorAttachments: [\n {\n view: targetView,\n clearValue: clearColor,\n loadOp: \"clear\" as const,\n storeOp: \"store\" as const,\n },\n ],\n depthStencilAttachment: {\n view: depthView,\n depthClearValue: 1.0,\n depthLoadOp: \"clear\" as const,\n depthStoreOp: \"store\" as const,\n },\n });\n\n pass.setPipeline(pipeline);\n\n for (const batch of config.batches.values()) {\n let bindGroup = bindGroups.get(batch.index);\n if (!bindGroup) {\n bindGroup = device.createBindGroup({\n layout: pipeline.getBindGroupLayout(0),\n entries: [\n { binding: 0, resource: { buffer: config.scene } },\n { binding: 1, resource: { buffer: batch.entityIds } },\n { binding: 2, resource: { buffer: config.matrices } },\n { binding: 3, resource: { buffer: config.colors } },\n { binding: 4, resource: { buffer: config.sizes } },\n ],\n });\n bindGroups.set(batch.index, bindGroup);\n }\n\n pass.setBindGroup(0, bindGroup);\n pass.setVertexBuffer(0, batch.buffers.vertex);\n pass.setIndexBuffer(batch.buffers.index, \"uint16\");\n pass.drawIndexedIndirect(config.indirect, batch.index * INDIRECT_SIZE);\n }\n\n pass.end();\n },\n };\n}\n"],"names":["INDIRECT_SIZE","createIndirectBuffer","device","slotCount","writeIndirect","buffer","slot","args","offset","data","view","litShader","createForwardPipeline","format","module","DEPTH_FORMAT","clearColor","createForwardNode","config","pipeline","bindGroups","ctx","encoder","targetView","depthView","pass","batch","bindGroup"],"mappings":";AAIO,MAAMA,IAAgB;AAUtB,SAASC,EAAqBC,GAAmBC,GAA8B;AAClF,SAAOD,EAAO,aAAa;AAAA,IACvB,OAAO;AAAA,IACP,MAAMC,IAAYH;AAAA,IAClB,OACI,eAAe,WACf,eAAe,UACf,eAAe,WACf,eAAe;AAAA,EAAA,CACtB;AACL;AAEO,SAASI,EACZF,GACAG,GACAC,GACAC,GACI;AACJ,QAAMC,IAASF,IAAON,GAChBS,IAAO,IAAI,YAAYT,CAAa,GACpCU,IAAO,IAAI,SAASD,CAAI;AAE9B,EAAAC,EAAK,UAAU,GAAGH,EAAK,YAAY,EAAI,GACvCG,EAAK,UAAU,GAAGH,EAAK,eAAe,EAAI,GAC1CG,EAAK,UAAU,GAAGH,EAAK,YAAY,EAAI,GACvCG,EAAK,SAAS,IAAIH,EAAK,YAAY,EAAI,GACvCG,EAAK,UAAU,IAAIH,EAAK,eAAe,EAAI,GAE3CL,EAAO,MAAM,YAAYG,GAAQG,GAAQC,CAAI;AACjD;AAEO,MAAME;AAAA;AA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EAAK,gBAAgB,GAAGC,EAAM,QAAQ,MAAM,GAC5CD,EAAK,eAAeC,EAAM,QAAQ,OAAO,QAAQ,GACjDD,EAAK,oBAAoBP,EAAO,UAAUQ,EAAM,QAAQ1B,CAAa;AAAA,MACzE;AAEA,MAAAyB,EAAK,IAAA;AAAA,IACT;AAAA,EAAA;AAER;"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Plugin } from '../../core';
|
|
2
|
-
import { ShapeBatch, MeshBuffers } from './mesh';
|
|
3
|
-
import { PostProcessUniforms } from './postprocess';
|
|
4
|
-
export * from './camera';
|
|
5
|
-
export * from './light';
|
|
6
|
-
export * from './mesh';
|
|
7
|
-
export * from './scene';
|
|
8
|
-
export * from './forward';
|
|
9
|
-
export * from './postprocess';
|
|
10
|
-
export interface RenderState {
|
|
11
|
-
scene: GPUBuffer;
|
|
12
|
-
matrices: GPUBuffer;
|
|
13
|
-
colors: GPUBuffer;
|
|
14
|
-
sizes: GPUBuffer;
|
|
15
|
-
indirect: GPUBuffer;
|
|
16
|
-
batches: Map<number, ShapeBatch>;
|
|
17
|
-
buffers: Map<number, MeshBuffers>;
|
|
18
|
-
postProcess: PostProcessUniforms;
|
|
19
|
-
}
|
|
20
|
-
export declare const Render: import('../..').ResourceKey<RenderState>;
|
|
21
|
-
export declare const RenderPlugin: Plugin;
|
|
22
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/standard/render/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,YAAY,CAAC;AAMxD,OAAO,EAMH,KAAK,UAAU,EACf,KAAK,WAAW,EACnB,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAAyB,KAAK,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEhF,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAE9B,MAAM,WAAW,WAAW;IACxB,KAAK,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACjC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAClC,WAAW,EAAE,mBAAmB,CAAC;CACpC;AAED,eAAO,MAAM,MAAM,0CAAkC,CAAC;AAsFtD,eAAO,MAAM,YAAY,EAAE,MAmD1B,CAAC"}
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import "bitecs";
|
|
2
|
-
import { MAX_ENTITIES as f } from "../../core/state.js";
|
|
3
|
-
import "../../core/builder.js";
|
|
4
|
-
import { resource as w } from "../../core/resource.js";
|
|
5
|
-
import "../../core/relation.js";
|
|
6
|
-
import "../../core/math.js";
|
|
7
|
-
import "fast-xml-parser";
|
|
8
|
-
import { ComputePlugin as M, Compute as y } from "../compute/index.js";
|
|
9
|
-
import { WorldTransform as P } from "../transforms/index.js";
|
|
10
|
-
import { Vignette as c, FXAA as S, Tonemap as m, Camera as u, uploadCamera as I } from "./camera.js";
|
|
11
|
-
import { DebugMode as te, RenderMode as ie, unpackColor as se } from "./camera.js";
|
|
12
|
-
import { DirectionalLight as s, AmbientLight as p, packLightUniforms as R } from "./light.js";
|
|
13
|
-
import { normalizeDirection as ce } from "./light.js";
|
|
14
|
-
import { Mesh as C, collectByShape as E, MeshColors as T, MeshSizes as U, updateBatches as q } from "./mesh/index.js";
|
|
15
|
-
import { MeshShape as pe, createGeometry as fe, createMeshBuffers as me } from "./mesh/index.js";
|
|
16
|
-
import { createSceneBuffer as D, ensureRenderTextures as z } from "./scene.js";
|
|
17
|
-
import { DEPTH_FORMAT as de, SCENE_UNIFORM_SIZE as le, invert as he, multiply as ge, perspective as Pe } from "./scene.js";
|
|
18
|
-
import { createIndirectBuffer as O, createForwardNode as _ } from "./forward.js";
|
|
19
|
-
import { INDIRECT_SIZE as Se, clearColor as Ce, createForwardPipeline as xe, litShader as Be, writeIndirect as ve } from "./forward.js";
|
|
20
|
-
import { createPostProcessNode as A } from "./postprocess.js";
|
|
21
|
-
const x = w("render"), N = {
|
|
22
|
-
group: "draw",
|
|
23
|
-
first: !0,
|
|
24
|
-
update(o) {
|
|
25
|
-
const e = x.from(o), n = y.from(o);
|
|
26
|
-
if (!e || !n || !o.canvas) return;
|
|
27
|
-
const { device: t, format: i, resources: a } = n, { width: d, height: l } = o.canvas;
|
|
28
|
-
z(
|
|
29
|
-
t,
|
|
30
|
-
i,
|
|
31
|
-
d,
|
|
32
|
-
l,
|
|
33
|
-
a.textures,
|
|
34
|
-
a.textureViews
|
|
35
|
-
);
|
|
36
|
-
for (const r of o.query([u]))
|
|
37
|
-
if (u.active[r]) {
|
|
38
|
-
I(t, e.scene, r, d / l), e.postProcess.tonemap = o.hasComponent(r, m), e.postProcess.tonemap && (e.postProcess.exposure = m.exposure[r]), e.postProcess.fxaa = o.hasComponent(r, S), o.hasComponent(r, c) && (e.postProcess.vignetteStrength = c.strength[r], e.postProcess.vignetteInner = c.inner[r], e.postProcess.vignetteOuter = c.outer[r]);
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
let h = { color: 8947848, intensity: 1 }, g = {
|
|
42
|
-
color: 16777215,
|
|
43
|
-
intensity: 1,
|
|
44
|
-
directionX: -0.5,
|
|
45
|
-
directionY: -1,
|
|
46
|
-
directionZ: -0.5
|
|
47
|
-
};
|
|
48
|
-
for (const r of o.query([p])) {
|
|
49
|
-
h = {
|
|
50
|
-
color: p.color[r],
|
|
51
|
-
intensity: p.intensity[r]
|
|
52
|
-
};
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
for (const r of o.query([s])) {
|
|
56
|
-
g = {
|
|
57
|
-
color: s.color[r],
|
|
58
|
-
intensity: s.intensity[r],
|
|
59
|
-
directionX: s.directionX[r],
|
|
60
|
-
directionY: s.directionY[r],
|
|
61
|
-
directionZ: s.directionZ[r]
|
|
62
|
-
};
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
const B = R(h, g);
|
|
66
|
-
t.queue.writeBuffer(e.scene, 128, B), t.queue.writeBuffer(
|
|
67
|
-
e.matrices,
|
|
68
|
-
0,
|
|
69
|
-
P.data
|
|
70
|
-
);
|
|
71
|
-
const v = o.query([C, P]), b = E(v);
|
|
72
|
-
t.queue.writeBuffer(e.colors, 0, T.data), t.queue.writeBuffer(e.sizes, 0, U.data), q(t, b, e, e.indirect);
|
|
73
|
-
}
|
|
74
|
-
}, ee = {
|
|
75
|
-
systems: [N],
|
|
76
|
-
components: { Camera: u, Mesh: C, AmbientLight: p, DirectionalLight: s, Tonemap: m, FXAA: S, Vignette: c },
|
|
77
|
-
dependencies: [M],
|
|
78
|
-
initialize(o) {
|
|
79
|
-
const e = y.from(o);
|
|
80
|
-
if (!e) return;
|
|
81
|
-
const { device: n } = e, t = (a) => n.createBuffer({
|
|
82
|
-
label: "property",
|
|
83
|
-
size: a,
|
|
84
|
-
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC
|
|
85
|
-
}), i = {
|
|
86
|
-
scene: D(n),
|
|
87
|
-
matrices: t(f * 64),
|
|
88
|
-
colors: t(f * 16),
|
|
89
|
-
sizes: t(f * 16),
|
|
90
|
-
indirect: O(n, 16),
|
|
91
|
-
batches: /* @__PURE__ */ new Map(),
|
|
92
|
-
buffers: /* @__PURE__ */ new Map(),
|
|
93
|
-
postProcess: {
|
|
94
|
-
tonemap: !1,
|
|
95
|
-
exposure: 1,
|
|
96
|
-
fxaa: !0,
|
|
97
|
-
vignetteStrength: 0,
|
|
98
|
-
vignetteInner: 0.4,
|
|
99
|
-
vignetteOuter: 0.8
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
o.setResource(x, i), e.graph.add(
|
|
103
|
-
_({
|
|
104
|
-
scene: i.scene,
|
|
105
|
-
matrices: i.matrices,
|
|
106
|
-
colors: i.colors,
|
|
107
|
-
sizes: i.sizes,
|
|
108
|
-
indirect: i.indirect,
|
|
109
|
-
batches: i.batches
|
|
110
|
-
})
|
|
111
|
-
), e.graph.add(A(i.postProcess));
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
export {
|
|
115
|
-
p as AmbientLight,
|
|
116
|
-
u as Camera,
|
|
117
|
-
de as DEPTH_FORMAT,
|
|
118
|
-
te as DebugMode,
|
|
119
|
-
s as DirectionalLight,
|
|
120
|
-
S as FXAA,
|
|
121
|
-
Se as INDIRECT_SIZE,
|
|
122
|
-
C as Mesh,
|
|
123
|
-
T as MeshColors,
|
|
124
|
-
pe as MeshShape,
|
|
125
|
-
U as MeshSizes,
|
|
126
|
-
x as Render,
|
|
127
|
-
ie as RenderMode,
|
|
128
|
-
ee as RenderPlugin,
|
|
129
|
-
le as SCENE_UNIFORM_SIZE,
|
|
130
|
-
m as Tonemap,
|
|
131
|
-
c as Vignette,
|
|
132
|
-
Ce as clearColor,
|
|
133
|
-
E as collectByShape,
|
|
134
|
-
_ as createForwardNode,
|
|
135
|
-
xe as createForwardPipeline,
|
|
136
|
-
fe as createGeometry,
|
|
137
|
-
O as createIndirectBuffer,
|
|
138
|
-
me as createMeshBuffers,
|
|
139
|
-
A as createPostProcessNode,
|
|
140
|
-
D as createSceneBuffer,
|
|
141
|
-
z as ensureRenderTextures,
|
|
142
|
-
he as invert,
|
|
143
|
-
Be as litShader,
|
|
144
|
-
ge as multiply,
|
|
145
|
-
ce as normalizeDirection,
|
|
146
|
-
R as packLightUniforms,
|
|
147
|
-
Pe as perspective,
|
|
148
|
-
se as unpackColor,
|
|
149
|
-
q as updateBatches,
|
|
150
|
-
I as uploadCamera,
|
|
151
|
-
ve as writeIndirect
|
|
152
|
-
};
|
|
153
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/standard/render/index.ts"],"sourcesContent":["import type { Plugin, State, System } from \"../../core\";\nimport { MAX_ENTITIES, resource } from \"../../core\";\nimport { Compute, ComputePlugin } from \"../compute\";\nimport { WorldTransform } from \"../transforms\";\nimport { Camera, Tonemap, FXAA, Vignette, uploadCamera } from \"./camera\";\nimport { AmbientLight, DirectionalLight, packLightUniforms } from \"./light\";\nimport {\n Mesh,\n MeshColors,\n MeshSizes,\n collectByShape,\n updateBatches,\n type ShapeBatch,\n type MeshBuffers,\n} from \"./mesh\";\nimport { createSceneBuffer, ensureRenderTextures } from \"./scene\";\nimport { createForwardNode, createIndirectBuffer } from \"./forward\";\nimport { createPostProcessNode, type PostProcessUniforms } from \"./postprocess\";\n\nexport * from \"./camera\";\nexport * from \"./light\";\nexport * from \"./mesh\";\nexport * from \"./scene\";\nexport * from \"./forward\";\nexport * from \"./postprocess\";\n\nexport interface RenderState {\n scene: GPUBuffer;\n matrices: GPUBuffer;\n colors: GPUBuffer;\n sizes: GPUBuffer;\n indirect: GPUBuffer;\n batches: Map<number, ShapeBatch>;\n buffers: Map<number, MeshBuffers>;\n postProcess: PostProcessUniforms;\n}\n\nexport const Render = resource<RenderState>(\"render\");\n\nconst RenderSystem: System = {\n group: \"draw\",\n first: true,\n\n update(state: State) {\n const render = Render.from(state);\n const compute = Compute.from(state);\n if (!render || !compute || !state.canvas) return;\n\n const { device, format, resources } = compute;\n const { width, height } = state.canvas;\n\n ensureRenderTextures(\n device,\n format,\n width,\n height,\n resources.textures,\n resources.textureViews\n );\n\n for (const eid of state.query([Camera])) {\n if (Camera.active[eid]) {\n uploadCamera(device, render.scene, eid, width / height);\n\n render.postProcess.tonemap = state.hasComponent(eid, Tonemap);\n if (render.postProcess.tonemap) {\n render.postProcess.exposure = Tonemap.exposure[eid];\n }\n render.postProcess.fxaa = state.hasComponent(eid, FXAA);\n if (state.hasComponent(eid, Vignette)) {\n render.postProcess.vignetteStrength = Vignette.strength[eid];\n render.postProcess.vignetteInner = Vignette.inner[eid];\n render.postProcess.vignetteOuter = Vignette.outer[eid];\n }\n break;\n }\n }\n\n let ambientData = { color: 0x888888, intensity: 1.0 };\n let directionalData = {\n color: 0xffffff,\n intensity: 1.0,\n directionX: -0.5,\n directionY: -1.0,\n directionZ: -0.5,\n };\n\n for (const eid of state.query([AmbientLight])) {\n ambientData = {\n color: AmbientLight.color[eid],\n intensity: AmbientLight.intensity[eid],\n };\n break;\n }\n\n for (const eid of state.query([DirectionalLight])) {\n directionalData = {\n color: DirectionalLight.color[eid],\n intensity: DirectionalLight.intensity[eid],\n directionX: DirectionalLight.directionX[eid],\n directionY: DirectionalLight.directionY[eid],\n directionZ: DirectionalLight.directionZ[eid],\n };\n break;\n }\n\n const lightUniforms = packLightUniforms(ambientData, directionalData);\n device.queue.writeBuffer(render.scene, 128, lightUniforms as Float32Array<ArrayBuffer>);\n\n device.queue.writeBuffer(\n render.matrices,\n 0,\n WorldTransform.data as Float32Array<ArrayBuffer>\n );\n\n const meshEntities = state.query([Mesh, WorldTransform]);\n const byShape = collectByShape(meshEntities);\n device.queue.writeBuffer(render.colors, 0, MeshColors.data);\n device.queue.writeBuffer(render.sizes, 0, MeshSizes.data);\n updateBatches(device, byShape, render, render.indirect);\n },\n};\n\nexport const RenderPlugin: Plugin = {\n systems: [RenderSystem],\n components: { Camera, Mesh, AmbientLight, DirectionalLight, Tonemap, FXAA, Vignette },\n dependencies: [ComputePlugin],\n\n initialize(state: State) {\n const compute = Compute.from(state);\n if (!compute) return;\n\n const { device } = compute;\n\n const createPropertyBuffer = (size: number) =>\n device.createBuffer({\n label: \"property\",\n size,\n usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC,\n });\n\n const renderState: RenderState = {\n scene: createSceneBuffer(device),\n matrices: createPropertyBuffer(MAX_ENTITIES * 64),\n colors: createPropertyBuffer(MAX_ENTITIES * 16),\n sizes: createPropertyBuffer(MAX_ENTITIES * 16),\n indirect: createIndirectBuffer(device, 16),\n batches: new Map(),\n buffers: new Map(),\n postProcess: {\n tonemap: false,\n exposure: 1.0,\n fxaa: true,\n vignetteStrength: 0,\n vignetteInner: 0.4,\n vignetteOuter: 0.8,\n },\n };\n\n state.setResource(Render, renderState);\n\n compute.graph.add(\n createForwardNode({\n scene: renderState.scene,\n matrices: renderState.matrices,\n colors: renderState.colors,\n sizes: renderState.sizes,\n indirect: renderState.indirect,\n batches: renderState.batches,\n })\n );\n\n compute.graph.add(createPostProcessNode(renderState.postProcess));\n },\n};\n"],"names":["Render","resource","RenderSystem","state","render","compute","Compute","device","format","resources","width","height","ensureRenderTextures","eid","Camera","uploadCamera","Tonemap","FXAA","Vignette","ambientData","directionalData","AmbientLight","DirectionalLight","lightUniforms","packLightUniforms","WorldTransform","meshEntities","Mesh","byShape","collectByShape","MeshColors","MeshSizes","updateBatches","RenderPlugin","ComputePlugin","createPropertyBuffer","size","renderState","createSceneBuffer","MAX_ENTITIES","createIndirectBuffer","createForwardNode","createPostProcessNode"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqCO,MAAMA,IAASC,EAAsB,QAAQ,GAE9CC,IAAuB;AAAA,EACzB,OAAO;AAAA,EACP,OAAO;AAAA,EAEP,OAAOC,GAAc;AACjB,UAAMC,IAASJ,EAAO,KAAKG,CAAK,GAC1BE,IAAUC,EAAQ,KAAKH,CAAK;AAClC,QAAI,CAACC,KAAU,CAACC,KAAW,CAACF,EAAM,OAAQ;AAE1C,UAAM,EAAE,QAAAI,GAAQ,QAAAC,GAAQ,WAAAC,EAAA,IAAcJ,GAChC,EAAE,OAAAK,GAAO,QAAAC,EAAA,IAAWR,EAAM;AAEhC,IAAAS;AAAA,MACIL;AAAA,MACAC;AAAA,MACAE;AAAA,MACAC;AAAA,MACAF,EAAU;AAAA,MACVA,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AU;AAAA,QACV,MAAM;AAAA,QACN,kBAAkB;AAAA,QAClB,eAAe;AAAA,QACf,eAAe;AAAA,MAAA;AAAA,IACnB;AAGJ,IAAAJ,EAAM,YAAYH,GAAQqC,CAAW,GAErChC,EAAQ,MAAM;AAAA,MACVoC,EAAkB;AAAA,QACd,OAAOJ,EAAY;AAAA,QACnB,UAAUA,EAAY;AAAA,QACtB,QAAQA,EAAY;AAAA,QACpB,OAAOA,EAAY;AAAA,QACnB,UAAUA,EAAY;AAAA,QACtB,SAASA,EAAY;AAAA,MAAA,CACxB;AAAA,IAAA,GAGLhC,EAAQ,MAAM,IAAIqC,EAAsBL,EAAY,WAAW,CAAC;AAAA,EACpE;AACJ;"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export declare const AmbientLight: {
|
|
2
|
-
color: number[];
|
|
3
|
-
intensity: number[];
|
|
4
|
-
};
|
|
5
|
-
export declare const DirectionalLight: {
|
|
6
|
-
color: number[];
|
|
7
|
-
intensity: number[];
|
|
8
|
-
directionX: number[];
|
|
9
|
-
directionY: number[];
|
|
10
|
-
directionZ: number[];
|
|
11
|
-
};
|
|
12
|
-
export declare function normalizeDirection(x: number, y: number, z: number): [number, number, number];
|
|
13
|
-
export interface AmbientLightData {
|
|
14
|
-
color: number;
|
|
15
|
-
intensity: number;
|
|
16
|
-
}
|
|
17
|
-
export interface DirectionalLightData {
|
|
18
|
-
color: number;
|
|
19
|
-
intensity: number;
|
|
20
|
-
directionX: number;
|
|
21
|
-
directionY: number;
|
|
22
|
-
directionZ: number;
|
|
23
|
-
}
|
|
24
|
-
export declare function packLightUniforms(ambient: AmbientLightData, directional: DirectionalLightData): Float32Array;
|
|
25
|
-
//# sourceMappingURL=light.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"light.d.ts","sourceRoot":"","sources":["../../../src/standard/render/light.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY;WACR,MAAM,EAAE;eACJ,MAAM,EAAE;CAC5B,CAAC;AAMF,eAAO,MAAM,gBAAgB;WACZ,MAAM,EAAE;eACJ,MAAM,EAAE;gBACP,MAAM,EAAE;gBACR,MAAM,EAAE;gBACR,MAAM,EAAE;CAC7B,CAAC;AAYF,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAM5F;AAED,MAAM,WAAW,gBAAgB;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,iBAAiB,CAC7B,OAAO,EAAE,gBAAgB,EACzB,WAAW,EAAE,oBAAoB,GAClC,YAAY,CA0Bd"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { setTraits as c } from "../../core/component.js";
|
|
2
|
-
import { unpackColor as e } from "./camera.js";
|
|
3
|
-
const f = {
|
|
4
|
-
color: [],
|
|
5
|
-
intensity: []
|
|
6
|
-
};
|
|
7
|
-
c(f, {
|
|
8
|
-
defaults: () => ({ color: 8947848, intensity: 1 })
|
|
9
|
-
});
|
|
10
|
-
const y = {
|
|
11
|
-
color: [],
|
|
12
|
-
intensity: [],
|
|
13
|
-
directionX: [],
|
|
14
|
-
directionY: [],
|
|
15
|
-
directionZ: []
|
|
16
|
-
};
|
|
17
|
-
c(y, {
|
|
18
|
-
defaults: () => ({
|
|
19
|
-
color: 16777215,
|
|
20
|
-
intensity: 1,
|
|
21
|
-
directionX: -0.5,
|
|
22
|
-
directionY: -1,
|
|
23
|
-
directionZ: -0.5
|
|
24
|
-
})
|
|
25
|
-
});
|
|
26
|
-
function g(o, n, t) {
|
|
27
|
-
const i = Math.sqrt(o * o + n * n + t * t);
|
|
28
|
-
return i < 1e-4 ? [0, -1, 0] : [o / i, n / i, t / i];
|
|
29
|
-
}
|
|
30
|
-
function a(o, n) {
|
|
31
|
-
const t = new Float32Array(12), i = e(o.color);
|
|
32
|
-
t[0] = i.r, t[1] = i.g, t[2] = i.b, t[3] = o.intensity;
|
|
33
|
-
const [s, d, u] = g(
|
|
34
|
-
n.directionX,
|
|
35
|
-
n.directionY,
|
|
36
|
-
n.directionZ
|
|
37
|
-
);
|
|
38
|
-
t[4] = s, t[5] = d, t[6] = u, t[7] = 0;
|
|
39
|
-
const r = e(n.color);
|
|
40
|
-
return t[8] = r.r * n.intensity, t[9] = r.g * n.intensity, t[10] = r.b * n.intensity, t[11] = 0, t;
|
|
41
|
-
}
|
|
42
|
-
export {
|
|
43
|
-
f as AmbientLight,
|
|
44
|
-
y as DirectionalLight,
|
|
45
|
-
g as normalizeDirection,
|
|
46
|
-
a as packLightUniforms
|
|
47
|
-
};
|
|
48
|
-
//# sourceMappingURL=light.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"light.js","sources":["../../../src/standard/render/light.ts"],"sourcesContent":["import { setTraits } from \"../../core/component\";\nimport { unpackColor } from \"./camera\";\n\nexport const AmbientLight = {\n color: [] as number[],\n intensity: [] as number[],\n};\n\nsetTraits(AmbientLight, {\n defaults: () => ({ color: 0x888888, intensity: 1.0 }),\n});\n\nexport const DirectionalLight = {\n color: [] as number[],\n intensity: [] as number[],\n directionX: [] as number[],\n directionY: [] as number[],\n directionZ: [] as number[],\n};\n\nsetTraits(DirectionalLight, {\n defaults: () => ({\n color: 0xffffff,\n intensity: 1.0,\n directionX: -0.5,\n directionY: -1.0,\n directionZ: -0.5,\n }),\n});\n\nexport function normalizeDirection(x: number, y: number, z: number): [number, number, number] {\n const len = Math.sqrt(x * x + y * y + z * z);\n if (len < 0.0001) {\n return [0, -1, 0];\n }\n return [x / len, y / len, z / len];\n}\n\nexport interface AmbientLightData {\n color: number;\n intensity: number;\n}\n\nexport interface DirectionalLightData {\n color: number;\n intensity: number;\n directionX: number;\n directionY: number;\n directionZ: number;\n}\n\nexport function packLightUniforms(\n ambient: AmbientLightData,\n directional: DirectionalLightData\n): Float32Array {\n const data = new Float32Array(12);\n\n const ambientRgb = unpackColor(ambient.color);\n data[0] = ambientRgb.r;\n data[1] = ambientRgb.g;\n data[2] = ambientRgb.b;\n data[3] = ambient.intensity;\n\n const [dx, dy, dz] = normalizeDirection(\n directional.directionX,\n directional.directionY,\n directional.directionZ\n );\n data[4] = dx;\n data[5] = dy;\n data[6] = dz;\n data[7] = 0;\n\n const sunRgb = unpackColor(directional.color);\n data[8] = sunRgb.r * directional.intensity;\n data[9] = sunRgb.g * directional.intensity;\n data[10] = sunRgb.b * directional.intensity;\n data[11] = 0;\n\n return data;\n}\n"],"names":["AmbientLight","setTraits","DirectionalLight","normalizeDirection","x","y","z","len","packLightUniforms","ambient","directional","data","ambientRgb","unpackColor","dx","dy","dz","sunRgb"],"mappings":";;AAGO,MAAMA,IAAe;AAAA,EACxB,OAAO,CAAA;AAAA,EACP,WAAW,CAAA;AACf;AAEAC,EAAUD,GAAc;AAAA,EACpB,UAAU,OAAO,EAAE,OAAO,SAAU,WAAW,EAAA;AACnD,CAAC;AAEM,MAAME,IAAmB;AAAA,EAC5B,OAAO,CAAA;AAAA,EACP,WAAW,CAAA;AAAA,EACX,YAAY,CAAA;AAAA,EACZ,YAAY,CAAA;AAAA,EACZ,YAAY,CAAA;AAChB;AAEAD,EAAUC,GAAkB;AAAA,EACxB,UAAU,OAAO;AAAA,IACb,OAAO;AAAA,IACP,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ,YAAY;AAAA,EAAA;AAEpB,CAAC;AAEM,SAASC,EAAmBC,GAAWC,GAAWC,GAAqC;AAC1F,QAAMC,IAAM,KAAK,KAAKH,IAAIA,IAAIC,IAAI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