Skip to content

Shaders

HackDev edited this page Aug 1, 2024 · 4 revisions

Convert Shadertoy To GLSL Shader

Here's some info about GLSL Shaders.

Initial Shadertoy Code.

Color Shifting Shader

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    float amp = 0.0125;
    vec2 uv = fragCoord/iResolution.xy;
    vec4 tex;
    tex.r = texture(iChannel0, vec2(uv.x-amp,uv.y)).r;
    tex.g = texture(iChannel0, uv).g;
    tex.b = texture(iChannel0, vec2(uv.x+amp,uv.y)).b;
    tex.a = texture(iChannel0, uv).a;
    fragColor = tex;
}
  1. Header:
    Add #pragma header at the first line of the shader.
#pragma header

void mainImage()
{

}
  1. Converting Variables:
    Add uniform float name; before the mainImage() function.
#pragma header

uniform float iTime;

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{

}
  1. FragCoord:
    If you see fragCoord/iResolution.xy, change that code to openfl_TextureCoordv
#pragma header

uniform float iTime;

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
   vec2 uv = openfl_TextureCoordv;
}
  1. Texture:
    The texture() should be texture2D()
texture2D()
  1. iChannel#:
    iChannel's are samplers (That displays images) If there is only iChannel0, or sampler, change them to bitmap. If there is more than one then use BitmapData.
texture2D(bitmap, x)
  1. End:
    Add this to the end of the shader
void main(out vec4 fragColor, in vec2 fragCoord)
{
	mainImage(gl_FragColor, gl_FragCoord);
}

Converted Code:

#pragma header

uniform float iTime;

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    float amp = 0.0125;
    vec2 uv = openfl_TextureCoordv;
    vec4 tex;
    tex.r = texture2D(bitmap, vec2(uv.x-amp,uv.y)).r;
    tex.g = texture2D(bitmap, uv).g;
    tex.b = texture2D(bitmap, vec2(uv.x+amp,uv.y)).b;
    tex.a = texture2D(bitmap, uv).a;
    fragColor = tex;
}

void main() {
    mainImage(gl_FragColor, gl_FragCoord);
}
Clone this wiki locally