Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
91 additions
and 4 deletions.
- +2 −0 mortar-combat.asd
- +54 −0 src/ball.lisp
- +1 −1 src/dude.lisp
- +1 −0 src/main.lisp
- +2 −2 src/mortar.lisp
- +1 −1 src/shaders/dude.lisp
- 0 src/shaders/{dude.f.glsl → passthru.f.glsl}
- +6 −0 src/shaders/passthru.lisp
- +24 −0 src/shaders/passthru.v.glsl
@@ -0,0 +1,54 @@ | ||
(in-package :mortar-combat) | ||
|
||
|
||
;;; | ||
;;; | ||
;;; | ||
(defclass ball-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")) | ||
(color :initform (vec3 0.3 0.3 0.3)) | ||
(mesh-asset :initarg :mesh) | ||
(program :initarg :program))) | ||
|
||
|
||
(defmethod make-node-mesh ((this ball-mesh)) | ||
(with-slots (mesh-asset) this | ||
(mesh-asset-mesh mesh-asset))) | ||
|
||
|
||
(defmethod scene-pass ((this ball-mesh) (pass rendering-pass) input) | ||
(with-slots (mesh-asset light program color) 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*)) | ||
(program-uniform-variable program "baseColor") color) | ||
(apply-light-source light program) | ||
(call-next-method)))) | ||
|
||
|
||
;;; | ||
;;; | ||
;;; | ||
(defclass ball-model (model) | ||
((mesh :initform nil) | ||
(program :initform nil))) | ||
|
||
|
||
(defmethod initialization-flow ((this ball-model) &key) | ||
(with-slots (mesh program) this | ||
(>> (resource-flow "Ball.0" (shading-program-resource-name "passthru-program")) | ||
(instantly (m p) | ||
(setf mesh m | ||
program p)) | ||
(call-next-method)))) | ||
|
||
|
||
(defmethod model-graph-assembly-flow ((this ball-model)) | ||
(with-slots (mesh program) this | ||
(scenegraph | ||
((ball-mesh :mesh mesh :program program))))) |
File renamed without changes.
@@ -0,0 +1,6 @@ | ||
(in-package :mortar-combat) | ||
|
||
|
||
(define-shading-program passthru-program | ||
:vertex-shader "passthru.v.glsl" | ||
:fragment-shader "passthru.f.glsl") |
@@ -0,0 +1,24 @@ | ||
#version 410 core | ||
|
||
#include <lighting> | ||
|
||
layout(location = 0) in vec3 vPosition; | ||
layout(location = 1) in vec3 vNormal; | ||
|
||
out gl_PerVertex { | ||
vec4 gl_Position; | ||
}; | ||
|
||
out v_PerVertex { | ||
vec4 color; | ||
}; | ||
|
||
uniform mat4 modelViewProjection; | ||
uniform mat3 normalTransform; | ||
uniform DirectionalLight dLight; | ||
uniform vec3 baseColor; | ||
|
||
void main() { | ||
color = computeLight(vec4(baseColor, 1.0), normalTransform * vNormal, dLight); | ||
gl_Position = modelViewProjection * vec4(vPosition, 1.0); | ||
} |