/// <inheritdoc/> public async Task <Image> CaptureCubemap() { return(await editor.Controller.InvokeAsync(() => { editor.ServiceProvider.TryGet <RenderDocManager>()?.StartFrameCapture(game.GraphicsDevice, IntPtr.Zero); var editorCompositor = game.EditorSceneSystem.GraphicsCompositor.Game; try { // Disable Gizmo game.EditorSceneSystem.GraphicsCompositor.Game = null; var editorCameraPosition = Camera.Position; // Capture cubemap using (var cubemap = CubemapSceneRenderer.GenerateCubemap(game, editorCameraPosition, 1024)) { return cubemap.GetDataAsImage(game.GraphicsContext.CommandList); } } finally { game.EditorSceneSystem.GraphicsCompositor.Game = editorCompositor; editor.ServiceProvider.TryGet <RenderDocManager>()?.EndFrameCapture(game.GraphicsDevice, IntPtr.Zero); } })); }
public static Dictionary <LightProbeComponent, FastList <Color3> > GenerateCoefficients(ISceneRendererContext context) { using (var cubemapRenderer = new CubemapSceneRenderer(context, 256)) { // Create target cube texture var cubeTexture = Texture.NewCube(context.GraphicsDevice, 256, PixelFormat.R16G16B16A16_Float); // Prepare shader for SH prefiltering var lambertFiltering = new LambertianPrefilteringSHNoCompute(cubemapRenderer.DrawContext.RenderContext) { HarmonicOrder = LambertHamonicOrder, RadianceMap = cubeTexture, }; var lightProbesCoefficients = new Dictionary <LightProbeComponent, FastList <Color3> >(); using (cubemapRenderer.DrawContext.PushRenderTargetsAndRestore()) { // Render light probe context.GraphicsContext.CommandList.BeginProfile(Color.Red, "LightProbes"); int lightProbeIndex = 0; foreach (var entity in context.SceneSystem.SceneInstance) { var lightProbe = entity.Get <LightProbeComponent>(); if (lightProbe == null) { continue; } var lightProbePosition = lightProbe.Entity.Transform.WorldMatrix.TranslationVector; context.GraphicsContext.ResourceGroupAllocator.Reset(context.GraphicsContext.CommandList); context.GraphicsContext.CommandList.BeginProfile(Color.Red, $"LightProbes {lightProbeIndex}"); lightProbeIndex++; cubemapRenderer.Draw(lightProbePosition, cubeTexture); context.GraphicsContext.CommandList.BeginProfile(Color.Red, "Prefilter SphericalHarmonics"); // Compute SH coefficients lambertFiltering.Draw(cubemapRenderer.DrawContext); var coefficients = lambertFiltering.PrefilteredLambertianSH.Coefficients; var lightProbeCoefficients = new FastList <Color3>(); for (int i = 0; i < coefficients.Length; i++) { lightProbeCoefficients.Add(coefficients[i] * SphericalHarmonics.BaseCoefficients[i]); } lightProbesCoefficients.Add(lightProbe, lightProbeCoefficients); context.GraphicsContext.CommandList.EndProfile(); // Prefilter SphericalHarmonics context.GraphicsContext.CommandList.EndProfile(); // Face XXX // Debug render } context.GraphicsContext.CommandList.EndProfile(); // LightProbes } cubeTexture.Dispose(); return(lightProbesCoefficients); } }