public override void Prepare(RenderDrawContext context) { renderVoxelVolumeData = Context.VisibilityGroup.Tags.Get(CurrentProcessedVoxelVolumes); if (renderVoxelVolumeData == null) { return; } foreach (var processedVolumeKeyValue in renderVoxelVolumeData) { var processedVolume = processedVolumeKeyValue.Value; foreach (VoxelizationPass pass in processedVolume.passList.passes) { var viewFeature = pass.view.Features[RootRenderFeature.Index]; // Find a PerView layout from an effect in normal state ViewResourceGroupLayout firstViewLayout = null; foreach (var viewLayout in viewFeature.Layouts) { // Only process view layouts in normal state if (viewLayout.State != RenderEffectState.Normal) { continue; } var viewLighting = viewLayout.GetLogicalGroup(VoxelizerStorerCasterKey); if (viewLighting.Hash != ObjectId.Empty) { firstViewLayout = viewLayout; break; } } // Nothing found for this view (no effects in normal state) if (firstViewLayout == null) { continue; } var viewParameters = new ParameterCollection(); var firstViewLighting = firstViewLayout.GetLogicalGroup(VoxelizerStorerCasterKey); // Prepare layout (should be similar for all PerView) { // Generate layout var viewParameterLayout = new ParameterCollectionLayout(); viewParameterLayout.ProcessLogicalGroup(firstViewLayout, ref firstViewLighting); viewParameters.UpdateLayout(viewParameterLayout); } ParameterCollection VSViewParameters = viewParameters; pass.storer.ApplyVoxelizationParameters(VSViewParameters); foreach (var attr in processedVolume.Attributes) { attr.Attribute.ApplyVoxelizationParameters(VSViewParameters); } foreach (var viewLayout in viewFeature.Layouts) { if (viewLayout.State != RenderEffectState.Normal) { continue; } var voxelizerStorer = viewLayout.GetLogicalGroup(VoxelizerStorerCasterKey); if (voxelizerStorer.Hash == ObjectId.Empty) { continue; } if (voxelizerStorer.Hash != firstViewLighting.Hash) { throw new InvalidOperationException("PerView VoxelizerStorer layout differs between different RenderObject in the same RenderView"); } var resourceGroup = viewLayout.Entries[pass.view.Index].Resources; resourceGroup.UpdateLogicalGroup(ref voxelizerStorer, VSViewParameters); } } } }
/// <inheritdoc/> public override void Prepare(RenderDrawContext context) { foreach (var view in RenderSystem.Views) { var viewFeature = view.Features[RootRenderFeature.Index]; RenderViewLightData renderViewData; if (!renderViewDatas.TryGetValue(view.LightingView ?? view, out renderViewData) || viewFeature.Layouts.Count == 0) { continue; } // Find a PerView layout from an effect in normal state ViewResourceGroupLayout firstViewLayout = null; foreach (var viewLayout in viewFeature.Layouts) { // Only process view layouts in normal state if (viewLayout.State != RenderEffectState.Normal) { continue; } var viewLighting = viewLayout.GetLogicalGroup(viewLightingKey); if (viewLighting.Hash != ObjectId.Empty) { firstViewLayout = viewLayout; break; } } // Nothing found for this view (no effects in normal state) if (firstViewLayout == null) { continue; } var viewIndex = renderViews.IndexOf(view); var viewParameterLayout = renderViewData.ViewParameterLayout; var viewParameters = renderViewData.ViewParameters; var firstViewLighting = firstViewLayout.GetLogicalGroup(viewLightingKey); // Prepare layout (should be similar for all PerView) if (firstViewLighting.Hash != renderViewData.ViewLayoutHash) { renderViewData.ViewLayoutHash = firstViewLighting.Hash; // Generate layout viewParameterLayout = renderViewData.ViewParameterLayout = new ParameterCollectionLayout(); viewParameterLayout.ProcessLogicalGroup(firstViewLayout, ref firstViewLighting); viewParameters.UpdateLayout(viewParameterLayout); } // Compute PerView lighting foreach (var directLightGroup in shaderPermutation.DirectLightGroups) { directLightGroup.ApplyViewParameters(context, viewIndex, viewParameters); } foreach (var environmentLight in shaderPermutation.EnvironmentLights) { environmentLight.ApplyViewParameters(context, viewIndex, viewParameters); } // Update PerView foreach (var viewLayout in viewFeature.Layouts) { // Only process view layouts in normal state if (viewLayout.State != RenderEffectState.Normal) { continue; } var viewLighting = viewLayout.GetLogicalGroup(viewLightingKey); if (viewLighting.Hash == ObjectId.Empty) { continue; } if (viewLighting.Hash != firstViewLighting.Hash) { throw new InvalidOperationException("PerView Lighting layout differs between different RenderObject in the same RenderView"); } var resourceGroup = viewLayout.Entries[view.Index].Resources; // Update resources resourceGroup.UpdateLogicalGroup(ref viewLighting, viewParameters); } // PerDraw Dispatcher.ForEach(viewFeature.RenderNodes, () => prepareThreadLocals.Value, (renderNodeReference, locals) => { var renderNode = RootRenderFeature.GetRenderNode(renderNodeReference); // Ignore fallback effects if (renderNode.RenderEffect?.State != RenderEffectState.Normal) { return; } var drawLayout = renderNode.RenderEffect?.Reflection?.PerDrawLayout; if (drawLayout == null) { return; } var drawLighting = drawLayout.GetLogicalGroup(drawLightingKey); if (drawLighting.Hash == ObjectId.Empty) { return; } // First time, let's build layout if (drawLighting.Hash != locals.DrawLayoutHash) { locals.DrawLayoutHash = drawLighting.Hash; // Generate layout var drawParameterLayout = new ParameterCollectionLayout(); drawParameterLayout.ProcessLogicalGroup(drawLayout, ref drawLighting); locals.DrawParameters.UpdateLayout(drawParameterLayout); } // TODO: Does this ever fail? Debug.Assert(drawLighting.Hash == locals.DrawLayoutHash, "PerDraw Lighting layout differs between different RenderObject in the same RenderView"); // Compute PerDraw lighting foreach (var directLightGroup in shaderPermutation.DirectLightGroups) { directLightGroup.ApplyDrawParameters(context, viewIndex, locals.DrawParameters, ref renderNode.RenderObject.BoundingBox); } foreach (var environmentLight in shaderPermutation.EnvironmentLights) { environmentLight.ApplyDrawParameters(context, viewIndex, locals.DrawParameters, ref renderNode.RenderObject.BoundingBox); } // Update resources renderNode.Resources.UpdateLogicalGroup(ref drawLighting, locals.DrawParameters); }); } }
public override void Prepare(RenderDrawContext context) { base.Prepare(context); if (!_shouldRenderAtmosphere) { return; } foreach (var view in RenderSystem.Views) { var viewFeature = view.Features[RootRenderFeature.Index]; RenderViewAtmosphereData renderViewData; if (!renderViewDatas.TryGetValue(view, out renderViewData) || viewFeature.Layouts.Count == 0) { continue; } // Find a PerView layout from an effect in normal state ViewResourceGroupLayout firstViewLayout = null; foreach (var viewLayout in viewFeature.Layouts) { // Only process view layouts in normal state if (viewLayout.State != RenderEffectState.Normal) { continue; } var viewAtmosphere = viewLayout.GetLogicalGroup(_atmosphereLogicalGroupKey); if (viewAtmosphere.Hash != ObjectId.Empty) { firstViewLayout = viewLayout; break; } } // Nothing found for this view (no effects in normal state) if (firstViewLayout == null) { continue; } var viewParameterLayout = renderViewData.ViewParameterLayout; var viewParameters = renderViewData.ViewParameters; var firstViewAtmosphere = firstViewLayout.GetLogicalGroup(_atmosphereLogicalGroupKey); // Prepare layout (should be similar for all PerView) if (firstViewAtmosphere.Hash != renderViewData.ViewLayoutHash) { renderViewData.ViewLayoutHash = firstViewAtmosphere.Hash; // Generate layout viewParameterLayout = renderViewData.ViewParameterLayout = new ParameterCollectionLayout(); viewParameterLayout.ProcessLogicalGroup(firstViewLayout, ref firstViewAtmosphere); viewParameters.UpdateLayout(viewParameterLayout); } var component = _atmosphereRenderFeature.Atmosphere; var atmosphereCameraScatteringVolumeTexture = _atmosphereRenderFeature.AtmosphereCameraScatteringVolumeTexture; viewParameters.Set(AtmosphereForwardRenderKeys.BottomRadius, component.PlanetRadius); viewParameters.Set(AtmosphereForwardRenderKeys.ScaleToSkyUnit, component.StrideToAtmosphereUnitScale); viewParameters.Set(AtmosphereForwardRenderKeys.AerialPerspectiveSlicesAndDistancePerSlice, new Vector4( atmosphereCameraScatteringVolumeTexture.Depth, component.AtmosphereScatteringVolumeKmPerSlice, 1.0f / atmosphereCameraScatteringVolumeTexture.Depth, 1.0f / component.AtmosphereScatteringVolumeKmPerSlice )); viewParameters.Set(AtmosphereForwardRenderKeys.AtmosphereCameraScatteringVolume, atmosphereCameraScatteringVolumeTexture); // Update PerView foreach (var viewLayout in viewFeature.Layouts) { // Only process view layouts in normal state if (viewLayout.State != RenderEffectState.Normal) { continue; } var viewAtmosphere = viewLayout.GetLogicalGroup(_atmosphereLogicalGroupKey); if (viewAtmosphere.Hash == ObjectId.Empty) { continue; } if (viewAtmosphere.Hash != firstViewAtmosphere.Hash) { throw new InvalidOperationException("PerView Atmosphere layout differs between different RenderObject in the same RenderView"); } var resourceGroup = viewLayout.Entries[view.Index].Resources; // Update resources resourceGroup.UpdateLogicalGroup(ref viewAtmosphere, viewParameters); } } }