diff --git a/README.md b/README.md index f7418ae..e212561 100644 --- a/README.md +++ b/README.md @@ -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)|
GETX R0
SINE R1
SETR R1
GETY R0
SINE R1
SETG R1
| -|![test4.png](images/test4.png)|
GETX R0
GETY R1
XOR R0 R1
SETRGB R0
| -|![test5.png](images/test5.png)|
GETY R1
LDI 1
AND R1 R0
IFNE R1
LDI 63
IFEQ R1
LDI 0
SETRGB R0
| -|![test7.png](images/test7.png)|
CLEAR R3
GETX R0
GETUSER R1
ADD R0 R1
SETRGB R0
SINE R0
HALF R0
GETY R1
IFGE R1
SETRGB R3
| +||| +|-|-|-|-| +|![test2.png](images/test2.png)|![test4.png](images/test4.png)|![test5.png](images/test5.png)|![test7.png](images/test7.png) +|
GETX R0
SINE R1
SETR R1
GETY R0
SINE R1
SETG R1
|
GETX R0
GETY R1
XOR R0 R1
SETRGB R0
|
GETY R1
LDI 1
AND R1 R0
IFNE R1
LDI 63
IFEQ R1
LDI 0
SETRGB R0
|
CLEAR R3
GETX R0
GETUSER R1
ADD R0 R1
SETRGB R0
SINE R0
HALF R0
GETY R1
IFGE R1
SETRGB R3
| + +Here is an animation using the time register: + +![animation.gif](/home/leo/Nextcloud/Programmieren/ASIC/tt06-tiny-shader/images/animation.gif) ## Architecture @@ -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 diff --git a/docs/info.md b/docs/info.md index e3fe743..18af8a9 100644 --- a/docs/info.md +++ b/docs/info.md @@ -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)|
GETX R0
SINE R1
SETR R1
GETY R0
SINE R1
SETG R1
| -|![test4.png](images/test4.png)|
GETX R0
GETY R1
XOR R0 R1
SETRGB R0
| -|![test5.png](images/test5.png)|
GETY R1
LDI 1
AND R1 R0
IFNE R1
LDI 63
IFEQ R1
LDI 0
SETRGB R0
| -|![test7.png](images/test7.png)|
CLEAR R3
GETX R0
GETUSER R1
ADD R0 R1
SETRGB R0
SINE R0
HALF R0
GETY R1
IFGE R1
SETRGB R3
| +||||| +|-|-|-|-| +|![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 @@ -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. diff --git a/images/animation.gif b/images/animation.gif new file mode 100644 index 0000000..ce6d312 Binary files /dev/null and b/images/animation.gif differ