Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mole99 committed Apr 13, 2024
1 parent 674ab30 commit 8d1b6ac
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 17 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

# Tiny Shader

Modern GPUs use fragment shaders to determine the color for each pixel. Thousands of shading units run in parallel to execute a program, the fragment shader, to determine the final color for each pixel.
Modern GPUs use fragment shaders to determine the color for each pixel. Thousands of shading units run in parallel to execute the fragment shader to determine the final color for each pixel.

Tiny Shader mimics such a shading unit, it executes a shader of 10 instructions for each pixel. No framebuffer is used, the color values are generated on the fly. Tiny Shader also offers an SPI interface with which a new shader can be loaded. The final result can be viewed via VGA output.

## Examples

These images and many more can be generated with Tiny Shader. Note, that using the time input the shaders can even be animated.
These images and many more can be generated with Tiny Shader. Note, that shaders can even be animated by acessing the user or time register.

|Image|Shader|
|-|-|
|![test2.png](images/test2.png)| <pre>GETX R0<br>SINE R1<br>SETR R1<br>GETY R0<br>SINE R1<br>SETG R1</pre> |
|![test4.png](images/test4.png)| <pre>GETX R0<br>GETY R1<br>XOR R0 R1<br>SETRGB R0</pre> |
|![test5.png](images/test5.png)| <pre>GETY R1<br>LDI 1<br>AND R1 R0<br>IFNE R1<br>LDI 63<br>IFEQ R1<br>LDI 0<br>SETRGB R0</pre> |
|![test7.png](images/test7.png)| <pre>CLEAR R3<br>GETX R0<br>GETUSER R1<br>ADD R0 R1<br>SETRGB R0<br>SINE R0<br>HALF R0<br>GETY R1<br>IFGE R1<br>SETRGB R3</pre> |
|||
|-|-|-|-|
|![test2.png](images/test2.png)|![test4.png](images/test4.png)|![test5.png](images/test5.png)|![test7.png](images/test7.png)
| <pre>GETX R0<br>SINE R1<br>SETR R1<br>GETY R0<br>SINE R1<br>SETG R1</pre> | <pre>GETX R0<br>GETY R1<br>XOR R0 R1<br>SETRGB R0</pre> | <pre>GETY R1<br>LDI 1<br>AND R1 R0<br>IFNE R1<br>LDI 63<br>IFEQ R1<br>LDI 0<br>SETRGB R0</pre> | <pre>CLEAR R3<br>GETX R0<br>GETUSER R1<br>ADD R0 R1<br>SETRGB R0<br>SINE R0<br>HALF R0<br>GETY R1<br>IFGE R1<br>SETRGB R3</pre> |

Here is an animation using the time register:

![animation.gif](/home/leo/Nextcloud/Programmieren/ASIC/tt06-tiny-shader/images/animation.gif)

## Architecture

Expand All @@ -27,7 +29,7 @@ The shader has four sources to get input from:

- `X` - X position of the current pixel
- `Y` - Y position of the current pixel
- `TIME` - Increases at 7.5 Hz, before it overflow it counts down again.
- `TIME` - Increments at 7.5 Hz, before it overflow it counts down again.
- `USER` - Register that can be set via the SPI interface.

### Output
Expand Down
42 changes: 34 additions & 8 deletions docs/info.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,40 @@ Tiny Shader mimics such a shading unit, it executes a shader of 10 instructions

### Examples

These images and many more can be generated with Tiny Shader. Note, that using the time input the shaders can even be animated.
These images and many more can be generated with Tiny Shader. Note, that shaders can even be animated by acessing the user or time register.

|Image|Shader|
|-|-|
|![test2.png](images/test2.png)| <pre>GETX R0<br>SINE R1<br>SETR R1<br>GETY R0<br>SINE R1<br>SETG R1</pre> |
|![test4.png](images/test4.png)| <pre>GETX R0<br>GETY R1<br>XOR R0 R1<br>SETRGB R0</pre> |
|![test5.png](images/test5.png)| <pre>GETY R1<br>LDI 1<br>AND R1 R0<br>IFNE R1<br>LDI 63<br>IFEQ R1<br>LDI 0<br>SETRGB R0</pre> |
|![test7.png](images/test7.png)| <pre>CLEAR R3<br>GETX R0<br>GETUSER R1<br>ADD R0 R1<br>SETRGB R0<br>SINE R0<br>HALF R0<br>GETY R1<br>IFGE R1<br>SETRGB R3</pre> |
|||||
|-|-|-|-|
|![test2.png](../images/test2.png)|![test4.png](../images/test4.png)|![test5.png](../images/test5.png)|![test7.png](../images/test7.png)|

The shader for the last image is shown here:

```
# Shader to display a rainbow colored sine wave
# Clear R3
CLEAR R3
# Get the sine value for x and add the user value
GETX R0
GETUSER R1
ADD R0 R1
# Set default color to R0
SETRGB R0
# Get the sine value for R0
SINE R0
HALF R0
# Get y coord
GETY R1
# If the sine value is greater
# or equal y, set color to black
IFGE R1
SETRGB R3
```

### Architecture

Expand Down Expand Up @@ -110,7 +136,7 @@ The following instructions are supported by Tiny Shader. A program consists of 1

## How to test

First set the clock to 25.175 MHz and reset the design. For a simple test, simply connect a Tiny VGA to the output Pmod. A shader is loaded by default should be displayed via VGA.
First set the clock to 25.175 MHz and reset the design. For a simple test, simply connect a Tiny VGA to the output Pmod. A shader is loaded by default and an image should be displayed via VGA.

For advanced features, connect an SPI controller to the bidir pmod. If ui[0], the mode signal, is set to 0, you can write to the user register via SPI. Note that only the last 6 bit are used.

Expand Down
Binary file added images/animation.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8d1b6ac

Please sign in to comment.