diff --git a/examples_proto/README-c00.md b/examples_proto/README-c00.md new file mode 100644 index 0000000..9fc6307 --- /dev/null +++ b/examples_proto/README-c00.md @@ -0,0 +1,18 @@ +# Gallery - Getting started + +## Examples + +Some blurb about what the chapter is about. Bacon ipsum dolor amet ham hock tongue picanha pancetta kevin sausage. Meatloaf biltong cupim pork loin ham turducken shoulder t-bone bacon capicola pancetta pork kielbasa. Meatball kevin bresaola beef ribs, meatloaf ribeye drumstick turkey. Cow pig ham picanha corned beef leberkas filet mignon landjaeger ribeye pork capicola short ribs doner. + +Read [getting started](../00/) + +
+ + + +## Shared Shaders + +Let's look at what your fellow learners are doing. Bellow are the shaders shared for this chapter by the readers of this book. + +
+ diff --git a/examples_proto/README-c05.md b/examples_proto/README-c05.md new file mode 100644 index 0000000..55183d6 --- /dev/null +++ b/examples_proto/README-c05.md @@ -0,0 +1,18 @@ +# Gallery - Shaping functions + +## Examples + +Some blurb about what the chapter is about. Bacon ipsum dolor amet ham hock tongue picanha pancetta kevin sausage. Meatloaf biltong cupim pork loin ham turducken shoulder t-bone bacon capicola pancetta pork kielbasa. Meatball kevin bresaola beef ribs, meatloaf ribeye drumstick turkey. Cow pig ham picanha corned beef leberkas filet mignon landjaeger ribeye pork capicola short ribs doner. + +Read [Shaping funcions](../05/) + +
+ + + +## Shared Shaders + +Let's look at what your fellow learners are doing. Bellow are the shaders shared for this chapter by the readers of this book. + +
+ diff --git a/examples_proto/README-shared.md b/examples_proto/README-shared.md new file mode 100644 index 0000000..84d4769 --- /dev/null +++ b/examples_proto/README-shared.md @@ -0,0 +1,7 @@ +# Gallery - All Shared Shaders + +## Shared shaders +Let's look at what your fellow learners are doing. This page features all the shaders shared by the readers of this book. + +
+ diff --git a/examples_proto/README.md b/examples_proto/README.md new file mode 100644 index 0000000..35957b3 --- /dev/null +++ b/examples_proto/README.md @@ -0,0 +1,42 @@ +# Shader Gallery + +The following is a list of examples present in this book more from our excellent contributers and readers. + +## Featured shaders + + +Featured examples from the shaders shared by our readers. + +
+ +
See All Shared Shaders
+ + +## Getting started +### "Hello World!" + + +Some blurb about what the chapter is about. Bacon ipsum dolor amet ham hock tongue picanha pancetta kevin sausage. Meatloaf biltong cupim pork loin ham turducken shoulder t-bone bacon capicola pancetta pork kielbasa. Meatball kevin bresaola beef ribs, meatloaf ribeye drumstick turkey. Cow pig ham picanha corned beef leberkas filet mignon landjaeger ribeye pork capicola short ribs doner. + +
+ + + +### Uniforms +
+ +Some blurb about what the chapter is about. Bacon ipsum dolor amet ham hock tongue picanha pancetta kevin sausage. Meatloaf biltong cupim pork loin ham turducken shoulder t-bone bacon capicola pancetta pork kielbasa. Meatball kevin bresaola beef ribs, meatloaf ribeye drumstick turkey. Cow pig ham picanha corned beef leberkas filet mignon landjaeger ribeye pork capicola short ribs doner. + +
+ + +## Algorithmic drawing +### Shaping functions + +
+ +Some blurb about what the chapter is about. Bacon ipsum dolor amet ham hock tongue picanha pancetta kevin sausage. Meatloaf biltong cupim pork loin ham turducken shoulder t-bone bacon capicola pancetta pork kielbasa. Meatball kevin bresaola beef ribs, meatloaf ribeye drumstick turkey. Cow pig ham picanha corned beef leberkas filet mignon landjaeger ribeye pork capicola short ribs doner. + +
+ +
See All Examples
diff --git a/examples_proto/c05.php b/examples_proto/c05.php new file mode 100644 index 0000000..f4a4fcb --- /dev/null +++ b/examples_proto/c05.php @@ -0,0 +1,24 @@ +

The Book of Shaders by Patricio Gonzalez Vivo

+
+ +
+ '; + + include("footer.php"); +?> diff --git a/examples_proto/css/gallery.css b/examples_proto/css/gallery.css new file mode 100644 index 0000000..a815b1d --- /dev/null +++ b/examples_proto/css/gallery.css @@ -0,0 +1,36 @@ +div.gallery { +} + +div.gallery ul, div.gallery ul { + list-style: none; + padding:0; + margin: 0; +} + +div.gallery li { + display: inline-block; + margin-bottom: 24px; + margin-left: 8px; + margin-right: 16px; +} + +div.gallery .imgcontainer { + width: 242px; +} +div.gallery .imgcontainer img { + width: 240px; + border: solid 1px #ccc; +} + +div.gallery h2 { + line-height: 64px; + border-bottom: solid 1px #9a9a9a; + margin-bottom: 24px; +} + +div.gallery h3 { + margin-top: 64px; +} +div.gallery div.extra-container { + text-align: right; +} diff --git a/examples_proto/footer.php b/examples_proto/footer.php new file mode 100644 index 0000000..9ad324d --- /dev/null +++ b/examples_proto/footer.php @@ -0,0 +1,18 @@ + +

Copyright 2015 Patricio Gonzalez Vivo

+ + + + + + '; +?> diff --git a/examples_proto/header.php b/examples_proto/header.php new file mode 100644 index 0000000..649ccfc --- /dev/null +++ b/examples_proto/header.php @@ -0,0 +1,52 @@ + + + + + The Book of Shaders'.$subtitle.' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +'; + +if ( $language !== '' && file_exists($path.'/css/style'.$language.'.css') ) { + echo ''; + } + +echo ' + + + '; +?> diff --git a/examples_proto/images/moon-texture.jpg b/examples_proto/images/moon-texture.jpg new file mode 100644 index 0000000..a1f70c2 Binary files /dev/null and b/examples_proto/images/moon-texture.jpg differ diff --git a/examples_proto/images/preview.png b/examples_proto/images/preview.png new file mode 100644 index 0000000..0d4a45c Binary files /dev/null and b/examples_proto/images/preview.png differ diff --git a/examples_proto/images/preview0.png b/examples_proto/images/preview0.png new file mode 100644 index 0000000..bb55e84 Binary files /dev/null and b/examples_proto/images/preview0.png differ diff --git a/examples_proto/images/preview1.png b/examples_proto/images/preview1.png new file mode 100644 index 0000000..8d5a402 Binary files /dev/null and b/examples_proto/images/preview1.png differ diff --git a/examples_proto/images/preview2.png b/examples_proto/images/preview2.png new file mode 100644 index 0000000..5b44518 Binary files /dev/null and b/examples_proto/images/preview2.png differ diff --git a/examples_proto/index.php b/examples_proto/index.php new file mode 100644 index 0000000..8780a3d --- /dev/null +++ b/examples_proto/index.php @@ -0,0 +1,24 @@ +

The Book of Shaders by Patricio Gonzalez Vivo

+
+ +
+ '; + + include("footer.php"); +?> diff --git a/examples_proto/moon.frag b/examples_proto/moon.frag new file mode 100644 index 0000000..4943a82 --- /dev/null +++ b/examples_proto/moon.frag @@ -0,0 +1,77 @@ +// Author @patriciogv - 2015 +// http://patriciogonzalezvivo.com + +#ifdef GL_ES +precision mediump float; +#endif + +#define PI 3.1415926535 +#define HALF_PI 1.57079632679 + +uniform vec2 u_resolution; +uniform float u_time; + +uniform sampler2D u_tex0; +uniform vec2 u_tex0Resolution; + +float speedMoon = 0.01; +float speedSun = 0.25; + +vec3 sphereNormals(in vec2 uv) { + uv = fract(uv)*2.0-1.0; + vec3 ret; + ret.xy = sqrt(uv * uv) * sign(uv); + ret.z = sqrt(abs(1.0 - dot(ret.xy,ret.xy))); + ret = ret * 0.5 + 0.5; + return mix(vec3(0.0), ret, smoothstep(1.0,0.98,dot(uv,uv)) ); +} + +vec2 sphereCoords(vec2 _st, float _scale){ + float maxFactor = sin(1.570796327); + vec2 uv = vec2(0.0); + vec2 xy = 2.0 * _st.xy - 1.0; + float d = length(xy); + if (d < (2.0-maxFactor)){ + d = length(xy * maxFactor); + float z = sqrt(1.0 - d * d); + float r = atan(d, z) / 3.1415926535 * _scale; + float phi = atan(xy.y, xy.x); + + uv.x = r * cos(phi) + 0.5; + uv.y = r * sin(phi) + 0.5; + } else { + uv = _st.xy; + } + return uv; +} + +vec4 sphereTexture(in sampler2D _tex, in vec2 _uv) { + vec2 st = sphereCoords(_uv, 1.0); + + float aspect = u_tex0Resolution.y/u_tex0Resolution.x; + st.x = fract(st.x*aspect + u_time*speedMoon); + + return texture2D(_tex, st); +} + +void main(){ + vec2 st = gl_FragCoord.xy/u_resolution.xy; + vec3 color = vec3(1.0); + + color *= sphereTexture(u_tex0, st).rgb; + + // Calculate sun direction + vec3 sunPos = normalize(vec3(cos(u_time*speedSun-HALF_PI),0.0,sin(speedSun*u_time-HALF_PI))); + vec3 surface = normalize(sphereNormals(st)*2.0-1.0); + + // Add Shadows + color *= dot(sunPos,surface); + + // Blend black the edge of the sphere + float radius = 1.0-length( vec2(0.5)-st )*2.0; + color *= smoothstep(0.001,0.05,radius); + + color = 1.0-color; + + gl_FragColor = vec4(color,1.0); +} \ No newline at end of file diff --git a/examples_proto/shared.php b/examples_proto/shared.php new file mode 100644 index 0000000..42be9ab --- /dev/null +++ b/examples_proto/shared.php @@ -0,0 +1,24 @@ +

The Book of Shaders by Patricio Gonzalez Vivo

+
+ +
+ '; + + include("footer.php"); +?> diff --git a/examples_proto/src/gallery.php b/examples_proto/src/gallery.php new file mode 100644 index 0000000..cf4de52 --- /dev/null +++ b/examples_proto/src/gallery.php @@ -0,0 +1,39 @@ +var examples = {}; + + + + +var gallery = function() { + function createLi(d) { + var li = $("
  • "); + var a = $("").attr("href", d.url); + var container = $("
    ").attr("class", "imgcontainer") + .append($("").attr({"src": d.src, "alt": d.caption})) + .append($("
    ").attr("class", "caption").text(d.caption)); + li.append(a); + a.append(container); + return li; + } + + function createUl(list, length) { + var ul = $("
      "); + for (var i = 0; i < length && i < list.length; i ++) { + ul.append(createLi(list[i])); + } + return ul; + } + + return { + createExampleList: function(id, length) { + if (!length) {length = examples[id].length;} + var div = $("#" + id + "-examples"); + div.append(createUl(examples[id], length)); + } + } +}(); diff --git a/examples_proto/src/gallery_c02.php b/examples_proto/src/gallery_c02.php new file mode 100644 index 0000000..667adec --- /dev/null +++ b/examples_proto/src/gallery_c02.php @@ -0,0 +1,18 @@ + diff --git a/examples_proto/src/gallery_c03.php b/examples_proto/src/gallery_c03.php new file mode 100644 index 0000000..6939f9b --- /dev/null +++ b/examples_proto/src/gallery_c03.php @@ -0,0 +1,19 @@ + diff --git a/examples_proto/src/gallery_c05.php b/examples_proto/src/gallery_c05.php new file mode 100644 index 0000000..ed14b22 --- /dev/null +++ b/examples_proto/src/gallery_c05.php @@ -0,0 +1,33 @@ +