https://github.com/michael-0acf4/ray0
A simple GLSL-like renderer on the terminal.
https://github.com/michael-0acf4/ray0
3d ascii-graphics blackhole console fragment-shaders parallel-computing ray-marching rendering sdf
Last synced: 29 days ago
JSON representation
A simple GLSL-like renderer on the terminal.
- Host: GitHub
- URL: https://github.com/michael-0acf4/ray0
- Owner: michael-0acf4
- License: mit
- Created: 2022-06-11T20:33:43.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-01-14T18:21:07.000Z (9 months ago)
- Last Synced: 2025-04-14T23:14:07.868Z (6 months ago)
- Topics: 3d, ascii-graphics, blackhole, console, fragment-shaders, parallel-computing, ray-marching, rendering, sdf
- Language: C++
- Homepage:
- Size: 425 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ray0
A GLSL-like renderer on the terminal.

## Examples
```bash
# Color gradient test program
make gradient# Simple sphere
make sphere# Raymarch a rotating donut
make donut# Raymarch a rotating 3d object
make composition# Blackhole
make blackhole
```## Usage
The shader function works the same as a typical GLSL fragment shader with the
main exception of `fragColor`, which is unidimensional instead of being a vec4
(but still normalized).The function will run on each fragment from left to right and top to bottom.
Here is a basic test program
```cpp
#include "ray0.hpp"const vec2 iResolution = {25, 25};
void shaderUVTest(float &fragColor, const vec2 &fragCoord) {
const vec2 uv = (fragCoord - 0.5 * iResolution) / iResolution.y;if (sqrt(uv.x * uv.x + uv.y * uv.y) < .4) {
float one = 0.25, two = 0.5, three = 0.75, four = 1.;
if (fragCoord.x > iResolution.x / 2) {
fragColor = fragCoord.y > iResolution.y / 2 ? one : two;
} else {
fragColor = fragCoord.y > iResolution.y / 2 ? three : four;
}
}
}int main() {
Engine engine(iResolution);
engine.update(shaderUVTest, 4);
engine.render("3210 ");return 0;
}
```
You can test the equivalent GLSL code
[here](https://www.shadertoy.com/view/lc3BWl).```glsl
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
float col = 0.;
if (length(uv) < 0.4) {
float one = 0.25, two = 0.5, three = 0.75, four = 1.0;
if (fragCoord.x > iResolution.x / 2.) {
col = fragCoord.y > iResolution.y / 2.0 ? one : two;
} else {
col = fragCoord.y > iResolution.y / 2.0 ? three : four;
}
}fragColor = vec4(col, col, col, 1.);
}
```