Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Great write up, that was a fun read.

In understanding how the rotation was implemented, it took me longer than it probably should have to realize that the normal map (which I think of in terms of lighting) is actually a radial position on the sphere.

I had to go back and forth with the final and original code a few times, and finally noted that "n" gets renamed to "point" when it becomes an argument to colorLookup.

This dual usage of the normal for lighting brightness calculation and as a radial position on the sphere surface for looking up the color makes sense in retrospect but is also a somewhat subtle aspect that you might want to address more explicitly in your text instead of just silently renaming the variable in the code.


In the final video, there are still some texture artifacts whenever the number is on the edge (e.g. the ball 4 at 5 seconds). Maybe because of mipmaps? I can't really think of a reason why it happens. It even happens at the bottom of the 4, even though that part is white in the texture.


Nice work! My only recommendation is to add a pow(color, 1.0/2.2) or similar at the end, and then turn down your light brightness. Your light falloff has the distinctive look of gamma-space lighting makes it look dated and less realistic. Doing your lighting in linear space should help.

It might also be simpler to do your rotations without a matrix, for the learners ( just expand out the functions, e.g. https://github.com/magcius/sw3dv/blob/gh-pages/b_vert.glsl#L... )


Great article! I would be interested in more info about the physics and ball path mapping that you mentioned in the beginning.

Over the last few months, I’ve started competing in billiards, and the roll vs slide, english, tangent lines, and even forced follow to be incredibly interesting.

Is any of that involved in the physics simulations that you’ve worked out? If it is, I would really like to know more.


Cool, I recently started with GLSL, and it’s interesting there are many roads that lead to a similar solution (how I draw circles or make a center is tad different)

Where or how did you learn GLSL?


I was around and writing OpenGL when we started getting the first programmable cards. Nvidia shot out first with their Cg language, but I held back and waited for the "Orange Book" to come up. I bought it right away and learned from it and by looking at other peoples shaders.

https://duckduckgo.com/?q=opengl+orange+book

Also the quick reference card helps

https://duckduckgo.com/?q=glsl+quick+reference&t=h_&ia=web


So you are a veteran, compared to me, just started this year, really reminded why I should have been more observant in math class :)

The resources are really good, hadn’t found something like that yet!


Small correction, NVidia Cg was only the first on PC.

We had Renderman on NeXT, TI TMS34010, and a couple of other attempts outside the PC world.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: