diff options
author | David Thompson <dthompson2@worcester.edu> | 2021-10-07 20:17:50 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2021-10-07 20:17:50 -0400 |
commit | 0e699be281c8dea53e589e08a5831837e0eae7ea (patch) | |
tree | 4266aebec927b13ca56410be1901e3ee78dff49e /manuals/chickadee/Shaders.html | |
parent | 38daa330f2194de5f39cd41b270c89d7b2e94427 (diff) |
Updates for Chickadee 0.8.0 and Guile-SDL2 0.7.0.
Diffstat (limited to 'manuals/chickadee/Shaders.html')
-rw-r--r-- | manuals/chickadee/Shaders.html | 79 |
1 files changed, 47 insertions, 32 deletions
diff --git a/manuals/chickadee/Shaders.html b/manuals/chickadee/Shaders.html index aed0f49..95c5186 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-2020 David Thompson davet@gnu.org +<!-- Copyright (C) 2017-2021 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 @@ -32,7 +32,7 @@ http://www.texinfo.org/ (GNU Texinfo). <link href="Index.html" rel="index" title="Index"> <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> <link href="Graphics.html" rel="up" title="Graphics"> -<link href="Audio.html" rel="next" title="Audio"> +<link href="Framebuffers.html" rel="next" title="Framebuffers"> <link href="Buffers.html" rel="prev" title="Buffers"> <style type="text/css"> <!-- @@ -82,10 +82,10 @@ ul.no-bullet {list-style: none} <body lang="en"> <span id="Shaders"></span><div class="header"> <p> -Previous: <a href="Buffers.html" accesskey="p" rel="prev">Buffers</a>, Up: <a href="Graphics.html" accesskey="u" rel="up">Graphics</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p> +Next: <a href="Framebuffers.html" accesskey="n" rel="next">Framebuffers</a>, Previous: <a href="Buffers.html" accesskey="p" rel="prev">Buffers</a>, Up: <a href="Graphics.html" accesskey="u" rel="up">Graphics</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p> </div> <hr> -<span id="Shaders-1"></span><h4 class="subsection">2.3.15 Shaders</h4> +<span id="Shaders-1"></span><h4 class="subsection">5.3.13 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 @@ -201,7 +201,7 @@ compile them into a GPU shader program. <dt id="index-shader_002duniform_002dset_0021">Procedure: <strong>shader-uniform-set!</strong> <em>shader uniform value</em></dt> </dl> -<span id="Attributes"></span><h4 class="subsubsection">2.3.15.1 Attributes</h4> +<span id="Attributes"></span><h4 class="subsubsection">5.3.13.1 Attributes</h4> <dl> <dt id="index-attribute_003f">Procedure: <strong>attribute?</strong> <em>obj</em></dt> @@ -223,7 +223,7 @@ compile them into a GPU shader program. <dd><p>Return the data type of <var>attribute</var>. </p></dd></dl> -<span id="Uniforms"></span><h4 class="subsubsection">2.3.15.2 Uniforms</h4> +<span id="Uniforms"></span><h4 class="subsubsection">5.3.13.2 Uniforms</h4> <dl> <dt id="index-uniform_003f">Procedure: <strong>uniform?</strong> <em>obj</em></dt> @@ -245,44 +245,49 @@ compile them into a GPU shader program. <dd><p>Return the current value of <var>uniform</var>. </p></dd></dl> -<span id="User_002dDefined-Shader-Types"></span><h4 class="subsubsection">2.3.15.3 User-Defined Shader Types</h4> +<span id="User_002dDefined-Shader-Types"></span><h4 class="subsubsection">5.3.13.3 User-Defined Shader Types</h4> <p>The shader examples in this manual thus far have only shown uniforms defined using primitive types. However, GLSL shaders support user-defined compound structs, such as this one: </p> <div class="example"> -<pre class="verbatim">struct DirectionalLight { - vec3 direction; - vec3 ambient; - vec3 diffuse; - vec3 specular; +<pre class="verbatim">struct Light { + bool enabled; + int type; + vec3 position; + vec3 direction; + vec4 color; + float intensity; + float cutOff; }; -uniform DirectionalLight light; +uniform Light light; </pre></div> <p>While <code>light</code> is declared as a single uniform in the shader code, -OpenGL translates this into <em>four</em> uniforms in this case: One -uniform each member of the <code>DirectionalLight</code> struct. This poses -a problem for sending Scheme data to the GPU. How can compound Scheme -data translate into compound uniform data on the GPU? The answer is -with shader types. Shader types are a special kind of Guile struct -that provide a one-to-one mapping between a Scheme data structure and -a shader struct. +OpenGL translates this into <em>seven</em> uniforms in this case: One +uniform each member of the <code>Light</code> struct. This poses a problem +for sending Scheme data to the GPU. How can compound Scheme data +translate into compound uniform data on the GPU? The answer is with +shader types. Shader types are a special kind of Guile struct that +provide a one-to-one mapping between a Scheme data structure and a +shader struct. </p> <p>Some example code will explain this concept best. Here is the Scheme -equivalent of the <code>DirectionalLight</code> struct: +equivalent of the <code>Light</code> struct: </p> <div class="example"> -<pre class="example">(define-shader-type <directional-light> - make-directional-light - directional-light? - (float-vec3 direction directional-light-direction) - (float-vec3 ambient directional-light-ambient) - (float-vec3 diffuse directional-light-diffuse) - (float-vec3 specular directional-light-specular) - (float shininess directional-light-shininess)) +<pre class="example">(define-shader-type <light> + make-light + light? + (bool enabled light-enabled?) + (int type light-type) + (float-vec3 position light-position) + (float-vec3 direction light-direction) + (float-vec4 color light-color) + (float intensity light-intensity) + (float cut-off light-cut-off)) </pre></div> <p>The macro <code>define-shader-type</code> closely resembles the familiar @@ -332,12 +337,17 @@ remains to be seen if this model is robust enough for all use-cases. <dl> <dt id="index-float_002dvec4">Variable: <strong>float-vec4</strong></dt> -<dd><p>A color. +<dd><p>A color (see <a href="Colors.html">Colors</a>) or rectangle (see <a href="Rectangles.html">Rectangles</a>.) +</p></dd></dl> + +<dl> +<dt id="index-mat3">Variable: <strong>mat3</strong></dt> +<dd><p>A 3x3 matrix (see <a href="Matrices.html">Matrices</a>.) </p></dd></dl> <dl> <dt id="index-mat4">Variable: <strong>mat4</strong></dt> -<dd><p>A matrix (see <a href="Matrices.html">Matrices</a>.) +<dd><p>A 4x4 matrix (see <a href="Matrices.html">Matrices</a>.) </p></dd></dl> <dl> @@ -346,6 +356,11 @@ remains to be seen if this model is robust enough for all use-cases. </p></dd></dl> <dl> +<dt id="index-sampler_002dcube">Variable: <strong>sampler-cube</strong></dt> +<dd><p>A cube map (see <a href="Textures.html">Textures</a>.) +</p></dd></dl> + +<dl> <dt id="index-local_002dfield">Variable: <strong>local-field</strong></dt> <dd><p>A special type that means that the data is for the client-side (Scheme-side) only and should not be sent to the GPU. Any object may @@ -381,7 +396,7 @@ optional. <hr> <div class="header"> <p> -Previous: <a href="Buffers.html" accesskey="p" rel="prev">Buffers</a>, Up: <a href="Graphics.html" accesskey="u" rel="up">Graphics</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p> +Next: <a href="Framebuffers.html" accesskey="n" rel="next">Framebuffers</a>, Previous: <a href="Buffers.html" accesskey="p" rel="prev">Buffers</a>, Up: <a href="Graphics.html" accesskey="u" rel="up">Graphics</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p> </div> |