Unity3D翻譯——Rendering with Replaced Shaders

Rendering with Replaced Shaders      使用替換着色器來渲染

原文地址:http://unity3d.com/support/documentation/Components/SL-ShaderReplacement.html

如有翻譯不當之處,還請幫忙指出!

 

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 usingCamera.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 isnot 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).

*      Opaque:用於大多數着色器(法線着色器、自發光着色器、反射着色器以及地形的着色器)。

*      Transparent: most semitransparent shaders (Transparent, Particle, Font, terrain additive pass shaders).

*      Transparent:用於半透明着色器(透明着色器、粒子着色器、字體着色器、地形額外通道的着色器)。

*      TransparentCutout: masked transparency shaders (Transparent Cutout, two pass vegetation shaders).

*      TransparentCutout:蒙皮透明着色器(Transparent Cutout,兩個通道的植被着色器)。

*      Background: Skybox shaders.

*      Background:天空盒着色器。

*      Overlay: GUITexture, Halo, Flare shaders.

*      Overlay: GUITexture、光暈着色器、閃光着色器。

*      TreeOpaque: terrain engine tree bark.

*      TreeOpaque:地形引擎中的樹皮。

*      TreeTransparentCutout: terrain engine tree leaves.

*      TreeTransparentCutout:地形引擎中的樹葉。

*      TreeBillboard: terrain engine billboarded trees.

*      TreeBillboard:地形引擎中的billboard樹。

*      Grass: terrain engine grass.

*      Grass:地形引擎中的草。

*      GrassBillboard: terrain engine billboarded grass.

*      GrassBillboard:地形引擎何中的billboard草。

 

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. SeeCamera Depth Texture page.

如果你在你的特效中需要的話,照相機自身也有能力來渲染深度或者深度+法線紋理。請參考Camera Depth Texture

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章