-
Notifications
You must be signed in to change notification settings - Fork 13
/
shader.rkt
70 lines (46 loc) · 1.9 KB
/
shader.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#lang racket
#|
Racket Arcade (r-cade) - a simple game engine
Copyright (c) 2020 by Jeffrey Massung
All rights reserved.
|#
(require csfml)
;; ----------------------------------------------------
(provide (all-defined-out))
;; ----------------------------------------------------
#|
The shader below has been a slow work in progress of mine, but
is based on work I learned from many other shaders, most of
found here:
https://github.com/libretro/glsl-shaders
A hearty thanks goes out to the CRT shader emulation community
for their hard work!!
|#
;; ----------------------------------------------------
(define basic-vertex-shader
(string-append "void main() {"
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"
" gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;"
"}"))
;; ----------------------------------------------------
(define crt-fragment-shader
(string-append "uniform sampler2D texture;"
"uniform vec2 resolution;"
"uniform float scale;"
"uniform float time;"
"float fmin = 0.25;"
; entry point
"void main() {"
" vec2 st = gl_FragCoord.xy;"
; color of pixel and scanline
" vec3 pixel = texture2D(texture, gl_TexCoord[0].xy).rgb;"
" vec4 scan = vec4(st.x, st.y, abs(sin(time)), 1.0);"
; every 3rd pixel should be a scanline
" float fmod = mod(scan.y, 3.0);"
" float fstep = fmin + (1.0 - fmin) * fmod;"
; alpha the color by the scanline
" gl_FragColor = vec4(pixel.rgb, fstep);"
"}"))
;; ----------------------------------------------------
(define vertex-shader basic-vertex-shader)
(define fragment-shader crt-fragment-shader)