SDF of cylinder slice

Hi,
I have been playing with the SDF nodes from FieldTrip, and have been quite happy. But now, I want to add a “wedge” primitive, but can’t quite figure out how to program it.
So, basically what I want is a primitive that looks like one of those Trivial Pursuit pieces - here, the red, yellow and blue:

So, what I would like is something similar to the Segment (DX11.Geometry) node, but that returns
SDF2D that I can then extrude, with inner radius, cycles and phase inputs. I need help writing the shader code!

1 Like

Maybe search for cylinder sector or circular sector.

Yeah… I understand the basic math/geometry that describes a sector of a circle.
Basically, this is what I have now:


So, the “Inner Radius” part can be handled by CombineSDF boolean operations. However, I’m not smart enough to translate my understanding of a sector into the SDF function of a wedge!
The shader code for a cylinder is:

float fCylinder(float3 p, float r, float height) 
{
	float d = length(p.xz) - r;
	d = max(d, abs(p.y) - height);
	return d;
}

I just can’t quite see how to change that so that it’s correct for a partial cylinder, ie. a wedge shape…?

i assume you’ve been here, i guess you can extrude that Shader - Shadertoy BETA
like here… Shader - Shadertoy BETA

No, I had not found that… I searched ShaderToy, but did not think of the term “pie” that is used here.

I think I can figure out how to add the Phase input based on this code… Thanks!

yea the “pie” is because it’s referred to pie chart mostly

well, i’ve added a pie slice sdf (which i call “sector”) to happy.fxh and FieldTrip:

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.