Support Forum       G3D Web Page     
Classes | Public Member Functions | Public Attributes | List of all members
glsl::g3dmath_glsl Class Reference

Shader program. More...

Classes

struct  Ray
 

Public Member Functions

mat3 _referenceFrameFromZAxis (vec3 n)
 
BUGGY More...
 
float computeSampleRate (vec2 texCoord, vec2 samplerSize)
 
Computes 2^mipLevel, avoiding the expensive log2 call needed for the actual MIP level. More...
 
float computeToksvigGlossyExponent (float rawGlossyExponent, float rawNormalLength)
 http://blog.selfshadow.com/2011/07/22/specular-showdown/ More...
 
vec3 cosPowHemiRandom (vec2 r, const float k)
 Returns cos^k distributed random values distributed on the hemisphere about +z. More...
 
uint expandBits (uint v)
 Expands a 10-bit integer into 30 bits by inserting 2 zeros after each bit. More...
 
uint extractEvenBits (uint x)
 
vec3 hammersleyCosHemi (uint i, const uint N)
 
Generate the ith 2D Hammersley point out of N on the cosine-weighted unit hemisphere with Z = up. More...
 
vec3 hammersleyHemi (uint i, const uint N)
 
Generate the ith 2D Hammersley point out of N on the cosine-weighted unit hemisphere with Z = up. More...
 
vec2 hammersleySquare (uint i, const uint N)
 
Generate the ith 2D Hammersley point out of N on the unit square [0, 1]^2 More...
 
vec3 hemisphereRandom (vec2 r)
 
vec3 HSVtoRGB (vec3 c)
 
mat4x4 identity4x4 ()
 
int indexOfMaxComponent (vec3 v)
 Returns the index of the largest element. More...
 
int indexOfMaxComponent (vec2 v)
 Returns the index of the largest element. More...
 
int indexOfMaxComponent (float v)
 Returns zero. More...
 
float infIfNegative (float x)
 
uint interleaveBits (uvec3 inputval)
 Calculates a 30-bit Morton code for the given 3D point located within the unit cube [0,1]. More...
 
bool isFinite (float x)
 
gentype lengthSquared ($(vectype) v)
 
float max3 (float a, float b, float c)
 
float max4 (float a, float b, float c, float d)
 
float maxComponent (vec2 a)
 
float maxComponent (vec3 a)
 
float maxComponent (vec4 a)
 
float mean (float a)
 
float mean (vec2 a)
 
float mean (vec3 a)
 
float mean (vec4 a)
 
float meanComponent (vec4 a)
 
float meanComponent (vec3 a)
 
float meanComponent (vec2 a)
 
float meanComponent (float a)
 
float min3 (float a, float b, float c)
 
float min4 (float a, float b, float c, float d)
 
float minComponent (vec2 a)
 
float minComponent (vec3 a)
 
float minComponent (vec4 a)
 
float mipMapLevel (in vec2 texture_coordinate, in vec2 textureSize)
 Computes the MIP-map level for a texture coordinate. More...
 
float norm1 (vec3 v)
 
float norm2 (vec3 v)
 
float norm4 (vec2 v)
 L^4 norm. More...
 
float norm8 (vec2 v)
 L^8 norm. More...
 
float normInf (vec3 v)
 
float packGlossyExponent (in float blinnPhongExponent)
 
mat4x4 pitch4x4 (float a)
 Constructs a 4x4 Y->Z rotation matrix, assuming R * v multiplication. More...
 
gentype pow16 ($(gentype) x)
 Compute x^8. More...
 
gentype pow2 ($(gentype) x)
 
gentype pow3 ($(gentype) x)
 
gentype pow4 ($(gentype) x)
 Compute x^4. More...
 
gentype pow5 ($(gentype) x)
 Computes x5 More...
 
gentype pow6 ($(gentype) x)
 Compute x^6. More...
 
gentype pow64 ($(gentype) v)
 Compute v^64. More...
 
gentype pow7 ($(gentype) x)
 
gentype pow8 ($(gentype) x)
 Compute x^8. More...
 
mat3 referenceFrameFromZAxis (vec3 z)
 Given a z-axis, construct an orthonormal tangent space. More...
 
float RGBtoCIELuminance (vec3 linearRGB)
 CIE luminance (Y) of linearRGB value (not sRGB!) More...
 
vec3 RGBtoHSV (vec3 c)
 
mat4x4 roll4x4 (float a)
 Constructs a 4x4 X->Y rotation matrix, assuming R * v multiplication. More...
 
vec3 schlickFresnel (in vec3 F0, in float cos_i, float smoothness)
 Compute Schlick's approximation of the Fresnel coefficient. More...
 
float signNotZero (in float k)
 
vec2 signNotZero (in vec2 v)
 
gentype smootherstep ($(gentype) edge0, $(gentype) edge1, $(gentype) x)
 
Perlin's smootherstep that is analogous to smoothstep() but has zero 1st and 2nd order derivatives at t=0 and t=1, from Texturing and Modeling, Third Edition: A Procedural Approach (see http://en.wikipedia.org/wiki/Smoothstep) More...
 
gentype smootherstep (float edge0, float edge1, $(gentype) x)
 
float smoothnessToBlinnPhongExponent (in float g3dSmoothness)
 Matches UniversalBSDF::smoothnessToBlinnPhongExponent. More...
 
vec3 sphereRandom (vec2 r)
 
vec3 sphericalFibonacci (float i, float n)
 Generate a spherical fibonacci point http://lgdv.cs.fau.de/publications/publication/Pub.2015.tech.IMMD.IMMD9.spheri/ To generate a nearly uniform point distribution on the unit sphere of size N, do for (float i = 0.0; i < N; i += 1.0) { float3 point = sphericalFibonacci(i,N); }. More...
 
gentype square ($(gentype) x)
 
float sum (float a)
 
float sum (vec2 a)
 
float sum (vec3 a)
 
float sum (vec4 a)
 
void swap (inout $(gentype) a, inout $(gentype) b)
 
vec4 textureLodBicubic (sampler2D tex, vec2 uv, int lod)
 
Implementation of Sigg and Hadwiger's Fast Third-Order Texture Filtering More...
 
vec4 textureLodSmooth (sampler2D tex, vec2 uv, int lod)
 
A bicubic magnification filter, primarily useful for magnifying LOD 0 without bilinear magnification artifacts. More...
 
mat4x4 translate4x4 (vec3 t)
 Constructs a 4x4 translation matrix, assuming T * v multiplication. More...
 
gentype unitSmootherstep ($(gentype) x)
 Avoids the clamping and division for smootherstep(0, 1, x) when x is known to be on the range [0, 1]. More...
 
gentype unitSmoothstep ($(gentype) x)
 Avoids the clamping and division for smoothstep(0, 1, x) when x is known to be on the range [0, 1]. More...
 
mat4x4 yaw4x4 (float a)
 Constructs a 4x4 Z->X rotation matrix, assuming R * v multiplication. More...
 

Public Attributes

const float centimeters = 0.01
 
const float inf
 32-bit floating-point infinity More...
 
const float inv8Pi = 1.0 / (8.0 * pi)
 
const float invPi = 1.0 / pi
 1 / pi More...
 
const float meters = 1.0
 
const float millimeters = 0.001
 
const float pi = 3.1415927
 Ratio of unit circle perimeter to its diameter. More...
 

Detailed Description

Shader program.

Member Function Documentation

◆ _referenceFrameFromZAxis()

mat3 glsl::g3dmath_glsl::_referenceFrameFromZAxis ( vec3  n)
inline


BUGGY

Given a z-axis (n), construct an orthonormal tangent space. Assumes z is a unit vector.

From http://jcgt.org/published/0006/01/01/ listing 3

Parameters
nThe unit z-axis (3rd column of the output)
Returns
The matrix

◆ computeSampleRate()

float glsl::g3dmath_glsl::computeSampleRate ( vec2  texCoord,
vec2  samplerSize 
)
inline


Computes 2^mipLevel, avoiding the expensive log2 call needed for the actual MIP level.

◆ computeToksvigGlossyExponent()

float glsl::g3dmath_glsl::computeToksvigGlossyExponent ( float  rawGlossyExponent,
float  rawNormalLength 
)
inline

◆ cosPowHemiRandom()

vec3 glsl::g3dmath_glsl::cosPowHemiRandom ( vec2  r,
const float  k 
)
inline

Returns cos^k distributed random values distributed on the hemisphere about +z.

Parameters
rTwo uniform random numbers on [0,1] See also cosHemiRandom texture.

◆ expandBits()

uint glsl::g3dmath_glsl::expandBits ( uint  v)
inline

Expands a 10-bit integer into 30 bits by inserting 2 zeros after each bit.

◆ extractEvenBits()

uint glsl::g3dmath_glsl::extractEvenBits ( uint  x)
inline

◆ hammersleyCosHemi()

vec3 glsl::g3dmath_glsl::hammersleyCosHemi ( uint  i,
const uint  N 
)
inline


Generate the ith 2D Hammersley point out of N on the cosine-weighted unit hemisphere with Z = up.

Referenced Code: http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html

◆ hammersleyHemi()

vec3 glsl::g3dmath_glsl::hammersleyHemi ( uint  i,
const uint  N 
)
inline


Generate the ith 2D Hammersley point out of N on the cosine-weighted unit hemisphere with Z = up.

Referenced Code: http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html

◆ hammersleySquare()

vec2 glsl::g3dmath_glsl::hammersleySquare ( uint  i,
const uint  N 
)
inline


Generate the ith 2D Hammersley point out of N on the unit square [0, 1]^2

Referenced Code: http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html

◆ hemisphereRandom()

vec3 glsl::g3dmath_glsl::hemisphereRandom ( vec2  r)
inline
Parameters
rTwo uniform random numbers on [0,1]
Returns
uniformly distributed random sample on unit hemisphere about +z See also hemisphereRandom texture.

◆ HSVtoRGB()

vec3 glsl::g3dmath_glsl::HSVtoRGB ( vec3  c)
inline
Referenced Code: http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl

◆ identity4x4()

mat4x4 glsl::g3dmath_glsl::identity4x4 ( )
inline

◆ indexOfMaxComponent() [1/3]

int glsl::g3dmath_glsl::indexOfMaxComponent ( vec3  v)
inline

Returns the index of the largest element.

◆ indexOfMaxComponent() [2/3]

int glsl::g3dmath_glsl::indexOfMaxComponent ( vec2  v)
inline

Returns the index of the largest element.

◆ indexOfMaxComponent() [3/3]

int glsl::g3dmath_glsl::indexOfMaxComponent ( float  v)
inline

Returns zero.

◆ infIfNegative()

float glsl::g3dmath_glsl::infIfNegative ( float  x)
inline

◆ interleaveBits()

uint glsl::g3dmath_glsl::interleaveBits ( uvec3  inputval)
inline

Calculates a 30-bit Morton code for the given 3D point located within the unit cube [0,1].

◆ isFinite()

bool glsl::g3dmath_glsl::isFinite ( float  x)
inline

◆ lengthSquared()

gentype glsl::g3dmath_glsl::lengthSquared (   $(vectype))
inline

◆ max3()

float glsl::g3dmath_glsl::max3 ( float  a,
float  b,
float  c 
)
inline

◆ max4()

float glsl::g3dmath_glsl::max4 ( float  a,
float  b,
float  c,
float  d 
)
inline

◆ maxComponent() [1/3]

float glsl::g3dmath_glsl::maxComponent ( vec2  a)
inline

◆ maxComponent() [2/3]

float glsl::g3dmath_glsl::maxComponent ( vec3  a)
inline

◆ maxComponent() [3/3]

float glsl::g3dmath_glsl::maxComponent ( vec4  a)
inline

◆ mean() [1/4]

float glsl::g3dmath_glsl::mean ( float  a)
inline

◆ mean() [2/4]

float glsl::g3dmath_glsl::mean ( vec2  a)
inline

◆ mean() [3/4]

float glsl::g3dmath_glsl::mean ( vec3  a)
inline

◆ mean() [4/4]

float glsl::g3dmath_glsl::mean ( vec4  a)
inline

◆ meanComponent() [1/4]

float glsl::g3dmath_glsl::meanComponent ( vec4  a)
inline

◆ meanComponent() [2/4]

float glsl::g3dmath_glsl::meanComponent ( vec3  a)
inline

◆ meanComponent() [3/4]

float glsl::g3dmath_glsl::meanComponent ( vec2  a)
inline

◆ meanComponent() [4/4]

float glsl::g3dmath_glsl::meanComponent ( float  a)
inline

◆ min3()

float glsl::g3dmath_glsl::min3 ( float  a,
float  b,
float  c 
)
inline

◆ min4()

float glsl::g3dmath_glsl::min4 ( float  a,
float  b,
float  c,
float  d 
)
inline

◆ minComponent() [1/3]

float glsl::g3dmath_glsl::minComponent ( vec2  a)
inline

◆ minComponent() [2/3]

float glsl::g3dmath_glsl::minComponent ( vec3  a)
inline

◆ minComponent() [3/3]

float glsl::g3dmath_glsl::minComponent ( vec4  a)
inline

◆ mipMapLevel()

float glsl::g3dmath_glsl::mipMapLevel ( in vec2  texture_coordinate,
in vec2  textureSize 
)
inline

Computes the MIP-map level for a texture coordinate.

Referenced Code: The OpenGL Graphics System: A Specification 4.2
chapter 3.9.11, equation 3.21

◆ norm1()

float glsl::g3dmath_glsl::norm1 ( vec3  v)
inline

◆ norm2()

float glsl::g3dmath_glsl::norm2 ( vec3  v)
inline

◆ norm4()

float glsl::g3dmath_glsl::norm4 ( vec2  v)
inline

L^4 norm.

◆ norm8()

float glsl::g3dmath_glsl::norm8 ( vec2  v)
inline

L^8 norm.

◆ normInf()

float glsl::g3dmath_glsl::normInf ( vec3  v)
inline

◆ packGlossyExponent()

float glsl::g3dmath_glsl::packGlossyExponent ( in float  blinnPhongExponent)
inline

◆ pitch4x4()

mat4x4 glsl::g3dmath_glsl::pitch4x4 ( float  a)
inline

Constructs a 4x4 Y->Z rotation matrix, assuming R * v multiplication.

a is in radians.

◆ pow16()

gentype glsl::g3dmath_glsl::pow16 (   $(gentype))
inline

Compute x^8.

◆ pow2()

gentype glsl::g3dmath_glsl::pow2 (   $(gentype))
inline

◆ pow3()

gentype glsl::g3dmath_glsl::pow3 (   $(gentype))
inline

◆ pow4()

gentype glsl::g3dmath_glsl::pow4 (   $(gentype))
inline

Compute x^4.

◆ pow5()

gentype glsl::g3dmath_glsl::pow5 (   $(gentype))
inline

Computes x5

◆ pow6()

gentype glsl::g3dmath_glsl::pow6 (   $(gentype))
inline

Compute x^6.

◆ pow64()

gentype glsl::g3dmath_glsl::pow64 (   $(gentype))
inline

Compute v^64.

◆ pow7()

gentype glsl::g3dmath_glsl::pow7 (   $(gentype))
inline

◆ pow8()

gentype glsl::g3dmath_glsl::pow8 (   $(gentype))
inline

Compute x^8.

◆ referenceFrameFromZAxis()

mat3 glsl::g3dmath_glsl::referenceFrameFromZAxis ( vec3  z)
inline

Given a z-axis, construct an orthonormal tangent space.

Assumes z is a unit vector.

Deprecated:

◆ RGBtoCIELuminance()

float glsl::g3dmath_glsl::RGBtoCIELuminance ( vec3  linearRGB)
inline

CIE luminance (Y) of linearRGB value (not sRGB!)

◆ RGBtoHSV()

vec3 glsl::g3dmath_glsl::RGBtoHSV ( vec3  c)
inline
Referenced Code: http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl

◆ roll4x4()

mat4x4 glsl::g3dmath_glsl::roll4x4 ( float  a)
inline

Constructs a 4x4 X->Y rotation matrix, assuming R * v multiplication.

a is in radians.

◆ schlickFresnel()

vec3 glsl::g3dmath_glsl::schlickFresnel ( in vec3  F0,
in float  cos_i,
float  smoothness 
)
inline

Compute Schlick's approximation of the Fresnel coefficient.

The original goes to 1.0 at glancing angles, which makes objects appear to glow, so we scale it down to 0.9.

We never put a Fresnel term on perfectly diffuse surfaces, so, if F0 is exactly black, then we keep the result black.

◆ signNotZero() [1/2]

float glsl::g3dmath_glsl::signNotZero ( in float  k)
inline

◆ signNotZero() [2/2]

vec2 glsl::g3dmath_glsl::signNotZero ( in vec2  v)
inline

◆ smootherstep() [1/2]

gentype glsl::g3dmath_glsl::smootherstep (   $(gentype),
  $(gentype),
  $(gentype) 
)
inline


Perlin's smootherstep that is analogous to smoothstep() but has zero 1st and 2nd order derivatives at t=0 and t=1, from Texturing and Modeling, Third Edition: A Procedural Approach (see http://en.wikipedia.org/wiki/Smoothstep)

◆ smootherstep() [2/2]

gentype glsl::g3dmath_glsl::smootherstep ( float  edge0,
float  edge1,
  $(gentype) 
)
inline

◆ smoothnessToBlinnPhongExponent()

float glsl::g3dmath_glsl::smoothnessToBlinnPhongExponent ( in float  g3dSmoothness)
inline

Matches UniversalBSDF::smoothnessToBlinnPhongExponent.

Maps smoothness [0, 1] to Blinn-Phong exponent [0, infinity].

◆ sphereRandom()

vec3 glsl::g3dmath_glsl::sphereRandom ( vec2  r)
inline
Parameters
rTwo uniform random numbers on [0,1]
Returns
uniformly distributed random sample on unit sphere

http://mathworld.wolfram.com/SpherePointPicking.html

See also g3d_sphereRandom texture and sphericalFibonacci()

◆ sphericalFibonacci()

vec3 glsl::g3dmath_glsl::sphericalFibonacci ( float  i,
float  n 
)
inline

Generate a spherical fibonacci point http://lgdv.cs.fau.de/publications/publication/Pub.2015.tech.IMMD.IMMD9.spheri/ To generate a nearly uniform point distribution on the unit sphere of size N, do for (float i = 0.0; i < N; i += 1.0) { float3 point = sphericalFibonacci(i,N); }.

The points go from z = +1 down to z = -1 in a spiral. To generate samples on the +z hemisphere, just stop before i > N/2.

◆ square()

gentype glsl::g3dmath_glsl::square (   $(gentype))
inline

◆ sum() [1/4]

float glsl::g3dmath_glsl::sum ( float  a)
inline

◆ sum() [2/4]

float glsl::g3dmath_glsl::sum ( vec2  a)
inline

◆ sum() [3/4]

float glsl::g3dmath_glsl::sum ( vec3  a)
inline

◆ sum() [4/4]

float glsl::g3dmath_glsl::sum ( vec4  a)
inline

◆ swap()

void glsl::g3dmath_glsl::swap ( inout $(gentype)  a,
inout $(gentype)  b 
)
inline

◆ textureLodBicubic()

vec4 glsl::g3dmath_glsl::textureLodBicubic ( sampler2D  tex,
vec2  uv,
int  lod 
)
inline


Implementation of Sigg and Hadwiger's Fast Third-Order Texture Filtering

http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter20.html

Referenced Code: http://vec3.ca/bicubic-filtering-in-fewer-taps/
Referenced Code: http://pastebin.com/raw.php?i=YLLSBRFq

◆ textureLodSmooth()

vec4 glsl::g3dmath_glsl::textureLodSmooth ( sampler2D  tex,
vec2  uv,
int  lod 
)
inline


A bicubic magnification filter, primarily useful for magnifying LOD 0 without bilinear magnification artifacts.

This just adjusts the rate at which we move between taps, not the number of taps.

Referenced Code: https://www.shadertoy.com/view/4df3Dn

◆ translate4x4()

mat4x4 glsl::g3dmath_glsl::translate4x4 ( vec3  t)
inline

Constructs a 4x4 translation matrix, assuming T * v multiplication.

◆ unitSmootherstep()

gentype glsl::g3dmath_glsl::unitSmootherstep (   $(gentype))
inline

Avoids the clamping and division for smootherstep(0, 1, x) when x is known to be on the range [0, 1].

◆ unitSmoothstep()

gentype glsl::g3dmath_glsl::unitSmoothstep (   $(gentype))
inline

Avoids the clamping and division for smoothstep(0, 1, x) when x is known to be on the range [0, 1].

◆ yaw4x4()

mat4x4 glsl::g3dmath_glsl::yaw4x4 ( float  a)
inline

Constructs a 4x4 Z->X rotation matrix, assuming R * v multiplication.

a is in radians.

Member Data Documentation

◆ centimeters

const float glsl::g3dmath_glsl::centimeters = 0.01

◆ inf

const float glsl::g3dmath_glsl::inf
Initial value:
=
1.0 / 0.0

32-bit floating-point infinity

◆ inv8Pi

const float glsl::g3dmath_glsl::inv8Pi = 1.0 / (8.0 * pi)

◆ invPi

const float glsl::g3dmath_glsl::invPi = 1.0 / pi

1 / pi

◆ meters

const float glsl::g3dmath_glsl::meters = 1.0

◆ millimeters

const float glsl::g3dmath_glsl::millimeters = 0.001

◆ pi

const float glsl::g3dmath_glsl::pi = 3.1415927

Ratio of unit circle perimeter to its diameter.


documentation generated on Wed Nov 24 2021 08:02:04 using doxygen 1.8.15