aboutsummaryrefslogtreecommitdiff
path: root/game/src/Game/GameSession/billboard.gdshader
diff options
context:
space:
mode:
Diffstat (limited to 'game/src/Game/GameSession/billboard.gdshader')
-rw-r--r--game/src/Game/GameSession/billboard.gdshader33
1 files changed, 33 insertions, 0 deletions
diff --git a/game/src/Game/GameSession/billboard.gdshader b/game/src/Game/GameSession/billboard.gdshader
new file mode 100644
index 0000000..e207ff9
--- /dev/null
+++ b/game/src/Game/GameSession/billboard.gdshader
@@ -0,0 +1,33 @@
+shader_type spatial;
+//render_mode unshaded;
+
+uniform sampler2D billboards[255];
+uniform int numframes[255];
+uniform float sizes[255];
+
+//COLOR/INSTANCE_CUSTOM is our custom data, used as follows:
+// x=image index
+// y=frame in image index
+// z=visible (0 = invisible, 1 = visible)
+
+void vertex() {
+ COLOR = INSTANCE_CUSTOM; //send instance_custom info to fragment
+ float size = sizes[int(COLOR.x)];
+
+ vec3 cam_right_worldspace = vec3(VIEW_MATRIX[0][0],VIEW_MATRIX[1][0],VIEW_MATRIX[2][0]);
+ vec3 cam_up_worldspace = vec3(VIEW_MATRIX[0][1],VIEW_MATRIX[1][1],VIEW_MATRIX[2][1]);
+ vec3 vert_pos_world =
+ cam_right_worldspace * VERTEX.x * size +
+ cam_up_worldspace * VERTEX.y * size;
+ VERTEX = vert_pos_world;
+}
+
+void fragment() {
+ int image_index = int(COLOR.x);
+ float frame_index = COLOR.y;
+
+ float uv_x_space = 1.0/float(numframes[image_index]);
+ vec2 uv_out = vec2(uv_x_space * (frame_index + UV.x),UV.y);
+ ALBEDO.rgb = texture( billboards[image_index] ,uv_out).rgb;
+ ALPHA = texture(billboards[image_index] ,uv_out).a * COLOR.z;
+}