Esempio n. 1
0
    private void Render()
    {
        _CommandBuffer      = new CommandBuffer();
        _CommandBuffer.name = "AdvancedRTR";

        // get rt
        _CommandBuffer.GetTemporaryRT(ShaderConstants._SourceRT, _Camera.pixelWidth, _Camera.pixelHeight, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf);
        _CommandBuffer.GetTemporaryRT(ShaderConstants._EdgeRT, _Camera.pixelWidth, _Camera.pixelHeight, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf);
        _CommandBuffer.GetTemporaryRT(ShaderConstants._BlendWeightRT, _Camera.pixelWidth, _Camera.pixelHeight, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf);

        // copy
        RuntimeUtilities.BuiltinBlit(_CommandBuffer, BuiltinRenderTextureType.CameraTarget, ShaderConstants._SourceRT);

        // SMAA
        _CommandBuffer.BeginSample("SMAA");

        // edge
        RuntimeUtilities.BlitFullscreenTriangle(_CommandBuffer, ShaderConstants._SourceRT, ShaderConstants._EdgeRT, _SMAAMat, 0);
        // weight
        RuntimeUtilities.BlitFullscreenTriangle(_CommandBuffer, ShaderConstants._EdgeRT, ShaderConstants._BlendWeightRT, _SMAAMat, 1);
        // blend
        _CommandBuffer.SetGlobalTexture("_BlendWeightTex", ShaderConstants._BlendWeightRT);
        RuntimeUtilities.BlitFullscreenTriangle(_CommandBuffer, ShaderConstants._SourceRT, BuiltinRenderTextureType.CameraTarget, _SMAAMat, 2);

        // release rt
        _CommandBuffer.ReleaseTemporaryRT(ShaderConstants._SourceRT);
        _CommandBuffer.ReleaseTemporaryRT(ShaderConstants._EdgeRT);
        _CommandBuffer.ReleaseTemporaryRT(ShaderConstants._BlendWeightRT);

        _CommandBuffer.EndSample("SMAA");

        _Camera.AddCommandBuffer(CameraEvent.BeforeImageEffects, _CommandBuffer);
    }
Esempio n. 2
0
    private void Render()
    {
        _CommandBuffer      = new CommandBuffer();
        _CommandBuffer.name = "AdvancedRTR";

        _CommandBuffer.GetTemporaryRT(ShaderConstants._SourceRT, _Camera.pixelWidth, _Camera.pixelHeight, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf);

        //copy
        RuntimeUtilities.BuiltinBlit(_CommandBuffer, BuiltinRenderTextureType.CameraTarget, ShaderConstants._SourceRT);

        //Paper
        _CommandBuffer.BeginSample("Paper");

        RuntimeUtilities.BlitFullscreenTriangle(_CommandBuffer, ShaderConstants._SourceRT, BuiltinRenderTextureType.CameraTarget, _PaperMat, (int)BlurMethod);

        _CommandBuffer.EndSample("Paper");

        _CommandBuffer.ReleaseTemporaryRT(ShaderConstants._SourceRT);
        _Camera.AddCommandBuffer(CameraEvent.BeforeImageEffects, _CommandBuffer);
    }
Esempio n. 3
0
    private void Render()
    {
        _CommandBuffer      = new CommandBuffer();
        _CommandBuffer.name = "AdvancedRTR";

        _CommandBuffer.GetTemporaryRT(ShaderConstants._SourceRT, _Camera.pixelWidth, _Camera.pixelHeight, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf);

        //copy
        RuntimeUtilities.BuiltinBlit(_CommandBuffer, BuiltinRenderTextureType.CameraTarget, ShaderConstants._SourceRT);

        //FXAA
        _CommandBuffer.BeginSample("SSR");

        _CommandBuffer.GetTemporaryRT(ShaderConstants._TestRT, _Camera.pixelWidth, _Camera.pixelHeight, 0, FilterMode.Bilinear, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
        RuntimeUtilities.BlitFullscreenTriangle(_CommandBuffer, ShaderConstants._SourceRT, ShaderConstants._TestRT, _SSRMat, 0);

        RuntimeUtilities.BuiltinBlit(_CommandBuffer, ShaderConstants._TestRT, BuiltinRenderTextureType.CameraTarget, _BlendMat, 0);

        _CommandBuffer.EndSample("SSR");

        _CommandBuffer.ReleaseTemporaryRT(ShaderConstants._SourceRT);
        _CommandBuffer.ReleaseTemporaryRT(ShaderConstants._TestRT);
        _Camera.AddCommandBuffer(CameraPoint, _CommandBuffer);
    }
Esempio n. 4
0
    private void Render()
    {
        _CommandBuffer      = new CommandBuffer();
        _CommandBuffer.name = "AdvancedRTR";

        _CommandBuffer.GetTemporaryRT(ShaderConstants._SourceRT, _Camera.pixelWidth, _Camera.pixelHeight, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear, 1, false);

        //copy
        RuntimeUtilities.BuiltinBlit(_CommandBuffer, BuiltinRenderTextureType.CameraTarget, ShaderConstants._SourceRT);

        //SSPR
        _CommandBuffer.BeginSample("SSPR");

        #region clear

        _CommandBuffer.GetTemporaryRT(ShaderConstants._IntermediateRT, _Camera.pixelWidth, _Camera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.RInt, RenderTextureReadWrite.Linear, 1, true);

        int width  = _Camera.pixelWidth;
        int height = _Camera.pixelHeight;

        int kernelClear = computeShader.FindKernel("CSMainClear");
        _CommandBuffer.SetComputeTextureParam(computeShader, kernelClear, ShaderConstants._IntermediateRT, ShaderConstants._IntermediateRT);

        _CommandBuffer.DispatchCompute(computeShader, kernelClear, Mathf.CeilToInt(width / 8f), Mathf.CeilToInt(height / 8f), 1);
        #endregion

        #region projection

        int kernelGet = computeShader.FindKernel("CSMainGet");
        _CommandBuffer.SetComputeTextureParam(computeShader, kernelGet, ShaderConstants._CameraDepthTexture, BuiltinRenderTextureType.ResolvedDepth);
        _CommandBuffer.SetComputeTextureParam(computeShader, kernelGet, ShaderConstants._IntermediateRT, ShaderConstants._IntermediateRT);
        _CommandBuffer.SetComputeVectorParam(computeShader, ShaderConstants._TextureSize, new Vector4(1f / width, 1f / height, width, height));
        _CommandBuffer.SetComputeVectorParam(computeShader, ShaderConstants._CameraPos, _Camera.transform.position);
        _CommandBuffer.SetComputeFloatParam(computeShader, ShaderConstants._PlaneHeight, _height);
        _CommandBuffer.SetComputeVectorParam(computeShader, ShaderConstants._PlaneBoxMin, _boxmin);
        _CommandBuffer.SetComputeVectorParam(computeShader, ShaderConstants._PlaneBoxMax, _boxmax);

        _CommandBuffer.SetComputeFloatParam(computeShader, ShaderConstants._StretchThreshold, _threshlod);
        _CommandBuffer.SetComputeFloatParam(computeShader, ShaderConstants._StretchIntensity, _intensity);

        var projectionMatrix = GL.GetGPUProjectionMatrix(_Camera.projectionMatrix, false);
        var vp = projectionMatrix * _Camera.worldToCameraMatrix;

        _CommandBuffer.SetComputeMatrixParam(computeShader, ShaderConstants._InverseProjectionMatrix, vp.inverse);
        _CommandBuffer.SetComputeMatrixParam(computeShader, ShaderConstants._ProjectionMatrix, vp);
        _CommandBuffer.SetComputeMatrixParam(computeShader, ShaderConstants._ViewMatrix, _Camera.worldToCameraMatrix);

        _CommandBuffer.DispatchCompute(computeShader, kernelGet, Mathf.CeilToInt(width / 8f), Mathf.CeilToInt(height / 8f), 1);

        #endregion

        #region resolve

        _CommandBuffer.GetTemporaryRT(ShaderConstants._ResultRT, _Camera.pixelWidth, _Camera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear, 1, true);

        int kernelSet = computeShader.FindKernel("CSMainSet");
        _CommandBuffer.SetComputeTextureParam(computeShader, kernelSet, ShaderConstants._SourceRT, ShaderConstants._SourceRT);
        _CommandBuffer.SetComputeTextureParam(computeShader, kernelSet, ShaderConstants._IntermediateRT, ShaderConstants._IntermediateRT);
        _CommandBuffer.SetComputeTextureParam(computeShader, kernelSet, ShaderConstants._ResultRT, ShaderConstants._ResultRT);
        _CommandBuffer.SetComputeVectorParam(computeShader, ShaderConstants._TextureSize, new Vector4(1f / width, 1f / height, width, height));

        _CommandBuffer.DispatchCompute(computeShader, kernelSet, Mathf.CeilToInt(width / 8f), Mathf.CeilToInt(height / 8f), 1);

        #endregion

        _CommandBuffer.EndSample("SSPR");

        _CommandBuffer.Blit(ShaderConstants._ResultRT, BuiltinRenderTextureType.CameraTarget, _SSPRBlendMat);

        _CommandBuffer.ReleaseTemporaryRT(ShaderConstants._SourceRT);
        _CommandBuffer.ReleaseTemporaryRT(ShaderConstants._IntermediateRT);
        _CommandBuffer.ReleaseTemporaryRT(ShaderConstants._ResultRT);
        _Camera.AddCommandBuffer(CameraEvent.BeforeImageEffects, _CommandBuffer);
    }