Esempio n. 1
0
        private void SetupLight(RenderDrawContext context, LightShaftProcessor.AssociatedData lightShaft, LightShadowMapTexture shadowMapTexture, ParameterCollection lightParameterCollection)
        {
            BoundingBoxExt box = new BoundingBoxExt(new Vector3(-float.MaxValue), new Vector3(float.MaxValue)); // TODO

            LightShaftRenderData data;

            if (!renderData.TryGetValue(lightShaft.Light, out data))
            {
                data = new LightShaftRenderData();
                renderData.Add(lightShaft.Light, data);
                UpdateRenderData(context, data, lightShaft, shadowMapTexture);
            }

            if (shadowMapTexture != null && data.ShadowMapRenderer != null)
            {
                // Detect changed shadow map renderer or type
                if (data.ShadowMapRenderer != shadowMapTexture.Renderer || data.ShadowType != shadowMapTexture.ShadowType)
                {
                    UpdateRenderData(context, data, lightShaft, shadowMapTexture);
                }
            }
            else if (shadowMapTexture?.Renderer != data.ShadowMapRenderer) // Change from no shadows to shadows
            {
                UpdateRenderData(context, data, lightShaft, shadowMapTexture);
            }

            data.RenderViews[0] = context.RenderContext.RenderView;
            data.ShaderGroup.Reset();
            data.ShaderGroup.SetViews(data.RenderViews);
            data.ShaderGroup.AddView(0, context.RenderContext.RenderView, 1);

            data.ShaderGroup.AddLight(lightShaft.LightComponent, shadowMapTexture);
            data.ShaderGroup.UpdateLayout("lightGroup");

            lightParameterCollection.Set(LightShaftsEffectKeys.LightGroup, data.ShaderGroup.ShaderSource);

            // Update the effect here so the layout is correct
            lightShaftsEffectShader.EffectInstance.UpdateEffect(GraphicsDevice);

            data.ShaderGroup.ApplyViewParameters(context, 0, lightParameterCollection);
            data.ShaderGroup.ApplyDrawParameters(context, 0, lightParameterCollection, ref box);

            data.UsageCounter = usageCounter;
        }
Esempio n. 2
0
        private void DrawLightShaft(RenderDrawContext context, LightShaftProcessor.AssociatedData lightShaft)
        {
            lightShaftsEffectShader.Parameters.Set(LightShaftsShaderKeys.DensityFactor, lightShaft.DensityFactor);

            lightShaftsEffectShader.Draw(context, $"Light shaft [{lightShaft.LightComponent.Entity.Name}]");
        }
Esempio n. 3
0
        private void UpdateRenderData(RenderDrawContext context, LightShaftRenderData data, LightShaftProcessor.AssociatedData lightShaft, LightShadowMapTexture shadowMapTexture)
        {
            if (lightShaft.Light is LightPoint)
            {
                data.GroupRenderer = new LightPointGroupRenderer();
            }
            else if (lightShaft.Light is LightSpot)
            {
                data.GroupRenderer = new LightSpotGroupRenderer();
            }
            else if (lightShaft.Light is LightDirectional)
            {
                data.GroupRenderer = new LightDirectionalGroupRenderer();
            }
            else
            {
                throw new InvalidOperationException("Unsupported light type");
            }

            ILightShadowMapShaderGroupData shadowGroup = null;

            if (shadowMapTexture != null)
            {
                data.ShadowType        = shadowMapTexture.ShadowType;
                data.ShadowMapRenderer = shadowMapTexture.Renderer;
                shadowGroup            = data.ShadowMapRenderer.CreateShaderGroupData(data.ShadowType);
            }
            else
            {
                data.ShadowType        = 0;
                data.ShadowMapRenderer = null;
            }
            data.ShaderGroup = data.GroupRenderer.CreateLightShaderGroup(context, shadowGroup);
        }