public override void SetupCullingParameters(ref ScriptableCullingParameters cullingParameters, ref CameraData cameraData)
        {
            ShadowTextureRenderer shadowTextureRenderer = cameraData.camera.GetComponent <ShadowTextureRenderer>();

            if (shadowTextureRenderer == null)
            {
#if UNITY_EDITOR
                Debug.LogWarning("No ShadowTextureRenderer found.");
#endif
                return;
            }
            shadowTextureRenderer.UpdateVisibilityAndPrepareRendering();
            cullingParameters.cullingMask = 0;
            if (shadowTextureRenderer.isProjectorVisible)
            {
                DrawSceneObject drawScene = cameraData.camera.GetComponent <DrawSceneObject>();
                if (drawScene != null)
                {
                    cullingParameters.cullingMask = (uint)drawScene.cullingMask.value;
                }
                DrawTargetObject drawTarget = shadowTextureRenderer.GetComponent <DrawTargetObject>();
                if (drawTarget != null)
                {
                    drawTarget.SendMessage("OnPreCull");
                }
                shadowTextureRenderer.ConfigureRenderTarget(m_renderShadowTexturePass, ref cameraData);
            }
            cullingParameters.cullingOptions = CullingOptions.None;
            cullingParameters.shadowDistance = 0;
        }
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            Camera camera = renderingData.cameraData.camera;

            DynamicShadowProjectorRenderer.DynamicShadowProjectorComponents components = m_renderer.GetDynamicShadowProjectorComponents(renderingData.cameraData.camera);
            ShadowTextureRenderer shadowTextureRenderer = components.shadowTextureRenderer;

            if (shadowTextureRenderer == null || !shadowTextureRenderer.isProjectorVisible)
            {
                return;
            }

            DrawSceneObject drawScene = components.drawSceneObject;

            if (drawScene != null)
            {
                if (m_overrideOpaqueMaterial == null)
                {
                    m_overrideOpaqueMaterial = new Material(shadowTextureRenderer.m_opaqueShadowShaderForLWRP);
                }
                else if (m_overrideOpaqueMaterial.shader != shadowTextureRenderer.m_opaqueShadowShaderForLWRP)
                {
                    m_overrideOpaqueMaterial.shader = shadowTextureRenderer.m_opaqueShadowShaderForLWRP;
                }
                if (m_overrideTransparentMaterial == null)
                {
                    m_overrideTransparentMaterial = new Material(shadowTextureRenderer.m_transparentShadowShaderForLWRP);
                }
                else if (m_overrideTransparentMaterial.shader != shadowTextureRenderer.m_transparentShadowShaderForLWRP)
                {
                    m_overrideTransparentMaterial.shader = shadowTextureRenderer.m_transparentShadowShaderForLWRP;
                }
                DrawingSettings drawingSettings = new DrawingSettings(m_shaderTagIds[0], new SortingSettings(camera));
                for (int i = 1; i < m_shaderTagIds.Length; ++i)
                {
                    drawingSettings.SetShaderPassName(i, m_shaderTagIds[i]);
                }
                // draw opaque objects
                drawingSettings.overrideMaterial          = m_overrideOpaqueMaterial;
                drawingSettings.overrideMaterialPassIndex = 0;
                drawingSettings.enableDynamicBatching     = renderingData.supportsDynamicBatching;
                drawingSettings.enableInstancing          = true;
                drawingSettings.perObjectData             = PerObjectData.None;
                FilteringSettings opaqueFilteringSettings = new FilteringSettings(new RenderQueueRange(RenderQueueRange.opaque.lowerBound, 2500), drawScene.cullingMask);
                context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref opaqueFilteringSettings);
                // draw transparent objects
                drawingSettings.overrideMaterial = m_overrideTransparentMaterial;
                FilteringSettings transparentFilteringSettings = new FilteringSettings(new RenderQueueRange(2500, RenderQueueRange.transparent.upperBound), drawScene.cullingMask);
                context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref transparentFilteringSettings);
            }
            DrawTargetObject drawTarget = components.drawTargetObject;

            if (drawTarget != null)
            {
                context.ExecuteCommandBuffer(drawTarget.commandBuffer);
            }
            shadowTextureRenderer.ExecutePostRenderProcess(context);
        }
Exemplo n.º 3
0
        void OnEnable()
        {
            DrawSceneObject component = target as DrawSceneObject;

            if (component.replacementShader == null)
            {
                component.replacementShader = Shader.Find("Hidden/DynamicShadowProjector/Shadow/Replacement");
                serializedObject.Update();
                EditorUtility.SetDirty(component);
            }
        }
Exemplo n.º 4
0
 public void SetComponentsFromCamera(Camera camera)
 {
     shadowTextureRenderer = camera.GetComponent <ShadowTextureRenderer>();
     if (shadowTextureRenderer != null)
     {
         drawTargetObject           = camera.GetComponent <DrawTargetObject>();
         drawSceneObject            = camera.GetComponent <DrawSceneObject>();
         m_hasShadowTextureRenderer = true;
     }
     else
     {
         drawTargetObject           = null;
         drawSceneObject            = null;
         m_hasShadowTextureRenderer = false;
     }
 }
Exemplo n.º 5
0
        private void Init()
        {
            if (m_ShadowProjector != null && mDrawSceneObject != null)
            {
                return;
            }

            UnityEngine.Object shadowObj = ResourceLoader.Instance.try_load_cached_asset("Assets/Res/Core/ShadowProjector/HardShadowProjector.prefab") as UnityEngine.Object;
            if (shadowObj != null)
            {
                m_ShadowProjector = GameObject.Instantiate(shadowObj) as GameObject;
                if (m_ShadowProjector != null)
                {
                    mDrawSceneObject = m_ShadowProjector.GetComponent <DrawSceneObject>();
                    GameObject.DontDestroyOnLoad(m_ShadowProjector);
                }
            }
        }
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            if (m_rendered)
            {
                // in case of multipass VR, render pass will be called twice even if renderPassEvent == RenderPassEvent.BeforeRendering...
                return;
            }
            CommandBuffer cmd = CommandBufferPool.Get();

            cmd.SetViewProjectionMatrices(m_renderer.projectorCamera.worldToCameraMatrix, m_renderer.projectorCamera.projectionMatrix);
            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
            DrawSceneObject drawScene = m_renderer.drawSceneObject;

            if (drawScene != null)
            {
                ScriptableCullingParameters cullingParameters = new ScriptableCullingParameters();
                if (m_renderer.projectorCamera.TryGetCullingParameters(false, out cullingParameters))
                {
                    cullingParameters.cullingMask = (uint)drawScene.cullingMask.value;
                    CullingResults cullingResults = context.Cull(ref cullingParameters);
                    if (m_overrideOpaqueMaterial == null)
                    {
                        m_overrideOpaqueMaterial = new Material(drawScene.replacementShader);
                    }
                    else if (m_overrideOpaqueMaterial.shader != drawScene.replacementShader)
                    {
                        m_overrideOpaqueMaterial.shader = drawScene.replacementShader;
                    }
                    if (m_overrideAlphaCutoffMaterial == null)
                    {
                        m_overrideAlphaCutoffMaterial = new Material(drawScene.replacementShader);
                        m_overrideAlphaCutoffMaterial.EnableKeyword("_ALPHATEST_ON");
                        m_overrideAlphaCutoffMaterial.SetFloat("_DstBlend", 10.0f);                         // OneMinusSrcAlpha
                    }
                    else if (m_overrideAlphaCutoffMaterial.shader != drawScene.replacementShader)
                    {
                        m_overrideAlphaCutoffMaterial.shader = drawScene.replacementShader;
                    }
                    if (m_overrideTransparentMaterial == null)
                    {
                        m_overrideTransparentMaterial = new Material(drawScene.replacementShader);
                        m_overrideTransparentMaterial.EnableKeyword("_ALPHATEST_ON");
                        m_overrideTransparentMaterial.EnableKeyword("_ALPHABLEND_ON");
                        m_overrideTransparentMaterial.SetFloat("_SrcBlend", 5.0f);                         // SrcAlpha
                        m_overrideTransparentMaterial.SetFloat("_DstBlend", 10.0f);                        // OneMinusSrcAlpha
                    }
                    else if (m_overrideTransparentMaterial.shader != drawScene.replacementShader)
                    {
                        m_overrideTransparentMaterial.shader = drawScene.replacementShader;
                    }
                    DrawingSettings drawingSettings = new DrawingSettings(drawScene.shaderTagIds[0], new SortingSettings(m_renderer.projectorCamera));
                    for (int i = 1; i < drawScene.shaderTagIds.Length; ++i)
                    {
                        drawingSettings.SetShaderPassName(i, drawScene.shaderTagIds[i]);
                    }
                    // draw opaque objects
                    drawingSettings.overrideMaterial          = m_overrideOpaqueMaterial;
                    drawingSettings.overrideMaterialPassIndex = 0;
                    drawingSettings.enableDynamicBatching     = renderingData.supportsDynamicBatching;
                    drawingSettings.enableInstancing          = true;
                    drawingSettings.perObjectData             = PerObjectData.None;
                    FilteringSettings opaqueFilteringSettings = new FilteringSettings(new RenderQueueRange(RenderQueueRange.opaque.lowerBound, 2400), drawScene.cullingMask);
                    context.DrawRenderers(cullingResults, ref drawingSettings, ref opaqueFilteringSettings);
                    // draw alpha-cutoff objects
                    drawingSettings.overrideMaterial = m_overrideAlphaCutoffMaterial;
                    FilteringSettings alphacutoutFilteringSettings = new FilteringSettings(new RenderQueueRange(2400, RenderQueueRange.opaque.upperBound), drawScene.cullingMask);
                    context.DrawRenderers(cullingResults, ref drawingSettings, ref alphacutoutFilteringSettings);
                    // draw transparent objects
                    drawingSettings.overrideMaterial = m_overrideTransparentMaterial;
                    FilteringSettings transparentFilteringSettings = new FilteringSettings(new RenderQueueRange(RenderQueueRange.transparent.lowerBound, RenderQueueRange.transparent.upperBound), drawScene.cullingMask);
                    context.DrawRenderers(cullingResults, ref drawingSettings, ref transparentFilteringSettings);
                }
            }
            DrawTargetObject drawTarget = m_renderer.drawTargetObject;

            if (drawTarget != null)
            {
                context.ExecuteCommandBuffer(drawTarget.commandBuffer);
            }
            m_renderer.ExecutePostRenderProcess(context);
            m_rendered = true;
        }