diff options
-rw-r--r-- | chickadee/graphics/9-patch.scm | 54 | ||||
-rw-r--r-- | chickadee/graphics/path.scm | 42 |
2 files changed, 48 insertions, 48 deletions
diff --git a/chickadee/graphics/9-patch.scm b/chickadee/graphics/9-patch.scm index dc14bc7..eac688d 100644 --- a/chickadee/graphics/9-patch.scm +++ b/chickadee/graphics/9-patch.scm @@ -58,33 +58,33 @@ (uniform sampler-2d color-texture) (uniform vec4 tint) (uniform int mode)) - (let ((patch (lambda (d m0 m1 length tex-length) - (cond - ;; Inside the left/bottom margin. - ((<= d m0) - (* d tex-length)) - ;; Inside the right/top margin. - ((>= d (- length m1)) - (- tex-length (* (- length d) tex-length))) - ;; In the middle: stretch mode. - ((= mode 0) - (mix m0 (- tex-length m1) (/ (- d m0) (- length m0 m1)))) - ;; In the middle: tile mode. - (else - (+ m0 (mod (- d m0) (- tex-length m0 m1)))))))) - (let ((texcoord (+ (vec2 (-> subtexture x) (-> subtexture y)) - (vec2 (patch (-> frag-distance x) - (-> margins x) - (-> margins y) - width - (-> subtexture z)) - (patch (-> frag-distance y) - (-> margins z) - (-> margins w) - height - (-> subtexture w)))))) - (outputs - (frag-color (* (texture-2d color-texture texcoord) tint)))))) + (define (patch d m0 m1 length tex-length) + (cond + ;; Inside the left/bottom margin. + ((<= d m0) + (* d tex-length)) + ;; Inside the right/top margin. + ((>= d (- length m1)) + (- tex-length (* (- length d) tex-length))) + ;; In the middle: stretch mode. + ((= mode 0) + (mix m0 (- tex-length m1) (/ (- d m0) (- length m0 m1)))) + ;; In the middle: tile mode. + (else + (+ m0 (mod (- d m0) (- tex-length m0 m1)))))) + (let ((texcoord (+ (vec2 (-> subtexture x) (-> subtexture y)) + (vec2 (patch (-> frag-distance x) + (-> margins x) + (-> margins y) + width + (-> subtexture z)) + (patch (-> frag-distance y) + (-> margins z) + (-> margins w) + height + (-> subtexture w)))))) + (outputs + (frag-color (* (texture-2d color-texture texcoord) tint))))) (define-graphics-variable 9-patch-shader (compile-shader 9-patch-vertex 9-patch-fragment)) diff --git a/chickadee/graphics/path.scm b/chickadee/graphics/path.scm index e2952dd..63a8049 100644 --- a/chickadee/graphics/path.scm +++ b/chickadee/graphics/path.scm @@ -1316,27 +1316,27 @@ (uniform vec4 end-color) (uniform vec2 gradient-range) (uniform float radial-gradient-ratio)) - (let ((gradient-mix (lambda (x) - (let* ((start (-> gradient-range x)) - (end (-> gradient-range y)) - (t (clamp (/ (- x start) (- end start)) - 0.0 1.0))) - (mix color end-color t))))) - (if (<= (-> color w) 0.0) - (discard) - (outputs - (frag-color - (case mode - ((0) - color) - ((1) - (gradient-mix (-> frag-position x))) - ((2) - (let ((p (* frag-position - (vec2 1.0 radial-gradient-ratio)))) - (gradient-mix (length p)))) - (else - (vec4 0.0 0.0 0.0 0.0)))))))) + (define (gradient-mix x) + (let* ((start (-> gradient-range x)) + (end (-> gradient-range y)) + (t (clamp (/ (- x start) (- end start)) + 0.0 1.0))) + (mix color end-color t))) + (if (<= (-> color w) 0.0) + (discard) + (outputs + (frag-color + (case mode + ((0) + color) + ((1) + (gradient-mix (-> frag-position x))) + ((2) + (let ((p (* frag-position + (vec2 1.0 radial-gradient-ratio)))) + (gradient-mix (length p)))) + (else + (vec4 0.0 0.0 0.0 0.0))))))) (define-graphics-variable fill-shader (compile-shader fill-vertex fill-fragment)) |