图形处理之Unity3DShader(一)Vertex and Fragment Shader
来源:互联网 发布:杭州恩牛网络 上市 编辑:程序博客网 时间:2024/06/13 22:47
一、Properties
_MyColor ("Some Color", Color) = (1,1,1,1)
_MyVector ("Some Vector", Vector) = (0,0,0,0)
_MyFloat ("My float", Float) = 0.5
_MyTexture ("Texture", 2D) = "white" {}
_MyCubemap ("Cubemap", CUBE) = "" {}
二、Tags
Possible values for LightMode tag are:
- Always: Always rendered; no lighting is applied.
- ForwardBase: Used in Forward rendering, ambient, main directional light, vertex/SH lights and lightmaps are applied.
- ForwardAdd: Used in Forward rendering; additive per-pixel lights are applied, one pass per light.
- Deferred: Used in Deferred Shading; renders g-buffer.
- ShadowCaster: Renders object depth into the shadowmap or a depth texture.
- PrepassBase: Used in legacy Deferred Lighting, renders normals and specular exponent.
- PrepassFinal: Used in legacy Deferred Lighting, renders final color by combining textures, lighting and emission.
- Vertex: Used in legacy Vertex Lit rendering when object is not lightmapped; all vertex lights are applied.
- VertexLMRGBM: Used in legacy Vertex Lit rendering when object is lightmapped; on platforms where lightmap is RGBM encoded (PC & console).
- VertexLM: Used in legacy Vertex Lit rendering when object is lightmapped; on platforms where lightmap is double-LDR encoded (mobile platforms).
Possible values for LightMode tag are:
- SoftVegetation: Render this pass only if Soft Vegetation is on in Quality Settings.
Possible values for Queue tag are:
Background
- this render queue is rendered before any others. You’d typically use this for things that really need to be in the background.Geometry
(default) - this is used for most objects. Opaque geometry uses this queue.AlphaTest
- alpha tested geometry uses this queue. It’s a separate queue fromGeometry
one since it’s more efficient to render alpha-tested objects after all solid ones are drawn.Transparent
- this render queue is rendered after Geometry andAlphaTest
, in back-to-front order. Anything alpha-blended (i.e. shaders that don’t write to depth buffer) should go here (glass, particle effects).Overlay
- this render queue is meant for overlay effects. Anything rendered last should go here (e.g. lens flares).Possible values for RenderType tag are:
- Opaque: most of the shaders (Normal, Self Illuminated, Reflective, terrain shaders).
- Transparent: most semitransparent shaders (Transparent, Particle, Font, terrain additive pass shaders).
- TransparentCutout: masked transparency shaders (Transparent Cutout, two pass vegetation shaders).
- Background: Skybox shaders.
- Overlay: GUITexture, Halo, Flare shaders.
- TreeOpaque: terrain engine tree bark.
- TreeTransparentCutout: terrain engine tree leaves.
- TreeBillboard: terrain engine billboarded trees.
- Grass: terrain engine grass.
- GrassBillboard: terrain engine billboarded grass.
DisableBatching tag
ForceNoShadowCasting tag
If ForceNoShadowCasting
tag is given and has a value of “True”, then an object that is rendered using this subshader will never cast
shadows. This is mostly useful when you are using shader replacement on transparent objects and you do not wont to inherit a shadow
pass from another subshader.
IgnoreProjector tag
if ignoreProjector tag is given and has a value of “True”, then an object that uses this shader will not be affected by Projectors. This is mostly
useful on semitransparent objects, because there is no good way for Projectors to affect them.
CanUseSpriteAtlas tag
Set CanUseSpriteAtlas
tag to “False” if the shader is meant for sprites, and will not work when they are packed into atlases .
PreviewType tag
PreviewType
indicates how the material inspector preview should display the material. By default materials are displayed as
spheres, but PreviewType can also be set to “Plane” (will display as 2D) or “Skybox” (will display as skybox).
三、测试Controls whether pixels from this object are written to the depth buffer (default is On). If you’re drawng solid objects, leave this on.
If you’re drawing semitransparent effects, switch to ZWrite Off. For more details read below.
3.ZTest Less | Greater | LEqual | GEqual | Equal | NotEqual | Always
How should depth testing be performed. Default is LEqual (draw objects in from or at the distance as existing objects;
hide objects behind them).
4.Offset Factor, Units
Allows you specify a depth offset with two parameters. factor and units. Factor scales the maximum Z slope, with respect to X or Y of the polygon,
and units scale the minimum resolvable depth buffer value. This allows you to force one polygon to be drawn on top of another although they are
actually in the same position. For example Offset 0, –1 pulls the polygon closer to the camera ignoring the polygon’s slope, whereas Offset –1, –1
will pull the polygon even closer when looking at a grazing angle.
5.Blend
Blend Off;Blend SrcFactor DstFactor;Blend SrcFactor DstFactor, SrcFactorA DstFactorA
OneThe value of one - use this to let either the source or the destination color come through fully.ZeroThe value zero - use this to remove either the source or the destination values.SrcColorThe value of this stage is multiplied by the source color value.SrcAlphaThe value of this stage is multiplied by the source alpha value.DstColorThe value of this stage is multiplied by frame buffer source color value.DstAlphaThe value of this stage is multiplied by frame buffer source alpha value.OneMinusSrcColorThe value of this stage is multiplied by (1 - source color).OneMinusSrcAlphaThe value of this stage is multiplied by (1 - source alpha).OneMinusDstColorThe value of this stage is multiplied by (1 - destination color).OneMinusDstAlphaThe value of this stage is multiplied by (1 - destination alpha).BlendOp
AddAdd source and destination together.SubSubtract destination from source.RevSubSubtract source from destination.MinUse the smaller of source and destination.MaxUse the larger of source and destination.
6.Stencil
Ref
Ref referenceValue
The value to be compared against (if Comp is anything else than always) and/or the value to be written to the buffer (if either Pass, Fail or ZFail is set to replace). 0–255 integer.
ReadMask
ReadMask readMask
An 8 bit mask as an 0–255 integer, used when comparing the reference value with the contents of the buffer (referenceValue & readMask) comparisonFunction (stencilBufferValue & readMask). Default: 255.
WriteMask
WriteMask writeMask
An 8 bit mask as an 0–255 integer, used when writing to the buffer. Default: 255.
Comp
Comp comparisonFunction
The function used to compare the reference value to the current contents of the buffer. Default: always.
Pass
Pass stencilOperation
What to do with the contents of the buffer if the stencil test (and the depth test) passes. Default: keep.
Fail
Fail stencilOperation
What to do with the contents of the buffer if the stencil test fails. Default: keep.
ZFail
ZFail stencilOperation
What to do with the contents of the buffer if the stencil test passes, but the depth test fails. Default: keep.
Comp, Pass, Fail and ZFail will be applied to the front-facing geometry, unless Cull Front is specified, in which case it’s back-facing geometry. You can also explicitly specify the two-sided stencil state by defining CompFront, PassFront, FailFront, ZFailFront (for front-facing geometry), and CompBack, PassBack, FailBack, ZFailBack (for back-facing geometry).
Comparison Function
Comparison function is one of the following:
Stencil Operation
Stencil operation is one of the following:
AlphaTest off; AlphaTest comparison AlphaValue;
Mode Off | Global | Linear | Exp | Exp2
Color ColorValue
Density FloatValue
Range FloatValue, FloatValue
四、#pragma
- #pragma vertex name - compile function name as the vertex shader.
- #pragma fragment name - compile function name as the fragment shader.
- #pragma geometry name - compile function name as DX10 geometry shader. Having this option automatically turns on #pragma target 4.0, described below.
- #pragma hull name - compile function name as DX11 hull shader. Having this option automatically turns on #pragma target 5.0, described below.
- #pragma domain name - compile function name as DX11 domain shader. Having this option automatically turns on #pragma target 5.0, described below.
Other compilation directives:
- #pragma target name - which shader target to compile to. See Shader targets below for details.
- #pragma only_renderers space separated names - compile shader only for given renderers. By default shaders are compiled for all renderers. See Renderers below for details.
- #pragma exclude_renderers space separated names - do not compile shader for given renderers. By default shaders are compiled for all renderers. See Renderers below for details.
- #pragma multi_compile …_ - for working with multiple shader variants.
- #pragma enable_d3d11_debug_symbols - generate debug information for shaders compiled for DirectX 11, this will allow you to debug shaders via Visual Studio 2012 (or higher) Graphics debugger.
NameValueUNITY_MATRIX_MVPCurrent model * view * projection matrix.UNITY_MATRIX_MVCurrent model * view matrix.UNITY_MATRIX_VCurrent view matrix.UNITY_MATRIX_PCurrent projection matrix.UNITY_MATRIX_VPCurrent view * projection matrix.UNITY_MATRIX_T_MVTranspose of model * view matrix.UNITY_MATRIX_IT_MVInverse transpose of model * view matrix._Object2WorldCurrent model matrix._World2ObjectInverse of current world matrix.
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._ScreenParamsfloat4x
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._ZBufferParamsfloat4Used to linearize Z buffer values. x
is (1-far/near), y
is (far/near), z
is (x/far) and w
is (y/far).unity_OrthoParamsfloat4x
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_CameraProjectionfloat4x4Camera’s projection matrix.unity_CameraInvProjectionfloat4x4Inverse of camera’s projection matrix.unity_CameraWorldClipPlanes[6]float4Camera frustum plane world space equations, in this order: left, right, bottom, top, near, far.NameTypeValue_Timefloat4Time since level load (t/20, t, t*2, t*3), use to animate things inside the shaders._SinTimefloat4Sine of time: (t/8, t/4, t/2, t)._CosTimefloat4Cosine of time: (t/8, t/4, t/2, t).unity_DeltaTimefloat4Delta time: (dt, 1/dt, smoothDt, 1/smoothDt).Forward rendering (ForwardBase
and ForwardAdd
pass types):
Deferred shading and deferred lighting, used in the lighting pass shader (all declared in UnityDeferredLibrary.cginc):
LOD
- VertexLit kind of shaders = 100
- Decal, Reflective VertexLit = 150
- Diffuse = 200
- Diffuse Detail, Reflective Bumped Unlit, Reflective Bumped VertexLit = 250
- Bumped, Specular = 300
- Bumped Specular = 400
- Parallax = 500
- Parallax Specular = 600
- 图形处理之Unity3DShader(一)Vertex and Fragment Shader
- Vertex and Fragment Shader
- vertex and fragment shader
- Vertex and fragment shader examples
- Vertex and Fragment Shader(可编程渲染管线)
- LIGHTING IN VERTEX AND FRAGMENT SHADER
- UNITY3D shader学习心得<三> Vertex and Fragment Shader
- Shader Learing(Surface and Vertex&Fragment Shader篇)
- 图形处理之Shader语言(一)GLSL语法篇
- Vertex & Fragment Shader入门
- Unity Shader 顶点和片段着色器(Vertex and Fragment Shader)
- Shader第三讲 Vertex&Fragment Shader
- Unity3D shader(5)——vertex shader(一)
- 【猫猫的Unity Shader之旅】之Vertex&Fragment Shader下的透明
- Vertex Shader - 散射光照处理
- unity shader 可编程管线(二) 顶点和片段着色器(Vertex Shader and Fragmet Shader)
- Unity3D Shader_vertex and fragment shader实例(一)
- shader 2: vertex, fragment, surf的区别
- Learning Informative Edge Maps for Indoor Scene Layout Prediction
- C/C++数组名与指针区别
- 罗马数字转整形(LeetCode题目)
- 机房合作总结
- JavaScript中的子类和父类的继承
- 图形处理之Unity3DShader(一)Vertex and Fragment Shader
- 关于char和int之间的字符关系
- luogu--约瑟夫 指针实现
- 性能优化工具:LeakCanary、Analyze
- Ubuntu下软件安装
- java程序调用dll文件方法
- 单例类的总结
- JAVA WEB项目部署说明
- Oracle2