Permalink
Browse files

Dude

  • Loading branch information...
borodust committed Apr 15, 2017
1 parent 7d49cae commit f03e3048cb6911d6433292e61b508423f0a2e049
Showing with 63,922 additions and 2 deletions.
  1. +63,789 −0 assets/dude-and-mortar.brf
  2. +3 −0 mortar-combat.asd
  3. +10 −0 src/camera.lisp
  4. +66 −0 src/dude.lisp
  5. +6 −2 src/main.lisp
  6. +11 −0 src/shaders/dude.f.glsl
  7. +6 −0 src/shaders/dude.lisp
  8. +31 −0 src/shaders/dude.v.glsl

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -14,6 +14,9 @@
:pathname "src/"
:components ((:file "packages")
(:file "utils")
(:file "camera")
(:file "dude")
(:file "shaders/dude")
(:file "main")))
@@ -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))
@@ -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))))))))
@@ -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)))
@@ -0,0 +1,11 @@
#version 410 core
out vec4 fColor;
in v_PerVertex {
vec4 color;
};
void main() {
fColor = color;
}
@@ -0,0 +1,6 @@
(in-package :mortar-combat)
(define-shading-program dude-program
:vertex-shader "dude.v.glsl"
:fragment-shader "dude.f.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.