-
Notifications
You must be signed in to change notification settings - Fork 0
/
spaceship.lisp
32 lines (26 loc) · 1.22 KB
/
spaceship.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
(in-package #:spacepilot)
(define-shader-entity spaceship (vertex-entity collision-body colored-entity listener)
((velocity :initform (vec 0 0 0) :initarg :velocity :accessor velocity)
(vertex-array :initform (// 'trial 'unit-sphere))
(color :initform (vec 0 1 1 1) :initarg :color :accessor color)))
(defmethod initialize-instance :after ((spaceship spaceship) &key)
(setf (physics-primitive spaceship)
(make-sphere :radius 1.5 :location (location spaceship))))
(defmethod stage :after ((spaceship spaceship) (area staging-area))
(stage (// 'spacepilot-sound 'explosion) area))
;; stolen from the collision.lisp example in Trial
(define-class-shader (spaceship :fragment-shader)
"in vec3 v_view_position;
in vec3 v_world_position;
uniform vec4 objectcolor;
out vec4 color;
void main(){
vec3 normal = cross(dFdx(v_view_position), dFdy(v_view_position));
normal = normalize(normal * sign(normal.z));
// Shitty phong diffuse lighting
vec3 light_dir = normalize(vec3(10, 5, 10) - v_world_position);
vec3 reflect_dir = reflect(-light_dir, normal);
vec3 radiance = vec3(0.75) * (objectcolor.xyz * max(dot(normal, light_dir), 0));
radiance += vec3(0.2) * objectcolor.xyz;
color = vec4(radiance, objectcolor.w);
}")