pelican-engine 0.0.0-stage → 0.3.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/AGENTS.md +147 -0
- package/LICENSE +22 -0
- package/README.md +129 -2
- package/distribution.json +197 -0
- package/docs/AI-WORKFLOW.md +517 -0
- package/docs/ARCHITECTURE.md +268 -0
- package/docs/CAPABILITIES.md +264 -0
- package/docs/DECISIONS.md +107 -0
- package/docs/M3-USAGE.md +192 -0
- package/docs/PELICAN-MIGRATION.md +38 -0
- package/docs/RENDER-BACKENDS.md +50 -0
- package/docs/ROADMAP.md +239 -0
- package/docs/THIRD-PARTY-NOTICES.md +151 -0
- package/docs/api/REFERENCE.md +1435 -0
- package/docs/api/index.json +1139 -0
- package/docs/npm/DISTRIBUTION.md +130 -0
- package/docs/npm/GAME-AUTHOR.md +147 -0
- package/engine.manifest.json +15 -0
- package/lib/assets/audio.js +67 -0
- package/lib/assets/errors.js +36 -0
- package/lib/assets/glb.js +277 -0
- package/lib/assets/index.js +53 -0
- package/lib/assets/jpeg.js +199 -0
- package/lib/assets/model.js +558 -0
- package/lib/assets/optimize.js +95 -0
- package/lib/assets/texture.js +187 -0
- package/lib/compiler/distribution.js +17 -0
- package/lib/compiler/extract.js +425 -0
- package/lib/compiler/graph.js +366 -0
- package/lib/compiler/index.js +574 -0
- package/lib/compiler/normalize.js +1194 -0
- package/lib/compiler/source-map.js +25 -0
- package/lib/compiler/types.js +2 -0
- package/lib/compiler/version.js +93 -0
- package/lib/experiments/simulation/index.js +2 -0
- package/lib/experiments/simulation/math.js +41 -0
- package/lib/experiments/simulation/probe.js +215 -0
- package/lib/experiments/simulation/scenes.js +192 -0
- package/lib/experiments/simulation/solver.js +346 -0
- package/lib/experiments/simulation/types.js +1 -0
- package/lib/experiments/world/adapters.js +30 -0
- package/lib/experiments/world/geometry.js +180 -0
- package/lib/experiments/world/index.js +2 -0
- package/lib/experiments/world/probe.js +288 -0
- package/lib/experiments/world/types.js +1 -0
- package/lib/experiments/world/world.js +599 -0
- package/lib/navigation/index.js +157 -0
- package/lib/physics/index.js +909 -0
- package/lib/protocol/index.js +92 -0
- package/lib/renderer/acceleration.js +609 -0
- package/lib/renderer/browser.js +2015 -0
- package/lib/renderer/bsdf.js +260 -0
- package/lib/renderer/checkpoint.js +88 -0
- package/lib/renderer/compute-executor.js +1034 -0
- package/lib/renderer/compute-texture-assets.js +49 -0
- package/lib/renderer/compute-view-contract.js +1 -0
- package/lib/renderer/denoiser.js +361 -0
- package/lib/renderer/dielectric.js +360 -0
- package/lib/renderer/embedded-image-pixels.js +368 -0
- package/lib/renderer/emissive-lights.js +67 -0
- package/lib/renderer/environment-importance.js +55 -0
- package/lib/renderer/environment.js +346 -0
- package/lib/renderer/gameplay.js +464 -0
- package/lib/renderer/geometry.js +103 -0
- package/lib/renderer/graph-expressions.js +485 -0
- package/lib/renderer/graph-tsl.js +141 -0
- package/lib/renderer/graph.js +214 -0
- package/lib/renderer/managed-texture-sampling.js +29 -0
- package/lib/renderer/material-graphs.js +297 -0
- package/lib/renderer/medium.js +348 -0
- package/lib/renderer/models.js +1053 -0
- package/lib/renderer/motion-shader.js +40 -0
- package/lib/renderer/path-shader.js +196 -0
- package/lib/renderer/pathtrace.js +324 -0
- package/lib/renderer/postprocess-contract.js +1 -0
- package/lib/renderer/postprocess.js +494 -0
- package/lib/renderer/render-buffers.js +132 -0
- package/lib/renderer/render-textures.js +155 -0
- package/lib/renderer/startup.js +50 -0
- package/lib/renderer/surface-capture.js +199 -0
- package/lib/renderer/surface-gpu.js +270 -0
- package/lib/renderer/surface-motion.js +84 -0
- package/lib/renderer/surface-ray-shader.js +91 -0
- package/lib/renderer/surface-shader.js +88 -0
- package/lib/renderer/surface-tracer.js +1720 -0
- package/lib/renderer/surface.js +1425 -0
- package/lib/renderer/temporal-filter.js +512 -0
- package/lib/renderer/texture-pixels.js +207 -0
- package/lib/renderer/traversal-nodes.js +54 -0
- package/lib/renderer/ui.js +446 -0
- package/lib/renderer/vertex-bounds.js +127 -0
- package/lib/renderer/vertex-contract.js +1 -0
- package/lib/renderer/vertex-graphs.js +197 -0
- package/lib/renderer/volume-shader.js +50 -0
- package/lib/runtime/compute-contract.js +1 -0
- package/lib/runtime/compute-service.js +674 -0
- package/lib/runtime/contracts.js +1 -0
- package/lib/runtime/error.js +37 -0
- package/lib/runtime/events.js +189 -0
- package/lib/runtime/game-services.js +772 -0
- package/lib/runtime/host.js +839 -0
- package/lib/runtime/material-parameters.js +145 -0
- package/lib/runtime/plugins.js +1 -0
- package/lib/runtime/postprocess-contract.js +1 -0
- package/lib/runtime/postprocess.js +189 -0
- package/lib/runtime/prefabs.js +13 -0
- package/lib/runtime/random.js +88 -0
- package/lib/runtime/render-buffer-contract.js +1 -0
- package/lib/runtime/render-buffers.js +243 -0
- package/lib/runtime/render-capabilities.js +17 -0
- package/lib/runtime/render-settings.js +249 -0
- package/lib/runtime/render-texture-contract.js +1 -0
- package/lib/runtime/render-textures.js +271 -0
- package/lib/runtime/resources.js +648 -0
- package/lib/runtime/scheduler.js +765 -0
- package/lib/runtime/storage.js +169 -0
- package/lib/runtime/world.js +594 -0
- package/lib/schema/index.js +24 -0
- package/lib/sdk/graph-values.js +16 -0
- package/lib/sdk/index.d.ts +800 -0
- package/lib/sdk/index.js +82 -0
- package/lib/tools/api-index.js +113 -0
- package/lib/tools/browser-session.js +89 -0
- package/lib/tools/cli.js +513 -0
- package/lib/tools/compress-dist.js +59 -0
- package/lib/tools/control-client.js +153 -0
- package/lib/tools/control-server.js +633 -0
- package/lib/tools/diagnostic-code.js +3 -0
- package/lib/tools/doctor.js +496 -0
- package/lib/tools/npm/browser-cli.js +6 -0
- package/lib/tools/npm/entry.js +40 -0
- package/lib/tools/npm/layout.js +195 -0
- package/lib/tools/setup.js +153 -0
- package/licenses/@dimforge/rapier2d-compat/LICENSE +201 -0
- package/licenses/@dimforge/rapier3d-compat/LICENSE +201 -0
- package/licenses/@gltf-transform/core/LICENSE.md +21 -0
- package/licenses/@gltf-transform/extensions/LICENSE.md +21 -0
- package/licenses/@gltf-transform/functions/LICENSE.md +21 -0
- package/licenses/@img/colour/LICENSE.md +82 -0
- package/licenses/@img/sharp-win32-x64/LICENSE +191 -0
- package/licenses/@oxc-project/types/LICENSE +22 -0
- package/licenses/@rolldown/pluginutils/LICENSE +21 -0
- package/licenses/@tweenjs/tween.js/LICENSE +23 -0
- package/licenses/@types/ndarray/LICENSE +21 -0
- package/licenses/@types/node/LICENSE +21 -0
- package/licenses/@types/stats.js/LICENSE +21 -0
- package/licenses/@types/three/@dimforge/rapier3d-compat/LICENSE +201 -0
- package/licenses/@types/three/LICENSE +21 -0
- package/licenses/@types/webxr/LICENSE +21 -0
- package/licenses/@webgpu/types/LICENSE +26 -0
- package/licenses/THIRD-PARTY-NOTICES.md +139 -0
- package/licenses/cwise-compiler/LICENSE +22 -0
- package/licenses/detect-libc/LICENSE +201 -0
- package/licenses/esbuild/LICENSE.md +21 -0
- package/licenses/fast-png/LICENSE +21 -0
- package/licenses/fdir/LICENSE +7 -0
- package/licenses/fflate/LICENSE +21 -0
- package/licenses/iobuffer/LICENSE +22 -0
- package/licenses/iota-array/LICENSE +22 -0
- package/licenses/is-buffer/LICENSE +21 -0
- package/licenses/ktx-parse/LICENSE +21 -0
- package/licenses/lightningcss/LICENSE +373 -0
- package/licenses/lightningcss-win32-x64-msvc/LICENSE +373 -0
- package/licenses/meshoptimizer/LICENSE.md +21 -0
- package/licenses/nanoid/LICENSE +20 -0
- package/licenses/ndarray/LICENSE +22 -0
- package/licenses/ndarray-lanczos/LICENSE +21 -0
- package/licenses/ndarray-ops/LICENSE +22 -0
- package/licenses/ndarray-pixels/LICENSE +21 -0
- package/licenses/ngraph.path/LICENSE +21 -0
- package/licenses/picocolors/LICENSE +15 -0
- package/licenses/picomatch/LICENSE +21 -0
- package/licenses/playwright/LICENSE +202 -0
- package/licenses/playwright/NOTICE +5 -0
- package/licenses/playwright-core/LICENSE +202 -0
- package/licenses/playwright-core/NOTICE +5 -0
- package/licenses/postcss/LICENSE +20 -0
- package/licenses/prettier/LICENSE +7 -0
- package/licenses/property-graph/LICENSE +21 -0
- package/licenses/rolldown/LICENSE +25 -0
- package/licenses/semver/LICENSE +15 -0
- package/licenses/sharp/LICENSE +191 -0
- package/licenses/source-map-js/LICENSE +28 -0
- package/licenses/three/LICENSE +21 -0
- package/licenses/tinyglobby/LICENSE +21 -0
- package/licenses/tsx/LICENSE +21 -0
- package/licenses/typescript/LICENSE.txt +55 -0
- package/licenses/undici-types/LICENSE +21 -0
- package/licenses/uniq/LICENSE +22 -0
- package/licenses/vite/LICENSE.md +2084 -0
- package/package.json +49 -4
- package/web/index.html +34 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import * as TSL from "three/tsl";
|
|
2
|
+
import { sampleManagedTexture } from "./managed-texture-sampling.js";
|
|
3
|
+
import { evaluateTypedGraph } from "./graph-expressions.js";
|
|
4
|
+
import { typedGraphToTSL } from "./graph-tsl.js";
|
|
5
|
+
const fail = (message) => {
|
|
6
|
+
throw new Error("TC_VERTEX_GRAPH: " +
|
|
7
|
+
message +
|
|
8
|
+
" Repair: Use finite vec3 vertex graphs, available attributes and declared texture/parameter bindings.");
|
|
9
|
+
};
|
|
10
|
+
const vec = (value, label) => {
|
|
11
|
+
if (!Array.isArray(value) ||
|
|
12
|
+
value.length !== 3 ||
|
|
13
|
+
value.some((component) => !Number.isFinite(Math.fround(component))))
|
|
14
|
+
return fail(label + " must produce a finite f32 vec3.");
|
|
15
|
+
return value.map(Math.fround);
|
|
16
|
+
};
|
|
17
|
+
const normalized = (value, fallback) => {
|
|
18
|
+
const scale = Math.max(...value.map(Math.abs));
|
|
19
|
+
if (!scale)
|
|
20
|
+
return [...fallback];
|
|
21
|
+
const scaled = value.map((component) => component / scale), length = Math.hypot(...scaled);
|
|
22
|
+
return scaled.map((component) => Math.fround(component / length));
|
|
23
|
+
};
|
|
24
|
+
export function evaluateVertexGraphs(binding, input, sampleTexture) {
|
|
25
|
+
if (!binding.vertex)
|
|
26
|
+
return { position: input.positionLocal };
|
|
27
|
+
const position = vec(input.positionLocal, "positionLocal");
|
|
28
|
+
const normal = normalized(vec(input.normalLocal, "normalLocal"), [0, 0, 0]);
|
|
29
|
+
const evaluate = (graph, channel) => {
|
|
30
|
+
try {
|
|
31
|
+
return vec(evaluateTypedGraph(graph, {
|
|
32
|
+
precision: "f32",
|
|
33
|
+
time: binding.time,
|
|
34
|
+
parameters: binding.parameters,
|
|
35
|
+
inputs: {
|
|
36
|
+
positionLocal: position,
|
|
37
|
+
normalLocal: normal,
|
|
38
|
+
vertexIndex: input.vertexIndex,
|
|
39
|
+
instanceIndex: input.instanceIndex,
|
|
40
|
+
...(input.uv ? { uv: input.uv } : {}),
|
|
41
|
+
...(input.uv1 ? { uv1: input.uv1 } : {}),
|
|
42
|
+
},
|
|
43
|
+
sampleTexture: (name, uv) => {
|
|
44
|
+
const sampler = graph.textureSlots && Object.hasOwn(graph.textureSlots, name)
|
|
45
|
+
? graph.textureSlots[name]
|
|
46
|
+
: undefined;
|
|
47
|
+
if (!sampler)
|
|
48
|
+
return sampleTexture(name, uv);
|
|
49
|
+
const resource = binding.managedTextures &&
|
|
50
|
+
Object.hasOwn(binding.managedTextures, name)
|
|
51
|
+
? binding.managedTextures[name]
|
|
52
|
+
: undefined;
|
|
53
|
+
if (!resource)
|
|
54
|
+
throw new Error("TC_RENDER_TEXTURE_UNBOUND: " + binding.id + ":" + name);
|
|
55
|
+
return sampleManagedTexture(resource, uv, sampler);
|
|
56
|
+
},
|
|
57
|
+
readBuffer: (name, index) => {
|
|
58
|
+
const resource = binding.buffers?.[name];
|
|
59
|
+
if (!resource)
|
|
60
|
+
throw new Error("TC_RENDER_BUFFER_UNBOUND: " + binding.id + ":" + name);
|
|
61
|
+
if (!Number.isSafeInteger(index) ||
|
|
62
|
+
index < 0 ||
|
|
63
|
+
index >= resource.values.length)
|
|
64
|
+
throw new Error("TC_RENDER_BUFFER_BOUNDS: " +
|
|
65
|
+
binding.id +
|
|
66
|
+
":" +
|
|
67
|
+
name +
|
|
68
|
+
":" +
|
|
69
|
+
index);
|
|
70
|
+
return resource.values[index];
|
|
71
|
+
},
|
|
72
|
+
}), channel);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
return fail(binding.id +
|
|
76
|
+
":" +
|
|
77
|
+
channel +
|
|
78
|
+
":vertex=" +
|
|
79
|
+
input.vertexIndex +
|
|
80
|
+
":instance=" +
|
|
81
|
+
input.instanceIndex +
|
|
82
|
+
": " +
|
|
83
|
+
String(error));
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const result = binding.vertex.position
|
|
87
|
+
? evaluate(binding.vertex.position, "position")
|
|
88
|
+
: position;
|
|
89
|
+
return {
|
|
90
|
+
position: result,
|
|
91
|
+
...(binding.vertex.normal
|
|
92
|
+
? {
|
|
93
|
+
normal: normalized(evaluate(binding.vertex.normal, "normal"), normal),
|
|
94
|
+
}
|
|
95
|
+
: {}),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/** Engine-private bridge shared by surface capture and object bounds. */
|
|
99
|
+
export function createVertexDeformer(bindings, sampler) {
|
|
100
|
+
const byUuid = new Map([...bindings].map(([material, binding]) => [material.uuid, binding]));
|
|
101
|
+
return {
|
|
102
|
+
evaluate(mesh, materialUuid, input) {
|
|
103
|
+
const binding = byUuid.get(materialUuid);
|
|
104
|
+
if (!binding?.vertex)
|
|
105
|
+
return undefined;
|
|
106
|
+
if (!mesh.geometry.hasAttribute("normal") &&
|
|
107
|
+
Object.values(binding.vertex).some((graph) => graph.requiredInputs?.includes("normalLocal")))
|
|
108
|
+
throw new Error("TC_VERTEX_NORMAL_ATTRIBUTE: The normalLocal vertex input requires a normal attribute.");
|
|
109
|
+
return evaluateVertexGraphs(binding, input, (asset, uv) => sampler(binding, asset, uv));
|
|
110
|
+
},
|
|
111
|
+
signature(mesh) {
|
|
112
|
+
const values = [];
|
|
113
|
+
for (const material of Array.isArray(mesh.material)
|
|
114
|
+
? mesh.material
|
|
115
|
+
: [mesh.material]) {
|
|
116
|
+
const binding = byUuid.get(material.uuid);
|
|
117
|
+
if (!binding?.vertex)
|
|
118
|
+
continue;
|
|
119
|
+
const graphs = Object.values(binding.vertex);
|
|
120
|
+
values.push(material.uuid, JSON.stringify(binding.vertex));
|
|
121
|
+
for (const name of [
|
|
122
|
+
...new Set(graphs.flatMap((graph) => Object.keys(graph.bufferTypes ?? {}))),
|
|
123
|
+
].sort()) {
|
|
124
|
+
const resource = binding.buffers?.[name] ??
|
|
125
|
+
fail(binding.id + ": missing buffer " + name);
|
|
126
|
+
values.push(name, resource.key, resource.type, resource.revision, resource.values.length);
|
|
127
|
+
}
|
|
128
|
+
if (graphs.some((graph) => graph.nodes.some((node) => node.op === "time")))
|
|
129
|
+
values.push(Math.fround(binding.time));
|
|
130
|
+
const names = [
|
|
131
|
+
...new Set(graphs.flatMap((graph) => (graph.parameters ?? []).map((parameter) => parameter.name))),
|
|
132
|
+
].sort();
|
|
133
|
+
for (const name of names)
|
|
134
|
+
values.push(name, JSON.stringify(binding.parameters[name]));
|
|
135
|
+
const managedNames = new Set(graphs.flatMap((graph) => Object.keys(graph.textureSlots ?? {})));
|
|
136
|
+
for (const name of [...managedNames].sort()) {
|
|
137
|
+
const resource = binding.managedTextures &&
|
|
138
|
+
Object.hasOwn(binding.managedTextures, name)
|
|
139
|
+
? binding.managedTextures[name]
|
|
140
|
+
: undefined;
|
|
141
|
+
if (!resource?.texture || resource.type !== "vec4")
|
|
142
|
+
return fail(binding.id + ": missing managed texture " + name);
|
|
143
|
+
values.push(name, resource.key, resource.revision, resource.texture.width, resource.texture.height, resource.values.length);
|
|
144
|
+
for (const graph of graphs) {
|
|
145
|
+
const sampler = graph.textureSlots?.[name];
|
|
146
|
+
if (sampler)
|
|
147
|
+
values.push(sampler.filter ?? "linear", sampler.wrapU ?? "clamp", sampler.wrapV ?? "clamp");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const textures = [
|
|
151
|
+
...new Set(graphs.flatMap((graph) => (graph.textureIds ?? []).filter((name) => !Object.hasOwn(graph.textureSlots ?? {}, name)))),
|
|
152
|
+
].sort();
|
|
153
|
+
for (const asset of textures) {
|
|
154
|
+
const texture = binding.textures.get(asset) ??
|
|
155
|
+
fail(binding.id + ": missing texture " + asset);
|
|
156
|
+
if (texture.matrixAutoUpdate)
|
|
157
|
+
texture.updateMatrix();
|
|
158
|
+
values.push(asset, texture.uuid, texture.version, texture.source.uuid, texture.source.version, texture.image, texture.flipY, texture.colorSpace, texture.wrapS, texture.wrapT, texture.magFilter, texture.minFilter, ...texture.matrix.elements);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return values;
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/** Position node runs after Three's built-in morph/skin/instance stages. */
|
|
166
|
+
export function vertexGraphsToTSL(binding, time, parameters, textures, readBuffer, sampleTextureSlot) {
|
|
167
|
+
if (!binding.vertex)
|
|
168
|
+
return null;
|
|
169
|
+
const safeNormal = (value, fallback) => {
|
|
170
|
+
const scale = TSL.max(TSL.max(TSL.abs(value.x), TSL.abs(value.y)), TSL.abs(value.z));
|
|
171
|
+
const scaled = value.div(TSL.select(scale.equal(0), 1, scale));
|
|
172
|
+
const length = scaled.length();
|
|
173
|
+
return TSL.select(length.equal(0), fallback, scaled.div(TSL.select(length.equal(0), 1, length)));
|
|
174
|
+
};
|
|
175
|
+
return TSL.Fn(() => {
|
|
176
|
+
const position = TSL.positionLocal.toVar();
|
|
177
|
+
const normal = safeNormal(TSL.normalLocal, TSL.vec3(0)).toVar();
|
|
178
|
+
const context = {
|
|
179
|
+
inputs: {
|
|
180
|
+
positionLocal: position,
|
|
181
|
+
normalLocal: normal,
|
|
182
|
+
vertexIndex: TSL.float(TSL.vertexIndex),
|
|
183
|
+
instanceIndex: TSL.float(TSL.instanceIndex),
|
|
184
|
+
},
|
|
185
|
+
readBuffer,
|
|
186
|
+
sampleTextureSlot,
|
|
187
|
+
};
|
|
188
|
+
const output = (binding.vertex.position
|
|
189
|
+
? typedGraphToTSL(binding.vertex.position, time, parameters, textures, context)
|
|
190
|
+
: position).toVar();
|
|
191
|
+
if (binding.vertex.normal) {
|
|
192
|
+
const changed = typedGraphToTSL(binding.vertex.normal, time, parameters, textures, context);
|
|
193
|
+
TSL.normalLocal.assign(safeNormal(changed, normal));
|
|
194
|
+
}
|
|
195
|
+
return output;
|
|
196
|
+
})();
|
|
197
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** Shared finite-roughness/delta dielectric mixture; medium state is owned by the path integrator. */
|
|
2
|
+
export const VOLUME_SHADER = /* wgsl */ String.raw `
|
|
3
|
+
struct TraceScatter{direction:vec3f,weight:vec3f,pdf:f32,eta:f32,event:u32,delta:u32,}
|
|
4
|
+
struct TraceShadowMedia{incident:vec3f,transmitted:vec3f,}
|
|
5
|
+
// Medium orientation comes from geometry, never a shading normal facing away from view.
|
|
6
|
+
fn traceDielectric(surface:SurfaceValue)->DielectricMaterial{
|
|
7
|
+
return DielectricMaterial(surface.medium.y,surface.medium.z,surface.roughness,0u,clamp(surface.base,vec3f(0),vec3f(1)));
|
|
8
|
+
}
|
|
9
|
+
fn traceOpaqueIor(surface:SurfaceValue)->f32{return select(surface.medium.y,1.5,surface.medium.x>0.0);}
|
|
10
|
+
fn traceEvaluate(surface:SurfaceValue,view:vec3f,light:vec3f)->vec3f{
|
|
11
|
+
if(dot(surface.normal,view)<=0.0){return vec3f(0);}
|
|
12
|
+
let opaque=bsdfEvaluateSpecular(surface.normal,view,light,clamp(surface.base,vec3f(0),vec3f(1)),surface.roughness,surface.metalness,traceOpaqueIor(surface),surface.specular.w,surface.specular.xyz);
|
|
13
|
+
if(!traceVolumeEnabled||surface.medium.x==0.0){return opaque;}let dielectric=dielectricEvaluate(surface.normal*surface.medium.w,view,light,traceDielectric(surface));return opaque*(1.0-surface.medium.x)+dielectric*surface.medium.x;
|
|
14
|
+
}
|
|
15
|
+
fn tracePdf(surface:SurfaceValue,view:vec3f,light:vec3f)->f32{
|
|
16
|
+
if(dot(surface.normal,view)<=0.0){return 0.0;}
|
|
17
|
+
let opaque=bsdfPdfSpecular(surface.normal,view,light,clamp(surface.base,vec3f(0),vec3f(1)),surface.roughness,surface.metalness,traceOpaqueIor(surface),surface.specular.w,surface.specular.xyz);
|
|
18
|
+
if(!traceVolumeEnabled||surface.medium.x==0.0){return opaque;}let dielectric=dielectricPdf(surface.normal*surface.medium.w,view,light,traceDielectric(surface));return opaque*(1.0-surface.medium.x)+dielectric*surface.medium.x;
|
|
19
|
+
}
|
|
20
|
+
fn traceScatter(surface:SurfaceValue,view:vec3f,branch:f32,random:vec3f)->TraceScatter{
|
|
21
|
+
if(dot(surface.normal,view)<=0.0){return TraceScatter(vec3f(0),vec3f(0),0,1,0u,0u);}
|
|
22
|
+
if(!traceVolumeEnabled||surface.medium.x==0.0){let sample=bsdfSampleSpecular(surface.normal,view,clamp(surface.base,vec3f(0),vec3f(1)),surface.roughness,surface.metalness,random,traceOpaqueIor(surface),surface.specular.w,surface.specular.xyz);return TraceScatter(sample.direction,sample.weight,sample.pdf,1,select(0u,1u,sample.pdf>0.0),0u);}
|
|
23
|
+
var direction:vec3f;var eta=1.0;var event=1u;
|
|
24
|
+
if(surface.medium.x>0.0&&branch<surface.medium.x){
|
|
25
|
+
let sample=dielectricSample(surface.normal*surface.medium.w,view,traceDielectric(surface),random);if(sample.event==0u){return TraceScatter(vec3f(0),vec3f(0),0,1,0u,0u);}
|
|
26
|
+
if(sample.delta!=0u){return TraceScatter(sample.direction,sample.weight,sample.pdf*surface.medium.x,sample.eta,sample.event,sample.delta);}
|
|
27
|
+
direction=sample.direction;eta=sample.eta;event=sample.event;
|
|
28
|
+
}else{let sample=bsdfSampleSpecular(surface.normal,view,clamp(surface.base,vec3f(0),vec3f(1)),surface.roughness,surface.metalness,random,traceOpaqueIor(surface),surface.specular.w,surface.specular.xyz);if(sample.pdf<=0.0){return TraceScatter(vec3f(0),vec3f(0),0,1,0u,0u);}direction=sample.direction;}
|
|
29
|
+
let pdf=tracePdf(surface,view,direction);if(pdf<=0.0){return TraceScatter(vec3f(0),vec3f(0),0,1,0u,0u);}let weight=traceEvaluate(surface,view,direction)*abs(dot(surface.normal,direction))/pdf;return TraceScatter(direction,weight,pdf,eta,event,0u);
|
|
30
|
+
}
|
|
31
|
+
fn traceValidDirection(geometric:vec3f,surface:SurfaceValue,direction:vec3f)->bool{
|
|
32
|
+
let gn=dot(geometric,direction);let sn=dot(surface.normal,direction);return select(gn>0.0&&sn>0.0,gn*sn>0.0,traceVolumeEnabled&&surface.medium.x>0.0);
|
|
33
|
+
}
|
|
34
|
+
fn traceCosine(surface:SurfaceValue,direction:vec3f)->f32{return select(max(dot(surface.normal,direction),0.0),abs(dot(surface.normal,direction)),traceVolumeEnabled&&surface.medium.x>0.0);}
|
|
35
|
+
struct TracePoint{position:vec3f,error:vec3f,}
|
|
36
|
+
fn tracePoint(triangle:SurfaceTriangle,bary:vec3f)->TracePoint{
|
|
37
|
+
let a=triangle.a.xyz*bary.x;let b=triangle.b.xyz*bary.y;let c=triangle.c.xyz*bary.z;
|
|
38
|
+
return TracePoint(a+b+c,(abs(a)+abs(b)+abs(c))*4.172327e-7);
|
|
39
|
+
}
|
|
40
|
+
fn traceOffset(point:TracePoint,geometric:vec3f,direction:vec3f)->vec3f{
|
|
41
|
+
let offset=geometric*(dot(abs(geometric),point.error)*select(-1.0,1.0,dot(geometric,direction)>0.0));
|
|
42
|
+
var result=point.position+offset;
|
|
43
|
+
for(var axis=0u;axis<3u;axis++){
|
|
44
|
+
if(offset[axis]==0.0){continue;}
|
|
45
|
+
if(result[axis]==0.0){result[axis]=select(-1.17549435e-38,1.17549435e-38,offset[axis]>0.0);}
|
|
46
|
+
else{let step=select(-1,1,(result[axis]>0.0)==(offset[axis]>0.0));result[axis]=bitcast<f32>(bitcast<i32>(result[axis])+step);}
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|