1. 程式人生 > >VR_Unity的基本Shader的剔除、深度測試、Alpha測試以及基本霧效

VR_Unity的基本Shader的剔除、深度測試、Alpha測試以及基本霧效

剔除是一種通過避免渲染背對觀察者的幾何體面來提高效能的優化措施。所有幾何體都包含正面和反面。剔除基於大多數物件都是封閉的事實;如果你有一個立方體,你不會看到背離你的那一面(總是隻有一面在你的前方),因此我們不需要繪製出背面。因此也被稱做背面剔除。
      The optimization measure is to improve the performance of the observer by avoiding the 
rendering of the geometry of the back of the observer. All geometry contains both positive and 
negative. It is closed to the fact that most objects are closed; if you have a cube, you don't see 
the one that has to deviate from your side (always only one side in front of you), so we don't 
need to draw back. So it is called the reverse side.

      一言以蔽之,所謂剔除,就是被擋住或視角以外的我們看不到的物體,因為它們無關緊要,所以我們就不去繪製,以節省資源,提高場景的執行效率。
        In a word, we can not see objects from the perspective of the object, because they do not 
matter, so we do not draw, to save resources, improve the operating efficiency of the scene.

                   


      1.2 深度測試(Depth Testing)的概念
        在複雜的場景中,通常有多個物體需要繪製,這些物體之間通常會存在遮擋關係,離觀察點較遠的物體會因為近處物體的者的遮擋而不可見或只有部分可見,Direct3D圖形系統提供了深度測試功能來實現這種效果。深度測試可以簡化複雜場景的繪製,確保只有場景內的物件的最靠近的表面參與繪製。
        In complex scene, there are usually multiple objects need to be drawn, these objects 
usually of the occlusion relationship, far away from the observation point objects because of 
nearby objects occlusion and not visible or only partially visible, Direct3D graphics system 
provides depth test function to achieve this effect. Depth testing can simplify the rendering of 
complex scenes, ensuring that only the most close to the object in the scene is involved in 
rendering.

       把深度測試看做在一口井的井口處向井中觀望。把所有物體都賦予一個深度值,放到井中來顯示。深度越深的物體,離井口就越遠。深度越淺的物體,離井口就越近。井表面的深度值為
0。離井口近而深度淺的物體,可能會把離井口遠的物體遮擋住。最終顯示在螢幕上的開啟深度測試後的畫面,就如在井口處向井中觀望裡面物體顯示出的遮擋與層次的效果一樣。當然,離井口的深度就是每個物體在世界座標系中的矩陣的Z座標值了。
        The depth of the test as well as the wellhead in a well to see the well. Give a depth value 
to all the objects, and put it in the well. The deeper the object, the farther away from the well. 
The more shallow the depth of the object, the more close to the wellhead. The depth of the 
well surface is 0. An object close to the mouth may be blocked by an object far from the mouth. 
Finally, on the screen to open the depth of the test after the test, as well as in the wellhead to 
see inside the object to see the effect of the same level as the object. Of course, the depth of 
the well head is the Z coordinates of each object in the world coordinate system.

         語句之二:ZWrite On | Off
        此語句用於控制是否將來之物件的畫素寫入深度緩衝(預設開啟),如果需要繪製純色物
體,便將此項開啟,也就是寫上ZWrite On。如果要繪製半透明效果,關閉深度緩衝,則用ZWrite Off。
      This statement is used to control whether the future object pixels are written to the depth buffer 
(enabled by default), if need to draw a solid objects, the open, is to write zwrite on. If you want to 
draw the translucent effect, close the depth buffer, then use Off ZWrite.

        語句之三:ZTest Less |Greater | LEqual | GEqual | Equal | NotEqual | Always

         此語句用於控制深度測試如何執行。
        This statement is used to control the depth of the test.

        預設值是LEqual (繪製和存在的物件一致或是在其中的物件;隱藏其背後的物件),含義列舉對應如下:
       The default value is LEqual (the object that is to be consistent or in the presence of the object; 
the object hidden behind it), and the meaning list is as follows:

        GEqual 只渲染大於等於AlphaValue值的畫素;  
        Less 只渲染小於AlphaValue值的畫素;
        LEqual 只渲染小於等於AlphaValue值的畫素;
        Equal 只渲染等於AlphaValue值的畫素;
        NotEqual 只渲染不等於AlphaValue值的畫素;
        Always 渲染所有畫素,等於關閉透明度測試。等於用AlphaTest Off
        Never 不渲染任何畫素
 
        語句之四:Offset Factor ,Units
        此語句用兩個引數(Facto和Units)來定義深度偏移。
       Two parameters for this statement (Facto and Units) to define the depth migration.