Skip to main content

Complete Function Reference

Mathematical Functions

Trigonometric Functions

FunctionDescriptionParametersReturn TypeVector Support
sin(x)Sinefloat|vec*Input type
cos(x)Cosinefloat|vec*Input type
tan(x)Tangentfloat|vec*Input type
asin(x)Arcsinefloat|vec*Input type
acos(x)Arccosinefloat|vec*Input type
atan(x)Arctangentfloat|vec*Input type
atan2(y, x)Two-argument arctangentfloat|vec*, float|vec*Higher precision type
// 基本的な三角関数
const angle = uniform('angle')
const wave = sin(angle.mul(PI))
const circle = vec2(cos(angle), sin(angle))

// 複数角の計算
const multiWave = sin(angle.mul(3)).add(cos(angle.mul(5)).mul(0.5))

Exponential Functions

FunctionDescriptionParametersReturn TypeVector Support
pow(x, y)Powerfloat|vec*, float|vec*Higher precision type
pow2(x)Squarefloat|vec*Input type
pow3(x)Cubefloat|vec*Input type
pow4(x)Fourth powerfloat|vec*Input type
sqrt(x)Square rootfloat|vec*Input type
inverseSqrt(x)Inverse square rootfloat|vec*Input type
exp(x)Natural exponentialfloat|vec*Input type
exp2(x)Base-2 exponentialfloat|vec*Input type
log(x)Natural logarithmfloat|vec*Input type
log2(x)Base-2 logarithmfloat|vec*Input type
// 指数・対数関数の使用例
const falloff = exp(distance.negate())
const brightness = pow(dot(normal, lightDir), shininess)
const octaves = log2(resolution)

Common Mathematical Functions

FunctionDescriptionParametersReturn TypeVector Support
abs(x)Absolute valuefloat|vec*Input type
sign(x)Sign extractionfloat|vec*Input type
floor(x)Floor functionfloat|vec*Input type
ceil(x)Ceiling functionfloat|vec*Input type
round(x)Round to nearestfloat|vec*Input type
fract(x)Fractional partfloat|vec*Input type
trunc(x)Truncatefloat|vec*Input type
mod(x, y)Modulofloat|vec*, float|vec*Higher precision type
// 基本数学関数の組み合わせ
const pattern = fract(position.mul(10))
const stepped = floor(value.mul(8)).div(8)
const ping_pong = abs(fract(time.mul(0.5)).mul(2).sub(1))

Interpolation Functions

FunctionDescriptionParametersReturn TypeVector Support
min(x, y)Minimumfloat|vec*, float|vec*Higher precision type
max(x, y)Maximumfloat|vec*, float|vec*Higher precision type
clamp(x, min, max)Clamp to rangefloat|vec*, float|vec*, float|vec*Higher precision type
saturate(x)Clamp to 0-1float|vec*Input type
mix(x, y, a)Linear interpolationfloat|vec*, float|vec*, float|vec*Higher precision type
step(edge, x)Step functionfloat|vec*, float|vec*Higher precision type
smoothstep(a, b, x)Smooth stepfloat|vec*, float|vec*, float|vec*Higher precision type
// 補間関数の活用
const gradient = smoothstep(0.2, 0.8, position.y)
const masked = mix(colorA, colorB, gradient)
const threshold = step(0.5, noise)

Vector Functions

Vector Operations

FunctionDescriptionParametersReturn TypeNotes
length(x)Vector lengthvec*floatEuclidean norm
distance(x, y)Distance between pointsvec*, vec*floatEuclidean distance
dot(x, y)Dot productvec*, vec*floatScalar product
cross(x, y)Cross productvec3, vec3vec33D only
normalize(x)Unit vectorvec*Input typeLength = 1
lengthSq(x)Squared lengthvec*floatFaster than length
// ベクトル演算の実用例
const lightDir = normalize(lightPos.sub(worldPos))
const intensity = max(0, dot(normal, lightDir))
const reflection = reflect(viewDir.negate(), normal)

Vector Utilities

FunctionDescriptionParametersReturn TypeNotes
reflect(I, N)Reflection vectorvec*, vec*Input typeMirror reflection
refract(I, N, eta)Refraction vectorvec*, vec*, floatInput typeSnell's law
faceforward(N, I, Nref)Orient normalvec*, vec*, vec*Input typeConsistent orientation
// 物理的なベクトル計算
const reflected = reflect(incident, normal)
const refracted = refract(incident, normal, ior)
const oriented = faceforward(normal, viewDir, geometryNormal)

Derivative Functions

FunctionDescriptionParametersReturn TypeFragment Only
dFdx(x)X-direction derivativefloat|vec*Input type
dFdy(x)Y-direction derivativefloat|vec*Input type
fwidth(x)Derivative widthfloat|vec*Input type
// 偏微分を使った計算
const normalFromHeight = normalize(vec3(dFdx(heightmap).negate(), dFdy(heightmap).negate(), 1))

const antialiasing = smoothstep(0, fwidth(pattern), pattern)

Logical Functions

Boolean Vector Functions

FunctionDescriptionParametersReturn TypeNotes
all(x)All components truebvec*boolLogical AND
any(x)Any component truebvec*boolLogical OR
not(x)Component-wise NOTbvec*Input typeLogical NOT
// 論理演算の応用
const inBounds = all(position.greaterThan(vec3(0)).and(position.lessThan(vec3(1))))
const hasColor = any(color.greaterThan(vec3(0)))

Utility Functions

Custom Utility Functions

FunctionDescriptionParametersReturn TypeNotes
oneMinus(x)One minus xfloat|vec*Input type1 - x
negate(x)Negate valuefloat|vec*Input type-x
reciprocal(x)Reciprocalfloat|vec*Input type1/x
remap(x, a, b, c, d)Remap rangefloat|vec*, ...Input typeLinear remapping
remapClamp(x, a, b, c, d)Clamped remapfloat|vec*, ...Input typeClamped remapping
// ユーティリティ関数の活用
const inverted = oneMinus(brightness)
const normalized = remap(worldPos.y, -100, 100, 0, 1)
const safety = reciprocal(max(EPSILON, denominator))

Geometric Functions

2D Transformations

FunctionDescriptionParametersReturn TypeNotes
rotate(pos, angle)2D rotationvec2, floatvec2Around origin
scale(pos, factor)2D scalingvec2, vec2|floatvec2Non-uniform scaling
// 2D幾何変換
const rotated = rotate(uv.sub(0.5), time).add(0.5)
const scaled = scale(uv, vec2(2, 1))

Noise and Random Functions

Pseudorandom Functions

FunctionDescriptionParametersReturn TypeNotes
hash(seed)Hash functionfloat|vec*float0-1 range
range(min, max)Random rangefloat, floatfloatAttribute-based
// ランダム関数の使用
const randomValue = hash(position.add(time))
const randomColor = vec3(hash(position), hash(position.add(1)), hash(position.add(2)))

Oscillator Functions

Wave Generation

FunctionDescriptionParametersReturn TypeNotes
oscSine(t)Sine wavefloatfloat-1 to 1
oscSquare(t)Square wavefloatfloat-1 to 1
oscTriangle(t)Triangle wavefloatfloat-1 to 1
oscSawtooth(t)Sawtooth wavefloatfloat-1 to 1
// オシレーター関数の組み合わせ
const wave = oscSine(time.mul(2))
.add(oscTriangle(time.mul(4)).mul(0.5))
.add(oscSquare(time.mul(8)).mul(0.25))

Color Space Functions

Color Utilities

FunctionDescriptionParametersReturn TypeNotes
directionToColor(dir)Direction to colorvec3vec3Normal encoding
colorToDirection(col)Color to directionvec3vec3Normal decoding
// 色空間の変換
const encoded = directionToColor(normal)
const decoded = colorToDirection(normalTexture)

Blend Mode Functions

Color Blending

FunctionDescriptionParametersReturn TypeNotes
blendBurn(a, b)Burn blendvec3, vec3vec3Color burn
blendDodge(a, b)Dodge blendvec3, vec3vec3Color dodge
blendOverlay(a, b)Overlay blendvec3, vec3vec3Overlay mode
blendScreen(a, b)Screen blendvec3, vec3vec3Screen mode
blendColor(a, b)Normal blendvec3, vec3vec3Alpha blend
// ブレンドモードの適用
const result = blendOverlay(baseColor, overlayColor)
const highlight = blendScreen(color, lightColor)

GLRE の Node System は、150 以上の数学関数とユーティリティを提供し、あらゆるシェーダープログラミングのニーズに対応します。