From b3a4d66171291795f4f31386123f05b42a8809c7 Mon Sep 17 00:00:00 2001 From: Patricio Gonzalez Vivo Date: Tue, 14 Jul 2015 17:00:06 -0400 Subject: [PATCH] fixing random stuff --- 09/iching-01.frag | 31 +++++++++++++------------- README.md | 6 ++++-- edit.html | 9 ++++---- src/codemirror/mode/clike.js | 42 +++++------------------------------- 4 files changed, 30 insertions(+), 58 deletions(-) diff --git a/09/iching-01.frag b/09/iching-01.frag index d05cca4..2c16d66 100644 --- a/09/iching-01.frag +++ b/09/iching-01.frag @@ -10,15 +10,15 @@ precision mediump float; uniform vec2 u_resolution; uniform float u_time; -float shape(vec2 st, int N){ +float shape(vec2 st, float N){ st = st*2.-1.; float a = atan(st.x,st.y)+PI; - float r = TWO_PI/float(N); - return cos(floor(.5+a/r)*r-a)*length(st); + float r = TWO_PI/N; + return abs(cos(floor(.5+a/r)*r-a)*length(st)); } float box(vec2 st, vec2 size){ - return shape(st*size,4); + return shape(st*size,4.); } float rect(vec2 _st, vec2 _size){ @@ -28,7 +28,7 @@ float rect(vec2 _st, vec2 _size){ return uv.x*uv.y; } -float hex(vec2 st, bool a, bool b, bool c, bool d, bool e, bool f){ +float hex(vec2 st, float a, float b, float c, float d, float e, float f){ st = st*vec2(2.,6.); vec2 fpos = fract(st); @@ -36,33 +36,34 @@ float hex(vec2 st, bool a, bool b, bool c, bool d, bool e, bool f){ if (ipos.x == 1.0) fpos.x = 1.-fpos.x; if (ipos.y < 1.0){ - return a? box(fpos-vec2(0.03,0.), vec2(1.)) : box(fpos, vec2(0.84,1.)); + return mix(box(fpos, vec2(0.84,1.)),box(fpos-vec2(0.03,0.),vec2(1.)),a); } else if (ipos.y < 2.0){ - return b? box(fpos-vec2(0.03,0.), vec2(1.)) : box(fpos, vec2(0.84,1.)); + return mix(box(fpos, vec2(0.84,1.)),box(fpos-vec2(0.03,0.),vec2(1.)),b); } else if (ipos.y < 3.0){ - return c? box(fpos-vec2(0.03,0.), vec2(1.)) : box(fpos, vec2(0.84,1.)); + return mix(box(fpos, vec2(0.84,1.)),box(fpos-vec2(0.03,0.),vec2(1.)),c); } else if (ipos.y < 4.0){ - return d? box(fpos-vec2(0.03,0.), vec2(1.)) : box(fpos, vec2(0.84,1.)); + return mix(box(fpos, vec2(0.84,1.)),box(fpos-vec2(0.03,0.),vec2(1.)),d); } else if (ipos.y < 5.0){ - return e? box(fpos-vec2(0.03,0.), vec2(1.)) : box(fpos, vec2(0.84,1.)); + return mix(box(fpos, vec2(0.84,1.)),box(fpos-vec2(0.03,0.),vec2(1.)),e); } else if (ipos.y < 6.0){ - return f? box(fpos-vec2(0.03,0.), vec2(1.)) : box(fpos, vec2(0.84,1.)); + return mix(box(fpos, vec2(0.84,1.)),box(fpos-vec2(0.03,0.),vec2(1.)),f); } return 0.0; } float hex(vec2 st, float N){ - bool b[6]; + float b[6]; float remain = floor(mod(N,64.)); for(int i = 0; i < 6; i++){ - b[i] = mod(remain,2.)==1.?true:false; + b[i] = 0.0; + b[i] = step(1.0,mod(remain,2.)); remain = ceil(remain/2.); } return hex(st,b[0],b[1],b[2],b[3],b[4],b[5]); } void main(){ - vec2 st = gl_FragCoord.xy/u_resolution.xy; + vec2 st = gl_FragCoord.xy/u_resolution.xy; st.y *= u_resolution.y/u_resolution.x; st *= 10.0; @@ -73,5 +74,5 @@ void main(){ float df = 1.0; df = hex(fpos,ipos.x+ipos.y+t)+(1.0-rect(fpos,vec2(0.7))); - gl_FragColor += vec4(mix(vec3(0.),vec3(1.),step(0.7,df)),1.0); + gl_FragColor += vec4(mix(vec3(0.),vec3(1.),step(0.7,df)),1.0); } \ No newline at end of file diff --git a/README.md b/README.md index 817619e..f1545db 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ This is a gentle step-by-step guide through the abstract and complex universe of Patricio studied and practiced psychotherapy and expressive art therapy. He holds an MFA in Design & Technology from Parsons The New School, where he now teaches. Currently he works as a Graphic Engineer at Mapzen making openSource mapping tools. -

Twitter - GitHub - Vimeo - Flickr +

Twitter - GitHub - Vimeo - Flickr
## Acknowledgements @@ -82,6 +82,8 @@ Thanks [Karim Naaji](http://karim.naaji.fr/) for contributing with support, good Thanks to everyone who has believed in this project and contributed with fixes or donations. -## Subscribe for new chapters +## Get new chapters + +Sign up for the news letter or [follow it on Twitter](https://twitter.com/bookofshaders)

diff --git a/edit.html b/edit.html index 0f2f360..884da50 100644 --- a/edit.html +++ b/edit.html @@ -203,15 +203,16 @@ void main(){\n\ } } + window.onload = function () { + loadTag(); + render(); + }; + function render() { billboard.setMouse(mouse) billboard.render() window.requestAnimFrame(render); } - window.onload = function () { - loadTag(); - render(); - }; diff --git a/src/codemirror/mode/clike.js b/src/codemirror/mode/clike.js index b04b22b..b7fc599 100644 --- a/src/codemirror/mode/clike.js +++ b/src/codemirror/mode/clike.js @@ -407,8 +407,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) { keywords: words("float int bool void " + "vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 " + "mat2 mat3 mat4 " + - "sampler1D sampler2D sampler3D samplerCube " + - "sampler1DShadow sampler2DShadow " + + "sampler2D samplerCube " + "const attribute uniform varying " + "break continue discard return " + "for while do if else struct " + @@ -417,45 +416,14 @@ CodeMirror.defineMode("clike", function(config, parserConfig) { builtin: words("radians degrees sin cos tan asin acos atan " + "pow exp log exp2 sqrt inversesqrt " + "abs sign floor ceil fract mod min max clamp mix step smoothstep " + - "length distance dot cross normalize ftransform faceforward " + + "length distance dot cross normalize faceforward " + "reflect refract matrixCompMult " + "lessThan lessThanEqual greaterThan greaterThanEqual " + "equal notEqual any all not " + - "texture1D texture1DProj texture1DLod texture1DProjLod " + - "texture2D texture2DProj texture2DLod texture2DProjLod " + - "texture3D texture3DProj texture3DLod texture3DProjLod " + - "textureCube textureCubeLod " + - "shadow1D shadow2D shadow1DProj shadow2DProj " + - "shadow1DLod shadow2DLod shadow1DProjLod shadow2DProjLod " + - "dFdx dFdy fwidth " + - "noise1 noise2 noise3 noise4"), + "texture2D textureCube"), atoms: words("true false " + - "gl_FragColor gl_SecondaryColor gl_Normal gl_Vertex " + - "gl_MultiTexCoord0 gl_MultiTexCoord1 gl_MultiTexCoord2 gl_MultiTexCoord3 " + - "gl_MultiTexCoord4 gl_MultiTexCoord5 gl_MultiTexCoord6 gl_MultiTexCoord7 " + - "gl_FogCoord gl_PointCoord " + - "gl_Position gl_PointSize gl_ClipVertex " + - "gl_FrontColor gl_BackColor gl_FrontSecondaryColor gl_BackSecondaryColor " + - "gl_TexCoord gl_FogFragCoord " + - "gl_FragCoord gl_FrontFacing " + - "gl_FragData gl_FragDepth " + - "gl_ModelViewMatrix gl_ProjectionMatrix gl_ModelViewProjectionMatrix " + - "gl_TextureMatrix gl_NormalMatrix gl_ModelViewMatrixInverse " + - "gl_ProjectionMatrixInverse gl_ModelViewProjectionMatrixInverse " + - "gl_TexureMatrixTranspose gl_ModelViewMatrixInverseTranspose " + - "gl_ProjectionMatrixInverseTranspose " + - "gl_ModelViewProjectionMatrixInverseTranspose " + - "gl_TextureMatrixInverseTranspose " + - "gl_NormalScale gl_DepthRange gl_ClipPlane " + - "gl_Point gl_FrontMaterial gl_BackMaterial gl_LightSource gl_LightModel " + - "gl_FrontLightModelProduct gl_BackLightModelProduct " + - "gl_TextureColor gl_EyePlaneS gl_EyePlaneT gl_EyePlaneR gl_EyePlaneQ " + - "gl_FogParameters " + - "gl_MaxLights gl_MaxClipPlanes gl_MaxTextureUnits gl_MaxTextureCoords " + - "gl_MaxVertexAttribs gl_MaxVertexUniformComponents gl_MaxVaryingFloats " + - "gl_MaxVertexTextureImageUnits gl_MaxTextureImageUnits " + - "gl_MaxFragmentUniformComponents gl_MaxCombineTextureImageUnits " + - "gl_MaxDrawBuffers"), + "u_time u_resolution u_mouse " + + "gl_FragColor gl_Position gl_PointSize gl_FragCoord "), hooks: {"#": cppHook}, modeProps: {fold: ["brace", "include"]} });