CrossGL Language
CrossGL is a unified, cross-platform shader language that simplifies graphics development across APIs like Vulkan, DirectX, and Metal. It allows developers to write once and compile to native shader languages, ensuring optimal performance and compatibility 🚀.
<div class="large-text">Syntax Overview</div>
<div class="large-text">Basic Structure</div>
shader main {
input vec3 position;
output vec4 color;
void vertex main() {
gl_Position = vec4(position, 1.0);
}
void fragment main() {
color = vec4(position, 1.0);
}
}
<div class="large-text">Data Types</div>
CrossGL GLSL HLSL Metal
[vec2]{.title-ref} [vec2]{.title-ref} [float2]{.title-ref} [float2]{.title-ref} [vec3]{.title-ref} [vec3]{.title-ref} [float3]{.title-ref} [float3]{.title-ref} [vec4]{.title-ref} [vec4]{.title-ref} [float4]{.title-ref} [float4]{.title-ref} [mat4]{.title-ref} [mat4]{.title-ref} [float4x4]{.title-ref} [float4x4]{.title-ref}
<div class="large-text">Functions and Operations</div>
float3 customFunction(float3 random, float factor) {
return random * factor;
}
void main() {
float3 color = vec3(0.0, 0.0, 0.0);
float factor = 1.0;
if (texCoord.x > 0.5) {
color = vec3(1.0, 0.0, 0.0);
} else {
color = vec3(0.0, 1.0, 0.0);
}
for (int i = 0; i < 3; i++) {
factor = factor * 0.5;
color = customFunction(color, factor);
}
if (length(color) > 1.0) {
color = normalize(color);
}
fragColor = vec4(color, 1.0);
}