Attached script grabs shaders from shadertoy, and dumps them out as .shader_test files which can be run through shader-db for compiler testing.
shadertoy only gives you a fragment shader (which works based on gl_FragCoord), so a generic vertex shader is used. And a blurb is inserted for the pre-defined uniforms and main() function (which just calls shadertoy mainImage() fxn). v2: updated w/ python suggestions from Dylan --- Note: we probably want to pick a couple shadertoy shaders and commit them (rather than pulling down *all* shadertoy shaders, which may change over time, etc). I can just pick a couple randomly unless anyone has some requests. Either way, seems useful to have the script in git in case anyone else wants to grab new/more shaders. grab-shadertoy.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 grab-shadertoy.py diff --git a/grab-shadertoy.py b/grab-shadertoy.py new file mode 100755 index 0000000..04db411 --- /dev/null +++ b/grab-shadertoy.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 + + +import os, requests, textwrap + +url = 'https://www.shadertoy.com/api/v1/shaders' +key = '?key=NdnKw7' + +header = textwrap.dedent("""\ + [require] + GLSL >= 1.30 + + [fragment shader] + #version 130 + uniform vec3 iResolution; + uniform float iGlobalTime; + uniform float iChannelTime[4]; + uniform vec4 iMouse; + uniform vec4 iDate; + uniform float iSampleRate; + uniform vec3 iChannelResolution[4]; + uniform sampler2D iChannel0; + uniform sampler2D iChannel1; + uniform sampler2D iChannel2; + uniform sampler2D iChannel3; + +""") + +footer = textwrap.dedent("""\ + + void main() { mainImage(gl_FragColor, gl_FragCoord.xy); } + + [vertex shader] + #version 130 + in vec2 position; + + void main() + { + gl_Position = vec4(position, 0.0, 1.0); + } +""") + +# Get the list of shaders +r = requests.get(url + key) +j = r.json() +print('Found {} shaders'.format(j['Shaders'])) + +shader_ids = j['Results'] +for id in shader_ids: + print('Fetching shader: {}'.format(id)) + print('url: {}/{}{}'.format(url, id, key)) + r = requests.get(url + '/' + id + key) + j = r.json() + s = j['Shader'] + info = s['info'] + print('Name: ' + info['name']) + print('Description: ' + info['description']) + if not os.path.exists('shaders/shadertoy'): + os.makedirs('shaders/shadertoy') + for i, p in enumerate(s['renderpass']): + #print('Inputs: {}'.format(p['inputs'])) + #print('Outputs: {}'.format(p['outputs'])) + with open('shaders/shadertoy/{}_{}.shader_test'.format(id, i), 'w') as fobj: + fobj.write(header) + fobj.write(p['code']) + fobj.write(footer) -- 2.4.3 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev