summaryrefslogtreecommitdiffhomepage
path: root/examples/shaders/shaders_palette_switch.data
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2021-10-17 21:02:18 +0200
committerraysan5 <[email protected]>2021-10-17 21:02:18 +0200
commit35e67da08e3d214589968c19b4b2fb31d8e566cc (patch)
tree5054bcea5f6df754f467590101789b17dd9d9944 /examples/shaders/shaders_palette_switch.data
parentb2228039039afc05c41edd12103123f2a36c8080 (diff)
downloadraylib.com-35e67da08e3d214589968c19b4b2fb31d8e566cc.tar.gz
raylib.com-35e67da08e3d214589968c19b4b2fb31d8e566cc.zip
UPDATED: examples to raylib 4.0
Some new examples added
Diffstat (limited to 'examples/shaders/shaders_palette_switch.data')
-rw-r--r--examples/shaders/shaders_palette_switch.data41
1 files changed, 41 insertions, 0 deletions
diff --git a/examples/shaders/shaders_palette_switch.data b/examples/shaders/shaders_palette_switch.data
new file mode 100644
index 0000000..e5b038d
--- /dev/null
+++ b/examples/shaders/shaders_palette_switch.data
@@ -0,0 +1,41 @@
+#version 100
+
+precision mediump float;
+
+const int colors = 8;
+
+// Input vertex attributes (from vertex shader)
+varying vec2 fragTexCoord;
+varying vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform ivec3 palette[colors];
+
+void main()
+{
+ // Texel color fetching from texture sampler
+ vec4 texelColor = texture2D(texture0, fragTexCoord)*fragColor;
+
+ // Convert the (normalized) texel color RED component (GB would work, too)
+ // to the palette index by scaling up from [0, 1] to [0, 255].
+ int index = int(texelColor.r*255.0);
+
+ ivec3 color = ivec3(0);
+
+ // NOTE: On GLSL 100 we are not allowed to index a uniform array by a variable value,
+ // a constantmust be used, so this logic...
+ if (index == 0) color = palette[0];
+ else if (index == 1) color = palette[1];
+ else if (index == 2) color = palette[2];
+ else if (index == 3) color = palette[3];
+ else if (index == 4) color = palette[4];
+ else if (index == 5) color = palette[5];
+ else if (index == 6) color = palette[6];
+ else if (index == 7) color = palette[7];
+
+ // Calculate final fragment color. Note that the palette color components
+ // are defined in the range [0, 255] and need to be normalized to [0, 1]
+ // for OpenGL to work.
+ gl_FragColor = vec4(float(color.x)/255.0, float(color.y)/255.0, float(color.z)/255.0, texelColor.a);
+}