Skip to content
Permalink
Browse files

Fix some stuff.

  • Loading branch information...
Shinmera committed Sep 18, 2019
1 parent af6bffc commit 144127d0db23ae5fa873dd7c8767dd2553522cb4
Showing with 16 additions and 4 deletions.
  1. +16 −4 workbench.lisp
@@ -14,11 +14,11 @@
(:default-initargs :vertex-array (asset 'workbench 'grid)))

(define-shader-entity lines (vertex-entity)
()
((line-width :initarg :line-width :initform 3.0 :accessor line-width))
(:inhibit-shaders (vertex-entity :vertex-shader)))

(defclass line-vertex (vertex)
((next :initarg)))
())

(defmethod initialize-instance :after ((lines lines) &key points)
(let ((mesh (make-instance 'vertex-mesh :vertex-type 'normal-vertex)))
@@ -33,23 +33,35 @@
(vertex :location a :normal (v- b a))))
(setf (vertex-array lines) (change-class mesh 'vertex-array :vertex-form :triangles))))

(defmethod paint :before ((lines lines) (target shader-pass))
(let ((program (shader-program-for-pass target lines)))
(setf (uniform program "line_width") (float (line-width lines)))
(setf (uniform program "view_size") (vec (width *context*) (height *context*)))))

(define-class-shader (lines :vertex-shader)
"layout(location = 0) in vec3 position;
layout(location = 1) in vec3 direction;
out vec2 line_normal;
uniform float line_width = 3.0;
uniform vec2 view_size = vec2(800,600);
uniform mat4 model_matrix;
uniform mat4 view_matrix;
uniform mat4 projection_matrix;
void main(){
float aspect = view_size.x/view_size.y;
mat4 PVM = projection_matrix * view_matrix * model_matrix;
vec4 screen1 = PVM * vec4(position, 1);
vec4 screen2 = PVM * vec4(position+direction, 1);
line_normal = normalize(screen2.xy/screen2.w-screen1.xy/screen1.w);
vec2 clip1 = screen1.xy/screen1.w;
vec2 clip2 = screen2.xy/screen2.w;
clip1.x *= aspect;
clip2.x *= aspect;
line_normal = normalize(clip2 - clip1);
line_normal = vec2(-line_normal.y, line_normal.x);
gl_Position = screen1 + vec4(line_normal*line_width/2, 0, 0);
line_normal.x /= aspect;
gl_Position = screen1 + screen1.w * vec4(line_normal*line_width/view_size, 0, 0);
}")

(define-class-shader (lines :fragment-shader)

0 comments on commit 144127d

Please sign in to comment.
You can’t perform that action at this time.