0
\$\begingroup\$

I am kinda looking for some ways out of this little rabbit hole.

I wanted to experiment with high fidelity per pixel cone drawing and shading. I have an application (radar) that really only needs cone 3D geometry and I figured it would be cool if I could render them implicitly and get sharp pixel perfect geometry by deriving the geometry in addition to the shading within the fragment shader.

This all works and I got quite far embedding the z-picking and occlusion logic such that now I finally am able to ignore parts of the cone that intersect my pixel rays behind the camera and to always show the nearest intersection in front of the camera (easier said than done!). Even computing the normal direction was a piece of cake and the lighting looks great.

Now I grapple with computing the texture coordinates, and I'm realizing I might be a bit screwed and forced to use atan2 for the radial angle coordinate on the cone.

Typically whenever we want to reach for atan2 in hot code or shader code, we're trying to do something further with the angle derived and can eliminate it by being clever with various vectors available to us from which various trig values can be derived efficiently. But here I need to directly use an angle for a texture lookup and it seems like I'm SOL and really actually need to use an atan function now in the shader due to the approach I took with this. So far this seems like a dealbreaker and I may actually need to go back to using a traditional cone made out of vertices and interpolated uv coordinates.

For background info, the way the shader is constructed is by substituting the implicit ray equation into an implicit cone equation; as this yields a quadratic equation in the ray's parameter variable, the coefficients of the quadratic equation are computed and substituted in and zero, one or two t-values (distance along ray) pop out.

\$\endgroup\$
6
  • \$\begingroup\$ Can you change the way you map the texture? e.g. projecting the texture along the cone's axis does not require the angle. Or is it required that one of the texture directions must wrap around a circular cross-section of the cone? \$\endgroup\$ Commented May 30, 2024 at 17:52
  • \$\begingroup\$ Yeah, imagine I design an OLED display in the shape of a cone. Or I have a cone and a projector points at it. \$\endgroup\$ Commented May 31, 2024 at 3:07
  • \$\begingroup\$ For that projection along the axis, you just need two basis vectors and some dot products to get a u and v coordinate — no atan. Want to show your cone intersection code and I or someone else can show you how to add the uv calculation to it? \$\endgroup\$ Commented May 31, 2024 at 10:51
  • \$\begingroup\$ Sorry, a projection as in a projection or a shadow with a texture, yeah that would not need the trig function at all! My mistake. I meant, the content wraps around the cone in cone-radial-space. So it seems I need the atan. I'm going back to the drawing board and doing it the normal way, with a bunch of vertices. It's going to be okay because i can leverage the fancy shader on high end clients to get the perfect curves of the cone rendered. And I'll get the texture coordinates from the vertices. \$\endgroup\$ Commented May 31, 2024 at 16:28
  • \$\begingroup\$ Fair enough. Want to share your solution as an Answer below then, to help future readers? \$\endgroup\$ Commented May 31, 2024 at 18:38

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.