Built-in shader helper functions 内置的着色器辅助函数
Unity has a number of built-in utility functions designed to make writing shaders simpler and easier.
Unity有许多内置的实用功能,可以让编写着色器变得更简单和简单。
Functions declared in UnityCG.cginc 函数中声明UnityCG.cginc
See Built-in shader include files for an overview of shader include files provided with Unity.
查看内置的着色器包括文件,用于对着色器的概述,其中包括提供Unity的文件。
Vertex transformation functions in UnityCG.cginc 在unitycg.cginc中的顶点转换函数
Function:
| Description:
|
---|---|
float4 UnityObjectToClipPos(float3 pos) | Transforms a point from object space to the camera’s clip space in homogeneous coordinates. This is the equivalent of mul(UNITY_MATRIX_MVP, float4(pos, 1.0)), and should be used in its place 将一个点从物体空间转换为在齐次坐标下的摄像机的剪辑空间。这相当于mul(UNITY_MATRIX_MVP, float4(pos, 1.0)),应该在它的位置使用。. |
float3 UnityObjectToViewPos(float3 pos) | Transforms a point from object space to view space. This is the equivalent of mul(UNITY_MATRIX_MV, float4(pos, 1.0)).xyz, and should be used in its place 将一个点从对象空间转换为视图空间。这相当于mul(UNITY_MATRIX_MV, float4(pos, 1.0)))。xyz,应该在它的位置使用。. |
Generic helper functions in UnityCG.cginc
Function:
| Description:
|
---|---|
float3 WorldSpaceViewDir (float4 v) | Returns world space direction (not normalized) from given object space vertex position towards the camera 从给定的物体空间顶点位置向相机返回世界空间方向(不规格化)。. |
float3 ObjSpaceViewDir (float4 v) | Returns object space direction (not normalized) from given object space vertex position towards the camera 从给定的对象空间顶点位置向摄像机返回对象空间方向(不规格化)。. |
float2 ParallaxOffset (half h, half height, half3 viewDir) | calculates UV offset for parallax normal mapping 计算视差贴图的UV偏移量。. |
fixed Luminance (fixed3 c) | Converts color to luminance (grayscale) 把颜色转换成亮度(灰度)。. |
fixed3 DecodeLightmap (fixed4 color) | Decodes color from Unity lightmap (RGBM or dLDR depending on platform) 从unity的lightmap(RGBM或dLDR根据平台)来解码颜色。. |
float4 EncodeFloatRGBA (float v) | Encodes [0..1) range float into RGBA color, for storage in low precision render target 编码0.1)范围浮动到RGBA颜色,用于低精度渲染目标的存储。. |
float DecodeFloatRGBA (float4 enc) | Decodes RGBA color into a float 将RGBA颜色转换为一个浮点数。. |
float2 EncodeFloatRG (float v) | Encodes [0..1) range float into a float2 编码0.1)范围浮动到浮动2。. |
float DecodeFloatRG (float2 enc) | Decodes a previously-encoded RG float 解码先前编码的RG浮点数。. |
float2 EncodeViewNormalStereo (float3 n) | Encodes view space normal into two numbers in 0..1 range. 将视图空间的正常值编码为0。1范围。\ |
float3 DecodeViewNormalStereo (float4 enc4) | Decodes view space normal from enc4.xy 解码从enc4.xy中正常的空间。. |
Forward rendering helper functions in UnityCG.cginc 在unitycg.cginc中向前呈现帮助函数
These functions are only useful when using forward rendering (ForwardBase or ForwardAdd pass types).
这些函数只有在使用向前呈现时才有用(向前推进或向前添加传递类型)。
Function:
| Description:
|
---|---|
float3 WorldSpaceLightDir (float4 v) | Computes world space direction (not normalized) to light, given object space vertex position 计算世界空间方向(不规格化)到光,给定物体空间顶点位置。. |
float3 ObjSpaceLightDir (float4 v) | Computes object space direction (not normalized) to light, given object space vertex position 计算对象空间方向(不规范化)到光,给定对象空间顶点位置。. |
float3 Shade4PointLights (...) | Computes illumination from four point lights, with light data tightly packed into vectors. Forward rendering uses this to compute per-vertex lighting 从四个点光源计算照明,将光数据紧密地压缩到矢量中。向前渲染利用这个来计算每个顶点的照明。. |
Screen-space helper functions in UnityCG.cginc 在unitycg.cginc中的屏幕空间助手函数
The following functions are helpers to compute coordinates used for sampling screen-space textures. They return float4
where the final coordinate to sample texture with can be computed via perspective division (for example xy/w
).
下面的函数是用来计算用于采样屏幕空间纹理的坐标的辅助工具。它们返回漂浮的地方,在那里,最终的坐标可以通过透视划分(例如xy/w)来计算纹理。
The functions also take care of platform differences in render texture coordinates.
这些函数还可以处理渲染纹理坐标的平台差异。
Function:
| Description:
|
---|---|
float4 ComputeScreenPos (float4 clipPos) | Computes texture coordinate for doing a screenspace-mapped texture sample. Input is clip space position omputes的纹理坐标用于做一个屏幕空间的纹理采样。输入是剪辑空间位置。. |
float4 ComputeGrabScreenPos (float4 clipPos) | Computes texture coordinate for sampling a GrabPass texure. Input is clip space position 计算纹理坐标,以对一个GrabPass材质进行采样。输入是剪辑空间位置。. |
Vertex-lit helper functions in UnityCG.cginc 在unitycg.cginc中,vertexlit的助手函数
These functions are only useful when using per-vertex lit shaders (“Vertex” pass type).
当使用每个顶点的光照着色器(“顶点”传递类型)时,这些函数才有用。
Function: | Description: |
---|---|
float3 ShadeVertexLights (float4 vertex, float3 normal) | Computes illumination from four per-vertex lights and ambient, given object space position & normal 根据给定的物体空间位置和正常情况,计算每个顶点灯光和环境的光照。.
|