Skip to content
Permalink
Browse files

clip layering workbench

  • Loading branch information
Shinmera committed Nov 9, 2019
1 parent 97356e6 commit 7a5b50fdf9d4b7ef0fa65474d913c98bd71a5441
Showing with 39 additions and 31 deletions.
  1. +39 −31 workbench.lisp
@@ -1,47 +1,55 @@
(in-package #:trial)

(defclass workbench (main) ()
(:default-initargs :clear-color (vec 0.3 0.3 0.3 0)))
(:default-initargs :clear-color (vec 0.25 0.3 0.35 0)))

(define-pool workbench
:base 'trial)

(define-asset (workbench grid) mesh
(make-line-grid 10 100 100))

(define-shader-subject grid (vertex-entity colored-entity)
()
(:default-initargs :vertex-array (asset 'workbench 'grid)))

(define-shader-subject simple-clock (lines) ()
(:default-initargs :vertex-array (change-class (make-lines ()) 'vertex-array :data-usage :stream-draw)))

(define-handler (simple-clock tick) (ev tt)
(let* ((h (mod (floor tt (* 60 60)) 24))
(m (mod (floor tt 60) 60))
(s (floor (mod tt 60)))
(hrad (+ (* (/ h 24) -2 PI) (/ PI 2)))
(mrad (+ (* (/ m 60) -2 PI) (/ PI 2)))
(srad (+ (* (/ s 60) -2 PI) (/ PI 2)))
(mesh (make-lines (list (vec 0 0 0) (vec (* (cos hrad) 70) (* (sin hrad) 70) 0)
(vec 0 0 0) (vec (* (cos mrad) 90) (* (sin mrad) 90) 0)
(list (vec 0 0 0) (vec 1 0 0 1)) (list (vec (* (cos srad) 90) (* (sin srad) 90) 0) (vec 1 0 0 1))))))
(replace-vertex-data (vertex-array simple-clock) mesh :update T)))
(define-shader-subject grid (vertex-entity)
((vertex-array :initform (asset 'workbench 'grid))))

(define-asset (workbench rectangle) mesh
(make-rectangle 800 600 :align :bottomleft))

(define-shader-entity filler (vertex-entity colored-entity)
((vertex-array :initform (asset 'workbench 'rectangle))
(color :initform (vec 1 0 0 0.1))))

(defvar *clip-depth* 0)

(defmethod render :before ((workbench workbench) renderable)
(setf *clip-depth* 0))

(define-shader-subject clipper (vertex-entity scaled-entity located-entity colored-entity)
((vertex-array :initform (asset 'workbench 'rectangle))
(color :initform (vec 1 1 0 1))))

(defmethod paint :around ((clipper clipper) target)
(gl:stencil-op :keep :incr :incr)
(gl:stencil-func :lequal *clip-depth* #xFF)
(gl:color-mask NIL NIL NIL NIL)
(gl:depth-mask NIL)
(call-next-method)
(incf *clip-depth*)
(gl:stencil-op :keep :keep :keep)
(gl:stencil-func :lequal *clip-depth* #xFF)
(gl:color-mask T T T T)
(gl:depth-mask T))

(progn
(defmethod setup-scene ((workbench workbench) scene)
(enter (make-instance 'grid) scene)
(enter (make-instance 'lines :vertex-array (asset 'trial 'axes)) scene)
;; Creating static lines
(let ((circle (loop for i from 0 to (* 2 PI) by (/ PI 30)
collect (vec (* 100 (cos i)) (* 100 (sin i)) 0)
collect (vec (* 100 (cos (+ i (/ PI 30)))) (* 100 (sin (+ i (/ PI 30)))) 0))))
(enter (make-instance 'lines :vertex-array (change-class (make-lines circle) 'vertex-array)
:line-width 5.0)
scene))
;; Creating lines that change
(enter (make-instance 'simple-clock) scene)
(enter (make-instance 'editor-camera) scene)
(disable :cull-face)
(enter (make-instance 'clipper :scaling (vec 0.5 0.5 1) :location (vec 100 100 0)) scene)
(enter (make-instance 'filler) scene)
(enter (make-instance 'clipper :scaling (vec 0.5 0.5 1) :location (vec 0 0 0)) scene)
(enter (make-instance 'filler) scene)
;; (enter (make-instance 'clipper :scaling (vec (/ (expt 1.1 i)) (/ (expt 1.1 i)) 1)) scene)
;; (enter (make-instance 'filler) scene)
(enter (make-instance '2d-camera) scene)
(enter (make-instance 'render-pass) scene))

(maybe-reload-scene))

0 comments on commit 7a5b50f

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