- 最后登录
- 2018-12-19
- 注册时间
- 2012-8-20
- 阅读权限
- 90
- 积分
- 54706
- 纳金币
- 32328
- 精华
- 41
|
Some rendering effects require rendering a scene with a different set of shaders. For example, good edge detection would need a texture with scene normals, so it could detect edges where surface orientations differ. Other effects might need a texture with scene depth, and so on. To achieve this, it is possible to render the scene with replaced shaders of all objects.一些渲染特效需要使用一些不同的着色器来渲染场景。比如,一个好的边界提取效果需要由一个记录场景法线信息的纹理才能检测出场景中的朝向变化的地方;其他效果也可能需要一个记录场景深度的纹理等等。要想达到这些效果,我们可能需要使用所有物体的替代着色器来渲染场景。Shader replacement is done from scripting using Camera.RenderWithShader or Camera.SetReplacementShader functions. Both functions take a shader and a replacementTag.着色器更换是从脚本使用 Camera.RenderWithShader 或 Camera.SetReplacementShader 函数来完成的。这两个函数均以一个着色器和一个replacementTag作为参数。It works like this: the camera renders the scene as it normally would. the objects still use their materials, but the actual shader that ends up being used is changed:它是像这样来进行工作的:相机还是像平常一样来渲染场景,物体也还是使用原有的材质,但是他们的真实材质是在使用时来进行改变: If replacementTag is empty, then all objects in the scene are rendered with the given replacement shader.
如果replacementTag是空的,那么场景中的所有物体都用给定的替换着色器来进行渲染。
If replacementTag is not empty, then for each object that would be rendered:
如果replacementTag不是空的,那么对于每个物体,将进行以下方式进行渲染:
The real object's shader is queried for the tag value.
按照标签值来查找物体真正的着色器。
If it does not have that tag, object is not rendered.
如果没有标签,物体将不进行渲染。
A subshader is found in the replacement shader that has a given tag with the found value. If no such subshader is found, object is not rendered.
在替换着色器中,我们可以根据一个具有查找值的标签来找到一个子着色器,如果没有这样的子着色器,该物体将不进行渲染。
Now that subshader is used to render the object.
现在可以应用子着色器来渲染物体。 So if all shaders would have, for example, a "RenderType" tag with values like "Opaque", "Transparent", "Background", "Overlay", you could write a replacement shader that only renders solid objects by using one subshader with RenderType=Solid tag. The other tag types would not be found in the replacement shader, so the objects would be not rendered. Or you could write several subshaders for different "RenderType" tag values. Incidentally, all built-in Unity shaders have a "RenderType" tag set.所以,如果所有着色器都拥有一个渲染类型标签,比如"不透明"、"透明"、"背景"、"叠加"等,你就可以编写一个含有"RenderType = Solid"的替换着色器来只渲染固体物体。其他标记并不会在该替换着色器中被找到,所以与其对应的物体将不会被渲染。,发现其他标记类型。或者,你可以编写拥有不同的"RenderType"标签值的子着色器。顺便说一下,所有Unity内置着色器都含有一个"RenderType"标签集。
Shader replacement tags in built-in Unity shaders
在Unity内置着色器的着色器替换标签All built-in Unity shaders have a "RenderType" tag set that can be used when rendering with replaced shaders. Tag values are the following:当使用替换着色器进行渲染时,Unity所有的着色器都含有一个"渲染类型"标签集,其中的标签值如下所示: 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).
蒙皮透明着色器(Transparent Cutout,两个通道的植被着色器)。
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. 地形引擎何中的广告牌草。Built-in scene depth/normals texture 内建的场景 深度/法线 纹理A Camera has a built-in capability to render depth or depth+normals texture, if you need that in some of your effects. See Camera Depth Texture page. Note that in some cases (depending on the hardware), the depth and depth+normals textures can internally be rendered using shader replacement. So it is important to have the correct "RenderType" tag in your shaders.如果你在你的特效中需要的话,照相机自身也有能力来渲染深度或者深度+法线纹理。请参考Camera Depth Texture页面。注意,某些情况下(取决于硬件),depth 和 depth+normals纹理可以使用着色器替换内部渲染。因此,在你的着色器具有正确的RenderType标签是很重要的。 【来源:互联网】
更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/ |
|