Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eltaurus-lt/hello-saturn
A collection of minimal 3D renderers, producing an image of a real-life scene from scratch with the least amount of code possible
https://github.com/eltaurus-lt/hello-saturn
Last synced: 3 days ago
JSON representation
A collection of minimal 3D renderers, producing an image of a real-life scene from scratch with the least amount of code possible
- Host: GitHub
- URL: https://github.com/eltaurus-lt/hello-saturn
- Owner: Eltaurus-Lt
- Created: 2023-02-09T03:57:51.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-13T08:23:56.000Z (6 months ago)
- Last Synced: 2024-07-14T00:17:32.578Z (6 months ago)
- Language: GLSL
- Homepage:
- Size: 4.48 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Hello Saturn
A collection of 3D renderers written with a single purpose - to produce a real-life scene from scratch with the least amount of code in each language. The scene is based on the general look of [raw Cassini photos](https://science.nasa.gov/mission/cassini/multimedia/featured-raw-images/), with some artistic liberties (primarily the Saturn's satellite is not to scale with the planet and its rings). Common features of each implementation include lambert shading, recursive drop shadows, and procedural generation of textures.
## Wolfram Mathematica
**The** shortest raytracer. The whole code is **477 characters** (line breaks added for "readability"):
```
W=320;H=180;v=.35/W;f=Norm;X={1,0,0};Z={0,0,1};L=Last;k=#/f@#&;t=Interpolation@RandomReal[1,99];
T[o_,n_,s_:1]:=(c=0;j=99;e=.05;l=X+e Z;S[u_,r_]:=(h=u-o;a=f[h\[Cross]n];
If[a#>e,c=If[p=o+n#;b=p-u;T[p,l]==0,l.k@b(t[50+L@p r]+6),s];
j=#]&/@(h.n+Sqrt[r^2-a^2]{-1,1})]);S[0X,4]S[{8,6,0},.4];a=L@n;If[f@a>e,h=-L@o/a;p=o+n h;
If[j>h>e&&6
#include
#include
#define O operator
#define R return
typedef int i;typedef float f;struct v{f x,y,z;v O+(v r){R v(x+r.x,y+r.y,z+r.z);}v O*(f r){R v(x*r,y*r,z*r);}
f O%(v r){R x*r.x+y*r.y+z*r.z;}v(){}v O^(v r){R v(y*r.z-z*r.y,z*r.x-x*r.z,x*r.y-y*r.x);}v(f a,f b,f c){x=a;y=b;z=c;}
v O!(){R*this*(1/sqrt(*this%*this));}}; f G[][4]={{0,0,0,1},{-2,-1.5,0,.2}};f u[99];i T(v o,v d,f& t,v& n){
t=1e9;i m=0;if (abs(d.z)>.01) {f p=-o.z/d.z;v w=o+d*p;if(.010){f s=-b-sqrt(q);
if(s.01)t=s,n=!(p+d*t),m=2;}}R m;}f W(f H) {i j=floor(H); H=H-j;R ((1-H)*u[j]+H*u[j+1]);}f S(v o,v d){
f t;v n;i m=T(o,d,t,n);if(!m)R 0;v h=o+d*t,l=!v(1,0,.07),r=d+n*(n%d*-2);f b=l%n;if(b<0||T(h,l,t,n))b=0;
f p=.9*W(19*(h.z+2)); if(m&1){p=.5*W(24*sqrt(h%h));} R p*b;}i main(){for (i j=99;j--;) {u[j]=(.5+.5*rand()/RAND_MAX);};
printf("P6 640 360 255 ");v g=!v(-7.1,4.5,-5.4),a=!(v(0,0,1)^g),b=!(g^a);for(i y=360;y--;)for(i x=640;x--;){
f p=11;{p=S(v(7.1, -4.5, 5.4),!((a*(x-320)+b*(y-180))*.00114+g))*250+p;}printf("%c%c%c",(i)p,(i)p,(i)p);}}
```(should be invoked with the output written to a `.ppm` file, e.g. ```hello > saturn.ppm```, where `hello` is the name for the compiled binary)
![C++ (1099 characters)](Images/C++.png)
## GLSL (shaders)
Not-as-minimal (but still rather short) real-time animated implementation. Comes with a mouse-controlled camera, an orbiting mode toggled by pressing `space`, antialiasing, and, for the lack thereof in the base language, a from-scratch random-number generator based on [logistic map](https://en.wikipedia.org/wiki/Logistic_map):
![GLSL](Images/GLSL.png)
The interactive version is available on [Shadertoy](https://www.shadertoy.com/embed/stByRG?paused=false)
Additionaly includes [the Satrun's hexagon](https://en.wikipedia.org/wiki/Saturn%27s_hexagon) on the north pole:
![Polar hexagon (GLSL)]()
## After Effects (JS)
![After Effects](Images/AE.png)
An After Effects project that utilizes the built-in 3D rasterizing engine (made for rendering exclusively flat square surfaces), and recreates the illusion of convex 3-dimensional objects with the help of built-in effects, generated textures, and Java Script expressions, which bind parameters of all pieces together to build a coherent scene and modify the look of each object based on the position of the camera:
![JS expressions]()
Also imitates the polar hexagon:
![Polar hexagon (AE)]()
but does not support drop shadows on the spheres due to technical limitations of the engine (adds semi-transparency to the rings though).
## Python
Intended mostly as a tutorial, this version has more readable code and includes detailed comments. Available online on [Google Colab](https://colab.research.google.com/drive/1PR4u2Hia5xthwy1G5SM-yVO5H_cr1HCY#scrollTo=5b39d429)