Default
This is a Shadertoy example. Because of the way this docs are built, its housed in a minimal Indigo project for built purposes, but the shader code isn't run because it's incompatible with Indigo, so all you get is a black screen.
This example is the default shader you are given when you make a new shadertoy project.
The GLSL Output
This is the shadertoy compatible GLSL code that Ultraviolet manufactures:
void mainImage(out vec4 fragColor,in vec2 fragCoord){
vec2 uv=fragCoord/iResolution.xy;
vec3 col=0.5+(0.5*(cos((iTime+uv.xyx)+vec3(0.0,2.0,4.0))));
fragColor=vec4(col,1.0);
}
Example Links
Ultraviolet Shadertoy code
Reminder: The live demo will not work, below is the Shadertoy compatible code.
Note the custom ShaderToyEnv
that is passed to the shader. This is a custom environment that
contains read-only information like the running time, mouse position, resolution, which are
supplied by shadertoy.
object ShaderToyExample:
inline def image =
Shader[ShaderToyEnv, Unit] { env =>
def mainImage(fragColor: vec4, fragCoord: vec2): vec4 = {
// Normalized pixel coordinates (from 0 to 1)
val uv: vec2 = fragCoord / env.iResolution.xy
// Time varying pixel color
val col: vec3 = 0.5f + 0.5f * cos(env.iTime + uv.xyx + vec3(0.0f, 2.0f, 4.0f))
// Output to screen
vec4(col, 1.0f)
}
}
Then to get the code as a String so that we might print it or output it to a file or whatever, we can do the following:
object Output:
val imageCode: String =
ShaderToyExample.image.toGLSL[ShaderToy].toOutput.code