There's a few more cleanups you could do if you wanted, but either way: Reviewed-by: Dylan Baker <baker.dyla...@gmail.com>
On Thu, Jul 09, 2015 at 10:41:05AM -0400, Rob Clark wrote: > 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) You're generating the same value twice, maybe store it? > + j = r.json() you could drop the j variable: r = requests.get(url + '/' + id + key).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'])) Probably, you should either uncomment, delete these, or put them behind some kind of guard. > + 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 >
signature.asc
Description: Digital signature
_______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev