Esempio n. 1
0
    // --------------------------------------------------------------------
    void RunPointLightRendering(L2DLPointLight pointLight)
    {
        SetupCommonLightRenderingProperties(m_pointLightRenderingBuffer, pointLight);
        m_pointLightRenderingBuffer.SetGlobalFloat("_lightAttenuation", 1f / Mathf.Max(pointLight.Range * pointLight.Range, 0.00001f));
        m_pointLightRenderingBuffer.SetGlobalVector("_lightPosition", pointLight.transform.position);

        m_pointLightRenderingBuffer.SetGlobalFloat("_maxIntensityOutput", pointLight.MaxIntensityOutput);

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

        L2DLRenderHelpers.ExecuteBuffer(m_context, m_pointLightRenderingBuffer);
    }
Esempio n. 2
0
 public void CalculateShadowMap(ScriptableRenderContext _context, CommandBuffer _buffer, L2DLPointLight _pointLight, L2DLDirectLightData _data, RenderTargetIdentifier i_occlusionMap, RenderTargetIdentifier o_shadowMap)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 3
0
    // --------------------------------------------------------------------
    public void CalculateShadowMap(ScriptableRenderContext _context, CommandBuffer _buffer, L2DLPointLight _pointLight, L2DLDirectLightData _data, RenderTargetIdentifier i_occlusionMap, RenderTargetIdentifier o_shadowMap)
    {
        if (!L2DLRenderHelpers.SupportsComputeShaders())
        {
            return;
        }

        ReloadComputeShaders();

        int occlusionTraceComputeKernel = m_pointLightOcclusionTraceCompute.FindKernel("PointLightOcclusionTrace");

        SetupCommonComputeShaderProperties(_buffer, m_pointLightOcclusionTraceCompute, occlusionTraceComputeKernel, _pointLight, _data);
        _buffer.SetComputeFloatParam(m_pointLightOcclusionTraceCompute, "_TextureSizeHalf", (int)_pointLight.ShadowMapSize / 2);
        _buffer.SetComputeFloatParam(m_pointLightOcclusionTraceCompute, "_TexturePercentagePerPixel", 1f / (int)_pointLight.ShadowMapSize);
        _buffer.SetComputeFloatParam(m_pointLightOcclusionTraceCompute, "_WorldDistPerStep", _pointLight.Range * 2f / (int)_pointLight.ShadowMapSize);
        _buffer.DispatchCompute(m_pointLightOcclusionTraceCompute, occlusionTraceComputeKernel, (int)_pointLight.ShadowMapSize / 16, 4, 1);
        L2DLRenderHelpers.ExecuteBuffer(_context, _buffer);
    }
Esempio n. 4
0
 void RunPointLightOcclusionMapTrace(L2DLPointLight pointLight)
 {
     m_directLightData.ShadowMapCalculator.CalculateShadowMap(m_context, m_pointLightRenderingBuffer, pointLight, m_directLightData, m_directLightOcclusionMapId, m_directLightShadowMapId);
 }
Esempio n. 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);
            }
        }
    }