from Hacker News

Rendering my (billiard) balls in a fragment shader

by sysrpl on 9/11/22, 5:26 AM with 84 comments

  • by sysrpl on 9/11/22, 5:26 AM

    Here is a summary I wrote on my attempt to render balls using only a fragment shader. I am pretty happy with the result, and I've included a breakdown of the creation process.
  • by the__alchemist on 9/11/22, 7:48 AM

    Good timing - I was procrastinating on HN instead of trying to fix my phucked-up phong; you've helped me do both.
  • by pixel_tracing on 9/11/22, 5:40 AM

    Came for the title, stayed for the shaders. Well written and very educational
  • by virtualritz on 9/11/22, 9:12 AM

    In the 90's, texture maps were a luxury for anything. As a result shaders (for offline rendering, realtime shading languages didn't exist yet) were doing everything procedurally.

    Here is the only image I could find of the RenderMan Shading Language VIDI SPORTS SHADERS Makina Works sold at the time (you got no source, just bytecode understood by Pixar's implementation at the time, AFAIK):

    https://web.cs.wpi.edu/~matt/courses/cs563/talks/renderman/S...

    What is interesting here is that the shaders did everything on a sphere primitive. All RenderMan implementations at the time (there were more than just Pixar's) were micropolygon renderers. I.e. displacement was almost free in terms of compute overhead.

    Even the football operated on a sphere that the shader deformed into the resp. shape. All patterns, stripes etc. were procedurally generated. Each shader had texture slots to apply custom logos.

  • by halaiis on 9/11/22, 7:48 AM

    This reminds me of the same rendering technique described in Hustle Kings for the PS3. There was a write up done, however shader code was not included.

    https://web.archive.org/web/20130913033312/http://www.voofoo...

  • by samlittlewood on 9/11/22, 7:08 AM

    It might be interesting to explore with the students why this would not be quite right for a general 3D view, and how it could be fixed. Conic sections, etc.
  • by MaxBorsch228 on 9/11/22, 8:57 AM

    I guessed correctly by the title that the article is about coding a 3d image, but was waiting for the classic "two balls and a cylinder" scene, which college students naturally come up with in path tracing assignment in computer graphics courses.
  • by spuz on 9/11/22, 7:38 AM

    I'm just getting my feet wet with shaders myself. Could this fragment shader be used in a "real" 3D game? At the moment, the sphere is orthographicly projected onto the screen so the sphere will always appear as a circle rather than an ellipse. How easy would it be to use this shader in place of a spherical mesh as you might find in a typical geometry based 3D render? I.e. could you use the same technique and render multiple balls on the screen with positions in 3D space and rendered correctly taking into account any distortion caused by the camera?
  • by londons_explore on 9/11/22, 6:54 AM

    What's the benefit of rendering using this technique over a regular sphere rendered with the usual pipeline?
  • by ricardobayes on 9/11/22, 9:24 AM

    Even after 10 years I still have anxiety looking at OpenGL code. I still don't understand why we needed to write ray-tracing during a BSc course starting from a blinking cursor. The professor tried to defend that at the time, but I firmly believe that it is the wrong curriculum for a 20 year old CS student. Computer graphics were and are niche programming, and should not be taught main-stream. Out of 100 graduates maybe one will ever use this, why not use some common sense and teach something useful?
  • by pfoof on 9/11/22, 6:31 AM

    Cool to read about C-like GLSL on a Pascal website
  • by gitgud on 9/11/22, 8:22 AM

    Very nice! not sure if you've heard of [1] ShaderToy, but it's pretty good for sharing/viewing shaders online.

    [1] https://www.shadertoy.com/

  • by pupppet on 9/11/22, 4:56 PM

    Pretty interesting how he's wrapping the text before the curved image on the right.
  • by drzel on 9/11/22, 3:02 PM

    not sure about that red 10-ball tho.
  • by xanthine on 9/11/22, 6:41 AM

    I happened to notice that PI is #define'd to 3.1415926538, which isn't the correctly rounded off value of 3.14159265358...

    Seems like they missed a '5'.

  • by causality0 on 9/11/22, 5:47 AM

    From the HN guidelines: please use the original title, unless it is misleading or linkbait; don't editorialize.

    The correct title is Rendering Pool Balls, not "Rendering my balls in a fragment shader".

  • by can16358p on 9/11/22, 5:41 AM

    Could we change the title to the actual title of the article?

    I was, let's say, really scared when tapping the link with the current title.

  • by noam_compsci on 9/11/22, 8:10 AM

    Risky click of the day
  • by benj111 on 9/11/22, 7:56 AM

    Fyi.

    "Rendering my balls" says something very different to "rendering balls".

    Although the hair would be impressive if you managed to do it.

    (Testicles btw)

  • by acqbu on 9/11/22, 8:38 AM

    To me, those balls are perfect
  • by rawoke083600 on 9/11/22, 8:26 AM

    The sexes(including all modern derivatives) may really be equal, but I for one truley enjoyed this title submitted most likely by a male :p