-
Notifications
You must be signed in to change notification settings - Fork 24
/
default-shaders.lisp
170 lines (154 loc) · 7.39 KB
/
default-shaders.lisp
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
;;; default-shaders.lisp
;;;; Please see the licence.txt for the CLinch
(in-package #:clinch)
(defparameter *generic-shader-hash-table* (make-hash-table))
(defun get-generic-single-texture-shader ()
"Creates/returns a shader-program which blits a texture to an entity.
Uniforms:
P: projection matrix
M: model-view matrix
t1: texture
Attributes:
v: Vertexes
tc1: texture coordinates"
(let ((shader (gethash 'generic-single-texture-shader *generic-shader-hash-table*)))
(if (and shader (program shader)) shader
(setf (gethash 'generic-single-texture-shader *generic-shader-hash-table*)
(make-instance 'clinch:shader-program
:name "generic-single-texture-shader"
:vertex-shader (alexandria:read-file-into-string
(concatenate 'string
(directory-namestring
(asdf:system-relative-pathname :clinch "clinch.asd"))
"shaders/generic-single-texture-shader.vert"))
:fragment-shader (alexandria:read-file-into-string
(concatenate 'string
(directory-namestring
(asdf:system-relative-pathname :clinch "clinch.asd"))
"shaders/generic-single-texture-shader.frag")))))))
(defun get-generic-solid-phong-shader ()
"Creates/returns a shader-program which uses simple phong shading with a single color.
Uniforms:
P: projection matrix
M: model-view matrix
ambientLight: Ambient Light Color
lightDirection: Direction of light
lightIntensity: Color of light
color: color of object
Attributes:
v: Vertexes"
(let ((shader (gethash 'generic-solid-phong-shader *generic-shader-hash-table*)))
(if (and shader (program shader)) shader
(setf (gethash 'generic-solid-phong-shader *generic-shader-hash-table*)
(make-instance 'clinch:shader-program
:name "generic-solid-phong-shader"
:vertex-shader (alexandria:read-file-into-string
(concatenate 'string
(directory-namestring
(asdf:system-relative-pathname :clinch "clinch.asd"))
"shaders/generic-solid-phong-shader.vert"))
:fragment-shader (alexandria:read-file-into-string
(concatenate 'string
(directory-namestring
(asdf:system-relative-pathname :clinch "clinch.asd"))
"shaders/generic-solid-phong-shader.frag")))))))
(defun get-generic-single-diffuse-light-shader ()
(let((shader (gethash 'generic-single-diffuse-light-shader *generic-shader-hash-table*)))
(if (and shader (program shader)) shader
(setf (gethash 'generic-single-diffuse-light-shader *generic-shader-hash-table*)
(make-instance 'clinch:shader-program
:name "generic-single-diffuse-light-shader"
:vertex-shader (alexandria:read-file-into-string
(concatenate 'string
(directory-namestring
(asdf:system-relative-pathname :clinch "clinch.asd"))
"shaders/generic-single-diffuse-light-shader.vert"))
:fragment-shader (alexandria:read-file-into-string
(concatenate 'string
(directory-namestring
(asdf:system-relative-pathname :clinch "clinch.asd"))
"shaders/generic-single-diffuse-light-shader.frag")))))))
(defun get-generic-single-diffuse-light-animation-shader ()
(let ((shader (gethash 'generic-single-diffuse-light-animation-shader *generic-shader-hash-table*)))
(if (and shader (program shader)) shader
(setf (gethash 'generic-single-diffuse-light-animation-shader *generic-shader-hash-table*)
(make-instance 'clinch:shader-program
:name "generic-single-diffuse-light-animation-shader"
:vertex-shader (alexandria:read-file-into-string
(concatenate 'string
(directory-namestring
(asdf:system-relative-pathname :clinch "clinch.asd"))
"shaders/generic-single-diffuse-light-animation-shader.vert"))
:fragment-shader (alexandria:read-file-into-string
(concatenate 'string
(directory-namestring
(asdf:system-relative-pathname :clinch "clinch.asd"))
"shaders/generic-single-diffuse-light-animation-shader.frag")))))))
(defun get-generic-single-diffuse-light-per-vertex-color-shader ()
(let ((shader (gethash 'generic-single-diffuse-light-per-vertex-color *generic-shader-hash-table*)))
(if (and shader (program shader)) shader
(setf (gethash 'generic-single-diffuse-light-per-vertex-color *generic-shader-hash-table*)
(make-instance 'clinch:shader-program
:name "generic-single-diffuse-light-per-vertex-color-shader"
:vertex-shader (alexandria:read-file-into-string
(concatenate 'string
(directory-namestring
(asdf:system-relative-pathname :clinch "clinch.asd"))
"shaders/generic-single-diffuse-light-per-vertex-color.vert"))
:fragment-shader (alexandria:read-file-into-string
(concatenate 'string
(directory-namestring
(asdf:system-relative-pathname :clinch "clinch.asd"))
"shaders/generic-single-diffuse-light-per-vertex-color.frag")))))))
(defun get-generic-single-color-shader ()
(let ((shader (gethash 'generic-single-color *generic-shader-hash-table*)))
(if (and shader (program shader)) shader
(setf (gethash 'generic-single-color *generic-shader-hash-table*)
(make-instance 'clinch:shader-program
:name "generic-single-color-shader"
:vertex-shader (alexandria:read-file-into-string
(concatenate 'string
(directory-namestring
(asdf:system-relative-pathname :clinch "clinch.asd"))
"shaders/generic-single-color-shader.vert"))
:fragment-shader (alexandria:read-file-into-string
(concatenate 'string
(directory-namestring
(asdf:system-relative-pathname :clinch "clinch.asd"))
"shaders/generic-single-color-shader.frag")))))))
(defun get-generic-per-vertex-color-shader ()
(let ((shader (gethash 'generic-per-vertex-color *generic-shader-hash-table*)))
(if (and shader (program shader)) shader
(setf (gethash 'generic-per-vertex-color *generic-shader-hash-table*)
(make-instance 'clinch:shader-program
:name "generic-per-vertex-color-shader"
:vertex-shader (alexandria:read-file-into-string
(concatenate 'string
(directory-namestring
(asdf:system-relative-pathname :clinch "clinch.asd"))
"shaders/generic-per-vertex-color-shader.vert"))
:fragment-shader (alexandria:read-file-into-string
(concatenate 'string
(directory-namestring
(asdf:system-relative-pathname :clinch "clinch.asd"))
"shaders/generic-per-vertex-color-shader.frag")))))))
(defmacro define-default-shader (name)
(let ((sym (intern (string-upcase (princ-to-string name))))
(func (intern (string-upcase (concatenate 'string "get-" (princ-to-string name)))))
(str (string-downcase (princ-to-string name))))
`(defun ,func ()
(let ((shader (gethash ',name *generic-shader-hash-table*)))
(if (and shader (program shader)) shader
(setf (gethash ',name *generic-shader-hash-table*)
(make-instance 'shader-program
:name ,str
:vertex-shader (alexandria:read-file-into-string
(concatenate 'string
(directory-namestring
(asdf:system-relative-pathname :clinch "clinch.asd"))
(concatenate 'string "shaders/" ,str ".vert"))
:fragment-shader (alexandria:read-file-into-string
(concatenate 'string
(directory-namestring
(asdf:system-relative-pathname :clinch "clinch.asd"))
(concatenate 'string "shaders/" ,str ".vert")))))))))))