Exemplo n.º 1
0
        //---------------------------------------------------------------------------------------------------------------------------------------------------
        private void RenderShadowSplit(ref ShadowSliceData slice, Vector3 lightDirection, Matrix4x4 proj, Matrix4x4 view, ref ScriptableRenderContext loop, DrawShadowsSettings settings)
        {
            var commandBuffer = new CommandBuffer {
                name = "ShadowSetup"
            };

            // Set viewport / matrices etc
            commandBuffer.SetViewport(new Rect(slice.atlasX, slice.atlasY, slice.shadowResolution, slice.shadowResolution));
            //commandBuffer.ClearRenderTarget (true, true, Color.green);
            commandBuffer.SetGlobalVector("g_vLightDirWs", new Vector4(lightDirection.x, lightDirection.y, lightDirection.z));
            commandBuffer.SetViewProjectionMatrices(view, proj);
            //  commandBuffer.SetGlobalDepthBias (1.0F, 1.0F);
            loop.ExecuteCommandBuffer(commandBuffer);
            commandBuffer.Dispose();

            // Render
            loop.DrawShadows(ref settings);
        }
Exemplo n.º 2
0
        private void SetupShadowSplitMatrices(ref ShadowSliceData lightData, Matrix4x4 proj, Matrix4x4 view)
        {
            var matScaleBias = Matrix4x4.identity;

            matScaleBias.m00 = 0.5f;
            matScaleBias.m11 = 0.5f;
            matScaleBias.m22 = 0.5f;
            matScaleBias.m03 = 0.5f;
            matScaleBias.m13 = 0.5f;
            matScaleBias.m23 = 0.5f;

            var matTile = Matrix4x4.identity;

            matTile.m00 = (float)lightData.shadowResolution / (float)m_Settings.shadowAtlasWidth;
            matTile.m11 = (float)lightData.shadowResolution / (float)m_Settings.shadowAtlasHeight;
            matTile.m03 = (float)lightData.atlasX / (float)m_Settings.shadowAtlasWidth;
            matTile.m13 = (float)lightData.atlasY / (float)m_Settings.shadowAtlasHeight;
            lightData.shadowTransform = matTile * matScaleBias * proj * view;
        }