// --------------------------------------------------------------------
    void RunDirectionalLightRendering(L2DLDirectionalLight directionalLight)
    {
        SetupCommonLightRenderingProperties(m_directionalLightRenderingBuffer, directionalLight);

        m_directionalLightRenderingBuffer.SetRenderTarget(new RenderTargetIdentifier[] { L2DLPipelineData.s_cameraDirectLightResultTextureId, L2DLPipelineData.s_cameraEmissionTextureId }, L2DLPipelineData.s_cameraFakeDepthTextureId);
        m_directionalLightRenderingBuffer.Blit(null, BuiltinRenderTextureType.CurrentActive, DirectionalLightPassMaterial);

        L2DLRenderHelpers.ExecuteBuffer(m_context, m_directionalLightRenderingBuffer);
    }
Beispiel #2
0
 public void CalculateShadowMap(ScriptableRenderContext _context, CommandBuffer _buffer, L2DLDirectionalLight _directionalLight, L2DLDirectLightData _data, RenderTargetIdentifier i_occlusionMap, RenderTargetIdentifier o_shadowMap)
 {
     // Here we run the code that calculates the shadow map using standard rendering...
     _buffer.SetGlobalTexture("_OcclusionMap", i_occlusionMap);
     _buffer.SetGlobalInt("_SamplesPerPixel", m_samplesPerPixel);
     _buffer.SetGlobalFloat("_WorldDistPerStep", _directionalLight.Height / m_samplesPerPixel);
     _buffer.Blit(i_occlusionMap, o_shadowMap, DirectionalShadowMapRenderMaterial);
     L2DLRenderHelpers.ExecuteBuffer(_context, _buffer);
 }
Beispiel #3
0
    // --------------------------------------------------------------------
    public void CalculateShadowMap(ScriptableRenderContext _context, CommandBuffer _buffer, L2DLDirectionalLight _directionalLight, L2DLDirectLightData _data, RenderTargetIdentifier i_occlusionMap, RenderTargetIdentifier o_shadowMap)
    {
        if (!L2DLRenderHelpers.SupportsComputeShaders())
        {
            return;
        }

        ReloadComputeShaders();

        int occlusionTraceComputeKernel = m_directionalLightOcclusionTraceCompute.FindKernel("DirectionalLightOcclusionTrace");

        SetupCommonComputeShaderProperties(_buffer, m_directionalLightOcclusionTraceCompute, occlusionTraceComputeKernel, _directionalLight, _data);
        _buffer.SetComputeFloatParam(m_directionalLightOcclusionTraceCompute, "_WorldDistPerStep", _directionalLight.Height / (int)_directionalLight.ShadowMapSize);
        _buffer.DispatchCompute(m_directionalLightOcclusionTraceCompute, occlusionTraceComputeKernel, (int)_directionalLight.ShadowMapSize / 64, 1, 1);
        L2DLRenderHelpers.ExecuteBuffer(_context, _buffer);
    }
 // --------------------------------------------------------------------
 void RunDirectionalLightOcclusionMapTrace(L2DLDirectionalLight directionalLight)
 {
     m_directLightData.ShadowMapCalculator.CalculateShadowMap(m_context, m_directionalLightRenderingBuffer, directionalLight, m_directLightData, m_directLightOcclusionMapId, m_directLightShadowMapId);
 }
Beispiel #5
0
    protected override void Render(ScriptableRenderContext context, Camera[] cameras)
    {
        // 2D Lights will have associated cameras because amazingly it's impossible to cull without a camera so here I'll need to filter light cameras out from non-light cameras
        // I can then handle the light cameras seperately to generate their occlusion / shadow maps and let each actual camera reuse them
        m_directLights.Clear();

        // When in the scene view it doesn't pass in all the cameras active in the scene
        // so we need to get them manually. The performance hit is only in scene view so won't hit in-game
        Camera[] directLightPotentialCameras = cameras;
#if UNITY_EDITOR
        directLightPotentialCameras = Object.FindObjectsOfType <Camera>();
        Camera mainCamera = null;
#endif

        foreach (Camera camera in directLightPotentialCameras)
        {
            if (camera.tag == "L2DLDirectLight")
            {
                L2DLDirectionalLight directionalLight = camera.gameObject.GetComponent <L2DLDirectionalLight>();
                if (directionalLight != null)
                {
                    m_directLights.m_directionalLights.Add(directionalLight);
                    continue;
                }

                L2DLPointLight pointLight = camera.gameObject.GetComponent <L2DLPointLight>();
                if (pointLight != null)
                {
                    m_directLights.m_pointLights.Add(pointLight);
                    continue;
                }

                L2DLSpotLight spotLight = camera.gameObject.GetComponent <L2DLSpotLight>();
                if (spotLight != null)
                {
                    m_directLights.m_spotLights.Add(spotLight);
                    continue;
                }
            }
#if UNITY_EDITOR
            else if (camera.tag == "MainCamera")
            {
                mainCamera = camera;
            }
#endif
        }

        // Only pass non-direct light rendering cameras to the pipeline
        // Direct light cameras can be accessed via the associated direct light component
        foreach (Camera camera in cameras)
        {
            if (camera.tag != "L2DLDirectLight")
            {
#if UNITY_EDITOR
                // The scene camera is in a strange place, and usually doesn't render depth
                // so we'll find the main camera, and bring it in line with that,
                // shift the clip plants, and render to the depth texture
                camera.depthTextureMode = DepthTextureMode.Depth;
                Vector3 cameraPosition = camera.transform.position;
                cameraPosition.z          = mainCamera.transform.position.z;
                camera.transform.position = cameraPosition;
                camera.nearClipPlane      = mainCamera.nearClipPlane;
                camera.farClipPlane       = mainCamera.farClipPlane;
#endif
                m_cameraRenderer.Render(context, camera, m_directLights);
            }
        }
    }