Taichi GLSL API references¶
Taichi GLSL is an extension library of the Taichi Programming Language, which provides a set of useful helper functions including but not limited to:
Handy scalar functions like
clamp
,smoothstep
,mix
,round
.GLSL-alike vector functions like
normalize
,distance
,reflect
.Well-behaved random generators including
randUnit3D
,randNDRange
.Handy vector and matrix initializer:
vec
andmat
.Handy vector component shuffle accessor like
v.xy
.Handy field sampler including
bilerp
andsample
.Useful physics helper functions like
boundReflect
.Shadertoy-alike inputed GUI base class
Animation
.
Let me know if you encountered bugs or got a good idea by opening an issue on GitHub.
Note
Here’s the documentation of Taichi GLSL, the extension library. For the documentation of Taichi itself, please click here | 这里.
Installation¶
To install, make sure you have installed taichi
first, then install
taichi_glsl
via pip
:
python3 -m pip install --user taichi_glsl
Import me using:
import taichi as ti
import taichi_glsl as ts
Or simply:
from taichi_glsl import *
Note that this will import taichi
as name ti
as well.
Scalar math¶
GLSL-alike scalar arithmetic functions.
Functions¶
|
Return the arc-tangent of the parameters |
|
Constrain a value to lie between two further values. |
|
Compute the fractional part of the argument. |
|
Return the inverse of the square root of the parameter. |
|
Determine whether the parameter is positive or negative infinity. |
|
Determine whether the parameter is a number. |
|
Linearly interpolate between two values. |
|
Find the nearest integer less than or equal to the parameter. |
|
Extract the sign of the parameter. |
|
Perform Hermite interpolation between two values. |
|
Generate a step function by comparing two values. |
Vector math¶
GLSL-alike linear algebra helper functions / aliases.
Functions¶
|
Calculate the cross product of two vectors. |
|
Calculate the distance between two points. |
|
Calculate the dot product of two vectors. |
|
Calculate the inverse of length of a vector. |
|
Calculate the length of a vector. |
|
Matrix initializer (WIP). |
|
Find the maximum value in all elements of a vector. |
|
Find the minimum value in all elements of a vector. |
|
Calculates the unit vector in the same direction as the original vector. |
|
Return a vector with same direction but with a n-powered length. |
|
|
|
Calculate the reflection direction for an incident vector. |
|
Calculate the refraction direction for an incident vector. |
|
|
|
Calculate the square of the length of a vector. |
|
Calculate the sum of all elements in a vector. |
|
Create a vector by scalars or vectors in arguments (GLSL-alike). |
|
An alias for vecND(2, *xs). |
|
An alias for vecND(3, *xs). |
|
An alias for vecND(4, *xs). |
|
Return a 2D vector of specific phase angle. |
|
Create a n-D vector whose all components are initialized by x. |
|
Create a n-D vector by scalars or vectors in arguments (GLSL-alike). |
|
Create a n-D vector whose components are specified by arguments. |
Field sampling¶
Some helper functions in processing fields & images.
Functions¶
|
Bilinear sampling an 2D field with a real index. |
|
Sampling a field, when indices out of the field shape, return the given default value. |
|
Sampling a field with indices clampped into the field shape. |
|
GUI Base Class¶
Display images or animations using Taichi GUI (WIP)
Random generator¶
Pseudo-random number or noise generators.
Functions¶
|
Generate a random floating number distributed evenly in range [0, 1]. |
|
Generate a random integer in range [a, b], including both end points. |
|
Generate a n-D random vector in a n-D cube ([0, 1]). |
|
Generate a n-D random vector in a n-D cube. |
|
Generate random floating numbers in range [a, b]. |
Generate a 2-D random unit vector whose length is <= 1.0. |
|
Generate a 2-D random unit vector whose length is equal to 1.0. |
|
Generate a 3-D random unit vector whose length is equal to 1.0. |
Particle simluation¶
Some helper functions that might be useful in physics simulation.
Functions¶
|
|
|
Reflect particle velocity from a rectangular boundary (if collides). |
|
Exchange momentum (bounce) between two objects. |