void Render() { if (!enabled) { return; } UpdateRenderTargets(); DSRenderer dsr = GetDSRenderer(); Graphics.SetRenderTarget(rtNormalCopy); GL.Clear(false, true, Color.black); matNormalPattern.SetTexture("g_position_buffer", dsr.rtPositionBuffer); matNormalPattern.SetTexture("g_normal_buffer", dsr.rtNormalBuffer); matNormalPattern.SetPass(0); DSRenderer.DrawFullscreenQuad(); Graphics.SetRenderTarget(dsr.rtNormalBuffer); matCopyGBuffer.SetTexture("g_normal_buffer", rtNormalCopy); matCopyGBuffer.SetPass(2); DSRenderer.DrawFullscreenQuad(); dsr.SetRenderTargetsGBuffer(); }
void Render() { if (!enabled) { return; } DSRenderer dsr = GetDSRenderer(); // if there is no subtract or and object, just create g-buffer if (DSSubtract.instances.Count == 0 && DSAnd.instances.Count == 0) { foreach (DSLogicOpReceiver l in DSLogicOpReceiver.instances) { l.matGBuffer.SetPass(0); Graphics.DrawMeshNow(l.mesh, l.trans.localToWorldMatrix); } return; } UpdateRenderTargets(); // and if (DSAnd.instances.Count > 0) { Graphics.SetRenderTarget(rtAndRDepth); GL.Clear(true, true, Color.black, 0.0f); foreach (DSAnd l in DSAnd.instances) { l.matReverseDepth.SetPass(0); Graphics.DrawMeshNow(l.mesh, l.trans.localToWorldMatrix); } Graphics.SetRenderTarget(rbAndGBuffer, rtAndNormalBuffer.depthBuffer); dsr.matGBufferClear.SetPass(0); DSRenderer.DrawFullscreenQuad(); foreach (DSAnd l in DSAnd.instances) { l.matGBuffer.SetPass(0); Graphics.DrawMeshNow(l.mesh, l.trans.localToWorldMatrix); } dsr.SetRenderTargetsGBuffer(); } // create g-buffer if (DSAnd.instances.Count > 0) { Graphics.SetRenderTarget(rtRDepth); GL.Clear(true, true, Color.black, 0.0f); foreach (DSLogicOpReceiver l in DSLogicOpReceiver.instances) { Graphics.SetRenderTarget(rtRDepth); l.matReverseDepth.SetPass(0); Graphics.DrawMeshNow(l.mesh, l.trans.localToWorldMatrix); dsr.SetRenderTargetsGBuffer(); l.matGBuffer.SetInt("_EnableLogicOp", 1); l.matGBuffer.SetTexture("_RDepthBuffer", rtRDepth); l.matGBuffer.SetTexture("_AndRDepthBuffer", rtAndRDepth); l.matGBuffer.SetTexture("_AndNormalBuffer", rtAndNormalBuffer); l.matGBuffer.SetTexture("_AndPositionBuffer", rtAndPositionBuffer); l.matGBuffer.SetTexture("_AndColorBuffer", rtAndColorBuffer); l.matGBuffer.SetTexture("_AndGlowBuffer", rtAndGlowBuffer); l.matGBuffer.SetPass(0); Graphics.DrawMeshNow(l.mesh, l.trans.localToWorldMatrix); Graphics.SetRenderTarget(rtRDepth); l.matDepthClear.SetPass(0); Graphics.DrawMeshNow(l.mesh, l.trans.localToWorldMatrix); } dsr.SetRenderTargetsGBuffer(); } else { foreach (DSLogicOpReceiver l in DSLogicOpReceiver.instances) { l.matGBuffer.SetInt("_EnableLogicOp", 0); l.matGBuffer.SetPass(0); Graphics.DrawMeshNow(l.mesh, l.trans.localToWorldMatrix); } } // create depth buffer with reversed meshes { Graphics.SetRenderTarget(rtRDepth); GL.Clear(true, true, Color.black, 0.0f); foreach (DSLogicOpReceiver l in DSLogicOpReceiver.instances) { l.matReverseDepth.SetPass(0); Graphics.DrawMeshNow(l.mesh, l.trans.localToWorldMatrix); } dsr.SetRenderTargetsGBuffer(); } // subtraction foreach (DSSubtract l in DSSubtract.instances) { l.matStencilWrite.SetPass(0); Graphics.DrawMeshNow(l.mesh, l.trans.localToWorldMatrix); l.matSubtractor.SetTexture("_Depth", rtRDepth); l.matSubtractor.SetPass(0); Graphics.DrawMeshNow(l.mesh, l.trans.localToWorldMatrix); l.matStencilClear.SetPass(0); Graphics.DrawMeshNow(l.mesh, l.trans.localToWorldMatrix); } }