Skip to content

Instantly share code, notes, and snippets.

@Vipitis
Created November 3, 2023 23:50
Show Gist options
  • Save Vipitis/e4b25bfe6e3acb8081dc1469a0e69b38 to your computer and use it in GitHub Desktop.
Save Vipitis/e4b25bfe6e3acb8081dc1469a0e69b38 to your computer and use it in GitHub Desktop.
wgpu panic: Semantic error due to switch/case with const
#version 450 core
vec3 i_resolution;
vec4 i_mouse;
float i_time;
float i_time_delta;
int i_frame;
// Shadertoy compatibility, see we can use the same code copied from shadertoy website
#define iTime i_time
#define iResolution i_resolution
#define iTimeDelta i_time_delta
#define iMouse i_mouse
#define iFrame i_frame
#define mainImage shader_main
// 1. declare constant integers
const int ID_left = 0;
const int ID_right = 1;
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = 2.0 * fragCoord/iResolution.xy;
int side = int(uv.x);
vec3 col = vec3(0.2);
// 2. switch case on an int
switch(side)
{
// 3. use those constants
case ID_left:
{
col *= 4.0;
}
case ID_right:
{
col *= 2.0;
}
}
fragColor = vec4(col,1.0);
}
layout(location = 0) in vec2 uv;
struct ShadertoyInput {
vec4 mouse;
vec3 resolution;
float time;
float time_delta;
int frame;
};
layout(binding = 0) uniform ShadertoyInput input;
out vec4 FragColor;
void main(){
i_time = input.time;
i_resolution = input.resolution;
i_time_delta = input.time_delta;
i_mouse = input.mouse;
i_frame = input.frame;
vec2 uv = vec2(uv.x, 1.0 - uv.y);
vec2 frag_coord = uv * i_resolution.xy;
shader_main(FragColor, frag_coord);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment