ShadersModule
The ShadersModule exposes APIs to create Visual Shaders using JavaScript.
The following is an explanation of the unique types and concepts specific to the ShadersModule.
TypeA->TypeB is a function that maps TypeA to TypeB.
For instance, Point2DSignal->Point4DSignal is a type of a function that maps a Point2DSignal to a Point4DSignal.
Texture2d_1ch is the same as Point2DSignal->ScalarSignal.
Texture2d_2ch is the same as Point2DSignal->Point2DSignal.
Texture2d_3ch is the same as Point2DSignal->PointSignal.
Texture2d_4ch is the same as Point2DSignal->Point4DSignal.
TextureSdf is the same as Point2DSignal->ScalarSignal.
Certain functions can accept multiple types. This is denoted by the following generic types:
GenericVector can be a ScalarSignal, Point2DSignal, PointSignal, Point4DSignal.
GenericMatrix can be a Matrix2, Matrix3, Matrix4.
Generic can be a GenericVector, GenericMatrix.
GenericFunction is the same as GenericA->GenericB.
When multiple arguments are marked with the same Generic they all have to be of the same type.
For instance, in composition(f: GenericA->GenericB, g: GenericA): GenericB
both occurrences of GenericA must refer to the same type, as do both occurrences of GenericB.
GenericA may, but doesn't have to, be different from GenericB though.
E.g. this is valid: composition(f: Point2DSignal->Point4DSignal, g: Point2DSignal): Point4DSignal
Note: Signals returned from methods within this module will not work in any other context.
Example
//==============================================================================
// The following example demonstrates how to use visual shaders to tile SDF
// shapes. This is a script version of the following Patch Editor example:
// https://fb.me/tiled-sdf-patch
//
// Project setup:
// - Insert a rectangle and set it to 'Fill Parent'
// - Create a new material and assign it to the rectangle
//==============================================================================
// Load in the required modules
const Materials = require('Materials');
const Reactive = require('Reactive');
const Shaders = require('Shaders');
// Create the SDF Star parameters
const center = Reactive.pack2(0.05,0.05);
const radius = 0.04;
const radius2 = Reactive.mul(radius,0.5);
const sides = 5;
// Create the SDF Star
const sdfStar = Shaders.sdfStar(center,radius,radius2,sides);
// Create the SDF Mix
const sdfMix = Shaders.sdfMix(sdfStar,0,0.993);
// Create the SDF Repeat parameters
const pivot = Reactive.pack2(0.05,0.05);
const size = Reactive.pack2(0.09,0.09);
// Create the SDF Repeat
const sdfRepeat = Shaders.sdfRepeat(sdfMix,pivot,size);
// Create the step
const step = Reactive.step(sdfRepeat,0);
// Create the gradient
const gradient = Shaders.gradient({"type" : Shaders.GradientType.HORIZONTAL});
// Create the first mix paramaters
const color1 = Reactive.pack4(1,0.57,0,1);
const color2 = Reactive.pack4(1,0.25,1,1);
// Create the first mix
const mix1 = Reactive.mix(color1,color2,gradient);
// Create the color for the second mix
const color3 = Reactive.pack4(0,0,0,0);
// Create the second mix
const mix2 = Reactive.mix(mix1,color3,step);
// Locate the material in the Assets
const material = Materials.get('defaultMaterial0');
// Define the texture slot of the material to update
const textureSlot = Shaders.DefaultMaterialTextures.DIFFUSE;
// Assign the shader signal to the texture slot
material.setTexture(mix2, {textureSlotName: textureSlot});Properties
This module exposes no properties.
Methods
| Method | Description |
|---|---|
|
Blends two colors with the specified blending mode. When a color is passed as PointSignal its alpha value is considered to be 1. When both colors are passed as PointSignal (i.e. without the alpha channel), the result is also PointSignal. |
|
Converts a color from the input color space to the output colorspace. |
|
Returns a signal for the shader composition of the two given functions (e.g. texture and a transform). |
|
Returns a signal for the specified shader derivative of the given signal. |
|
Forwards the main input if present, otherwise uses fallback. |
|
Places the subsequent computation on val to the fragment stage. |
|
Returns a signal for the identity function over the specified type. |
|
Returns a signal for the identity function over the specified type. |
|
Returns a signal for the identity function over the specified type. |
|
Returns a signal for the identity function over the specified type. |
|
Returns a signal for the specified gradient. |
|
Returns a signal of the current render target's size. |
|
Returns a signal of the given SDF shape made annular (ring-like) by the specified width. |
|
Returns a signal for a circle SDF shape. |
|
Returns a signal of the complement of the given SDF shape. |
|
Returns a signal of the difference of the two given SDF shapes. |
|
Returns a signal for an ellipse SDF shape. |
|
Returns a signal of the given SDF shape flipped around the plane given by the offset an normal. |
|
Returns a signal for a half-plane SDF shape. |
|
Returns a signal of the intersection of the two given SDF shapes. |
|
Returns a signal for a line SDF shape. |
|
Returns a signal of the linear interpolation of the two given SDF shapes, modulated by alpha. |
|
Returns a signal for a polygon SDF shape. |
|
Returns a signal for a rectangle SDF shape. |
|
Returns a signal of the given SDF shape's grid repetition. The shape should be centered on the pivot and fit within the given size. |
|
Returns a signal of the given SDF shape rotated around the given pivot by the given angle. |
|
Returns a signal of the given SDF shape's rotational repetition numTimes at the given radius. The shape should be centered on the pivot and fit within the angular sector defined by numTimes at the given radius. |
|
Returns a signal of the given SDF shape rounded by the specified radius. |
|
Returns a signal of the given SDF shape scaled around the given pivot by the given size. |
|
Returns a signal of the given SDF shape scaled around the given pivot by the given shear amount. |
|
Returns a signal of the smooth difference of the two given SDF shapes, modulated by K. |
|
Returns a signal of the smooth intersection of the two given SDF shapes, modulated by K. |
|
Returns a signal of the smooth union of the two given SDF shapes, modulated by K. |
|
Returns a signal for a star SDF shape. |
|
Returns a signal of the given SDF shape translated by the given offset. |
|
Returns a signal of the given SDF shape twisted around the pivot by the given amount. |
|
Returns a signal of the union of the two given SDF shapes. |
|
Samples the given texture at the specified uv coordinates. |
|
Transforms the given texture with the specified Mat3 transform. |
|
Returns a signal for the specified vertex attribute depending on the VertexAttribute used:
|
|
Returns a signal for the specified vertex transform depending on the BuiltinUniform used:
|
Classes
This module exposes no classes.
Enums
| Enum | Description |
|---|---|
The | |
The | |
The | |
The | |
The | |
The | |
The | |
The | |
The | |
The | |
The |