From 63f096c9f1fc04fe0ae080d67b42437ca5958678 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 15 Feb 2014 20:14:20 -0500 Subject: Use GLSL shaders for sprites. * 2d/sprite.scm: (sprite-vertex): Remove color vertex. (r-offset): Delete it. (pack-sprite-vertices): Remove logic moved to shader. (draw-sprite-vertices): Remove color vertex array rendering. (sprite-shader): New variable. (): Remove dirty field and adjust setters. (make-anchor): New procedure. (update-sprite-vertices!): Use new 'pack-sprite-vertices'. (make-sprite): Use 'make-anchor' and 'update-sprite-vertices!'. (dirty-sprite-setter): Delete it. (load-sprite): Formatting. (sprite-animation-texture): Delete it. (drawable-texture): New procedure. (sprite-texture): Extract body to 'drawable-texture'. (sprite-anchor-vector): Delete it. (set-sprite-anchor!): Reimplemented. (update-sprite-animator!): Update vertices. (draw-sprite): Use shader program. (, make-sprite-batch, sprite-batch?, sprite-batch-max-size, sprite-batch-size, set-sprite-batch-size!, sprite-batch-texture, set-sprite-batch-texture!, sprite-batch-vertices, sprite-batch-draw, with-sprite-batch): Delete all sprite batch code. * data/Makefile.am (shadersdir, shaders_DATA): New variables. * data/shaders/sprite-fragment.glsl: New shader. * data/shaders/sprite-vertex.glsl: New shader. --- data/shaders/sprite-fragment.glsl | 8 ++++++++ data/shaders/sprite-vertex.glsl | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 data/shaders/sprite-fragment.glsl create mode 100644 data/shaders/sprite-vertex.glsl (limited to 'data/shaders') diff --git a/data/shaders/sprite-fragment.glsl b/data/shaders/sprite-fragment.glsl new file mode 100644 index 0000000..3dd10f1 --- /dev/null +++ b/data/shaders/sprite-fragment.glsl @@ -0,0 +1,8 @@ +#version 120 + +uniform sampler2D color_texture; +uniform vec4 color; + +void main (void) { + gl_FragColor = texture2D(color_texture, gl_TexCoord[0].st) * color; +} diff --git a/data/shaders/sprite-vertex.glsl b/data/shaders/sprite-vertex.glsl new file mode 100644 index 0000000..d6efd3f --- /dev/null +++ b/data/shaders/sprite-vertex.glsl @@ -0,0 +1,26 @@ +#version 120 + +uniform mat4 projection; +uniform vec2 position; +uniform vec2 anchor; +uniform vec2 scale; +uniform float rotation; + +void main(void) { + mat4 rotationMatrix = mat4(cos(rotation), -sin(rotation), 0.0, 0.0, + sin(rotation), cos(rotation), 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0); + mat4 translationMatrix = mat4(1.0, 0.0, 0.0, position.x - anchor.x, + 0.0, 1.0, 0.0, position.y - anchor.y, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0); + mat4 scaleMatrix = mat4(scale.x, 0.0, 0.0, 0.0, + 0.0, scale.y, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0); + + gl_Position = projection * (gl_Vertex * scaleMatrix * + rotationMatrix * translationMatrix); + gl_TexCoord[0] = gl_MultiTexCoord0; +} -- cgit v1.2.3