Skip to content

Commit

Permalink
Untested visualizer-pass helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Mar 27, 2019
1 parent e724b68 commit c0c8e47
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
39 changes: 39 additions & 0 deletions effects.lisp
Expand Up @@ -115,3 +115,42 @@ void main(){

(define-class-shader (light-scatter-pass :fragment-shader)
(pool-path 'effects #p"light-scatter.frag"))

(define-shader-pass visualizer-pass (post-effect-pass)
((t[0] :port-type input)
(t[1] :port-type input)
(t[2] :port-type input)
(t[3] :port-type input)))

(defmethod check-consistent ((pass visualizer-pass))
;; Skip consistency checks to allow optional inputs
T)

(define-class-shader (visualizer-pass :fragment-shader)
"out vec4 color;
in vec2 tex_coord;
uniform sampler2D t[4];
uniform int channel_count[4] = int[4](4,4,4,4);
uniform int texture_count[2] = int[2](1, 1);
void main(){
// Determine which texture we're currently in.
int x = floor(tex_coord*texture_count[0]);
int y = floor(tex_coord*texture_count[1]);
// Compute texture and local UV
sampler2D tex = t[x+y*texture_count[0]];
vec2 uv = vec2(tex_coord.x/texture_count[0]+float(x)/texture_count[0],
tex_coord.y/texture_count[1]+float(y)/texture_count[0]);
// Sample the texture
vec4 local = texture(tex, uv);
int channels = channels[x+y*texture_count[0]];
switch(channels){
case 0: color = vec4(0); break;
case 1: color = vec4(local.r, local.r, local.r, 1); break;
case 2: color = vec4(local.rg, 0, 1); break;
case 3: color = vec2(local.rgb, 1); break;
case 4: color = local; break;
}
}")
3 changes: 1 addition & 2 deletions pipeline.lisp
Expand Up @@ -44,8 +44,7 @@

(defmethod check-consistent ((pipeline pipeline))
(dolist (node (nodes pipeline))
(dolist (port (flow:ports node))
(check-consistent port))))
(check-consistent node)))

(defun texspec-real-size (texspec width height)
(flet ((eval-size (size)
Expand Down
4 changes: 4 additions & 0 deletions shader-pass.lisp
Expand Up @@ -73,6 +73,10 @@
(define-class-shader (shader-pass :fragment-shader)
"#version 330 core")

(defmethod check-consistent ((pass shader-pass))
(dolist (port (flow:ports pass))
(check-consistent port)))

(defgeneric register-object-for-pass (pass object))
(defgeneric shader-program-for-pass (pass object))
(defgeneric make-pass-shader-program (pass object))
Expand Down

0 comments on commit c0c8e47

Please sign in to comment.