Example #1
0
        /// <summary>
        /// Gets the collection of parameters from the data.
        /// </summary>
        /// <returns>The parameter collection.</returns>
        public ParameterCollectionData GetCollection()
        {
            var parameters = new ParameterCollectionData();

            parameters.Set(LightingKeys.MaxDirectionalLights, MaxNumDirectionalLight);
            parameters.Set(LightingKeys.MaxPointLights, MaxNumPointLight);
            parameters.Set(LightingKeys.MaxSpotLights, MaxNumSpotLight);
            parameters.Set(LightingKeys.UnrollDirectionalLightLoop, UnrollDirectionalLightLoop);
            parameters.Set(LightingKeys.UnrollPointLightLoop, UnrollPointLightLoop);
            parameters.Set(LightingKeys.UnrollSpotLightLoop, UnrollSpotLightLoop);

            if (ShadowConfigurations != null && ShadowConfigurations.Groups != null && ShadowConfigurations.Groups.Count > 0)
            {
                var shadow = new List <ShadowMapParameters>();
                foreach (var shadowConfig in ShadowConfigurations.Groups)
                {
                    var shadowParams = new ShadowMapParameters();
                    shadowParams.Set(ShadowMapParameters.LightType, shadowConfig.LightType);
                    shadowParams.Set(ShadowMapParameters.ShadowMapCount, shadowConfig.ShadowCount);
                    shadowParams.Set(ShadowMapParameters.ShadowMapCascadeCount, shadowConfig.LightType == LightType.Directional ? shadowConfig.CascadeCount : 1);
                    shadowParams.Set(ShadowMapParameters.FilterType, shadowConfig.FilterType);
                    shadow.Add(shadowParams);
                }
                parameters.Set(ShadowMapParameters.ShadowMaps, shadow.ToArray());
            }
            return(parameters);
        }
        private static void CreateParametersFromLightingConfiguration(LightingConfiguration config, ParameterCollection parameters)
        {
            // Apply parameters for effect change
            parameters.Set(LightingKeys.MaxDirectionalLights, config.MaxNumDirectionalLight);
            parameters.Set(LightingKeys.MaxPointLights, config.MaxNumPointLight);
            parameters.Set(LightingKeys.MaxSpotLights, config.MaxNumSpotLight);

            // TODO: cache some objects since it is done at each frame
            // TODO: try to reuse the parameter collections?

            if (config.ShadowConfigurations != null)
            {
                var groupCount = 0;
                foreach (var group in config.ShadowConfigurations.Groups)
                {
                    groupCount += (group.ShadowCount > 0 ? 1 : 0);
                }

                if (groupCount == 0)
                {
                    parameters.Remove(ShadowMapParameters.ShadowMaps);
                    return;
                }

                var shadowMapParameters = new ShadowMapParameters[groupCount];
                var index = 0;
                for (var i = 0; i < config.ShadowConfigurations.Groups.Count; ++i)
                {
                    if (config.ShadowConfigurations.Groups[i].ShadowCount > 0)
                    {
                        var shadowParams = new ShadowMapParameters();
                        shadowParams.Set(ShadowMapParameters.LightType, config.ShadowConfigurations.Groups[i].LightType);
                        shadowParams.Set(ShadowMapParameters.ShadowMapCount, config.ShadowConfigurations.Groups[i].ShadowCount);
                        shadowParams.Set(ShadowMapParameters.ShadowMapCascadeCount, config.ShadowConfigurations.Groups[i].CascadeCount);
                        shadowParams.Set(ShadowMapParameters.FilterType, config.ShadowConfigurations.Groups[i].FilterType);
                        shadowMapParameters[index] = shadowParams;
                        ++index;
                    }
                }
                parameters.Set(ShadowMapParameters.ShadowMaps, shadowMapParameters);
            }
            else
            {
                parameters.Remove(ShadowMapParameters.ShadowMaps);
            }

            //mesh.SharedParameters.Set(LightingKeys.UnrollDirectionalLightLoop, foundConfiguration.UnrollDirectionalLightLoop);
            //mesh.SharedParameters.Set(LightingKeys.UnrollPointLightLoop, foundConfiguration.UnrollPointLightLoop);
            //mesh.SharedParameters.Set(LightingKeys.UnrollSpotLightLoop, foundConfiguration.UnrollSpotLightLoop);
        }