Render Type & Rendering with Replaced Shaders
2018-01-01 22:27
405 查看
【Rendering with Replaced Shaders】
1、RenderType tag
2、Rendering with Replaced Shaders
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.
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.
If replacementTag is not empty, then for each object that would be rendered:
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.
3、Shader replacement tags in built-in Unity shaders
All built-in Unity shaders have a “RenderType” tag set that can be used when rendering with replaced shaders. Tag values are the following:
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.
4、
1、RenderType tag
RenderTypetag categorizes shaders into several predefined groups, e.g. is is an opaque shader, or an alpha-tested shader etc. This is used by Shader Replacement and in some cases used to produce camera’s depth texture.
2、Rendering with Replaced Shaders
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.
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.
If replacementTag is not empty, then for each object that would be rendered:
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.
3、Shader replacement tags in built-in Unity shaders
All built-in Unity shaders have a “RenderType” tag set that can be used when rendering with replaced shaders. Tag values are the following:
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.
4、
void Start() { camera.SetReplacementShader (EffectShader, "RenderType"); }
相关文章推荐
- unity 替换渲染 ( Rendering with Replaced Shaders )
- Rendering with Replaced Shaders
- unity 替换渲染 ( Rendering with Replaced Shaders )
- unity, 替换shader渲染(Rendering with Replaced Shaders)
- unity, 替换shader渲染(Rendering with Replaced Shaders)
- unity, 替换shader渲染(Rendering with Replaced Shaders)
- Unity3D翻译——Rendering with Replaced Shaders
- 错误argument of type "char *" is incompatible with parameter of type "LPCWSTR"的解决方法
- LNK1112:module machine type 'x86' conflicts with target machine type 'X64' 和 module machine type 'x6
- The type List is not generic; it cannot be parameterized with arguments <Integer>
- JDBC操作存储过程错误:必须说明 'QUERYCHARGESTATWITHNETTYPE' 组件
- Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server
- vc-complex-type.2.4.a: Invalid content was found starting with element 'init-param'. One of '{"http:
- Initalizing 'AppDelegate * __strong' with an expression of incompatible type ''id<UIApplicatioinDele
- LNK1112: module machine type 'x64' conflicts with target machine type 'X86'
- Error_9_fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'
- There is no result type defined for type 'json' mapped with name 'success'.
- The type JComboBox is not generic; it cannot be parameterized with arguments <String>错误
- error: ISO C++ forbids declaration of 'XXXX' with no type
- babel & browserify 报错 'import' and 'export' may appear only with 'sourceType: module' (2:0)