Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Shadertoy shaders to be used #6

Open
llewelld opened this issue Mar 21, 2015 · 3 comments
Open

Allow Shadertoy shaders to be used #6

llewelld opened this issue Mar 21, 2015 · 3 comments

Comments

@llewelld
Copy link
Owner

Test out whether shaders uploaded to shadertoy.com can be used. If not, figure out a way that they can be transferred over easily.

https://www.shadertoy.com

@llewelld
Copy link
Owner Author

It turns out, for many of the shaders, the transfer if pretty straightforward.

Here's an example of a rather excellent shader by Inigo Quilez:

http://www.flypig.co.uk/shaders/test.html?shader=shadertoy-iq.txt

using the original code from Shadertoy.com: https://www.shadertoy.com/view/Xds3zN

The change just involved adding some conversion variables at the top:

varying vec2 vTextureCoord;
uniform highp float time;
uniform float width;
uniform float height;
vec3 iResolution;
float iGlobalTime;
vec2 iMouse;

and a wrapper function to perform the conversions at the bottom:

void main () {
    vec4 fragColor;
    vec2 fragCoord = vTextureCoord * vec2(width, height);
    iResolution = vec3 (width, height, width / height);
    iGlobalTime = time / 1000.0;
    iMouse = vec2(0.0, 0.0);

    mainImage(fragColor, fragCoord);

    gl_FragColor = fragColor;
    gl_FragColor.a = 1.0;
}

This could be integrated directly into shaderback.js with a helper function.

@llewelld
Copy link
Owner Author

Shadertoy has an API that could be used: https://www.shadertoy.com/api

@llewelld
Copy link
Owner Author

As of version 0.03, commit 5c21c80, the Time, vTextureCoord, width and height inputs have now been refactored to iGlobalTime, fragCoord and iResolution. These now match the Shadertoy inputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant