summaryrefslogtreecommitdiff
path: root/manuals/chickadee/Shaders.html
diff options
context:
space:
mode:
Diffstat (limited to 'manuals/chickadee/Shaders.html')
-rw-r--r--manuals/chickadee/Shaders.html176
1 files changed, 166 insertions, 10 deletions
diff --git a/manuals/chickadee/Shaders.html b/manuals/chickadee/Shaders.html
index 70173a4..9d3e555 100644
--- a/manuals/chickadee/Shaders.html
+++ b/manuals/chickadee/Shaders.html
@@ -1,6 +1,6 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
-<!-- Copyright (C) 2017 David Thompson davet@gnu.org
+<!-- Copyright (C) 2017, 2018, 2019 David Thompson davet@gnu.org
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
@@ -13,6 +13,8 @@ A copy of the license is also available from the Free Software
Foundation Web site at http://www.gnu.org/licenses/fdl.html.
+* Chickadee: (chickadee). Game programming toolkit for Guile.
+
The document was typeset with
http://www.texinfo.org/ (GNU Texinfo).
-->
@@ -30,8 +32,8 @@ http://www.texinfo.org/ (GNU Texinfo).
<link href="Index.html#Index" rel="index" title="Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Graphics.html#Graphics" rel="up" title="Graphics">
-<link href="Framebuffers.html#Framebuffers" rel="next" title="Framebuffers">
-<link href="Vertex-Arrays.html#Vertex-Arrays" rel="prev" title="Vertex Arrays">
+<link href="Scripting.html#Scripting" rel="next" title="Scripting">
+<link href="Buffers.html#Buffers" rel="prev" title="Buffers">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
@@ -90,18 +92,172 @@ ul.no-bullet {list-style: none}
<a name="Shaders"></a>
<div class="header">
<p>
-Next: <a href="Framebuffers.html#Framebuffers" accesskey="n" rel="next">Framebuffers</a>, Previous: <a href="Vertex-Arrays.html#Vertex-Arrays" accesskey="p" rel="prev">Vertex Arrays</a>, Up: <a href="Graphics.html#Graphics" accesskey="u" rel="up">Graphics</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
+Previous: <a href="Buffers.html#Buffers" accesskey="p" rel="prev">Buffers</a>, Up: <a href="Graphics.html#Graphics" accesskey="u" rel="up">Graphics</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Shaders-1"></a>
-<h4 class="subsection">2.3.9 Shaders</h4>
+<h4 class="subsection">2.3.12 Shaders</h4>
+
+<p>Shaders are programs that the GPU can evaluate that allow the
+programmer to completely customized the final output of a GPU draw
+call. The <code>(chickadee render shader)</code> module provides an API for
+building custom shaders.
+</p>
+<p>Shaders are written in the OpenGL Shading Language, or GLSL for short.
+Chickadee aspires to provide a domain specific language for writing
+shaders in Scheme, but we are not there yet.
+</p>
+<p>Shader programs consist of two components: A vertex shader and a
+fragment shader. A vertex shader receives vertex data (position
+coordinates, texture coordinates, normals, etc.) and transforms them
+as desired, whereas a fragment shader controls the color of each
+pixel.
+</p>
+<p>Sample vertex shader:
+</p>
+<div class="example">
+<pre class="verbatim">#version 130
+
+in vec2 position;
+in vec2 tex;
+out vec2 fragTex;
+uniform mat4 mvp;
+
+void main(void) {
+ fragTex = tex;
+ gl_Position = mvp * vec4(position.xy, 0.0, 1.0);
+}
+</pre></div>
+
+<p>Sample fragment shader:
+</p>
+<div class="example">
+<pre class="verbatim">#version 130
+
+in vec2 fragTex;
+uniform sampler2D colorTexture;
+
+void main (void) {
+ gl_FragColor = texture2D(colorTexture, fragTex);
+}
+</pre></div>
+
+<p>This manual will not cover GLSL features and syntax as there is lots
+of information already available about this topic.
+</p>
+<p>One way to think about rendering with shaders, and the metaphor
+Chickadee uses, is to think about it as a function call: The shader is
+a function, and it is applied to some &ldquo;attributes&rdquo; (positional
+arguments), and some &ldquo;uniforms&rdquo; (keyword arguments).
+</p>
+<div class="example">
+<pre class="example">(define my-shader (load-shader &quot;vert.glsl&quot; &quot;frag.glsl&quot;))
+(define vertices (make-vertex-array &hellip;))
+(gpu-apply my-shader vertices #:color red)
+</pre></div>
-<p>Shaders are programs for the GPU to evaluate. They are written in the
-OpenGL Shading Language, or GLSL. Chickadee does not currently
-provide a Scheme-like domain specific language for writing shaders.
-Since shaders must be written in GLSL and not Scheme, they are
-considered an advanced feature.
+<p>See <a href="Rendering-Engine.html#Rendering-Engine">Rendering Engine</a> for more details about the <code>gpu-apply</code>
+procedure.
+</p>
+<p>Shaders are incredibly powerful tools, and there&rsquo;s more information
+about them than we could ever fit into this manual, so we highly
+recommend searching the web for more information and examples. What
+we can say, though, is how to use our API:
</p>
+<dl>
+<dt><a name="index-strings_002d_003eshader"></a>Procedure: <strong>strings-&gt;shader</strong> <em>vertex-source fragment-source</em></dt>
+<dd><p>Compile <var>vertex-source</var>, the GLSL code for the vertex shader, and
+<var>fragment-source</var>, the GLSL code for the fragment shader, into a
+GPU shader program.
+</p></dd></dl>
+
+<dl>
+<dt><a name="index-load_002dshader"></a>Procedure: <strong>load-shader</strong> <em>vertex-source-file fragment-source-file</em></dt>
+<dd><p>Compile the GLSL source code within <var>vertex-source-file</var> and
+<var>fragment-source-file</var> into a GPU shader program.
+</p></dd></dl>
+
+<dl>
+<dt><a name="index-make_002dshader"></a>Procedure: <strong>make-shader</strong> <em>vertex-port fragment-port</em></dt>
+<dd><p>Read GLSL source from <var>vertex-port</var> and <var>fragment-port</var> and
+compile them into a GPU shader program.
+</p></dd></dl>
+
+<dl>
+<dt><a name="index-shader_003f"></a>Procedure: <strong>shader?</strong> <em>obj</em></dt>
+<dd><p>Return <code>#t</code> if <var>obj</var> is a shader.
+</p></dd></dl>
+
+<dl>
+<dt><a name="index-null_002dshader"></a>Variable: <strong>null-shader</strong></dt>
+<dd><p>Represents the absence shader program.
+</p></dd></dl>
+
+<dl>
+<dt><a name="index-shader_002duniform"></a>Procedure: <strong>shader-uniform</strong> <em>shader name</em></dt>
+<dd><p>Return the metadata for the uniform <var>name</var> in <var>shader</var>.
+</p></dd></dl>
+
+<dl>
+<dt><a name="index-shader_002duniforms"></a>Procedure: <strong>shader-uniforms</strong> <em>shader</em></dt>
+<dd><p>Return a hash table of uniforms for <var>shader</var>.
+</p></dd></dl>
+
+<dl>
+<dt><a name="index-shader_002dattributes"></a>Procedure: <strong>shader-attributes</strong> <em>shader</em></dt>
+<dd><p>Return a hash table of attributes for <var>shader</var>.
+</p></dd></dl>
+
+<dl>
+<dt><a name="index-uniform_003f"></a>Procedure: <strong>uniform?</strong> <em>obj</em></dt>
+<dd><p>Return <code>#t</code> if <var>obj</var> is a uniform.
+</p></dd></dl>
+
+<dl>
+<dt><a name="index-uniform_002dname"></a>Procedure: <strong>uniform-name</strong> <em>uniform</em></dt>
+<dd><p>Return the variable name of <var>uniform</var>.
+</p></dd></dl>
+
+<dl>
+<dt><a name="index-uniform_002dtype"></a>Procedure: <strong>uniform-type</strong> <em>uniform</em></dt>
+<dd><p>Return the data type of <var>uniform</var>.
+</p></dd></dl>
+
+<dl>
+<dt><a name="index-uniform_002dvalue"></a>Procedure: <strong>uniform-value</strong> <em>uniform</em></dt>
+<dd><p>Return the current value of <var>uniform</var>.
+</p></dd></dl>
+
+<dl>
+<dt><a name="index-uniform_002ddefault_002dvalue"></a>Procedure: <strong>uniform-default-value</strong> <em>uniform</em></dt>
+<dd><p>Return the default value of <var>uniform</var>.
+</p></dd></dl>
+
+<dl>
+<dt><a name="index-attribute_003f"></a>Procedure: <strong>attribute?</strong> <em>obj</em></dt>
+<dd><p>Return <code>#t</code> if <var>obj</var> is an attribute.
+</p></dd></dl>
+
+<dl>
+<dt><a name="index-attribute_002dname"></a>Procedure: <strong>attribute-name</strong> <em>attribute</em></dt>
+<dd><p>Return the variable name of <var>attribute</var>.
+</p></dd></dl>
+
+<dl>
+<dt><a name="index-attribute_002dlocation"></a>Procedure: <strong>attribute-location</strong> <em>attribute</em></dt>
+<dd><p>Return the binding location of <var>attribute</var>.
+</p></dd></dl>
+
+<dl>
+<dt><a name="index-attribute_002dtype"></a>Procedure: <strong>attribute-type</strong> <em>attribute</em></dt>
+<dd><p>Return the data type of <var>attribute</var>.
+</p></dd></dl>
+
+<hr>
+<div class="header">
+<p>
+Previous: <a href="Buffers.html#Buffers" accesskey="p" rel="prev">Buffers</a>, Up: <a href="Graphics.html#Graphics" accesskey="u" rel="up">Graphics</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html#Index" title="Index" rel="index">Index</a>]</p>
+</div>