fennec
Loading...
Searching...
No Matches
Geometric

The Geometric Functions defined in the OpenGL 4.6 Shading Language Specification.

Geometric Functions

Syntax Description

float dot(genFType x, genFType y)
double dot(genDType x, genDType x)

Returns the dot product of \(x\) and \(y\), i.e., \(x_0 \cdot y_0 + x_1 \cdot y_1 + \ldots\).

Returns
the dot product of \(x\) and \(y\), i.e., \(x_0 \cdot y_0 + x_0 \cdot y_0 + \ldots\)

we can represent this in linear algebra as the following,

let \(X=\left[\begin{array}\\ x_0 \\ x_1 \\ \vdots \\ x_N \end{array}\right]\)
let \(Y=\left[\begin{array}\\ y_0 \\ y_1 \\ \vdots \\ y_N \end{array}\right]\)

then \(\text{dot}(X, Y)=X \cdot Y^T\)

Parameters
xfirst vector
ysecond vector

float length2(genFType x)
double length2(genDType x)

Returns the squared length of vector \(x\), i.e., \(x_0^2 + x_1^2 + \ldots\).

Returns
the squared length of vector \(x\), i.e., \(x_0^2 + x_1^2 + \ldots\)

we can represent this in linear algebra as the following,

let \(X=\left[\begin{array}\\ x_0 \\ x_1 \\ \vdots \\ x_N \end{array}\right]\)

then \(\text{length2}(X)=X \cdot X^T\)

Parameters
xthe vector

float length(genFType x)
double length(genDType x)

Returns the length of vector \(x\), i.e., \(\sqrt{x_0^2 + x_1^2 + \ldots}\).

Returns
the length of vector \(x\), i.e., \(\sqrt{x_0^2 + x_1^2 + \ldots}\)

we can represent this in linear algebra as the following,

let \(X=\left[\begin{array}\\ x_0 \\ x_1 \\ \vdots \\ x_N \end{array}\right]\)

then, \(\text{length}(X)=\left|\left|X\right|\right|\)

Parameters
xthe vector

float distance(genFType x, genFType y)
double distance(genDType x, genDType x)

Returns the length of vector \(x\), i.e., \(\sqrt{x_0^2 + x_1^2 + \ldots}\).

Returns
the distance between \(p_0\) and \(p_1\), i.e., \(\left|{p_1-p_0}\right|\)

we can represent this in linear algebra as the following,

let \(X=\left[\begin{array}\\ x_0 \\ x_1 \\ \vdots \\ x_N \end{array}\right]\)
let \(Y=\left[\begin{array}\\ y_0 \\ y_1 \\ \vdots \\ y_N \end{array}\right]\)

then \(\text{distance}(X, Y)=\left|\left|Y-X\right|\right|\)

Parameters
p0first vector
p1second vector

float normalize(genFType x)
double normalize(genDType x)

Returns a vector in the same direction as \(x\), but with a length of \(1\), i.e.

Returns
a vector in the same direction as \(x\), but with a length of \(1\), i.e. \(\frac{x}{||x||}\)

we can represent this in linear algebra as the following,

let \(X=\left[\begin{array}\\ x_0 \\ x_1 \\ \vdots \\ x_N \end{array}\right]\)

then, \(\text{length}(X)=\frac{X}{\left|\left|X\right|\right|}\)

Parameters
x

vec3 cross(vec3 x, vec3 y)
dvec3 cross(dvec3 x, dvec3 x)

Returns the cross product of \(x\) and \(y\), i.e., \(\left({x_1 \cdot y_2 - y_1 \cdot x_2, x_2 \cdot y_0 - y_2 \cdot x_0, x_0 \cdot y_1 - y_0 \cdot x_1}\right)\).

Returns
the cross product of \(x\) and \(y\), i.e., \(\left({x_1 \cdot y_2 - y_1 \cdot x_2, x_2 \cdot y_0 - y_2 \cdot x_0, x_0 \cdot y_1 - y_0 \cdot x_1}\right)\)

we can represent this in linear algebra as the following,

let \(X=\left[\begin{array}\\ x_0 \\ x_1 \\ \vdots \\ x_N \end{array}\right]\)
let \(Y=\left[\begin{array}\\ y_0 \\ y_1 \\ \vdots \\ y_N \end{array}\right]\)

then \(\text{cross}(X, Y)=X \times Y\)

Parameters
xfirst vector
ysecond vector

genFType faceforward(genFType N, genFType I, genFType Nref)
genDType faceforward(genDType N, genDType I, genDType Nref)

If \(\text{dot}(Nref, I)<0\) return \(N\), otherwise return \(-N\).

Returns
\(N\) if \(\text{dot}(Nref,I)<0\), otherwise, returns \(-N\).

Parameters
Nthe vector
Ithe incident
Nrefthe reference

genFType reflect(genFType I, genFType N)
genDType reflect(genDType I, genDType N)

For the incident vector \(I\) and surface orientation \(N\), returns the reflection direction.

Returns
The reflection direction, given the incident vector \(I\) and surface orientation \(N\)

We can express this as,

\(\text{reflect}(I, N) = I - 2 N \cdot \text{dot}(N, I)\)

Parameters
Ithe incident
Nthe surface orientation

genFType refract(genFType N, genFType I, float eta)
genDType refract(genDType N, genDType I, double eta)

For the incident vector \(I\) and surface normal \(N\), and the ratio of indices of refraction \(eta\), return the refraction vector.

Returns
The refraction vector, given the incident vector \(I\), surface normal \(N\), and ratio \(eta\).

The result is computed by the refraction equation,

let \(k=1.0-eta^2 \cdot (1.0 - \text{dot}(N, I)^2)\)
then, \(\text{refract}(I, N, eta)=\begin{cases} 0.0 & k<0.0, \\ eta \cdot I - N \cdot (eta \cdot \text{dot}(N, I) + \sqrt{k}) \end{cases}\)

Parameters
Ithe incident
Nthe surface normal
etathe ratio of indices of refraction