Skip to content

Commit

Permalink
Dude
Browse files Browse the repository at this point in the history
  • Loading branch information
borodust committed Apr 15, 2017
1 parent 7d49cae commit f03e304
Show file tree
Hide file tree
Showing 8 changed files with 63,922 additions and 2 deletions.
63,789 changes: 63,789 additions & 0 deletions assets/dude-and-mortar.brf

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions mortar-combat.asd
Expand Up @@ -14,6 +14,9 @@
:pathname "src/"
:components ((:file "packages")
(:file "utils")
(:file "camera")
(:file "dude")
(:file "shaders/dude")
(:file "main")))


Expand Down
10 changes: 10 additions & 0 deletions src/camera.lisp
@@ -0,0 +1,10 @@
(in-package :mortar-combat)


(defclass player-camera (camera-node) ())


(defmethod scene-pass ((this player-camera) pass input)
(setf (transform-of this) (mult (translation-mat4 0 -5 -30)
(euler-angles->mat4 (vec3 (/ pi -2) 0.0 0.0))))
(call-next-method))
66 changes: 66 additions & 0 deletions src/dude.lisp
@@ -0,0 +1,66 @@
(in-package :mortar-combat)


;;;
;;;
;;;
(defclass dude-mesh (mesh-node)
((light :initform (make-directional-light-source
(vec3 -0.57735026 -0.57735026 -0.57735026)
(vec4 0.2 0.2 0.2 1.0)
(vec4 0.8 0.8 0.8 1.0)
"dLight"))
(mesh-asset :initarg :mesh)
(program :initarg :program)))


(defmethod make-node-mesh ((this dude-mesh))
(with-slots (mesh-asset) this
(mesh-asset-mesh mesh-asset)))


(defmethod scene-pass ((this dude-mesh) (pass rendering-pass) input)
(with-slots (mesh-asset light program) this
(with-active-shading-program (program)
(setf (program-uniform-variable program "modelViewProjection") (model-view-projection-matrix)
(program-uniform-variable program "normalTransform") (mat4->mat3 (mult *view-matrix*
*model-matrix*)))
(apply-light-source light program)
(loop for (name . offset) across (mesh-asset-bones mesh-asset)
for idx = 0 then (1+ idx) do
(setf (program-uniform-variable program (format nil "bones[~d].transform" idx))
(mult (bone-transform name) offset)))
(call-next-method))))


;;;
;;;
;;;
(defclass dude-model (model)
((mesh :initform nil)
(program :initform nil)
(animation :initform nil)
(control-skeleton :initform nil)
(skeleton :initform nil)))


(defmethod initialization-flow ((this dude-model) &key)
(with-slots (mesh animation skeleton program control-skeleton) this
(>> (resource-flow "Dude.4" "Pelvis" "Bone" ".animation.0"
(shading-program-resource-name "dude-program"))
(instantly (m s cs a p)
(setf mesh m
skeleton s
control-skeleton cs
animation a
program p))
(call-next-method))))


(defmethod model-graph-assembly-flow ((this dude-model))
(with-slots (animation skeleton control-skeleton mesh program) this
(scenegraph
((animation-node :frames animation)
((animated-skeleton-node :root-bone control-skeleton)
((animated-skeleton-node :root-bone skeleton)
((dude-mesh :mesh mesh :program program))))))))
8 changes: 6 additions & 2 deletions src/main.lisp
Expand Up @@ -17,12 +17,16 @@

(defun scenegraph-flow ()
(scenegraph
(transform-node)))
(transform-node
((projection-node :aspect (/ 800 600))
(player-camera
(dude-model))))))


(defmethod initialize-system :after ((this mortar-combat))
(with-slots (scene) this
(register-resource-loader (make-resource-loader (asset-path "font.brf")))
(register-resource-loader (make-resource-loader (asset-path "font.brf")
(asset-path "dude-and-mortar.brf")))
(run (>> (-> ((host)) ()
(setf (viewport-title) "Mortar Combat")
(setf (viewport-size) (vec2 800 600)))
Expand Down
11 changes: 11 additions & 0 deletions src/shaders/dude.f.glsl
@@ -0,0 +1,11 @@
#version 410 core

out vec4 fColor;

in v_PerVertex {
vec4 color;
};

void main() {
fColor = color;
}
6 changes: 6 additions & 0 deletions src/shaders/dude.lisp
@@ -0,0 +1,6 @@
(in-package :mortar-combat)


(define-shading-program dude-program
:vertex-shader "dude.v.glsl"
:fragment-shader "dude.f.glsl")
31 changes: 31 additions & 0 deletions src/shaders/dude.v.glsl
@@ -0,0 +1,31 @@
#version 410 core

#include <lighting>
#include <skinning>

layout(location = 0) in vec3 vPosition;
layout(location = 1) in vec3 vNormal;

layout(location = 2) in vec4 vWeights;
layout(location = 3) in ivec4 vBones;


out gl_PerVertex {
vec4 gl_Position;
};

out v_PerVertex {
vec4 color;
};

uniform mat4 modelViewProjection;
uniform mat3 normalTransform;
uniform DirectionalLight dLight;

void main() {
mat4 weightedTransform = weightedTransform(vBones, vWeights);
color = computeLight(vec4(0.4, 0.2, 0.2, 1.0),
normalTransform * mat3(weightedTransform) * vNormal,
dLight);
gl_Position = modelViewProjection * weightedTransform * vec4(vPosition, 1.0);
}

0 comments on commit f03e304

Please sign in to comment.