Пример #1
0
        internal RenderStateBlock GetDefaultRenderStateBlock(bool stencilTest, StencilTestOptions stencilTestOptions)
        {
            RenderStateBlock renderStateBlock = new RenderStateBlock();

            if (stencilTest && m_stencilTestState != StencilTestState.None)
            {
                int stencilMask = StencilMaskAllocator.GetCurrentBit();
                renderStateBlock.mask             = RenderStateMask.Stencil;
                renderStateBlock.stencilReference = stencilMask;
                if (m_stencilTestState == StencilTestState.BothSide)
                {
                    if ((stencilTestOptions & StencilTestOptions.PreventOverwriting) == 0)
                    {
                        renderStateBlock.stencilState = new StencilState(true, (byte)stencilMask, 0, CompareFunction.Equal, StencilOp.Keep, StencilOp.Keep, StencilOp.Keep);
                    }
                    else
                    {
                        renderStateBlock.stencilState = new StencilState(true, (byte)stencilMask, (byte)stencilMask, CompareFunction.Equal, StencilOp.Zero, StencilOp.Keep, StencilOp.Keep);
                    }
                }
                else
                {
                    if ((stencilTestOptions & StencilTestOptions.PreventOverwriting) == 0)
                    {
                        renderStateBlock.stencilState = new StencilState(true, (byte)stencilMask, 0, CompareFunction.NotEqual, StencilOp.Keep, StencilOp.Keep, StencilOp.Keep);
                    }
                    else
                    {
                        renderStateBlock.stencilState = new StencilState(true, (byte)stencilMask, (byte)stencilMask, CompareFunction.NotEqual, StencilOp.Replace, StencilOp.Keep, StencilOp.Keep);
                    }
                }
            }
            return(renderStateBlock);
        }
Пример #2
0
 internal void ClearStencil(ScriptableRenderContext context, Material nonSharedStencilMaterial, StencilTestOptions stencilTestOptions)
 {
     if (m_stencilTestState != StencilTestState.None)
     {
         if ((stencilTestOptions & StencilTestOptions.ClearStencil) == StencilTestOptions.ClearStencil)
         {
             CommandBuffer commandBuffer = CommandBufferPool.Get();
             if (m_stencilTestState == StencilTestState.BackfaceOnly)
             {
                 if ((stencilTestOptions & StencilTestOptions.PreventOverwriting) == 0)
                 {
                     commandBuffer.DrawMesh(GetFrustumMesh(), transform.localToWorldMatrix, nonSharedStencilMaterial, 0, 1);
                 }
                 else
                 {
                     ClearFullscreenStencil(commandBuffer);
                     StencilMaskAllocator.Init(StencilMaskAllocator.availableBits);                             // reset stencil allocator
                 }
             }
             else
             {
                 commandBuffer.DrawMesh(GetFrustumMesh(), transform.localToWorldMatrix, nonSharedStencilMaterial, 0, 3);
             }
             context.ExecuteCommandBuffer(commandBuffer);
             CommandBufferPool.Release(commandBuffer);
         }
         else
         {
             // allocate new stencil bit for the next projector
             StencilMaskAllocator.AllocateSingleBit();
         }
         m_stencilTestState = StencilTestState.None;
     }
 }