Ejemplo n.º 1
0
    // OnLoad() is called when the GameObject is added to the IGameObjectService.
    protected override void OnLoad()
    {
      // ----- Create prototype of a lava ball:

      // Use a sphere for physics simulation.
      _bodyPrototype = new RigidBody(new SphereShape(0.5f));

      // Load the graphics model.
      var content = _services.GetInstance<ContentManager>();
      _modelPrototype = content.Load<ModelNode>("LavaBall/LavaBall").Clone();

      // Attach a point light to the model. The light projects the glowing lava 
      // veins (cube map texture) onto the environment.
      _pointLight = new PointLight
      {
        Color = new Vector3F(1, 1, 1),
        DiffuseIntensity = 2,
        SpecularIntensity = 2,
        Range = 1.5f,
        Attenuation = 0.5f,
        Texture = content.Load<TextureCube>("LavaBall/LavaCubeMap"),
      };
      var pointLightNode = new LightNode(_pointLight);
      _modelPrototype.Children.Add(pointLightNode);

      // Get the emissive color binding of the material because the emissive color
      // will be animated.
      // The model contains one mesh node with a single material.
      var meshNode = (MeshNode)_modelPrototype.Children[0];
      var mesh = meshNode.Mesh;
      var material = mesh.Materials[0];

      // The material contains several effect bindings. The "EmissiveColor" is applied
      // in the "Material" pass. 
      // (For reference see material definition file: Samples\Media\LavaBall\Lava.drmat)
      _emissiveColorBinding = (ConstParameterBinding<Vector3>)material["Material"].ParameterBindings["EmissiveColor"];

      // Use the animation service to animate glow intensity of the lava.
      var animationService = _services.GetInstance<IAnimationService>();

      // Create an AnimatableProperty<float>, which stores the animation value.
      _glowIntensity = new AnimatableProperty<float>();

      // Create sine animation and play the animation back-and-forth.
      var animation = new SingleFromToByAnimation
      {
        From = 0.3f,
        To = 3.0f,
        Duration = TimeSpan.FromSeconds(1),
        EasingFunction = new SineEase { Mode = EasingMode.EaseInOut },
      };
      var clip = new AnimationClip<float>
      {
        Animation = animation,
        Duration = TimeSpan.MaxValue,
        LoopBehavior = LoopBehavior.Oscillate
      };
      animationService.StartAnimation(clip, _glowIntensity).AutoRecycle();
    }
Ejemplo n.º 2
0
    public InterlaceSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      var effect = ContentManager.Load<Effect>("PostProcessing/Interlace");

      var postProcessor = new EffectPostProcessor(GraphicsService, effect);
      GraphicsScreen.PostProcessors.Add(postProcessor);

      _strengthParameterBinding = (ConstParameterBinding<float>)postProcessor.EffectBinding.ParameterBindings["Strength"];
      _strengthParameterBinding.Value = 1;
    }
Ejemplo n.º 3
0
        public InterlaceSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            var effect = ContentManager.Load <Effect>("PostProcessing/Interlace");

            var postProcessor = new EffectPostProcessor(GraphicsService, effect);

            GraphicsScreen.PostProcessors.Add(postProcessor);

            _strengthParameterBinding       = (ConstParameterBinding <float>)postProcessor.EffectBinding.ParameterBindings["Strength"];
            _strengthParameterBinding.Value = 1;
        }
Ejemplo n.º 4
0
    public LensDistortionSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      var effect = ContentManager.Load<Effect>("PostProcessing/LensDistortion");

      var postProcessor = new EffectPostProcessor(GraphicsService, effect);
      GraphicsScreen.PostProcessors.Add(postProcessor);

      var powerParameterBinding = (ConstParameterBinding<float>)postProcessor.EffectBinding.ParameterBindings["Power"];
      powerParameterBinding.Value = 1f;

      _distortionParameterBinding = (ConstParameterBinding<Vector3>)postProcessor.EffectBinding.ParameterBindings["Distortion"];
      _distortionParameterBinding.Value = new Vector3(
        _distortion,
        _distortion + _chromaticDistortion,
        _distortion + 2 * _chromaticDistortion);
    }
        public LensDistortionSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            var effect = ContentManager.Load <Effect>("PostProcessing/LensDistortion");

            var postProcessor = new EffectPostProcessor(GraphicsService, effect);

            GraphicsScreen.PostProcessors.Add(postProcessor);

            var powerParameterBinding = (ConstParameterBinding <float>)postProcessor.EffectBinding.ParameterBindings["Power"];

            powerParameterBinding.Value = 1f;

            _distortionParameterBinding       = (ConstParameterBinding <Vector3>)postProcessor.EffectBinding.ParameterBindings["Distortion"];
            _distortionParameterBinding.Value = new Vector3(
                _distortion,
                _distortion + _chromaticDistortion,
                _distortion + 2 * _chromaticDistortion);
        }
Ejemplo n.º 6
0
    public VignetteSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      var effect = ContentManager.Load<Effect>("PostProcessing/Vignette");

      var postProcessor = new EffectPostProcessor(GraphicsService, effect);
      GraphicsScreen.PostProcessors.Add(postProcessor);

      // "Scale" defines the vignette size and shape.
      _scaleParameterBinding = (ConstParameterBinding<Vector2>)postProcessor.EffectBinding.ParameterBindings["Scale"];
      // Elliptic vignette.
      _scaleParameterBinding.Value = new Vector2(2.0f, 2.0f);
      // Circular vignette.
      //_scaleParameterBinding.Value = new Vector2(2.0f, 2.0f * 1280 / 720);

      // "Power" defines the vignette curve. 
      // 1 .... linear brightness falloff
      // >1 ... non-linear brightness falloff
      _powerParameterBinding = (ConstParameterBinding<float>)postProcessor.EffectBinding.ParameterBindings["Power"];
      _powerParameterBinding.Value = 2;
    }
Ejemplo n.º 7
0
        public VignetteSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            var effect = ContentManager.Load <Effect>("PostProcessing/Vignette");

            var postProcessor = new EffectPostProcessor(GraphicsService, effect);

            GraphicsScreen.PostProcessors.Add(postProcessor);

            // "Scale" defines the vignette size and shape.
            _scaleParameterBinding = (ConstParameterBinding <Vector2>)postProcessor.EffectBinding.ParameterBindings["Scale"];
            // Elliptic vignette.
            _scaleParameterBinding.Value = new Vector2(2.0f, 2.0f);
            // Circular vignette.
            //_scaleParameterBinding.Value = new Vector2(2.0f, 2.0f * 1280 / 720);

            // "Power" defines the vignette curve.
            // 1 .... linear brightness falloff
            // >1 ... non-linear brightness falloff
            _powerParameterBinding       = (ConstParameterBinding <float>)postProcessor.EffectBinding.ParameterBindings["Power"];
            _powerParameterBinding.Value = 2;
        }
Ejemplo n.º 8
0
    public CustomProcessorSample2(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      // Load effect.
      var effect = ContentManager.Load<Effect>("PostProcessing/NegativeFilter");

      // Create an EffectPostProcessor that uses the effect and controls the effect parameters
      // using automatically generated effect parameter bindings.
      _negativeFilter = new EffectPostProcessor(GraphicsService, effect);
      GraphicsScreen.PostProcessors.Add(_negativeFilter);

      // An EffectBinding wraps an Effect and automatically creates effect parameter bindings 
      // based on the names, semantics and/or annotations specified in the fx file. 
      // The effect parameters "ViewportSize" and "SourceTexture" have names which are known
      // by the graphics service (see IDs in class DefaultEffectParameterUsages), those effect 
      // parameters will automatically be set by the graphics engine. 
      // The effect parameter "Strength" is not a known name and does not have a semantic, 
      // therefore InitializeBindings() has created a ConstParameterBinding for this parameter 
      // with the default value that was specified in the fx file. We can get this parameter 
      // binding and change the value in Update().
      _strengthParameterBinding = (ConstParameterBinding<float>)_negativeFilter.EffectBinding.ParameterBindings["Strength"];
      _strengthParameterBinding.Value = 1;
    }
Ejemplo n.º 9
0
    public CustomProcessorSample2(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      // Load effect.
      var effect = ContentManager.Load<Effect>("PostProcessing/NegativeFilter");

      // Create an EffectPostProcessor that uses the effect and controls the effect parameters
      // using automatically generated effect parameter bindings.
      _negativeFilter = new EffectPostProcessor(GraphicsService, effect);
      GraphicsScreen.PostProcessors.Add(_negativeFilter);

      // An EffectBinding wraps an Effect and automatically creates effect parameter bindings 
      // based on the names, semantics and/or annotations specified in the fx file. 
      // The effect parameters "ViewportSize" and "SourceTexture" have names which are known
      // by the graphics service (see IDs in class DefaultEffectParameterUsages), those effect 
      // parameters will automatically be set by the graphics engine. 
      // The effect parameter "Strength" is not a known name and does not have a semantic, 
      // therefore InitializeBindings() has created a ConstParameterBinding for this parameter 
      // with the default value that was specified in the fx file. We can get this parameter 
      // binding and change the value in Update().
      _strengthParameterBinding = (ConstParameterBinding<float>)_negativeFilter.EffectBinding.ParameterBindings["Strength"];
      _strengthParameterBinding.Value = 1;
    }
Ejemplo n.º 10
0
        // OnLoad() is called when the GameObject is added to the IGameObjectService.
        protected override void OnLoad()
        {
            // ----- Create prototype of a lava ball:

            // Use a sphere for physics simulation.
            _bodyPrototype = new RigidBody(new SphereShape(0.5f));

            // Load the graphics model.
            var content = _services.GetInstance <ContentManager>();

            _modelPrototype = content.Load <ModelNode>("LavaBall/LavaBall").Clone();

            // Attach a point light to the model. The light projects the glowing lava
            // veins (cube map texture) onto the environment.
            _pointLight = new PointLight
            {
                Color             = new Vector3F(1, 1, 1),
                DiffuseIntensity  = 2,
                SpecularIntensity = 2,
                Range             = 1.5f,
                Attenuation       = 0.5f,
                Texture           = content.Load <TextureCube>("LavaBall/LavaCubeMap"),
            };
            var pointLightNode = new LightNode(_pointLight);

            _modelPrototype.Children.Add(pointLightNode);

            // Get the emissive color binding of the material because the emissive color
            // will be animated.
            // The model contains one mesh node with a single material.
            var meshNode = (MeshNode)_modelPrototype.Children[0];
            var mesh     = meshNode.Mesh;
            var material = mesh.Materials[0];

            // The material contains several effect bindings. The "EmissiveColor" is applied
            // in the "Material" pass.
            // (For reference see material definition file: Samples\Media\LavaBall\Lava.drmat)
            _emissiveColorBinding = (ConstParameterBinding <Vector3>)material["Material"].ParameterBindings["EmissiveColor"];

            // Use the animation service to animate glow intensity of the lava.
            var animationService = _services.GetInstance <IAnimationService>();

            // Create an AnimatableProperty<float>, which stores the animation value.
            _glowIntensity = new AnimatableProperty <float>();

            // Create sine animation and play the animation back-and-forth.
            var animation = new SingleFromToByAnimation
            {
                From           = 0.3f,
                To             = 3.0f,
                Duration       = TimeSpan.FromSeconds(1),
                EasingFunction = new SineEase {
                    Mode = EasingMode.EaseInOut
                },
            };
            var clip = new AnimationClip <float>
            {
                Animation    = animation,
                Duration     = TimeSpan.MaxValue,
                LoopBehavior = LoopBehavior.Oscillate
            };

            animationService.StartAnimation(clip, _glowIntensity).AutoRecycle();
        }