shun_iwasawa 36e06f
shun_iwasawa 36e06f
	Toonz Shader Fxs Manual
shun_iwasawa 36e06f
shun_iwasawa 36e06f
==========================================================
shun_iwasawa 36e06f
shun_iwasawa 36e06f
 1. Introduction
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Toonz 7.1 allows users to write new Fxs using GLSL (the
shun_iwasawa 36e06f
OpenGL Shading Language).
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Shader Fx interfaces are read once at Toonz's startup,
shun_iwasawa 36e06f
but the underlying fx algorithm can be modified in
shun_iwasawa 36e06f
real time to ease the fx creation process.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Users reading these notes for the first time may want to
shun_iwasawa 36e06f
refer to the official GLSL guide at:
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  http://www.opengl.org/documentation/glsl/
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Up-and-running examples of GLSL (fragment) shader programs
shun_iwasawa 36e06f
can be found at the GLSL sanbox gallery, from which some of
shun_iwasawa 36e06f
the provided examples are adapted from (requires a
shun_iwasawa 36e06f
WebGL-compatible web browser, such as Firefox or Google
shun_iwasawa 36e06f
Chrome):
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  http://glsl.heroku.com/
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Further examples can be found at the beautiful gallery at:
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  https://www.shadertoy.com/
shun_iwasawa 36e06f
shun_iwasawa 36e06f
==========================================================
shun_iwasawa 36e06f
shun_iwasawa 36e06f
 2. Requirements
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
The most recent version of your graphics drivers, as well
shun_iwasawa 36e06f
as a fairly recent graphics card.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Specifically, graphics drivers must support OpenGL 2.1,
shun_iwasawa 36e06f
Transform Feedback and Pixel Buffers (either as a built-in
shun_iwasawa 36e06f
feature or through extensions).
shun_iwasawa 36e06f
shun_iwasawa 36e06f
==========================================================
shun_iwasawa 36e06f
shun_iwasawa 36e06f
 3. Limitations
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Shader fxs are rendered on the GPU, meaning that they are
shun_iwasawa 36e06f
typically executed in a massively parallel fashion - ie fast.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
However, since most systems only adopt one GPU, only one
shun_iwasawa 36e06f
Shader fx is allowed to be rendered at the same time.
shun_iwasawa 36e06f
This means that Shader Fxs do not take advantage of multiple
shun_iwasawa 36e06f
rendering threads in a Toonz rendering process like common
shun_iwasawa 36e06f
CPU-based fxs do.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Shader Fx are intended to apply a fragment shader on the
shun_iwasawa 36e06f
output surface for the fx. In other words, each output pixel
shun_iwasawa 36e06f
is processed separately using the supplied fragment shader
shun_iwasawa 36e06f
program.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
This prevents the implementation of more complex output
shun_iwasawa 36e06f
patterns that span multiple pixels at the same time.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Furthermore, there is no way to specify intermediate buffer
shun_iwasawa 36e06f
objects to read or write data to - which is often a common
shun_iwasawa 36e06f
need when writing fxs.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
==========================================================
shun_iwasawa 36e06f
shun_iwasawa 36e06f
 3. Implementing a Shader Fx
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
In order to implement a shader fx it's currently necessary
shun_iwasawa 36e06f
to either create or edit the following files:
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  a. <toonz path="" stuff="">/config/current.txt</toonz>
shun_iwasawa 36e06f
shun_iwasawa 36e06f
	This file hosts the associations between fxs and
shun_iwasawa 36e06f
	their parameters and the names displayed in the GUI
shun_iwasawa 36e06f
	(which are not locale-dependent).
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  b. <toonz path="" stuff="">/profiles/layouts/fxs/fxs.lst</toonz>
shun_iwasawa 36e06f
shun_iwasawa 36e06f
	The list of fxs as displayed in the right-click
shun_iwasawa 36e06f
	contextual menus like "Add Fx" or "Insert Fx"
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  c. <toonz path="" stuff="">/profiles/layouts/fxs/<your fx="" name="" shader="">.xml</your></toonz>
shun_iwasawa 36e06f
shun_iwasawa 36e06f
	Parameters tabbing in the Fx Parameters Editor
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  d. <toonz library="" path="">/shaders/<your fx="" name="" shader="">.xml</your></toonz>
shun_iwasawa 36e06f
shun_iwasawa 36e06f
	The Shader Fx interface.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  e. The actual shader program files
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Please, observe that the paths and names outside brackets
shun_iwasawa 36e06f
are mandatory.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Apart from point (d) and (e) discussed separately, it is best
shun_iwasawa 36e06f
to locate existing entries and emulate their behavior.
shun_iwasawa 36e06f
You can typically find related entries by searching "Shader"
shun_iwasawa 36e06f
in each file.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
==========================================================
shun_iwasawa 36e06f
shun_iwasawa 36e06f
 4. The Shader Interface File
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
The Shader Fx Interface file at (3.d) is an xml document that
shun_iwasawa 36e06f
defines the main properties of the fx.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Specifically:
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  a. Shader program files to be compiled at run-time
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  b. Input ports for the fx
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  c. Parameters
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  d. Restrictions to the class of world/output coordinates
shun_iwasawa 36e06f
     transforms handled by the fx
shun_iwasawa 36e06f
shun_iwasawa 36e06f
The file is read once when Toonz starts, so any modification
shun_iwasawa 36e06f
will not be recognized until Toonz is restarted.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
The complete recognized file structure is as follows:
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
<mainprogram>                       // (4.a) The applied fragment shader</mainprogram>
shun_iwasawa 36e06f
  <name></name>
shun_iwasawa 36e06f
    SHADER_myShaderName             // Internal name of the fx (mandatory, a simple app-unique literal id)
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
  <programfile></programfile>
shun_iwasawa 36e06f
    "programs/myShader.frag"        // The shader program file (3.e), relative to the
shun_iwasawa 36e06f
                      // path of the interface file.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
<inputports>                        // (4.b) - Only a *fixed* number of ports allowed</inputports>
shun_iwasawa 36e06f
  <inputport>                       // A first port</inputport>
shun_iwasawa 36e06f
    "Source"                        // The displayed port name
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  <inputport>                       // Second port</inputport>
shun_iwasawa 36e06f
    "Control"
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
  <portsprogram>                    // (4.a) Vertex shader used to acquire the geometry of</portsprogram>
shun_iwasawa 36e06f
    <name>                          // input images. See (5.b).</name>
shun_iwasawa 36e06f
      SHADER_myShader_ports         // The unique id for the vertex shader program (mandatory)
shun_iwasawa 36e06f
    
shun_iwasawa 36e06f
    <programfile></programfile>
shun_iwasawa 36e06f
      "programs/myShader_ports.vert"
shun_iwasawa 36e06f
    
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
<bboxprogram>                       // (4.a) Vertex shader used to calculate the fx's bbox.</bboxprogram>
shun_iwasawa 36e06f
  <name>                            //  See (5.c).</name>
shun_iwasawa 36e06f
    SHADER_myShader_bbox
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
  <programfile></programfile>
shun_iwasawa 36e06f
    "programs/myShader_bbox.vert"
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
<handledworldtransforms>            // (4.d) Optional, see (5.a)</handledworldtransforms>
shun_iwasawa 36e06f
  isotropic                         // May be either 'any' (default) or 'isotropic'.
shun_iwasawa 36e06f
           // Isotropic transforms exclude shears and non-uniform scales.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
<parameters>                        // (4.c)</parameters>
shun_iwasawa 36e06f
  <parameter></parameter>
shun_iwasawa 36e06f
shun_iwasawa 36e06f
    float radius                    // Parameter declaration
shun_iwasawa 36e06f
luz paz 67b4e9
    <default>                       // Additional Parameter attributes (can be omitted)</default>
shun_iwasawa 36e06f
      10                            // The parameter default
shun_iwasawa 36e06f
    
shun_iwasawa 36e06f
    <range></range>
shun_iwasawa 36e06f
      0 20                          // The parameter range
shun_iwasawa 36e06f
    
shun_iwasawa 36e06f
    <concept></concept>
shun_iwasawa 36e06f
      length                        // The parameter concept type - or, how it is represented
shun_iwasawa 36e06f
                          // by the Toonz GUI
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  <parameter></parameter>
shun_iwasawa 36e06f
shun_iwasawa 36e06f
    float angle
shun_iwasawa 36e06f
shun_iwasawa 36e06f
    <concept></concept>
shun_iwasawa 36e06f
      angle_ui                      // Concepts of type <concept type="">_ui are editable in</concept>
shun_iwasawa 36e06f
      <name>                        // camera stand</name>
shun_iwasawa 36e06f
        "My Angle"
shun_iwasawa 36e06f
      
shun_iwasawa 36e06f
    
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
<concept>                           // Composite parameter concepts can be formed by 2 or</concept>
shun_iwasawa 36e06f
                                    // more parameters
shun_iwasawa 36e06f
  polar_ui
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  <name></name>
shun_iwasawa 36e06f
    "My Polar Coordinates"
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
  <parameter>                       // List of involved parameters</parameter>
shun_iwasawa 36e06f
    radius
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
  <parameter></parameter>
shun_iwasawa 36e06f
    angle
shun_iwasawa 36e06f
  
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
----------------------------------------------------------
shun_iwasawa 36e06f
shun_iwasawa 36e06f
4.1. Parameter Declarations
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Parameters are introduced by a declaration typically matching
shun_iwasawa 36e06f
the corresponding GLSL variable declaration.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
The complete recognized list of supported parameter types is:
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  bool, float, vec2, int, ivec2, rgb, rgba
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
The 'rgb' and 'rgba' types map to GLSL 'vec3' and 'vec4'
shun_iwasawa 36e06f
variables respectively, but are displayed with the appropriate
shun_iwasawa 36e06f
color editors by Toonz - plus, the range of their components
shun_iwasawa 36e06f
automatically maps from [0, 255] in Toonz and the Shader
shun_iwasawa 36e06f
Interface file to [0.0, 1.0] in the corresponding shader program
shun_iwasawa 36e06f
files.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
----------------------------------------------------------
shun_iwasawa 36e06f
shun_iwasawa 36e06f
4.2. Parameter Concepts
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Parameter 'concepts' are additional parameter properties that
shun_iwasawa 36e06f
regard the way Toonz represents a certain parameter type.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
For example, a 'float' variable type may either indicate
shun_iwasawa 36e06f
an angle, the length of a segment, a percentage value,
shun_iwasawa 36e06f
and more.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Fx writers may want to explicitly specify a parameter concept
shun_iwasawa 36e06f
for the following reasons:
shun_iwasawa 36e06f
luz paz 6454c4
  a. Impose a measure to the parameter (e.g. degrees, inches, %)
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  b. Make the parameter editable in camera-stand
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
The complete list of supported parameter concepts is the following:
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  percent            - Displayed with the percentage '%' unit
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  length             - Displayed in length units (inches, mm, cm, etc..)
shun_iwasawa 36e06f
luz paz 6454c4
  angle              - Displayed in angular units 'ďż˝'
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  point              - A vec2 displayed in length units
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  radius_ui          - Like length, displaying a radius in camstand. May compose with a point (the center)
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  width_ui           - Like length, displaying a vertical line width. May compose with the line's angle.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  angle_ui           - Like angle, displaying it in camstand
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  point_ui           - Like point, in camstand
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  xy_ui              - Composes two float types in a point
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  vector_ui          - Composes two float types in an 'arrow'-like vector
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  polar_ui           - Like vector_ui, from a length and an angle
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  size_ui            - Displays a square indicating a size. May compose width and height in a rect.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  quad_ui            - Composes 4 points in a quadrilateral
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  rect_ui            - Composes width, height, and the optional center point in a rect
shun_iwasawa 36e06f
shun_iwasawa 36e06f
==========================================================
shun_iwasawa 36e06f
shun_iwasawa 36e06f
 5. Shader program files
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
A shader program file is a simple text file containing the
shun_iwasawa 36e06f
actual algorithms of a shader fx.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
In the current implementation of Toonz Shader Fxs, there are
shun_iwasawa 36e06f
3 possible shader program files that need to be specified:
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  a. The main fragment shader program, responsible of
shun_iwasawa 36e06f
     executing the code that actually renders the fx
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  b. An optional vertex shader program to calculate the 
shun_iwasawa 36e06f
     geometries of contents required from input ports
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  c. An optional vertex shader program to calculate the
shun_iwasawa 36e06f
     bounding box of the fx output
shun_iwasawa 36e06f
shun_iwasawa 36e06f
----------------------------------------------------------
shun_iwasawa 36e06f
shun_iwasawa 36e06f
 5.a. The 'MainProgram' Fragment Shader
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
The main program is in practice a standard GLSL fragment
shun_iwasawa 36e06f
shader - however, Toonz will provide it a set of additional
shun_iwasawa 36e06f
uniform input variables that must be addressed to correctly
shun_iwasawa 36e06f
compute the desired output.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
The complete list of additional variables always supplied
shun_iwasawa 36e06f
by Toonz is:
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  uniform mat3    worldToOutput;
shun_iwasawa 36e06f
  uniform mat3    outputToWorld;
shun_iwasawa 36e06f
shun_iwasawa 36e06f
These matrix variables describe the affine transforms mapping
shun_iwasawa 36e06f
output coordinates to Toonz's world coordinates, and vice-versa.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
They include an additional coordinate as an OpenGL version-portable
shun_iwasawa 36e06f
way to perform translations by natural multiplication - transforming
shun_iwasawa 36e06f
a point is then done like:
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  vec2 worldPoint = (outputToWorld * vec3(outPoint, 1.0)).xy
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Fx parameters are typically intended in world coordinates,
shun_iwasawa 36e06f
and should be adjusted through these transforms - for example,
shun_iwasawa 36e06f
a camstand-displayed radius value must be multiplied by the
shun_iwasawa 36e06f
'worldToOutput' scale factors in order to get the corresponding
shun_iwasawa 36e06f
value in output coordinates.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
World/Output transforms may be restricted to a specific sub-class
shun_iwasawa 36e06f
of affine transforms by specifying so in the Shader Interface File.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Restricting to isotropic transforms may be useful to simplify
shun_iwasawa 36e06f
cases where angular values are taken into account, since this
shun_iwasawa 36e06f
transforms class preserves angles by allowing only uniform scales,
shun_iwasawa 36e06f
rotations and translations. Non-uniform scales and shears are
shun_iwasawa 36e06f
later applied by Toonz on the produced fx output if necessary.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
In case input ports have been specified, we also have:
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  uniform sampler2D inputImage[n];
shun_iwasawa 36e06f
  uniform mat3      outputToInput[n];
shun_iwasawa 36e06f
  uniform mat3      inputToOutput[n];
shun_iwasawa 36e06f
shun_iwasawa 36e06f
The sampler variables correspond to the input content to the
shun_iwasawa 36e06f
fx. The matrix variables are the reference transforms from
shun_iwasawa 36e06f
output to input variables, and vice-versa.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Additional uniform variables corresponding to fx parameters
shun_iwasawa 36e06f
will also be supplied by Toonz. For example, if a "float radius"
shun_iwasawa 36e06f
parameter was specified, a corresponding
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  uniform float radius;
shun_iwasawa 36e06f
shun_iwasawa 36e06f
input variable will be provided to the program.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
WARNING: Toonz requires that *output* colors must be 
shun_iwasawa 36e06f
         'premultiplied' - that is, common RGB components
shun_iwasawa 36e06f
         (in the range [0, 1]) must be stored multiplied
shun_iwasawa 36e06f
         by their alpha component.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
----------------------------------------------------------
shun_iwasawa 36e06f
shun_iwasawa 36e06f
 5.b. The optional 'PortsProgram' Vertex Shader
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
The shader program (b) is required in case an fx specifies
shun_iwasawa 36e06f
input ports, AND it needs to calculate some input content
shun_iwasawa 36e06f
in a different region than the required output.
shun_iwasawa 36e06f
It can be neglected otherwise.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
For example, a blur fx requires that input contents outside
shun_iwasawa 36e06f
the required output rectangle are 'blurred in' it.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
The 'PortsProgram' vertex shader is a one-shot shader
shun_iwasawa 36e06f
run by Toonz on a single dummy vertex - which uses
shun_iwasawa 36e06f
OpenGL 3.0's "Transform Feedback" extension to return a
shun_iwasawa 36e06f
set of predefined 'varying' output variables
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
The complete set of variables supplied by Toonz and required
shun_iwasawa 36e06f
in output by the program is:
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  uniform mat3    worldToOutput;
shun_iwasawa 36e06f
  uniform mat3    outputToWorld;
shun_iwasawa 36e06f
  uniform vec4    outputRect;
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  varying vec4    inputRect[portsCount];
shun_iwasawa 36e06f
  varying vec4    worldToInput[portsCount];
shun_iwasawa 36e06f
shun_iwasawa 36e06f
The transforms are intended in the same way as (5.a).
shun_iwasawa 36e06f
shun_iwasawa 36e06f
The outputRect and inputRect[] variables store the
shun_iwasawa 36e06f
(left, bottom, right, top) rect components in output
shun_iwasawa 36e06f
and input coordinates respectively.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Parameter input variables are obviously also supplied.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
WARNING: *All* the required output variables must be
shun_iwasawa 36e06f
	 declared AND filled with values.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
         There is no recognized default for them, and the
shun_iwasawa 36e06f
         fx will (silently) fail to render if some are not
shun_iwasawa 36e06f
         assigned.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
----------------------------------------------------------
shun_iwasawa 36e06f
shun_iwasawa 36e06f
 5.c. The optional 'BBoxProgram' Vertex Shader
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Some fx may be able to restrict their opaque renderable
shun_iwasawa 36e06f
area inside a rect.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
For example, blurring an image will 'blur out' the image
shun_iwasawa 36e06f
content by the specified blur radius. Beyond that, the fx
shun_iwasawa 36e06f
will render full transparent pixels. Thus, the bounding
shun_iwasawa 36e06f
box of the fx in this case will be calculated as the
shun_iwasawa 36e06f
input bounding box, enlarged by the blur radius.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
The default output bounding box is assumed to be infinite;
shun_iwasawa 36e06f
if that is the case, the BBoxProgram can be omitted.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
Fx writers may want to supply an explicit program to
shun_iwasawa 36e06f
calculate the bounding box of the fx, given its input
shun_iwasawa 36e06f
bounding boxes. This is be useful in Toonz's rendering
shun_iwasawa 36e06f
pipeline because the software is then allowed to
shun_iwasawa 36e06f
restrict memory allocation (and fxs calculations)
shun_iwasawa 36e06f
for the output image to said output bounding box, resulting
shun_iwasawa 36e06f
in less memory consumption and increased speed.
shun_iwasawa 36e06f
shun_iwasawa 36e06f
shun_iwasawa 36e06f
The complete set of variables supplied by Toonz and required
shun_iwasawa 36e06f
in output by the program is:
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  uniform vec4 infiniteRect;
shun_iwasawa 36e06f
  uniform vec4 inputBBox[portsCount];
shun_iwasawa 36e06f
shun_iwasawa 36e06f
  varying vec4 outputBBox;
shun_iwasawa 36e06f
shun_iwasawa 36e06f
The infiniteRect variable should be used to identify both
shun_iwasawa 36e06f
input and output infinite bboxes.
shun_iwasawa 36e06f