Ejemplo n.º 1
0
        private void Awake()
        {
            s_instance = this;

            cam = GetComponent <Camera>();

            compositeResultBufferMtrl = new Material(Shader.Find("Hidden/JCDeferredShading/CompositeResultBuffer"));
            ssrMtrl = new Material(Shader.Find("Hidden/JCDeferredShading/ScreenSpaceReflection"));

            frontFaceDepthShader = Shader.Find("Hidden/JCDeferredShading/FrontFaceDepth");
            backFaceDepthShader  = Shader.Find("Hidden/JCDeferredShading/BackFaceDepth");

            shaderPropId_diffuseBuffer         = Shader.PropertyToID("_DiffuseBuffer");
            shaderPropId_normalBuffer          = Shader.PropertyToID("_NormalBuffer");
            shaderPropId_positionBuffer        = Shader.PropertyToID("_PositionBuffer");
            shaderPropId_resultBuffer          = Shader.PropertyToID("_ResultBuffer");
            shaderPropId_ssrBuffer             = Shader.PropertyToID("_SSRBuffer");
            shaderPropId_doubleFaceDepthBuffer = Shader.PropertyToID("_DoubleFaceDepthBuffer");

            shaderPropId_ssrVMatrix = Shader.PropertyToID("_SSR_V_MATRIX");
            shaderPropId_ssrPMatrix = Shader.PropertyToID("_SSR_P_MATRIX");

            shaderPropId_screenPixelSize = Shader.PropertyToID("_ScreenPixelSize");

            shaderPropId_dirLightDir   = Shader.PropertyToID("_DirLightDir");
            shaderPropId_dirLightColor = Shader.PropertyToID("_DirLightColor");

            shaderPropId_pointLightPos   = Shader.PropertyToID("_PointLightPos");
            shaderPropId_pointLightColor = Shader.PropertyToID("_PointLightColor");
            shaderPropId_pointLightRange = Shader.PropertyToID("_PointLightRange");

            mrtGBuffer = new JCDSRenderTexture(
                3, Screen.width, Screen.height,
                JCDSRenderTexture.ValueToMask(null),
                RenderTextureFormat.ARGBHalf, FilterMode.Point, false
                );

            resultRT = new JCDSRenderTexture(
                1, Screen.width, Screen.height,
                JCDSRenderTexture.ValueToMask(new bool[] { true }),
                RenderTextureFormat.ARGB32, FilterMode.Point, false
                );

            ssrRT = new JCDSRenderTexture(
                1, Screen.width, Screen.height,
                JCDSRenderTexture.ValueToMask(null),
                RenderTextureFormat.ARGB32, FilterMode.Point, false
                );

            doubleFaceDepthRT = new JCDSRenderTexture(
                1, Screen.width, Screen.height,
                JCDSRenderTexture.ValueToMask(new bool[] { true }),
                RenderTextureFormat.ARGBFloat, FilterMode.Point, false
                );

            CollectLights();

            CreateDoubleFaceDepthCamera();
        }
Ejemplo n.º 2
0
        private void OnDestroy()
        {
            if (mrtGBuffer != null)
            {
                mrtGBuffer.Destroy();
                mrtGBuffer = null;
            }
            if (resultRT != null)
            {
                resultRT.Destroy();
                resultRT = null;
            }
            if (ssrRT != null)
            {
                ssrRT.Destroy();
                ssrRT = null;
            }
            if (doubleFaceDepthRT != null)
            {
                doubleFaceDepthRT.Destroy();
                doubleFaceDepthRT = null;
            }

            if (compositeResultBufferMtrl != null)
            {
                Material.Destroy(compositeResultBufferMtrl);
                compositeResultBufferMtrl = null;
            }

            if (ssrMtrl != null)
            {
                Material.Destroy(ssrMtrl);
                ssrMtrl = null;
            }

            frontFaceDepthShader = null;
            backFaceDepthShader  = null;

            s_instance = null;
        }