Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add a cutout for the meter
  • Loading branch information
Aleksander Katan committed Nov 17, 2025
commit 4304aea088117ad0d41633fc54e56243059d09db
33 changes: 29 additions & 4 deletions apps/typegpu-docs/src/examples/rendering/jelly-knob/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,45 @@ const getJellyBounds = () => {

const GroundParams = {
groundThickness: 0.03,
groundRadius: 0.38,
groundRoundness: 0.02,
jellyCutoutRadius: 0.38,
meterCutoutRadius: 0.7,
meterCutoutGirth: 0.08,
};

const sdFloorCutout = (position: d.v2f) => {
const sdJellyCutout = (position: d.v2f) => {
'use gpu';
const groundRoundness = GroundParams.groundRoundness;
const groundRadius = GroundParams.groundRadius;
const groundRadius = GroundParams.jellyCutoutRadius;

return sdf.sdDisk(
position,
groundRadius + groundRoundness,
);
};

const sdMeterCutout = (position: d.v2f) => {
'use gpu';
const groundRoundness = GroundParams.groundRoundness;
const meterCutoutRadius = GroundParams.meterCutoutRadius;
const meterCutoutGirth = GroundParams.meterCutoutGirth;
const angle = Math.PI / 2;

return sdf.sdArc(
position,
d.vec2f(std.sin(angle), std.cos(angle)),
meterCutoutRadius,
meterCutoutGirth + groundRoundness,
);
};

const sdFloorCutout = (position: d.v2f) => {
'use gpu';
const jellyCutoutDistance = sdJellyCutout(position);
const meterCutoutDistance = sdMeterCutout(position);
return sdf.opUnion(jellyCutoutDistance, meterCutoutDistance);
};

const sdArrowHead = (p: d.v3f) => {
'use gpu';
return sdf.sdRhombus(
Expand All @@ -168,7 +192,7 @@ const getMainSceneDist = (position: d.v3f) => {
const groundRoundness = GroundParams.groundRoundness;

let dist = std.min(
sdf.sdPlane(position, d.vec3f(0, 1, 0), 0.1),
sdf.sdPlane(position, d.vec3f(0, 1, 0), 0.1), // the plane underneath the jelly
sdf.opExtrudeY(
position,
-sdFloorCutout(position.xz),
Expand Down Expand Up @@ -480,6 +504,7 @@ const rayMarch = (rayOrigin: d.v3f, rayDirection: d.v3f, uv: d.v2f) => {
const p = rayOrigin.add(rayDirection.mul(backgroundDist));
const hit = getMainSceneDist(p);
backgroundDist += hit;
// AAA performance check
if (hit < SURF_DIST) {
break;
}
Expand Down