Add modifiers normalColor and depthColor. Add examples/debug-color to show how to use them on SplatMeshes. (#58)

This commit is contained in:
Andreas Sundquist
2025-06-20 14:23:45 -07:00
committed by GitHub
parent a83c99eb86
commit 690e09ac95
8 changed files with 207 additions and 0 deletions
+35
View File
@@ -70,6 +70,13 @@ export const hashVec4 = <T extends ValueTypes>(
): DynoVal<"vec4"> => {
return new HashVec4({ value });
};
export const normalizedDepth = (
z: DynoVal<"float">,
zNear: DynoVal<"float">,
zFar: DynoVal<"float">,
): DynoVal<"float"> => {
return new NormalizedDepth({ z, zNear, zFar }).outputs.depth;
};
export class DynoRemapIndex
extends Dyno<{ from: "int"; to: "int"; index: "int" }, { index: "int" }>
@@ -404,3 +411,31 @@ export class HashVec4<T extends ValueTypes>
return new DynoOutput(this, "hash");
}
}
export class NormalizedDepth
extends Dyno<
{ z: "float"; zNear: "float"; zFar: "float" },
{ depth: "float" }
>
implements HasDynoOut<"float">
{
constructor({
z,
zNear,
zFar,
}: { z: DynoVal<"float">; zNear: DynoVal<"float">; zFar: DynoVal<"float"> }) {
super({
inTypes: { z: "float", zNear: "float", zFar: "float" },
outTypes: { depth: "float" },
inputs: { z, zNear, zFar },
statements: ({ inputs, outputs }) => [
`float clamped = clamp(${inputs.z}, ${inputs.zNear}, ${inputs.zFar});`,
`${outputs.depth} = (log2(clamped + 1.0) - log2(${inputs.zNear} + 1.0)) / (log2(${inputs.zFar} + 1.0) - log2(${inputs.zNear} + 1.0));`,
],
});
}
dynoOut(): DynoValue<"float"> {
return new DynoOutput(this, "depth");
}
}