GpuCode
Description
This class is the base for GPU programs and provides a set of intrinsic functions that can be mapped to other GPU programming languages (like HLSL and GLSL) with zero or trivial effort.
A GPU program is a group of shader functions that reads data from one or more input resource object (such as IGpuBuffer or ITexture) and writes data to one or more output resource objects (such as IRenderTarget, IGpuBuffer or ITexture). If a class is derived from GpuCode, it becomes a GPU code class, which contains functions that will be executed by a GPU (after syntactic and semantic translation to GPU code, such as HLSL/GLSL, following by compilation and linking by the native graphics API). To define a shader function, a function of a GPU code class must be annotated with one of the following attributes, which turns the function into a pipeline stage:
-
Compute pipeline stages:
-
ComputeShader (required)
-
-
Graphics pipeline stages:
-
VertexShader (required)
-
GeometryShader (optional)
-
TessellatePatchShader (optional)
-
TessellateVertexShader (optional)
-
PixelShader (required)
-
Data may be passed between pipeline stages with struct
values that are annotated with StageInOut. To pass data within a pipeline stage, struct
values that are annotated with Stage may be used, in addition to values of the following types:
The following attributes may be used to specify value semantics and custom behaviour:
Constant data may be fed into a GPU program via constant buffers, which are defined via class
types that are annotated with ConstantBuffer. GPU code reads values from a constant buffer by accessing the static
fields and CPU code writes values via the IRenderEffectParameters interface, where the mapping between from constant buffer field name to parameter slot is obtained via IRenderEffectParameters.ParameterDeclare. Usually, the mapping is handled internally by a RenderEffectParameters class and thus hidden from client code. Shader resource objects are specified in a way similar to how constant data is specified: via a class
type that is annotated with ShaderResources. Global configuration data may be specified via class
types that are annotated with the Configuration attribute. Configuration data is compile-time constant and may thus be used to implement conditional compilation.
Public / Constants
Protected / Methods
atan2
Computes the arc-tangent in the range [-pi..+pi] of the given value valueY in / valueX in (per component).
ceil
Computes the smallest integral value that is greater than or equal to the given value (per component).
floor
Computes the greatest integral value that is less than or equal to the given value (per component).
mul
7 overloads
Multiplies the given matrix and column-vector.
This is the standard form of a multiplication of a matrix and a vector:
| m11 m12 | | x | | m11 * x + m12 * y | | m21 m22 | * | y | = | m21 * x + m22 * y |
Multiplies the given matrix and column-vector.
This is the standard form of a multiplication of a matrix and a vector:
| m11 m12 m13 | | x | | m11 * x + m12 * y + m13 * z | | m21 m22 m23 | * | y | = | m21 * x + m22 * y + m23 * z | | m31 m32 m33 | | z | | m31 * x + m32 * y + m33 * z |
Multiplies the given matrix and column-vector.
This is the standard form of a multiplication of a matrix and a vector:
| m11 m12 m13 m14 | | x | | m11 * x + m12 * y + m13 * z + m14 * w | | m21 m22 m23 m24 | * | y | = | m21 * x + m22 * y + m23 * z + m24 * w | | m31 m32 m33 m34 | | z | | m31 * x + m32 * y + m33 * z + m34 * w |
Multiplies the given matrix and column-vector.
This is the standard form of a multiplication of a matrix and a vector:
| m11 m12 m13 m14 | | x | | m11 * x + m12 * y + m13 * z + m14 * w | | m21 m22 m23 m24 | * | y | = | m21 * x + m22 * y + m23 * z + m24 * w | | m31 m32 m33 m34 | | z | | m31 * x + m32 * y + m33 * z + m34 * w | | m41 m42 m43 m44 | | w | | m41 * x + m42 * y + m43 * z + m44 * w |
Multiplies the given row-vector and matrix.
This is the transposed form of a multiplication of a matrix and a vector:
| x |T | m11 m12 | | m11 * x + m21 * y |T | y | * | m21 m22 | = | m12 * x + m22 * y |
Calling mul2 with the transpose of m in yields the same result.
Multiplies the given row-vector and matrix.
This is the transposed form of a multiplication of a matrix and a vector:
| x |T | m11 m12 m13 | | m11 * x + m21 * y + m31 * z |T | y | * | m21 m22 m23 | = | m12 * x + m22 * y + m32 * z | | z | | m31 m32 m33 | | m13 * x + m23 * y + m32 * z |
Calling mul2 with the transpose of m in yields the same result.
Multiplies the given row-vector and matrix.
This is the transposed form of a multiplication of a matrix and a vector:
| x |T | m11 m12 m13 m14 | | m11 * x + m21 * y + m31 * z + m41 * w |T | y | * | m21 m22 m23 m24 | = | m12 * x + m22 * y + m32 * z + m42 * w | | z | | m31 m32 m33 m34 | | m13 * x + m23 * y + m32 * z + m43 * w | | w | | m41 m42 m43 m44 | | m14 * x + m24 * y + m33 * z + m44 * w |
Calling mul4 with the transpose of m in yields the same result.
reflect
Computes a reflection vector using an incident ray and a surface normal:
result := i - n * 2 * dot(i, n)
sign
Computes -1, 0 or +1, depending on whether the given value is less than zero, equal to zero or greater than zero (per component).