Beispiel #1
0
        /// <summary>
        /// Updates the dynamic effect if the shader code has changed
        /// </summary>
        /// <param name="graphicsDevice">The current <see cref="GraphicsDevice"/></param>
        private void UpdateEffect(GraphicsDevice graphicsDevice)
        {
            if (effectCompilationAttemptCountdown > 0)
            {
                effectCompilationAttemptCountdown--;
                return;
            }

            try
            {
                effectCompiler.Update(effectInstance, null);
            }
            catch (Exception)
            {
                // If the compilation fails do not update the current effect and try again later
                effectCompilationAttemptCountdown = 30; // Try again in 30 frames
                VertexLayoutHasChanged            = false;
                return;
            }

            effect = effectInstance.Effect;

            NewParameterCollections.Clear();
            NewParameterCollections.AddRange(ParameterCollections.ToArray());

            // Get or create parameter collection
            if (parameterCollectionGroup == null || parameterCollectionGroup.Effect != effect || !ArrayExtensions.ArraysReferenceEqual(ref OldParameterCollections, ref NewParameterCollections))
            {
                // It is quite inefficient if user is often switching effect without providing a matching ParameterCollectionGroup
                parameterCollectionGroup = new EffectParameterCollectionGroup(graphicsDevice, effect, ParameterCollections.ToArray());

                OldParameterCollections.Clear();
                OldParameterCollections.AddRange(NewParameterCollections);
            }
        }
Beispiel #2
0
        protected override void DrawCore()
        {
            // Dynamically update/compile the effect based on the current parameters.
            effectCompiler.Update(effectInstance);

            // Draw a full screen quad
            GraphicsDevice.DrawQuad(effectInstance.Effect, parameterCollections);
        }
Beispiel #3
0
        private void DrawCustomEffect()
        {
            GraphicsDevice.Clear(GraphicsDevice.BackBuffer, Color.Black);
            GraphicsDevice.Clear(GraphicsDevice.DepthStencilBuffer, DepthStencilClearOptions.DepthBuffer);
            GraphicsDevice.SetDepthAndRenderTarget(GraphicsDevice.DepthStencilBuffer, GraphicsDevice.BackBuffer);

            effectParameters.Set(MyCustomShaderKeys.ColorFactor2, (Vector4)Color.Red);
            effectParameters.Set(CustomShaderKeys.SwitchEffectLevel, switchEffectLevel);
            effectParameters.Set(TexturingKeys.Texture0, UVTexture);
            switchEffectLevel++; // TODO: Add switch Effect to test and capture frames
            dynamicEffectCompiler.Update(effectInstance, null);
            parameterCollection = new EffectParameterCollectionGroup(GraphicsDevice, effectInstance.Effect, new[] { effectParameters });

            GraphicsDevice.DrawQuad(effectInstance.Effect, parameterCollection);
        }
Beispiel #4
0
 protected void UpdateEffect()
 {
     // Dynamically update/compile the effect based on the current parameters.
     effectCompiler.Update(EffectInstance, null);
 }