Unity Manual


  • 首页

  • 分类

  • 公益404

  • 搜索

ShaderLab: Blending

发表于 2017-07-11 | 更新于 2017-07-26 | 分类于 Graphics , Graphics Reference , Shader Reference , ShaderLab Syntax , ShaderLab SubShader , ShaderLab Pass , ShaderLab Blending

网址:ShaderLab: Blending

ShaderLab: Blending

PipelineBlend

Syntax

  • Blend Off: Turn off blending (this is the default)
  • Blend SrcFactor DstFactor: Configure and enable blending. The generated color is multiplied by the SrcFactor. The color already on screen is multiplied by DstFactor and the two are added together.
  • Blend SrcFactor DstFactor, SrcFactorA DstFactorA: Same as above, but use different factors for blending the alpha channel.
  • BlendOp Op: Instead of adding blended colors together, carry out a different operation on them.
  • BlendOp OpColor, OpAlpha: Same as above, but use different blend operation for color (RGB) and alpha (A) channels.
  • AlphaToMask On: Turns on alpha-to-coverage. When MSAA is used, alpha-to-coverage modifies multisample coverage mask proportionally to the pixel Shader result alpha value. This is typically used for less aliased outlines than regular alpha test; useful for vegetation and other alpha-tested Shaders.

ShaderLab: Culling & Depth Testing

发表于 2017-07-11 | 更新于 2017-07-26 | 分类于 Graphics , Graphics Reference , Shader Reference , ShaderLab Syntax , ShaderLab SubShader , ShaderLab Pass , ShaderLab Culling & Depth Testing

网址:ShaderLab: Culling & Depth Testing

ShaderLab: Culling & Depth Testing

PipelineCullDepth

Syntax

Cull

  • 控制多边形的边的剔除
  • Back 不渲染远离观察者的背面,默认
  • Front 不渲染面向观察者的面
  • Off 关闭剔除

ZTest

  • 控制深度测试
  • ZTest Less | Greater | LEqual | GEqual | Equal | NotEqual | Always
  • 默认 LEqual

Offset

  • Offset Factor, Units

Shader data types and precision

发表于 2017-07-11 | 更新于 2017-07-11 | 分类于 Graphics , Graphics Reference , Shader Reference , Writing vertex and fragment shaders , Shader data types and precision

网址:Shader data types and precision

Basic data types

High precision: float

  • 32 bits
  • 世界坐标
  • 纹理坐标
  • 复杂的三角函数和指数运算

Medium precision: half

  • 16 bits,-6000~6000,大致0.001精度
  • 简单的向量
  • 方向
  • 物体坐标
  • HDR 颜色

Low precision: fixed

  • 11 bits,-2~2,1/256 精度
  • 一般颜色
  • 简单计算

Integer data types

  • 像 ES2 这种 GPU 会不支持

Composite vector/matrix types

  • 像 ES2 这种 GPU 只支持正方形矩阵

Precision, Hardware Support and Performance

  • PC 上都是使用 32 bits 的,不管使用的是 half 还是 fixed
  • 即使是在 Mobile 上,对精度类型的占位也是不一样的

Shader Compilation Target Levels

发表于 2017-07-11 | 更新于 2017-07-11 | 分类于 Graphics , Graphics Reference , Shader Reference , Writing vertex and fragment shaders , Shader Compilation Target Levels

网址:Shader Compilation Target Levels

Default compilation target

  • Unity 默认使用2.5
  • 使用 geometry 会导致使用4.0
  • 使用 hull 或者 domain 会导致使用4.6

Supported #pragma target names

  • Note that all OpenGL-like platforms (including mobile) are treated as “capable of shader model 3.0”. WP8/WinRT platforms (DX11 feature level 9.x) are treated as only capable of shader model 2.5.

#pragma target 2.0

  • Works on all platforms supported by Unity. DX9 shader model 2.0.
  • Limited amount of arithmetic & texture instructions; 8 interpolators; no vertex texture sampling; no derivatives in fragment shaders; no explicit LOD texture sampling.

#pragma target 2.5 (default)

  • Almost the same as 3.0 target (see below), except still only has 8 interpolators, and does not have explicit LOD texture sampling.
  • Compiles into SM3.0 on DX9, and DX11 feature level 9.3 on Windows Phone.

#pragma target 3.0

  • DX9 shader model 3.0: derivative instructions, texture LOD sampling, 10 interpolators, more math/texture instructions allowed.
  • Not supported on DX11 feature level 9.x GPUs (e.g. most Windows Phone devices).
  • Might not be fully supported by some OpenGL ES 2.0 devices, depending on driver extensions present and features used.

#pragma target 3.5 (or es3.0)

  • OpenGL ES 3.0 capabilities (DX10 SM4.0 on D3D platforms, just without geometry shaders).
  • Not supported on DX9, DX11 9.x (WinPhone), OpenGL ES 2.0.
  • Supported on DX11+, OpenGL 3.2+, OpenGL ES 3+, Metal, Vulkan, PS4/XB1 consoles.
  • Native integer operations in shaders, texture arrays, etc.

#pragma target 4.0

  • DX11 shader model 4.0.
  • Not supported on DX9, DX11 9.x (WinPhone), OpenGL ES 2.0/3.0/3.1, Metal.
  • Supported on DX11+, OpenGL 3.2+, OpenGL ES 3.1+AEP, Vulkan, PS4/XB1 consoles.
  • Has geometry shaders and everything that es3.0 target has.

#pragma target 4.5 (or es3.1)

  • OpenGL ES 3.1 capabilities (DX11 SM5.0 on D3D platforms, just without tessellation shaders).
  • Not supported on DX9, DX11 before SM5.0, OpenGL before 4.3 (i.e. Mac), OpenGL ES 2.0/3.0.
  • Supported on DX11+ SM5.0, OpenGL 4.3+, OpenGL ES 3.1, Metal, Vulkan, PS4/XB1 consoles.
  • Has compute shaders, random access texture writes, atomics etc. No geometry or tessellation shaders.

#pragma target 4.6 (or gl4.1)

  • OpenGL 4.1 capabilities (DX11 SM5.0 on D3D platforms, just without compute shaders). This is basically the highest OpenGL level supported by Macs.
  • Not supported on DX9, DX11 before SM5.0, OpenGL before 4.1, OpenGL ES 2.0/3.0/3.1, Metal.
  • Supported on DX11+ SM5.0, OpenGL 4.1+, OpenGL ES 3.1+AEP, PS4/XB1 consoles.

#pragma target 5.0

  • DX11 shader model 5.0.
  • Not supported on DX9, DX11 before SM5.0, OpenGL before 4.3 (i.e. Mac), OpenGL ES 2.0/3.0/3.1, Metal.
  • Supported on DX11+ SM5.0, OpenGL 4.3+, OpenGL ES 3.1+AEP, Vulkan, PS4/XB1 consoles.
  • Note that all OpenGL-like platforms (including mobile) are treated as “capable of shader model 3.0”. WP8/WinRT platforms (DX11 feature level 9.x) are treated as only capable of shader model 2.5.

Making multiple shader program variants

发表于 2017-07-10 | 更新于 2017-07-11 | 分类于 Graphics , Graphics Reference , Shader Reference , Writing vertex and fragment shaders , Making multiple shader program variants

网址:Making multiple shader program variants

How multi_compile works

一般的

  • 每一个都是一个 variant,如果没有开启任何一个,默认启用第一个

特殊的

  • 对于所有的都是以“__”开头的,则默认创建一个空的,避免另外创建一个关键词

Difference between shader_feature and multi_compile

  • shader_feature 等价于 multi_compile __
  • shader_feature 可以在面板上设置,multi_compile 通过代码来设置

Built-in multi_compile shortcuts

  • multi_compile_fwdbase compiles all variants needed by ForwardBase (forward rendering base) pass type. The variants deal with different lightmap types and main directional light having shadows on or off.
  • multi_compile_fwdadd compiles variants for ForwardAdd (forward rendering additive) pass type. This compiles variants to handle directional, spot or point light types, and their variants with cookie textures.
  • multi_compile_fwdadd_fullshadows - same as above, but also includes ability for the lights to have realtime shadows.
  • multi_compile_fog expands to several variants to handle different fog types (off/linear/exp/exp2).

Built-in shader variables

发表于 2017-07-10 | 更新于 2017-07-10 | 分类于 Graphics , Graphics Reference , Shader Reference , Writing vertex and fragment shaders , Built-in shader variables

网址:Built-in shader variables

Transformations

  • 都是 float4
  • UNITY_MATRIX_MVP Current model view projection matrix.
  • UNITY_MATRIX_MV Current model * view matrix.
  • UNITY_MATRIX_V Current view matrix.
  • UNITY_MATRIX_P Current projection matrix.
  • UNITY_MATRIX_VP Current view * projection matrix.
  • UNITY_MATRIX_T_MV Transpose of model * view matrix.
  • UNITY_MATRIX_IT_MV Inverse transpose of model * view matrix.
  • _Object2World Current model matrix.
  • _World2Object Inverse of current world matrix.

Camera and screen

  • _WorldSpaceCameraPos float3 World space position of the camera.
  • _ProjectionParams float4 x is 1.0 (or –1.0 if currently rendering with a flipped projection matrix), y is the camera’s near plane, z is the camera’s far plane and w is 1/FarPlane.
  • _ScreenParams float4 x is the camera’s render target width in pixels, y is the camera’s render target height in pixels, z is 1.0 + 1.0/width and w is 1.0 + 1.0/height.
  • _ZBufferParams float4 Used to linearize Z buffer values. x is (1-far/near), y is (far/near), z is (x/far) and w is (y/far).
  • unity_OrthoParams float4 x is orthographic camera’s width, y is orthographic camera’s height, z is unused and w is 1.0 when camera is orthographic, 0.0 when perspective.
  • unity_CameraProjection float4x4 Camera’s projection matrix.
  • unity_CameraInvProjection float4x4 Inverse of camera’s projection matrix.
  • unity_CameraWorldClipPlanes[6] float4 Camera frustum plane world space equations, in this order: left, right, bottom, top, near, far.

Time

  • _Time float4 Time since level load (t/20, t, t2, t3), use to animate things inside the shaders.
  • _SinTime float4 Sine of time: (t/8, t/4, t/2, t).
  • _CosTime float4 Cosine of time: (t/8, t/4, t/2, t).
  • unity_DeltaTime float4 Delta time: (dt, 1/dt, smoothDt, 1/smoothDt).

Lighting

  • _LightColor0 (declared in Lighting.cginc) fixed4 Light color.
  • _WorldSpaceLightPos0 float4 Directional lights: (world space direction, 0). Other lights: (world space position, 1).
  • _LightMatrix0 (declared in AutoLight.cginc) float4x4 World-to-light matrix. Used to sample cookie & attenuation textures.
  • unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0 float4 (ForwardBase pass only) world space positions of first four non-important point lights.
  • unity_4LightAtten0 float4 (ForwardBase pass only) attenuation factors of first four non-important point lights.
  • unity_LightColor half4[4] (ForwardBase pass only) colors of of first four non-important point lights.

  • _LightColor float4 Light color.

  • _LightMatrix0 float4x4 World-to-light matrix. Used to sample cookie & attenuation textures.

  • unity_LightColor half4[8] Light colors.

  • unity_LightPosition float4[8] View-space light positions. (-direction,0) for directional lights; (position,1) for point/spot lights.
  • unity_LightAtten half4[8] Light attenuation factors. x is cos(spotAngle/2) or –1 for non-spot lights; y is 1/cos(spotAngle/4) or 1 for non-spot lights; z is quadratic attenuation; w is squared light range.
  • unity_SpotDirection float4[8] View-space spot light positions; (0,0,1,0) for non-spot lights.

Fog and Ambient

  • unity_AmbientSky fixed4 Sky ambient lighting color in gradient ambient lighting case.
  • unity_AmbientEquator fixed4 Equator ambient lighting color in gradient ambient lighting case.
  • unity_AmbientGround fixed4 Ground ambient lighting color in gradient ambient lighting case.
    UNITY_LIGHTMODEL_AMBIENT fixed4 Ambient lighting color (sky color in gradient ambient case). Legacy variable.
  • unity_FogColor fixed4 Fog color.
  • unity_FogParams float4 Parameters for fog calculation: (density / sqrt(ln(2)), density / ln(2), –1/(end-start), end/(end-start)). x is useful for Exp2 fog mode, y for Exp mode, z and w for Linear mode.

Various

  • unity_LODFade float4 Level-of-detail fade when using LODGroup. x is fade (0..1), y is fade quantized to 16 levels, z and w unused.

Built-in shader helper functions

发表于 2017-07-10 | 更新于 2017-07-10 | 分类于 Graphics , Graphics Reference , Shader Reference , Writing vertex and fragment shaders , Built-in shader helper functions

网址:Built-in shader helper functions

Built-in shader helper functions

Vertex transformation functions in UnityCG.cginc

  • float4 UnityObjectToClipPos(float3 pos) 将点从物体坐标空间转到齐次坐标
  • float3 UnityObjectToViewPos(float3 pos) 将点从物体坐标空间转到视图坐标

Generic helper functions in UnityCG.cginc

  • 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.
  • fixed Luminance (fixed3 c) Converts color to luminance (grayscale).
  • fixed3 DecodeLightmap (fixed4 color) Decodes color from Unity lightmap (RGBM or dLDR depending on platform).
  • float4 EncodeFloatRGBA (float v) Encodes [0..1) range float into RGBA color, for storage in low precision render target.
  • float DecodeFloatRGBA (float4 enc) Decodes RGBA color into a float.
  • float2 EncodeFloatRG (float v) Encodes [0..1) range float into a float2.
  • float DecodeFloatRG (float2 enc) Decodes a previously-encoded RG float.
  • float2 EncodeViewNormalStereo (float3 n) Encodes view space normal into two numbers in 0..1 range.
  • float3 DecodeViewNormalStereo (float4 enc4) Decodes view space normal from enc4.xy.

Forward rendering helper functions in UnityCG.cginc

  • 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

  • float4 ComputeScreenPos (float4 clipPos) Computes texture coordinate for doing a screenspace-mapped texture sample. Input is clip space position.
  • float4 ComputeGrabScreenPos (float4 clipPos) Computes texture coordinate for sampling a GrabPass texure. Input is clip space position.

Vertex-lit helper functions in UnityCG.cginc

  • float3 ShadeVertexLights (float4 vertex, float3 normal) Computes illumination from four per-vertex lights and ambient, given object space position & normal.

Predefined Shader preprocessor macros

发表于 2017-07-10 | 更新于 2017-07-10 | 分类于 Graphics , Graphics Reference , Shader Reference , Writing vertex and fragment shaders , Predefined Shader preprocessor macros

网址:Predefined Shader preprocessor macros

Target platform

Shader target model

Unity version

Platform difference helpers

Shadow mapping macros

Texture/Sampler declaration macros

Surface Shader pass indicators


Built-in shader include files

发表于 2017-07-10 | 更新于 2017-07-10 | 分类于 Graphics , Graphics Reference , Shader Reference , Writing vertex and fragment shaders , Built-in shader include files

网址:Built-in shader include files

Built-in shader include files

  • HLSLSupport.cginc - (automatically included) Helper macros and definitions for cross-platform shader compilation.
  • UnityShaderVariables.cginc - (automatically included) Commonly used global variables.
  • UnityCG.cginc - commonly used helper functions.
  • AutoLight.cginc - lighting & shadowing functionality, e.g. surface shaders use this file internally.
  • Lighting.cginc - standard surface shader lighting models; automatically included when you’re writing surface shaders.
  • TerrainEngine.cginc - helper functions for Terrain & Vegetation shaders.

UnityCG.cginc

Data structures in UnityCG.cginc

  • struct appdata_base: vertex shader input with position, normal, one texture coordinate.
  • struct appdata_tan: vertex shader input with position, normal, tangent, one texture coordinate.
  • struct appdata_full: vertex shader input with position, normal, tangent, vertex color and two texture coordinates.
  • struct appdata_img: vertex shader input with position and one texture coordinate.

Providing vertex data to vertex programs

发表于 2017-07-10 | 更新于 2017-07-10 | 分类于 Graphics , Graphics Reference , Shader Reference , Writing vertex and fragment shaders , Providing vertex data to vertex programs

网址:Providing vertex data to vertex Providing-vertex-data-to-vertex-programs.md

Providing vertex data to vertex programs

  • appdata_base: position, normal and one texture coordinate.
  • appdata_tan: position, tangent, normal and one texture coordinate.
  • appdata_full: position, tangent, normal, four texture coordinates and color.

  • POSITION is the vertex position, typically a float3 or float4.

  • NORMAL is the vertex normal, typically a float3.
  • TEXCOORD0 is the first UV coordinate, typically float2, float3 or float4.
  • TEXCOORD1, TEXCOORD2 and TEXCOORD3 are the 2nd, 3rd and 4th UV coordinates, respectively.
  • TANGENT is the tangent vector (used for normal mapping), typically a float4.
  • COLOR is the per-vertex color, typically a float4.

1…345…7
Fly

Fly

作者懒得写

69 日志
113 分类
GitHub CSDN
© 2018 Fly
由 Hexo 强力驱动
主题 - NexT.Pisces
0%