Пример #1
0
        public static LightingGroupInfo GetOrCreate(Effect effect)
        {
            if (effect == null)
            {
                throw new ArgumentNullException("effect");
            }
            LightingGroupInfo value;

            if (!effect.Tags.TryGetValue(Key, out value))
            {
                value = new LightingGroupInfo();
                effect.Tags.Add(Key, value);
            }
            return(value);
        }
Пример #2
0
        /// <summary>
        /// Update the light values of the shader.
        /// </summary>
        /// <param name="context">The render context.</param>
        /// <param name="renderMesh">The current RenderMesh (the same as <seealso cref="PreEffectUpdate"/>)</param>
        public void PostEffectUpdate(RenderContext context, RenderMesh renderMesh)
        {
            var lightingGroupInfo = LightingGroupInfo.GetOrCreate(renderMesh.Effect);

            // update the info if necessary
            if (!lightingGroupInfo.IsLightingSetup)
            {
                lightingGroupInfo.LightingParameters = CreateLightingUpdateInfo(renderMesh);
                if (lastConfiguration.ShadowConfigurations != null)
                {
                    lightingGroupInfo.ShadowParameters = CreateEffectShadowParams(lastConfiguration);
                }

                lightingGroupInfo.IsLightingSetup = true;
            }

            if (lightingGroupInfo.LightingParameters.Count == 0)
            {
                return;
            }

            // TODO: is it always available?
            var viewMatrix = context.CurrentPass.Parameters.Get(TransformationKeys.View);

            if (lightingGroupInfo.ShadowParameters != null)
            {
                for (var i = 0; i < lightingGroupInfo.ShadowParameters.Count; ++i)
                {
                    UpdateShadowParameters(renderMesh.Parameters, lightingGroupInfo.ShadowParameters[i], shadowMapGroups[i]);
                }
            }

            // Apply parameters
            foreach (var info in lightingGroupInfo.LightingParameters)
            {
                switch (info.Type)
                {
                case LightingUpdateType.Point:
                    UpdateLightingParameters(info, ref renderMesh, ref viewMatrix, pointLightsForMesh);
                    break;

                case LightingUpdateType.Directional:
                    UpdateLightingParameters(info, ref renderMesh, ref viewMatrix, directionalLightsForMesh);
                    break;

                case LightingUpdateType.Spot:
                    UpdateLightingParameters(info, ref renderMesh, ref viewMatrix, spotLightsForMesh);
                    break;

                case LightingUpdateType.DirectionalShadow:
                    UpdateLightingParameters(info, ref renderMesh, ref viewMatrix, directionalLightsWithShadowForMeshGroups[info.Index]);
                    break;

                case LightingUpdateType.SpotShadow:
                    UpdateLightingParameters(info, ref renderMesh, ref viewMatrix, spotLightsWithShadowForMeshGroups[info.Index]);
                    break;

                //TODO: implement later when shadow map are supported
                case LightingUpdateType.PointShadow:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }