Exemple #1
0
        public override void PrepareEffectPermutations(RenderDrawContext context)
        {
            base.PrepareEffectPermutations(context);

            // Try finding root atmosphere render feature
            foreach (var renderFeature in ((RootEffectRenderFeature)RootRenderFeature).RenderSystem.RenderFeatures)
            {
                if (renderFeature is AtmosphereRenderFeature atmosphereRenderFeature)
                {
                    _atmosphereRenderFeature = atmosphereRenderFeature;
                }
            }

            if (_atmosphereRenderFeature == null)
            {
                _shouldRenderAtmosphere = false;
                return;
            }

            _shouldRenderAtmosphere = _atmosphereRenderFeature.Atmosphere != null;

            var renderEffectKey = ((RootEffectRenderFeature)RootRenderFeature).RenderEffectKey;

            var renderEffects   = RootRenderFeature.RenderData.GetData(renderEffectKey);
            int effectSlotCount = ((RootEffectRenderFeature)RootRenderFeature).EffectPermutationSlotCount;

            foreach (var renderObject in RootRenderFeature.RenderObjects)
            {
                var staticObjectNode = renderObject.StaticObjectNode;

                if (renderObject is not RenderMesh renderMesh)
                {
                    continue;
                }

                var material = renderMesh.MaterialPass;
                var shouldRenderAtmosphereForRenderObject = material.HasTransparency && _shouldRenderAtmosphere;

                for (int i = 0; i < effectSlotCount; ++i)
                {
                    var staticEffectObjectNode = staticObjectNode * effectSlotCount + i;
                    var renderEffect           = renderEffects[staticEffectObjectNode];

                    // Skip effects not used during this frame
                    if (renderEffect == null || !renderEffect.IsUsedDuringThisFrame(RenderSystem))
                    {
                        continue;
                    }

                    renderEffect.EffectValidator.ValidateParameter(AtmosphereForwardShadingEffectParameters.RenderAerialPerspective, shouldRenderAtmosphereForRenderObject);
                }
            }
        }
Exemple #2
0
            private void SetAtmosphereParameters(RenderDrawContext context, int viewIndex, ParameterCollection parameters)
            {
                var lightRange = lightRanges[viewIndex];

                if (lightRange.Start == lightRange.End)
                {
                    return;
                }

                if (!(lights[lightRange.Start].Light.Type is AtmosphereLightDirectional light))
                {
                    return;
                }

                // Fetch compositor and find atmosphere render feature
                var sceneSystem        = context.RenderContext.Services.GetService <SceneSystem>();
                var graphicsCompositor = sceneSystem.GraphicsCompositor;

                AtmosphereRenderFeature atmosphereRenderFeature = null;

                foreach (var feature in graphicsCompositor.RenderFeatures)
                {
                    if (feature is AtmosphereRenderFeature atmoshpere)
                    {
                        atmosphereRenderFeature = atmoshpere;
                    }
                }

                if (atmosphereRenderFeature == null || atmosphereRenderFeature.TransmittanceLutTexture == null)
                {
                    return;
                }

                parameters.Set(AtmosphereLightDirectionalGroupKeys.BottomRadius.ComposeWith(_compositionName), light.Atmosphere.PlanetRadius);
                parameters.Set(AtmosphereLightDirectionalGroupKeys.TopRadius.ComposeWith(_compositionName), light.Atmosphere.PlanetRadius + light.Atmosphere.AtmosphereHeight);
                parameters.Set(AtmosphereLightDirectionalGroupKeys.ScaleToSkyUnit.ComposeWith(_compositionName), light.Atmosphere.StrideToAtmosphereUnitScale);
                parameters.Set(AtmosphereLightDirectionalGroupKeys.TransmittanceLutTexture, atmosphereRenderFeature.TransmittanceLutTexture);
            }
Exemple #3
0
            private void SetAtmosphereParameters(RenderDrawContext context, int viewIndex, ParameterCollection parameters)
            {
                var lightRange = lightRanges[viewIndex];

                if (lightRange.Start == lightRange.End)
                {
                    return;
                }

                if (!(lights[lightRange.Start].Light.Type is AtmosphereLightDirectional light))
                {
                    return;
                }

                // Fetch compositor and find atmosphere render feature
                var sceneSystem        = context.RenderContext.Services.GetService <SceneSystem>();
                var graphicsCompositor = sceneSystem.GraphicsCompositor;

                AtmosphereRenderFeature atmosphereRenderFeature = null;

                foreach (var feature in graphicsCompositor.RenderFeatures)
                {
                    if (feature is AtmosphereRenderFeature atmoshpere)
                    {
                        atmosphereRenderFeature = atmoshpere;
                    }
                }

                if (atmosphereRenderFeature == null || atmosphereRenderFeature.TransmittanceLutTexture == null)
                {
                    return;
                }

                atmosphereRenderFeature.SetParameters(null, light.Atmosphere, parameters, null);
                parameters.Set(AtmosphereParametersBaseKeys.TransmittanceLutTexture, atmosphereRenderFeature.TransmittanceLutTexture);
            }