GLSL Reference
Math Functionsedit
// TDMath
// Creates a rotation matrix that rotates starting from looking down +Z, to the 'forward' vector direction.
// The 'forward' and 'up' vectors passed to this function do not need to be normalized.
mat3 TDRotateToVector(vec3 forward, vec3 up);
// Creates a rotation matrix that rotates around the 'axis', the given number of 'radians'
// The 'axis' vector must already be normalized before being passed to this function.
mat3 TDRotateOnAxis(float radians, vec3 axis);
// Creates a rotation matrix that rotates around the +X, +Y and +Z axis repectively.
mat3 TDRotateX(float radians);
mat3 TDRotateY(float radians);
mat3 TDRotateZ(float radians);
// Creates a scale matrix for the given 3 scale values.
mat3 TDScale(float x, float y, float z);
// Creates a translation matrix for the given 3 translation values.
mat4 TDTranslate(float x, float y, float z);
// A function that gives a half-sine ramp from 0 to 1.
// Sampling it with a coordinate outside the (0, 1) range will return 0 for anything below 0 and 1 for anything above 1.
// It's possibly faster than using the GLSL sin() function, depending on the hardware.
float TDSineLookup(float v);
// Creates a rotation matrix to rotate from vector 'from' to vector 'to'. The solution isn't particularly stable, but useful in some cases.
// The 'from' and 'to' vectors must already be normalized before being passed to this function.
mat3 TDCreateRotMatrix(vec3 from, vec3 to);
// Takes a surface normal, the tangent to the surface, and a handedness value (either -1 or 1)
// Returns a matrix that will convert vectors from tangent space, to the space the normal and tangent are in
// Both the normal and the tangent must be normalized before this function is called.
// The w coordinate of the T attribute created by the [[Attribute Create SOP]] contains the handedness
// that should be passed in as-is.
mat3 TDCreateTBNMatrix(vec3 N, vec3 T, float handedness);
// Converts between RGB and HSV color space
vec3 TDRGBToHSV(vec3 c);
vec3 TDHSVToRGB(vec3 c);
// Converts a 0-1 equirectangular texture coordinate into cubemap coordinates.
// A 0 for the U coordinate corresponds to the middle of the +X face. So along the vec3(1, Y, 0) plane.
// As U rises, equirectangular coordinates rotate from +X, to +Z, then -X and -Z.vec3 TDEquirectangularToCubeMap(vec2 mapCoord);
vec3 TDEquirectangularToCubeMap(vec2 mapCoord);
// Converts from cubemap coordinates to equirectangular
// cubemapCoord MUST be normalized before calling this function.
vec2 TDCubeMapToEquirectangular(vec3 envMapCoord)
// Available in builds 2019.18140
// This version will also output a mipmap bias float. This float should be passed in the 'bias'
// parameter of texture(), to help select the mipmap level. This helps avoids seams at the edge
// of equirectangular map.
vec2 TDCubeMapToEquirectangular(vec3 envMapCoord, out float mipMapBias)
// Converts from RGB to monochrome using the standard weights of luminance (0.2126, 0.7152, 0.0722)
float TDLuminance(vec3 c);
// Returns a looping value between low and high
float TDLoop(float val, float low, float high);
// Returns a value that zigzags between low and high
float TDZigZag(float val, float low, float high);
// Returns the average between the two values.
float TDAverage(float valA, float valB);
// Like the remap feature in the Math CHOP, will remap 'value' frmo thew range [low1, high1] to the range [low2, high2].
float TDRemap(float value, float low1, float high1, float low2, float high2);
vec2 TDRemap(vec2 value, vec2 low1, vec2 high1, vec2 low2, vec2 high2);
vec3 TDRemap(vec3 value, vec3 low1, vec3 high1, vec3 low2, vec3 high2);
vec4 TDRemap(vec4 value, vec4 low1, vec4 high1, vec4 low2, vec4 high2);
// Triplanar blend function. Blends between the 3 orthogonal color values weighted by the normal vector. <code>blendPower</code> argument is the exponent taken by the weight function to control the falloff.
vec4 TDTriplanarBlend(vec3 normal, vec4 xcolor, vec4 ycolor, vec4 zcolor, int blendPower);
// Performs Tricubic and bicubic sampling/interlolation on the given sampler.
// texSize and invTexSize should be the resolution and 1.0 / resolution of the texture.
vec4 TDBicubicInterpolation(sampler2D tex, vec2 texCoord, vec2 texSize, vec2 invTexSize);
vec4 TDBicubicInterpolation(sampler2D tex, vec2 texCoord);
vec4 TDTricubicInterpolation(sampler3D tex, vec3 texCoord, vec3 texSize, vec3 invTexSize);
vec4 TDTricubicInterpolation(sampler3D tex, vec3 texCoord);
// Generate 2D coordinates to look up into a sphere-map from 3D environment coordinates.
vec2 TDTexGenSphere(vec3 envMapCoord);
// TDQuaternionMath
// Builds a quaternion representing a rotation around an axis, using an angle in radians.
vec4 TDAxisAngleToQuaternion(vec3 axis, float angle) ;
// Builds a 3×3 rotation matrix from a quaternion.
mat3 TDQuaternionToRotMatrix(vec4 q);
// Extracts a quaternion representing the rotation of a 3×3 matrix.
vec4 TDRotMatrixToQuaternion(mat3 rotMat);
// Rotates a vector or a point using a quaternion rotation.
vec3 TDRotateFromQuaternion(vec3 v, vec4 q);
// Combines two quaternions to apply their rotations sequentially.
vec4 TDQuaternionMultiply(vec4 Q1, vec4 Q2);
// Performs spherical linear interpolation between two quaternions.
vec4 TDSlerpQuaternions(vec4 q0, vec4 q1, float t);
// Extracts the pure rotation component from a 4×4 transform matrix.
mat3 TDExtractRotation(mat4 m);
// Interpolates smoothly between two rotation matrices via quaternion slerp.
mat3 TDSlerpRotationMatrices(mat3 m0, mat3 m1, float t);
// Interpolates translation, rotation, and scale between two transform matrices.
mat4 TDInterpolateTransformMatrices(mat4 m0, mat4 m1, float t);
// Computes the quaternion that rotates one vector direction into another.
vec4 TDQuaternionFromTo(vec3 from, vec3 to);
Noise Functionsedit
// Returns <code>t*t*t*(t*(t*6.0-15.0)+10.0);</code>.
float TDFade(float t);
// Perlin 2D,3D,4D noise functions
float TDPerlinNoise(vec2 P);
float TDPerlinNoise(vec3 P);
float TDPerlinNoise(vec4 P);
// Simplex 2D,3D,4D noise functions
float TDSimplexNoise(vec2 P);
float TDSimplexNoise(vec3 P);
float TDSimplexNoise(vec4 P);
// Derivative of the TDFade() function. Returns <code>30*t*t*(t*(t-2)+1)</code>
float TDFadeDeriv(float t);
// Gradients of the TDPerlinNoise() functions. The gradient is an analytical derivative, calculated in the noise space.
vec4 TDPerlinNoiseDeriv(vec2 P);
vec4 TDPerlinNoiseDeriv(vec3 P);
vec4 TDPerlinNoiseDeriv(vec4 P, out float outNoise);
vec4 TDPerlinNoiseDeriv(vec4 P);
// Gradients of the TDSimplexNoise() functions. The gradient is an analytical derivative, calculated in the noise space.
vec4 TDSimplexNoiseDeriv(vec2 P);
vec4 TDSimplexNoiseDeriv(vec3 P);
vec4 TDSimplexNoiseDeriv(vec4 P, out float outNoise);
vec4 TDSimplexNoiseDeriv(vec4 P);
Color Space Functionsedit
The TDTransfer* functions will convert between a linear and non-linear transfer for the color data. If a vec4 is provided then the RGB will be un-premultipled by Alpha before applying the operation, and then then mulitpled by alpha again at the end.
// TDBasicColorSpace
vec3 TDTransferLinearToSRGB(vec3 c);
vec4 TDTransferLinearToSRGB(vec4 c);
vec3 TDTransferSRGBToLinear(vec3 c);
vec4 TDTransferSRGBToLinear(vec4 c);
// TDColorSpace
vec3 TDTransferLinearToRec709(vec3 c);
vec3 TDTransferRec709ToLinear(vec3 c);
vec3 TDTransferLinearToGamma1_8(vec3 c);
vec3 TDTransferLinearToGamma2_2(vec3 c);
vec3 TDTransferLinearToGamma2_4(vec3 c);
vec3 TDTransferLinearToGamma2_6(vec3 c);
vec3 TDTransferLinearToGamma2_8(vec3 c);
vec3 TDTransferACESproxyToLinear(vec3 c);
vec3 TDTransferLinearToACESproxy(vec3 c);
vec3 TDTransferGamma1_8ToLinear(vec3 c);
vec3 TDTransferGamma2_2ToLinear(vec3 c);
vec3 TDTransferGamma2_4ToLinear(vec3 c);
vec3 TDTransferGamma2_6ToLinear(vec3 c);
vec3 TDTransferGamma2_8ToLinear(vec3 c);
// referenceWhiteNits denotes what brightness in nits a value of 1.0 will be for the linear data.
vec3 TDTransferLinearToST2084PQ(vec3 color, float referenceWhiteNits);
vec3 TDTransferST2084PQToLinear(vec3 color, float referenceWhiteNits);
vec3 TDTransferBT2100HLGToLinear(vec3 color, float peakNits, float referenceWhiteNits);
vec3 TDTransferLinearToBT2100HLG(vec3 color, float peakNits, float referenceWhiteNits);
vec3 TDGamutRec709ToRec2020(vec3 c);
vec3 TDGamutRec2020ToRec709(vec3 c);