mirror of
https://github.com/storytold/spark.git
synced 2026-10-14 23:52:59 +00:00
Add modifiers normalColor and depthColor. Add examples/debug-color to show how to use them on SplatMeshes. (#58)
This commit is contained in:
committed by
GitHub
parent
a83c99eb86
commit
690e09ac95
@@ -0,0 +1,60 @@
|
||||
import type { SplatTransformer } from "../SplatGenerator";
|
||||
import type { SplatMesh } from "../SplatMesh";
|
||||
import {
|
||||
type DynoVal,
|
||||
Gsplat,
|
||||
combineGsplat,
|
||||
dynoBlock,
|
||||
dynoConst,
|
||||
neg,
|
||||
normalizedDepth,
|
||||
select,
|
||||
split,
|
||||
splitGsplat,
|
||||
sub,
|
||||
} from "../dyno";
|
||||
|
||||
export function makeDepthColorModifier(
|
||||
splatToView: SplatTransformer,
|
||||
minDepth: DynoVal<"float">,
|
||||
maxDepth: DynoVal<"float">,
|
||||
reverse: DynoVal<"bool">,
|
||||
) {
|
||||
return dynoBlock({ gsplat: Gsplat }, { gsplat: Gsplat }, ({ gsplat }) => {
|
||||
if (!gsplat) {
|
||||
throw new Error("No gsplat input");
|
||||
}
|
||||
let { center } = splitGsplat(gsplat).outputs;
|
||||
center = splatToView.apply(center);
|
||||
const { z } = split(center).outputs;
|
||||
let depth = normalizedDepth(neg(z), minDepth, maxDepth);
|
||||
depth = select(reverse, sub(dynoConst("float", 1), depth), depth);
|
||||
|
||||
gsplat = combineGsplat({ gsplat, r: depth, g: depth, b: depth });
|
||||
return { gsplat };
|
||||
});
|
||||
}
|
||||
|
||||
export function setDepthColor(
|
||||
splats: SplatMesh,
|
||||
minDepth: number,
|
||||
maxDepth: number,
|
||||
reverse?: boolean,
|
||||
) {
|
||||
splats.enableWorldToView = true;
|
||||
const dynoMinDepth = dynoConst("float", minDepth);
|
||||
const dynoMaxDepth = dynoConst("float", maxDepth);
|
||||
const dynoReverse = dynoConst("bool", reverse ?? false);
|
||||
splats.worldModifier = makeDepthColorModifier(
|
||||
splats.context.worldToView,
|
||||
dynoMinDepth,
|
||||
dynoMaxDepth,
|
||||
dynoReverse,
|
||||
);
|
||||
splats.updateGenerator();
|
||||
return {
|
||||
minDepth: dynoMinDepth,
|
||||
maxDepth: dynoMaxDepth,
|
||||
reverse: dynoReverse,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user