summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2023-02-14 21:11:42 -0500
committerDavid Thompson <dthompson2@worcester.edu>2023-06-08 08:14:41 -0400
commitffdac9a41872974f9227b9cc45552725b4a7783b (patch)
tree4091a73e1fa586fa1f71cebe3802497e115ad09f
parentf65880b27ea51be81641c97a76d9d44b217dbae2 (diff)
Port sprite shader to Seagull.
-rw-r--r--chickadee/graphics/sprite.scm139
1 files changed, 108 insertions, 31 deletions
diff --git a/chickadee/graphics/sprite.scm b/chickadee/graphics/sprite.scm
index b2663cf..f2fcfe4 100644
--- a/chickadee/graphics/sprite.scm
+++ b/chickadee/graphics/sprite.scm
@@ -24,6 +24,7 @@
#:use-module (chickadee graphics blend)
#:use-module (chickadee graphics color)
#:use-module (chickadee graphics engine)
+ #:use-module (chickadee graphics seagull)
#:use-module (chickadee graphics shader)
#:use-module (chickadee graphics texture)
#:use-module (chickadee graphics buffer)
@@ -55,21 +56,24 @@
(make-geometry <sprite-vertex> 4 #:index-capacity 6))
(define-graphics-variable sprite-model-matrix (make-null-matrix4))
(define-graphics-variable sprite-mvp-matrix (make-null-matrix4))
+(define-vertex-shader sprite-vertex
+ ((in vec2 position)
+ (in vec2 tex)
+ (out vec2 frag-tex)
+ (uniform mat4 mvp))
+ (outputs
+ (vertex:position (* mvp (vec4 (-> position x) (-> position y) 0.0 1.0)))
+ (frag-tex tex)))
+(define-fragment-shader sprite-fragment
+ ((in vec2 frag-tex)
+ (out vec4 frag-color)
+ (uniform sampler-2d texture)
+ (uniform vec4 tint))
+ (outputs
+ (frag-color (* (texture-2d texture frag-tex) tint))))
+
(define-graphics-variable sprite-shader
- (make-shader*
- ((in vec2 position)
- (in vec2 tex)
- (out vec2 fragTex)
- (uniform mat4 mvp)
- (define (void main)
- (= fragTex tex)
- (= gl_Position (* mvp (vec4 (-> position xy) 0.0 1.0)))))
- ((in vec2 fragTex)
- (out vec4 fragColor)
- (uniform sampler2D colorTexture)
- (uniform vec4 tint)
- (define (void main)
- (= fragColor (* (texture colorTexture fragTex) tint))))))
+ (compile-shader sprite-vertex sprite-fragment))
(define* (draw-sprite* texture
rect
@@ -158,24 +162,97 @@ BLEND-MODE."
(texture vec2)
(tint vec4))
+(define-vertex-shader sprite-batch-vertex
+ ((in vec2 position)
+ (in vec2 tex)
+ (in vec4 tint)
+ (out vec2 frag-tex)
+ (out vec4 frag-tint)
+ (uniform mat4 mvp))
+ (outputs
+ (vertex:position (* mvp (vec4 (-> position x) (-> position y) 0.0 1.0)))
+ (frag-tex tex)
+ (frag-tint tint)))
+;; #ifdef GLSL120
+;; varying vec2 fragTex;
+;; varying vec4 fragTint;
+;; #else
+;; in vec2 fragTex;
+;; in vec4 fragTint;
+;; #endif
+;; #ifdef GLSL330
+;; out vec4 fragColor;
+;; #endif
+;; uniform sampler2D colorTexture;
+
+;; void main (void) {
+;; #ifdef GLSL330
+;; fragColor = texture(colorTexture, fragTex) * fragTint;
+;; #else
+;; gl_FragColor = texture2D(colorTexture, fragTex) * fragTint;
+;; #endif
+;; }
+(define-fragment-shader sprite-batch-fragment
+ ((in vec2 frag-tex)
+ (in vec4 frag-tint)
+ (out vec4 frag-color)
+ (uniform sampler-2d texture))
+ (outputs
+ (frag-color (* (texture-2d texture frag-tex) frag-tint))))
(define-graphics-variable sprite-batch-shader
- (make-shader*
- ((in vec2 position)
- (in vec2 tex)
- (in vec4 tint)
- (out vec2 fragTex)
- (out vec4 fragTint)
- (uniform mat4 mvp)
- (define (void main)
- (= fragTex tex)
- (= fragTint tint)
- (= gl_Position (* mvp (vec4 (-> position xy) 0.0 1.0)))))
- ((in vec2 fragTex)
- (in vec4 fragTint)
- (out vec4 fragColor)
- (uniform sampler2D colorTexture)
- (define (void main)
- (= fragColor (* (texture colorTexture fragTex) fragTint))))))
+ (compile-shader sprite-batch-vertex sprite-batch-fragment))
+;; (define-graphics-variable sprite-batch-shader
+;; (strings->shader
+;; "
+;; #ifdef GLSL330
+;; layout (location = 0) in vec2 position;
+;; layout (location = 1) in vec2 tex;
+;; layout (location = 2) in vec4 tint;
+;; #elif defined(GLSL130)
+;; in vec2 position;
+;; in vec2 tex;
+;; in vec4 tint;
+;; #elif defined(GLSL120)
+;; attribute vec2 position;
+;; attribute vec2 tex;
+;; attribute vec4 tint;
+;; #endif
+;; #ifdef GLSL120
+;; varying vec2 fragTex;
+;; varying vec4 fragTint;
+;; #else
+;; out vec2 fragTex;
+;; out vec4 fragTint;
+;; #endif
+;; uniform mat4 mvp;
+
+;; void main(void) {
+;; fragTex = tex;
+;; fragTint = tint;
+;; gl_Position = mvp * vec4(position.xy, 0.0, 1.0);
+;; }
+;; "
+;; "
+;; #ifdef GLSL120
+;; varying vec2 fragTex;
+;; varying vec4 fragTint;
+;; #else
+;; in vec2 fragTex;
+;; in vec4 fragTint;
+;; #endif
+;; #ifdef GLSL330
+;; out vec4 fragColor;
+;; #endif
+;; uniform sampler2D colorTexture;
+
+;; void main (void) {
+;; #ifdef GLSL330
+;; fragColor = texture(colorTexture, fragTex) * fragTint;
+;; #else
+;; gl_FragColor = texture2D(colorTexture, fragTex) * fragTint;
+;; #endif
+;; }
+;; "))
(define-record-type <sprite-batch>
(%make-sprite-batch texture geometry size)