TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Rendering my (billiard) balls in a fragment shader

244 pointsby sysrplover 2 years ago

21 comments

sysrplover 2 years ago
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.
评论 #32797495 未加载
评论 #32797860 未加载
评论 #32799875 未加载
评论 #32805691 未加载
评论 #32797483 未加载
the__alchemistover 2 years ago
Good timing - I was procrastinating on HN instead of trying to fix my phucked-up phong; you've helped me do both.
评论 #32797720 未加载
评论 #32799989 未加载
pixel_tracingover 2 years ago
Came for the title, stayed for the shaders. Well written and very educational
评论 #32797360 未加载
virtualritzover 2 years ago
In the 90&#x27;s, texture maps were a luxury for anything. As a result shaders (for offline rendering, realtime shading languages didn&#x27;t exist yet) were doing everything procedurally.<p>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&#x27;s implementation at the time, AFAIK):<p><a href="https:&#x2F;&#x2F;web.cs.wpi.edu&#x2F;~matt&#x2F;courses&#x2F;cs563&#x2F;talks&#x2F;renderman&#x2F;SportsBalls.jpg" rel="nofollow">https:&#x2F;&#x2F;web.cs.wpi.edu&#x2F;~matt&#x2F;courses&#x2F;cs563&#x2F;talks&#x2F;renderman&#x2F;S...</a><p>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&#x27;s) were micropolygon renderers. I.e. displacement was almost free in terms of compute overhead.<p>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.
halaiisover 2 years ago
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.<p><a href="https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20130913033312&#x2F;http:&#x2F;&#x2F;www.voofoostudios.com&#x2F;?p=33" rel="nofollow">https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20130913033312&#x2F;http:&#x2F;&#x2F;www.voofoo...</a>
评论 #32797693 未加载
samlittlewoodover 2 years ago
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.
MaxBorsch228over 2 years ago
I guessed correctly by the title that the article is about coding a 3d image, but was waiting for the classic &quot;two balls and a cylinder&quot; scene, which college students naturally come up with in path tracing assignment in computer graphics courses.
spuzover 2 years ago
I&#x27;m just getting my feet wet with shaders myself. Could this fragment shader be used in a &quot;real&quot; 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?
评论 #32797790 未加载
评论 #32797756 未加载
评论 #32799975 未加载
评论 #32797657 未加载
londons_exploreover 2 years ago
What&#x27;s the benefit of rendering using this technique over a regular sphere rendered with the usual pipeline?
评论 #32797464 未加载
评论 #32797441 未加载
ricardobayesover 2 years ago
Even after 10 years I still have anxiety looking at OpenGL code. I still don&#x27;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?
评论 #32798190 未加载
评论 #32798580 未加载
评论 #32798224 未加载
pfoofover 2 years ago
Cool to read about C-like GLSL on a Pascal website
评论 #32797399 未加载
评论 #32801082 未加载
gitgudover 2 years ago
Very nice! not sure if you&#x27;ve heard of [1] ShaderToy, but it&#x27;s pretty good for sharing&#x2F;viewing shaders online.<p>[1] <a href="https:&#x2F;&#x2F;www.shadertoy.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.shadertoy.com&#x2F;</a>
评论 #32798951 未加载
pupppetover 2 years ago
Pretty interesting how he&#x27;s wrapping the text before the curved image on the right.
drzelover 2 years ago
not sure about that red 10-ball tho.
xanthineover 2 years ago
I happened to notice that PI is #define&#x27;d to 3.1415926538, which isn&#x27;t the correctly rounded off value of 3.14159265358...<p>Seems like they missed a &#x27;5&#x27;.
评论 #32797675 未加载
评论 #32797394 未加载
评论 #32797719 未加载
评论 #32797676 未加载
causality0over 2 years ago
From the HN guidelines: <i>please use the original title, unless it is misleading or linkbait; don&#x27;t editorialize.</i><p>The correct title is <i>Rendering Pool Balls</i>, not &quot;Rendering my balls in a fragment shader&quot;.
评论 #32797182 未加载
评论 #32798027 未加载
评论 #32797703 未加载
评论 #32797967 未加载
can16358pover 2 years ago
Could we change the title to the actual title of the article?<p>I was, let&#x27;s say, really scared when tapping the link with the current title.
评论 #32797181 未加载
noam_compsciover 2 years ago
Risky click of the day
benj111over 2 years ago
Fyi.<p>&quot;Rendering <i>my</i> balls&quot; says something very different to &quot;rendering balls&quot;.<p>Although the hair would be impressive if you managed to do it.<p>(Testicles btw)
评论 #32797683 未加载
评论 #32803969 未加载
acqbuover 2 years ago
To me, those balls are perfect
rawoke083600over 2 years ago
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