Appearance
引擎内置的ShaderAPI参考
类型
虽然可以直接使用GLSL类型(vec4或mat4),但我们建议使用以下类型别名:
Name | GLSL type | Description |
---|---|---|
bool2 | bvec2 | A vector of 2 booleans |
bool3 | bvec3 | A vector of 3 booleans |
bool4 | bvec4 | A vector of 4 booleans |
int2 | ivec2 | A vector of 2 integers |
int3 | ivec3 | A vector of 3 integers |
int4 | ivec4 | A vector of 4 integers |
uint2 | uvec2 | A vector of 2 unsigned integers |
uint3 | uvec3 | A vector of 3 unsigned integers |
uint4 | uvec4 | A vector of 4 unsigned integers |
float2 | float2 | A vector of 2 floats |
float3 | float3 | A vector of 3 floats |
float4 | float4 | A vector of 4 floats |
float4x4 | mat4 | A 4x4 float matrix |
float3x3 | mat3 | A 3x3 float matrix |
数学相关
Name | Type | Description |
---|---|---|
PI | float | A constant that represent $\pi$ |
HALF_PI | float | A constant that represent $\frac{\pi}{2}$ |
saturate(float x) | float | Clamps the specified value between 0.0 and 1.0 |
pow5(float x) | float | Computes $x^5$ |
sq(float x) | float | Computes $x^2$ |
max3(float3 v) | float | Returns the maximum value of the specified float3 |
mulMat4x4Float3(float4x4 m, float3 v) | float4 | Returns $m * v$ |
mulMat3x3Float3(float4x4 m, float3 v) | float4 | Returns $m * v$ |
矩阵相关
Name | Type | Description |
---|---|---|
getViewFromWorldMatrix() | float4x4 | Matrix that converts from world space to view/eye space |
getWorldFromViewMatrix() | float4x4 | Matrix that converts from view/eye space to world space |
getClipFromViewMatrix() | float4x4 | Matrix that converts from view/eye space to clip (NDC) space |
getViewFromClipMatrix() | float4x4 | Matrix that converts from clip (NDC) space to view/eye space |
getClipFromWorldMatrix() | float4x4 | Matrix that converts from world to clip (NDC) space |
getWorldFromClipMatrix() | float4x4 | Matrix that converts from clip |
帧数据常量
Name | Type | Description |
---|---|---|
getResolution() | float4 | Dimensions of the view's effective (physical) viewport in pixels: width , height , 1 / width , 1 / height . This might be different from View::getViewport() for instance because of added rendering guard-bands. |
getWorldCameraPosition() | float3 | Position of the camera/eye in world space (see note below) |
getWorldOffset() | float3 | [deprecated] The shift required to obtain API-level world space. Use getUserWorldPosition() instead |
getUserWorldFromWorldMatrix() | float4x4 | Matrix that converts from world space to API-level (user) world space. |
getTime() | float | Current time as a remainder of 1 second. Yields a value between 0 and 1 |
getUserTime() | float4 | Current time in seconds: time , (double)time - time , 0 , 0 |
getUserTimeMod(float m) | float | Current time modulo m in seconds |
getExposure() | float | Photometric exposure of the camera |
getEV100() | float | Exposure value at ISO 100 of the camera |
仅顶点着色器可访问
Name | Type | Description |
---|---|---|
getPosition() | float4 | Vertex position in the domain defined by the material (default: object/model space) |
getCustom0() to getCustom7() | float4 | Custom vertex attribute |
getWorldFromModelMatrix() | float4x4 | Matrix that converts from model (object) space to world space |
getWorldFromModelNormalMatrix() | float3x3 | Matrix that converts normals from model (object) space to world space |
getVertexIndex() | int | Index of the current vertex |
仅像素着色器可访问
Name | Type | Description |
---|---|---|
getWorldTangentFrame() | float3x3 | Matrix containing in each column the tangent (frame[0] ), bi-tangent (frame[1] ) and normal (frame[2] ) of the vertex in world space. If the material does not compute a tangent space normal for bump mapping or if the shading is not anisotropic, only the normal is valid in this matrix. |
getWorldPosition() | float3 | Position of the fragment in world space (see note below about world-space) |
getUserWorldPosition() | float3 | Position of the fragment in API-level (user) world-space (see note below about world-space) |
getWorldViewVector() | float3 | Normalized vector in world space from the fragment position to the eye |
getWorldNormalVector() | float3 | Normalized normal in world space, after bump mapping (must be used after prepareMaterial() ) |
getWorldGeometricNormalVector() | float3 | Normalized normal in world space, before bump mapping (can be used before prepareMaterial() ) |
getWorldReflectedVector() | float3 | Reflection of the view vector about the normal (must be used after prepareMaterial() ) |
getNormalizedViewportCoord() | float3 | Normalized user viewport position (i.e. NDC coordinates normalized to [0, 1] for the position, [1, 0] for the depth), can be used before prepareMaterial() ). Because the user viewport is smaller than the actual physical viewport, these coordinates can be negative or superior to 1 in the non-visible area of the physical viewport. |
getNdotV() | float | The result of dot(normal, view) , always strictly greater than 0 (must be used after prepareMaterial() ) |
getColor() | float4 | Interpolated color of the fragment, if the color attribute is required |
getUV0() | float2 | First interpolated set of UV coordinates, only available if the uv0 attribute is required |
getUV1() | float2 | First interpolated set of UV coordinates, only available if the uv1 attribute is required |
getMaskThreshold() | float | Returns the mask threshold, only available when blending is set to masked |
inverseTonemap(float3) | float3 | Applies the inverse tone mapping operator to the specified linear sRGB color and returns a linear sRGB color. This operation may be an approximation and works best with the "Filmic" tone mapping operator |
inverseTonemapSRGB(float3) | float3 | Applies the inverse tone mapping operator to the specified non-linear sRGB color and returns a linear sRGB color. This operation may be an approximation and works best with the "Filmic" tone mapping operator |
luminance(float3) | float | Computes the luminance of the specified linear sRGB color |
ycbcrToRgb(float, float2) | float3 | Converts a luminance and CbCr pair to a sRGB color |
uvToRenderTargetUV(float2) | float2 | Transforms a UV coordinate to allow sampling from a RenderTarget attachment |