public VXGIRenderPipeline(VXGIRenderPipelineAsset asset)
    {
        _renderer = new VXGIRenderer(this);
        _command  = new CommandBuffer()
        {
            name = "VXGI.RenderPipeline"
        };
        _filterSettings = new FilterRenderersSettings(true)
        {
            renderQueueRange = RenderQueueRange.opaque
        };

        _drawRendererFlags = DrawRendererFlags.None;
        if (asset.dynamicBatching)
        {
            _drawRendererFlags |= DrawRendererFlags.EnableDynamicBatching;
        }

        _rendererConfiguration = RendererConfiguration.None;

        if (asset.environmentLighting)
        {
            _rendererConfiguration |= RendererConfiguration.PerObjectLightProbe;
        }
        if (asset.environmentReflections)
        {
            _rendererConfiguration |= RendererConfiguration.PerObjectReflectionProbes;
        }

        Shader.globalRenderPipeline = "VXGI";

        GraphicsSettings.lightsUseLinearIntensity            = true;
        GraphicsSettings.useScriptableRenderPipelineBatching = asset.SRPBatching;
    }
Exemplo n.º 2
0
    public VXGIRenderPipeline(VXGIRenderPipelineAsset asset)
    {
        _renderer = new VXGIRenderer(this);
        _command  = new CommandBuffer()
        {
            name = "VXGI.RenderPipeline"
        };
        _filterSettings = new FilteringSettings()
        {
            renderQueueRange = RenderQueueRange.opaque
        };



        _perObjectData = PerObjectData.None;

        if (asset.environmentLighting)
        {
            _perObjectData |= PerObjectData.LightProbe;
        }
        if (asset.environmentReflections)
        {
            _perObjectData |= PerObjectData.ReflectionProbes;
        }

        Shader.globalRenderPipeline = "VXGI";

        GraphicsSettings.lightsUseLinearIntensity            = true;
        GraphicsSettings.useScriptableRenderPipelineBatching = asset.SRPBatching;
    }
Exemplo n.º 3
0
    public void Render(ScriptableRenderContext renderContext, Camera camera, VXGIRenderer renderer)
    {
        UpdateResolution();

        float realtime         = Time.realtimeSinceStartup;
        bool  tracingThrottled = throttleTracing;

#if UNITY_EDITOR
        tracingThrottled &= UnityEditor.EditorApplication.isPlaying;
#endif

        if (tracingThrottled)
        {
            if (_previousTrace + 1f / tracingRate < realtime)
            {
                _previousTrace = realtime;

                PrePass(renderContext, renderer);
            }
        }
        else
        {
            PrePass(renderContext, renderer);
        }

        renderContext.SetupCameraProperties(camera, camera.stereoEnabled);
        if (camera.stereoEnabled)
        {
            renderContext.StartMultiEye(camera);
        }

        _command.ClearRenderTarget(
            (camera.clearFlags & CameraClearFlags.Depth) != 0,
            camera.clearFlags == CameraClearFlags.Color,
            camera.backgroundColor
            );
        renderContext.ExecuteCommandBuffer(_command);
        _command.Clear();

        if (camera.clearFlags == CameraClearFlags.Skybox)
        {
            renderContext.DrawSkybox(camera);
        }

        if (visualizeMipmap)
        {
            renderer.RenderMipmap(renderContext, camera, this);
        }
        else
        {
            SetupShader(renderContext);
            renderer.RenderDeferred(renderContext, camera, this);
        }

        if (camera.stereoEnabled)
        {
            renderContext.StopMultiEye(camera);
            renderContext.StereoEndRender(camera);
        }
    }
Exemplo n.º 4
0
    public void Voxelize(ScriptableRenderContext renderContext, VXGIRenderer renderer)
    {
        ScriptableCullingParameters cullingParams;

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

        _lightColors.Clear();
        _lightPositions.Clear();

        foreach (var light in _cullResults.visibleLights)
        {
            if (light.lightType == LightType.Point)
            {
                _lightColors.Add(light.finalColor);
                _lightPositions.Add(light.light.transform.position);
            }
        }

        UpdateCamera();

        _camera.pixelRect = _rect;

        _command.BeginSample(_command.name);

        _command.GetTemporaryRT(_propDummyTarget, _cameraDescriptor);
        _command.SetRenderTarget(_propDummyTarget, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.DontCare);

        _command.SetGlobalInt("Resolution", _resolution);
        _command.SetGlobalMatrix("WorldToVoxel", _vxgi.worldToVoxel);
        _command.SetGlobalMatrix("VoxelToProjection", GL.GetGPUProjectionMatrix(_camera.projectionMatrix, true) * _camera.worldToCameraMatrix * _vxgi.voxelToWorld);
        _command.SetRandomWriteTarget(1, _vxgi.voxelBuffer, false);

        _drawSettings.flags = renderer.drawRendererFlags;
        _drawSettings.rendererConfiguration = renderer.rendererConfiguration;

        renderContext.ExecuteCommandBuffer(_command);
        renderContext.DrawRenderers(_cullResults.visibleRenderers, ref _drawSettings, _filterSettings);

        _command.Clear();

        _command.ClearRandomWriteTargets();
        _command.ReleaseTemporaryRT(_propDummyTarget);

        _command.EndSample(_command.name);

        renderContext.ExecuteCommandBuffer(_command);

        _command.Clear();
    }
Exemplo n.º 5
0
    public void Voxelize(ScriptableRenderContext renderContext, VXGIRenderer renderer)
    {
        if (!_camera.TryGetCullingParameters(_camera, out var cullingParams))
        {
            return;
        }
        _cullResults = renderContext.Cull(ref cullingParams);

        _vxgi.lights.Clear();

        foreach (var light in _cullResults.visibleLights)
        {
            if (VXGI.supportedLightTypes.Contains(light.lightType) && light.finalColor.maxColorComponent > 0f)
            {
                _vxgi.lights.Add(new LightSource(light, _vxgi.worldToVoxel));
            }
        }

        UpdateCamera();

        _camera.pixelRect = _rect;

        _command.BeginSample(_command.name);

        _command.GetTemporaryRT(ShaderIDs.Dummy, _cameraDescriptor);
        _command.SetRenderTarget(ShaderIDs.Dummy, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.DontCare);

        _command.SetGlobalInt(ShaderIDs.Resolution, _resolution);
        _command.SetGlobalMatrix(ShaderIDs.WorldToVoxel, _vxgi.worldToVoxel);
        _command.SetGlobalMatrix(ShaderIDs.VoxelToProjection, GL.GetGPUProjectionMatrix(_camera.projectionMatrix, true) * _camera.worldToCameraMatrix * _vxgi.voxelToWorld);
        _command.SetRandomWriteTarget(1, _vxgi.voxelBuffer, false);


        _drawSettings.enableDynamicBatching = true;
        _drawSettings.enableInstancing      = true;

        _drawSettings.perObjectData = renderer.perObjectData;

        renderContext.ExecuteCommandBuffer(_command);
        renderContext.DrawRenderers(_cullResults, ref _drawSettings, ref _filterSettings);

        _command.Clear();

        _command.ClearRandomWriteTargets();
        _command.ReleaseTemporaryRT(ShaderIDs.Dummy);

        _command.EndSample(_command.name);

        renderContext.ExecuteCommandBuffer(_command);

        _command.Clear();
    }
Exemplo n.º 6
0
    public VXGIRenderPipeline(VXGIRenderPipelineAsset asset)
    {
        _renderer = new VXGIRenderer(this);
        _command  = new CommandBuffer()
        {
            name = "VXGI.RenderPipeline"
        };
        _filteringSettings = FilteringSettings.defaultValue;

        PerObjectData = asset.perObjectData;
        Shader.globalRenderPipeline = "VXGI";
        GraphicsSettings.lightsUseLinearIntensity            = true;
        GraphicsSettings.useScriptableRenderPipelineBatching = asset.SRPBatching;
    }
Exemplo n.º 7
0
  public VXGIRenderPipeline(VXGIRenderPipelineAsset asset) {
    _renderer = new VXGIRenderer(this);
    _command = new CommandBuffer() { name = "VXGIRenderPipeline" };
    _filterSettings = new FilterRenderersSettings(true) { renderQueueRange = RenderQueueRange.opaque };

    _drawRendererFlags = DrawRendererFlags.None;
    if (asset.dynamicBatching) _drawRendererFlags |= DrawRendererFlags.EnableDynamicBatching;

    Shader.globalRenderPipeline = "VXGI";
    Shader.SetGlobalVectorArray("LightColors", new Vector4[64]);
    Shader.SetGlobalVectorArray("LightPositions", new Vector4[64]);

    GraphicsSettings.useScriptableRenderPipelineBatching = asset.SRPBatching;
  }
Exemplo n.º 8
0
    public void Render(ScriptableRenderContext renderContext, Camera camera, VXGIRenderer renderer)
    {
        VXGIRenderPipeline.TriggerCameraCallback(camera, "OnPreRender", Camera.onPreRender);

        _command.BeginSample(_command.name);
        renderContext.ExecuteCommandBuffer(_command);
        _command.Clear();

        UpdateResolution();

        float realtime         = Time.realtimeSinceStartup;
        bool  tracingThrottled = throttleTracing;

        if (tracingThrottled)
        {
            if (_previousTrace + 1f / tracingRate < realtime)
            {
                _previousTrace = realtime;

                PrePass(renderContext, renderer);
            }
        }
        else
        {
            PrePass(renderContext, renderer);
        }

        renderContext.SetupCameraProperties(camera);

        _command.ClearRenderTarget(
            (camera.clearFlags & CameraClearFlags.Depth) != 0,
            camera.clearFlags == CameraClearFlags.Color,
            camera.backgroundColor
            );
        renderContext.ExecuteCommandBuffer(_command);
        _command.Clear();

        SetupShader(renderContext);

        VXGIRenderPipeline.TriggerCameraCallback(camera, "OnPreCull", Camera.onPreCull);

        renderer.RenderDeferred(renderContext, camera, this);

        _command.EndSample(_command.name);
        renderContext.ExecuteCommandBuffer(_command);
        _command.Clear();

        VXGIRenderPipeline.TriggerCameraCallback(camera, "OnPostRender", Camera.onPostRender);
    }
    public VXGIRenderPipeline()
    {
        _renderer = new VXGIRenderer();
        _command  = new CommandBuffer()
        {
            name = "VXGIRenderPipeline"
        };
        _filterSettings = new FilterRenderersSettings(true)
        {
            renderQueueRange = RenderQueueRange.opaque
        };

        Shader.globalRenderPipeline = "VXGI";
        Shader.SetGlobalVectorArray("LightColors", new Vector4[64]);
        Shader.SetGlobalVectorArray("LightPositions", new Vector4[64]);
    }
    public void Voxelize(ScriptableRenderContext renderContext, VXGIRenderer renderer)
    {
        if (!_camera.TryGetCullingParameters(out _cullingParameters))
        {
            return;
        }

        var cullingResults = renderContext.Cull(ref _cullingParameters);

        _vxgi.lights.Clear();

        foreach (var light in cullingResults.visibleLights)
        {
            if (VXGI.supportedLightTypes.Contains(light.lightType) && light.finalColor.maxColorComponent > 0f)
            {
                _vxgi.lights.Add(new LightSource(light, _vxgi.worldToVoxel));
            }
        }

        UpdateCamera();

        _command.BeginSample(_command.name);

        _command.GetTemporaryRT(ShaderIDs.Dummy, _cameraDescriptor);
        _command.SetRenderTarget(ShaderIDs.Dummy, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.DontCare);

        _command.SetGlobalInt(ShaderIDs.Resolution, _resolution);
        _command.SetRandomWriteTarget(1, _vxgi.voxelBuffer, false);
        _command.SetViewProjectionMatrices(_camera.worldToCameraMatrix, _camera.projectionMatrix);

        _drawingSettings.perObjectData = renderer.RenderPipeline.PerObjectData;

        renderContext.ExecuteCommandBuffer(_command);
        renderContext.DrawRenderers(cullingResults, ref _drawingSettings, ref _filteringSettings);

        _command.Clear();

        _command.ClearRandomWriteTargets();
        _command.ReleaseTemporaryRT(ShaderIDs.Dummy);

        _command.EndSample(_command.name);

        renderContext.ExecuteCommandBuffer(_command);

        _command.Clear();
    }
Exemplo n.º 11
0
    public void Render(ScriptableRenderContext renderContext, Camera camera, VXGIRenderer renderer)
    {
        UpdateResolution();

        float realtime         = Time.realtimeSinceStartup;
        bool  tracingThrottled = throttleTracing;

#if UNITY_EDITOR
        tracingThrottled &= UnityEditor.EditorApplication.isPlaying;
#endif

        if (tracingThrottled)
        {
            if (_previousTrace + 1f / tracingRate < realtime)
            {
                _previousTrace = realtime;

                PrePass(renderContext, renderer);
            }
        }
        else
        {
            PrePass(renderContext, renderer);
        }

        renderContext.SetupCameraProperties(camera);

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

        if (pass == VXGIRenderer.Pass.Mipmap)
        {
            renderer.RenderMipmap(renderContext, camera, this);
        }
        else
        {
            SetupShader(renderContext);
            renderer.RenderDeferred(renderContext, camera, this);
        }

        renderContext.Submit();
    }
Exemplo n.º 12
0
    void PrePass(ScriptableRenderContext renderContext, VXGIRenderer renderer)
    {
        if (followCamera)
        {
            center = transform.position;
        }

        var displacement = (voxelSpaceCenter - _lastVoxelSpaceCenter) / voxelSize;

        if (displacement.sqrMagnitude > 0f)
        {
            _mipmapper.Shift(renderContext, Vector3Int.RoundToInt(displacement));
        }

        _voxelizer.Voxelize(renderContext, renderer);
        _voxelShader.Render(renderContext);
        _mipmapper.Filter(renderContext);

        _lastVoxelSpaceCenter = voxelSpaceCenter;
    }
    public void Render(ScriptableRenderContext renderContext, Camera camera, VXGIRenderer renderer)
    {
        VXGIRenderPipeline.TriggerCameraCallback(Camera, "OnPreRender", Camera.onPreRender);

        _command.BeginSample(_command.name);
        renderContext.ExecuteCommandBuffer(_command);
        _command.Clear();

        UpdateResolution();

        var time = Time.realtimeSinceStartup;

        if (!limitRefreshRate || (_previousRefresh + 1f / refreshRate < time))
        {
            _previousRefresh = time;

            PrePass(renderContext, renderer);
        }

        renderContext.SetupCameraProperties(camera);

        _command.ClearRenderTarget(
            (camera.clearFlags & CameraClearFlags.Depth) != 0,
            camera.clearFlags == CameraClearFlags.Color,
            camera.backgroundColor
            );
        renderContext.ExecuteCommandBuffer(_command);
        _command.Clear();

        SetupShader(renderContext);

        VXGIRenderPipeline.TriggerCameraCallback(Camera, "OnPreCull", Camera.onPreCull);

        renderer.RenderDeferred(renderContext, camera, this);

        _command.EndSample(_command.name);
        renderContext.ExecuteCommandBuffer(_command);
        _command.Clear();

        VXGIRenderPipeline.TriggerCameraCallback(Camera, "OnPostRender", Camera.onPostRender);
    }
Exemplo n.º 14
0
 public void Render(ScriptableRenderContext renderContext, VXGIRenderer renderer)
 {
     Render(renderContext, _camera, renderer);
 }