]> git.tdb.fi Git - libs/gl.git/blobdiff - tests/glsl/ternary_operator.glsl
Implement the ternary operator in GLSL
[libs/gl.git] / tests / glsl / ternary_operator.glsl
diff --git a/tests/glsl/ternary_operator.glsl b/tests/glsl/ternary_operator.glsl
new file mode 100644 (file)
index 0000000..1a1a098
--- /dev/null
@@ -0,0 +1,56 @@
+uniform Colors
+{
+       vec4 color1;
+       vec4 color2;
+};
+uniform sampler2D mask;
+uniform Transform
+{
+       mat4 mvp;
+} transform;
+
+#pragma MSP stage(vertex)
+layout(location=0) in vec4 position;
+layout(location=1) in vec2 texcoord;
+void main()
+{
+       passthrough;
+       gl_Position = transform.mvp*position;
+}
+
+#pragma MSP stage(fragment)
+layout(location=0) out vec4 frag_color;
+void main()
+{
+       frag_color = texture(mask, texcoord).r > 0.5 ? color1 : color2;
+}
+
+/* Expected output: vertex
+uniform Transform
+{
+  mat4 mvp;
+} transform;
+layout(location=0) in vec4 position;
+layout(location=1) in vec2 texcoord;
+out vec2 _vs_out_texcoord;
+void main()
+{
+  _vs_out_texcoord = texcoord;
+  gl_Position = transform.mvp*position;
+}
+*/
+
+/* Expected output: fragment
+uniform Colors
+{
+  vec4 color1;
+  vec4 color2;
+};
+uniform sampler2D mask;
+layout(location=0) out vec4 frag_color;
+in vec2 _vs_out_texcoord;
+void main()
+{
+  frag_color = texture(mask, _vs_out_texcoord).r>0.5?color1:color2;
+}
+*/