Drift Shader
Introduction
DriftShader is responsible for rendering the background of maps.
- It is inspired by
ShaderToy, which usesGLSLas the shading language. BG.ShaderToy.glslis compiled to a shader and used to render the map and minimap background.- Browse https://www.shadertoy.com/ for documentation and examples.
Entry Function
- You are required to set the output variable
outSRGBto color you want the "pixel" to be. outSRGBis expected to be insRGB- I would prefer the output to be in
linear, but ShaderToy usessRGB-- and I want to maintain as much similarity as possible. - If you want to output in
linear, you need to set the option underBackgroundtab in the map editor.
- I would prefer the output to be in
- There are other settings in the
Backgroundtab such as rotation, speed, enable dither, etc..
Global Uniform Values
uniform vec3 iResolution; // resolution (sort-of)
uniform float iTime; // game-time (seconds)
uniform int iFrame; // not supported yet (always 0)
uniform vec3 iChannelResolution[4]; // iChannel# texture resolution
uniform vec4 iMouse; // not supported yet (vec4(0,0,0,0))
uniform sampler2D iChannel0; // can set via Background tab
uniform sampler2D iChannel1; // can be set via Background tab
uniform sampler2D iChannel2; // can be set via Background tab
uniform sampler2D iChannel3; // can be set via Background tab
Color Conversion Functions
float gx_linear_to_srgb(float linear)
float gx_srgb_to_linear(float srgb)
vec3 gx_linear_to_srgb(vec3 linear)
vec4 gx_linear_to_srgb(vec4 linear)
vec3 gx_srgb_to_linear(vec3 srgb)
vec4 gx_srgb_to_linear(vec4 srgb)
vec3 gx_hsv_to_srgb(vec3 hsv);
vec4 gx_hsv_to_srgb(vec4 hsva);
vec3 gx_srgb_to_hsv(vec3 srgb);
vec4 gx_srgb_to_hsv(vec4 srgba);
gx_get_bg_shader_val
- retrieves the shader value at slot
index - the initial shader values can be set under
Background -> Shader Valuesin the map editor - these values can be changed via
.DriftScriptusing thevoid gx_set_bg_shader_val(int index, float value)function.
gx_flip_uv
- Helper to convert between
ShaderToy (OpenGL)andDriftShader (vulkan)coordinate systems - (usually you don't need to use this, provided for convenience)
gx_flip_frag_coord
- Helper to convert between
ShaderToy (OpenGL)andDriftShader (vulkan)coordinate systems - (usually you don't need to use this, provided for convenience)
VSCode Extension
WebGL GLSL EditororGLSL Lintvscode extensions (or any, really..)- There is no
DriftShaderspecific extension yet
Warning!!
There are differences between DriftShader and ShaderToy!!
ShaderToy / WebGLauto-initializes variables to0!DriftShaderdoes not!!!- If you copy a
ShaderToyshader and it is not working (or crashing), VERIFY all variables are manually initialized to0!
- If you copy a
ShaderToy (OpenGL)andDriftShader (vulkan)use different coordinate systems!- If you copy a
ShaderToyshader toDriftShader, it may render upside-down! - May need to use
gx_flip_uvandgx_flip_frag_coord.
- If you copy a
DriftShaderdoes not support all ofShaderToyinputs and features.