/// <summary>
        /// Applies the specified parameters to the effect including all dependent parameters (<see cref="ViewProjectionParameter"/>, <see cref="WorldViewParameter"/>...etc.) if they are defined in the effect.
        /// </summary>
        /// <param name="context">The context caching precompute value (like ViewProjection).</param>
        /// <param name="world">The world.</param>
        /// <param name="view">The view.</param>
        /// <param name="projection">The projection.</param>
        public void Apply(ref EffectDefaultParametersContext context, ref Matrix world, ref Matrix view, ref Matrix projection)
        {
            // If effect doesn't implement IEffectMatrices, we can still use
            // directly standard dynamic parameters.
            if (WorldParameter != null)
                WorldParameter.SetValue(ref world);

            if (ViewParameter != null)
                ViewParameter.SetValue(ref view);

            if (ProjectionParameter != null)
                ProjectionParameter.SetValue(ref projection);

            if(ViewInverseParameter != null)
            {
                if(!context.IsViewInverseCalculated)
                {
                    Matrix.Invert(ref view, out context.ViewInverse);
                    context.IsViewInverseCalculated = true;
                }
                ViewInverseParameter.SetValue(ref context.ViewInverse);
            }

            if (WorldViewParameter != null)
            {
                Matrix worldView;
                Matrix.Multiply(ref world, ref view, out worldView);
                WorldViewParameter.SetValue(ref worldView);
            }

            if (ViewProjectionParameter != null)
            {
                if (!context.IsViewProjectionCalculated)
                {
                    Matrix.Multiply(ref view, ref projection, out context.ViewProjection);
                    context.IsViewProjectionCalculated = true;
                }
                ViewProjectionParameter.SetValue(ref context.ViewProjection);
            }

            if (WorldInverseTransposeParameter != null || WorldInverseTransposeViewParameter != null)
            {
                Matrix worldTranspose;
                Matrix worldInverseTranspose;
                Matrix.Invert(ref world, out worldTranspose);
                Matrix.Transpose(ref worldTranspose, out worldInverseTranspose);

                if(WorldInverseTransposeParameter != null)
                {
                    WorldInverseTransposeParameter.SetValue(ref worldInverseTranspose);
                }

                if(WorldInverseTransposeViewParameter != null)
                {
                    Matrix worldInverseViewTranspose;
                    Matrix.Multiply(ref worldInverseTranspose, ref view, out worldInverseViewTranspose);
                    WorldInverseTransposeViewParameter.SetValue(ref worldInverseViewTranspose);
                }
            }

            if (WorldViewProjectionParameter != null)
            {
                if (!context.IsViewProjectionCalculated)
                {
                    Matrix.Multiply(ref view, ref projection, out context.ViewProjection);
                    context.IsViewProjectionCalculated = true;
                }

                Matrix worldViewProjection;
                Matrix.Multiply(ref world, ref context.ViewProjection, out worldViewProjection);

                WorldViewProjectionParameter.SetValue(ref worldViewProjection);
            }
        }
示例#2
0
        /// <summary>
        /// Applies the specified parameters to the effect including all dependent parameters (<see cref="ViewProjectionParameter"/>, <see cref="WorldViewParameter"/>...etc.) if they are defined in the effect.
        /// </summary>
        /// <param name="context">The context caching precompute value (like ViewProjection).</param>
        /// <param name="world">The world.</param>
        /// <param name="view">The view.</param>
        /// <param name="projection">The projection.</param>
        public void Apply(ref EffectDefaultParametersContext context, ref Matrix world, ref Matrix view, ref Matrix projection)
        {
            // If effect doesn't implement IEffectMatrices, we can still use
            // directly standard dynamic parameters.
            if (WorldParameter != null)
            {
                WorldParameter.SetValue(ref world);
            }

            if (ViewParameter != null)
            {
                ViewParameter.SetValue(ref view);
            }

            if (ProjectionParameter != null)
            {
                ProjectionParameter.SetValue(ref projection);
            }

            if (ViewInverseParameter != null)
            {
                if (!context.IsViewInverseCalculated)
                {
                    Matrix.Invert(ref view, out context.ViewInverse);
                    context.IsViewInverseCalculated = true;
                }
                ViewInverseParameter.SetValue(ref context.ViewInverse);
            }

            if (WorldViewParameter != null)
            {
                Matrix worldView;
                Matrix.Multiply(ref world, ref view, out worldView);
                WorldViewParameter.SetValue(ref worldView);
            }

            if (ViewProjectionParameter != null)
            {
                if (!context.IsViewProjectionCalculated)
                {
                    Matrix.Multiply(ref view, ref projection, out context.ViewProjection);
                    context.IsViewProjectionCalculated = true;
                }
                ViewProjectionParameter.SetValue(ref context.ViewProjection);
            }

            if (WorldInverseTransposeParameter != null || WorldInverseTransposeViewParameter != null)
            {
                Matrix worldTranspose;
                Matrix worldInverseTranspose;
                Matrix.Invert(ref world, out worldTranspose);
                Matrix.Transpose(ref worldTranspose, out worldInverseTranspose);

                if (WorldInverseTransposeParameter != null)
                {
                    WorldInverseTransposeParameter.SetValue(ref worldInverseTranspose);
                }

                if (WorldInverseTransposeViewParameter != null)
                {
                    Matrix worldInverseViewTranspose;
                    Matrix.Multiply(ref worldInverseTranspose, ref view, out worldInverseViewTranspose);
                    WorldInverseTransposeViewParameter.SetValue(ref worldInverseViewTranspose);
                }
            }

            if (WorldViewProjectionParameter != null)
            {
                if (!context.IsViewProjectionCalculated)
                {
                    Matrix.Multiply(ref view, ref projection, out context.ViewProjection);
                    context.IsViewProjectionCalculated = true;
                }

                Matrix worldViewProjection;
                Matrix.Multiply(ref world, ref context.ViewProjection, out worldViewProjection);

                WorldViewProjectionParameter.SetValue(ref worldViewProjection);
            }
        }
 /// <summary>
 /// Applies the specified parameters to the effect including all dependent parameters (<see cref="ViewProjectionParameter"/>, <see cref="WorldViewParameter"/>...etc.) if they are defined in the effect.
 /// </summary>
 /// <param name="world">The world.</param>
 /// <param name="view">The view.</param>
 /// <param name="projection">The projection.</param>
 public void Apply(ref Matrix world, ref Matrix view, ref Matrix projection)
 {
     var context = new EffectDefaultParametersContext();
     Apply(ref context, ref world, ref view, ref projection);
 }
示例#4
0
        /// <summary>
        /// Applies the specified parameters to the effect including all dependent parameters (<see cref="ViewProjectionParameter"/>, <see cref="WorldViewParameter"/>...etc.) if they are defined in the effect.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="view">The view.</param>
        /// <param name="projection">The projection.</param>
        public void Apply(ref Matrix world, ref Matrix view, ref Matrix projection)
        {
            var context = new EffectDefaultParametersContext();

            Apply(ref context, ref world, ref view, ref projection);
        }