Пример #1
0
 public void DrawBuffer(GBufferType buffer)
 {
     Bind(FramebufferTarget.ReadFramebuffer);
     SetReadBuffer(buffer);
     GL.BlitFramebuffer(0, 0, _width, _height, 0, 0, _width, _height, ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Linear);
     Unbind(FramebufferTarget.ReadFramebuffer);
 }
Пример #2
0
 private void SetBuffer(GBufferType buffer)
 {
     if (_renderGBuffer && _renderbufferType == buffer)
     {
         _renderGBuffer = false;
         return;
     }
     _renderGBuffer    = true;
     _renderbufferType = buffer;
 }
Пример #3
0
    string GetGBufferKeyword(GBufferType type)
    {
        switch (type)
        {
        case GBufferType.Diffuse: return("GBUFFER_DIFFUSE");

        case GBufferType.Depth: return("GBUFFER_DEPTH");

        case GBufferType.Normal: return("GBUFFER_NORMAL");

        case GBufferType.Emission: return("GBUFFER_EMISSION");

        case GBufferType.Glossiness: return("GBUFFER_GLOSSINESS");

        case GBufferType.Metallic: return("GBUFFER_METALLIC");

        default: return("GBUFFER_DIFFUSE");
        }
    }
Пример #4
0
    public void RenderDeferred(ScriptableRenderContext renderContext, Camera camera, VXGI vxgi)
    {
        ScriptableCullingParameters cullingParams;

        if (!CullResults.GetCullingParameters(camera, out cullingParams))
        {
            return;
        }
        CullResults.Cull(ref cullingParams, renderContext, ref _cullResults);

        _command.BeginSample(_command.name);

        _command.GetTemporaryRT(_propDepth, camera.pixelWidth, camera.pixelHeight, 24, FilterMode.Point, RenderTextureFormat.Depth);
        _command.GetTemporaryRT(_propDiffuse, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf);
        _command.GetTemporaryRT(_propNormal, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGBFloat);
        _command.GetTemporaryRT(_propEmission, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf);
        _command.GetTemporaryRT(_propOther, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf);
        _command.GetTemporaryRT(_propIrradiance,
                                (int)(vxgi.diffuseResolutionScale * camera.pixelWidth),
                                (int)(vxgi.diffuseResolutionScale * camera.pixelHeight),
                                0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf
                                );

        var binding = new RenderTargetBinding(
            new RenderTargetIdentifier[] { _propDiffuse, _propNormal, _propEmission, _propOther },
            new[] { RenderBufferLoadAction.DontCare, RenderBufferLoadAction.DontCare, RenderBufferLoadAction.DontCare, RenderBufferLoadAction.DontCare },
            new[] { RenderBufferStoreAction.DontCare, RenderBufferStoreAction.DontCare, RenderBufferStoreAction.DontCare, RenderBufferStoreAction.DontCare },
            _propDepth, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.DontCare
            );

        _command.SetRenderTarget(binding);
        _command.ClearRenderTarget(true, true, Color.clear);
        renderContext.ExecuteCommandBuffer(_command);
        _command.Clear();

        var drawSettings = new DrawRendererSettings(camera, new ShaderPassName("Deferred"));

        drawSettings.sorting.flags = SortFlags.CommonOpaque;

        renderContext.DrawRenderers(_cullResults.visibleRenderers, ref drawSettings, _filterSettings);

        if (vxgi.pass == Pass.ConeTracing)
        {
            renderContext.SetupCameraProperties(camera);
            renderContext.DrawSkybox(camera);
        }

        if (_gBufferType != vxgi.gBufferType)
        {
            _command.DisableShaderKeyword(GetGBufferKeyword(_gBufferType));
            _command.EnableShaderKeyword(GetGBufferKeyword(vxgi.gBufferType));
            _gBufferType = vxgi.gBufferType;
        }

        if (_coneType != vxgi.coneType)
        {
            var keyword = GetConeKeyword(_coneType);
            if (keyword != null)
            {
                _command.DisableShaderKeyword(keyword);
            }

            keyword = GetConeKeyword(vxgi.coneType);
            if (keyword != null)
            {
                _command.EnableShaderKeyword(keyword);
            }

            _coneType = vxgi.coneType;
        }

        if (vxgi.skybox == null)
        {
            _command.DisableShaderKeyword("REFLECT_SKYBOX");
        }
        else
        {
            _command.EnableShaderKeyword("REFLECT_SKYBOX");
            _command.SetGlobalTexture("Skybox", vxgi.skybox);
        }

        Matrix4x4 clipToWorld = camera.cameraToWorldMatrix * GL.GetGPUProjectionMatrix(camera.projectionMatrix, false).inverse;

        _command.SetGlobalVector("CameraPosition", camera.transform.position);
        _command.SetGlobalMatrix("ClipToWorld", clipToWorld);
        _command.SetGlobalMatrix("ClipToVoxel", vxgi.worldToVoxel * clipToWorld);
        _command.SetGlobalMatrix("WorldToVoxel", vxgi.worldToVoxel);
        _command.SetGlobalMatrix("VoxelToWorld", vxgi.voxelToWorld);

        _command.EndSample(_command.name);

        renderContext.ExecuteCommandBuffer(_command);

        _command.Clear();

        if (vxgi.pass == Pass.ConeTracing)
        {
            _commandDiffuse.BeginSample(_commandDiffuse.name);
            _commandDiffuse.Blit(_propDiffuse, _propIrradiance, material, (int)Pass.DiffuseConeTracing);
            _commandDiffuse.EndSample(_commandDiffuse.name);

            renderContext.ExecuteCommandBuffer(_commandDiffuse);

            _commandDiffuse.Clear();
        }

        _commandReflection.BeginSample(_commandReflection.name);
        _commandReflection.Blit(_propDiffuse, BuiltinRenderTextureType.CameraTarget, material, (int)vxgi.pass);
        _commandReflection.EndSample(_commandReflection.name);

        renderContext.ExecuteCommandBuffer(_commandReflection);

        _commandReflection.Clear();

        _command.BeginSample(_command.name);

        _command.ReleaseTemporaryRT(_propDepth);
        _command.ReleaseTemporaryRT(_propDiffuse);
        _command.ReleaseTemporaryRT(_propNormal);
        _command.ReleaseTemporaryRT(_propEmission);
        _command.ReleaseTemporaryRT(_propOther);
        _command.ReleaseTemporaryRT(_propIrradiance);

        _command.EndSample(_command.name);

        renderContext.ExecuteCommandBuffer(_command);

        _command.Clear();
    }
Пример #5
0
 public void DrawGBuffer(GBufferType buffer)
 {
     _gbuffer.DrawBuffer(buffer);
 }
Пример #6
0
 private void SetReadBuffer(GBufferType buffer)
 {
     _fbo.AssertActive(FramebufferTarget.ReadFramebuffer);
     GL.ReadBuffer(ReadBufferMode.ColorAttachment0 + (int)buffer);
 }