//--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="CubeMapShadowMaskRenderer"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public CubeMapShadowMaskRenderer(IGraphicsService graphicsService)
        {
            if (graphicsService == null)
            throw new ArgumentNullException("graphicsService");

              _effect = graphicsService.Content.Load<Effect>("DigitalRune/Deferred/CubeMapShadowMask");
              _parameterViewInverse = _effect.Parameters["ViewInverse"];
              _parameterFrustumCorners = _effect.Parameters["FrustumCorners"];
              _parameterGBuffer0 = _effect.Parameters["GBuffer0"];
              _parameterParameters0 = _effect.Parameters["Parameters0"];
              _parameterParameters1 = _effect.Parameters["Parameters1"];
              _parameterParameters2 = _effect.Parameters["Parameters2"];
              _parameterLightPosition = _effect.Parameters["LightPosition"];
              _parameterShadowView = _effect.Parameters["ShadowView"];
              _parameterJitterMap = _effect.Parameters["JitterMap"];
              _parameterShadowMap = _effect.Parameters["ShadowMap"];
              _parameterSamples = _effect.Parameters["Samples"];

              Debug.Assert(_parameterSamples.Elements.Count == _samples.Length);

              // TODO: Use struct parameter. Not yet supported in MonoGame.
              // Struct effect parameters are not yet supported in the MonoGame effect processor.
              //var parameterShadow = _effect.Parameters["ShadowParam"];
              //_parameterNear = parameterShadow.StructureMembers["Near"];
              //...
        }
        public SkyObjectRenderer(IGraphicsService graphicsService)
        {
            if (graphicsService == null)
            throw new ArgumentNullException("graphicsService");

              if (graphicsService.GraphicsDevice.GraphicsProfile == GraphicsProfile.Reach)
            throw new NotSupportedException("The SkyObjectRenderer does not support the Reach profile.");

              // Load effect.
              _effect = graphicsService.Content.Load<Effect>("DigitalRune/Sky/SkyObject");
              _effectParameterViewProjection = _effect.Parameters["ViewProjection"];
              _effectParameterUp = _effect.Parameters["Up"];
              _effectParameterRight = _effect.Parameters["Right"];
              _effectParameterNormal = _effect.Parameters["Normal"];
              _effectParameterSunDirection = _effect.Parameters["SunDirection"];
              _effectParameterSunLight = _effect.Parameters["SunLight"];
              _effectParameterAmbientLight = _effect.Parameters["AmbientLight"];
              _effectParameterObjectTexture = _effect.Parameters["ObjectTexture"];
              _effectParameterTextureParameters = _effect.Parameters["TextureParameters"];
              _effectParameterLightWrapSmoothness = _effect.Parameters["LightWrapSmoothness"];
              _effectParameterGlow0 = _effect.Parameters["Glow0"];
              _effectParameterGlow1 = _effect.Parameters["Glow1"];
              _effectPassObjectLinear = _effect.Techniques[0].Passes["ObjectLinear"];
              _effectPassObjectGamma = _effect.Techniques[0].Passes["ObjectGamma"];
              _effectPassGlowLinear = _effect.Techniques[0].Passes["GlowLinear"];
              _effectPassGlowGamma = _effect.Techniques[0].Passes["GlowGamma"];
        }
Exemple #3
0
        protected Sample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            // Get services from the global service container.
              var services = (ServiceContainer)ServiceLocator.Current;
              SampleFramework = services.GetInstance<SampleFramework>();
              ContentManager = services.GetInstance<ContentManager>();
              UIContentManager = services.GetInstance<ContentManager>("UIContent");
              InputService = services.GetInstance<IInputService>();
              AnimationService = services.GetInstance<IAnimationService>();
              Simulation = services.GetInstance<Simulation>();
              ParticleSystemService = services.GetInstance<IParticleSystemService>();
              GraphicsService = services.GetInstance<IGraphicsService>();
              GameObjectService = services.GetInstance<IGameObjectService>();
              UIService = services.GetInstance<IUIService>();

              // Create a local service container which can be modified in samples:
              // The local service container is a child container, i.e. it inherits the
              // services of the global service container. Samples can add new services
              // or override existing entries without affecting the global services container
              // or other samples.
              Services = services.CreateChildContainer();

              // Store a copy of the original graphics screens.
              _originalGraphicsScreens = GraphicsService.Screens.ToArray();

              // Mouse is visible by default.
              SampleFramework.IsMouseVisible = true;
        }
Exemple #4
0
    public DistortionFilter(IGraphicsService graphicsService, ContentManager content)
      : base(graphicsService)
    {
      _billboardRenderer = new BillboardRenderer(GraphicsService, 512)
      {
        EnableSoftParticles = true,
      };

      _effect = content.Load<Effect>("PostProcessing/DistortionFilter");
      _viewportSizeParameter = _effect.Parameters["ViewportSize"];
      _strengthParameter = _effect.Parameters["Strength"];
      _sourceTextureParameter = _effect.Parameters["SourceTexture"];
      _distortionTextureParameter = _effect.Parameters["DistortionTexture"];

      // The distortion texture can have a lower resolution to improve performance.
      DistortionTexture = new RenderTarget2D(
        GraphicsService.GraphicsDevice,
        320,
        180,
        false, SurfaceFormat.Color,
        DepthFormat.None);

      Scene = new Scene();

      Strength = 0.01f;
    }
Exemple #5
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="GodRayFilter"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public GodRayFilter(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            Effect effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/GodRayFilter");
              _viewportSizeParameter = effect.Parameters["ViewportSize"];
              _parameters0Parameter = effect.Parameters["Parameters0"];
              _parameters1Parameter = effect.Parameters["Parameters1"];
              _intensityParameter = effect.Parameters["Intensity"];
              _numberOfSamplesParameter = effect.Parameters["NumberOfSamples"];
              _sourceTextureParameter = effect.Parameters["SourceTexture"];
              _gBuffer0Parameter = effect.Parameters["GBuffer0"];
              _rayTextureParameter = effect.Parameters["RayTexture"];
              _createMaskPass = effect.CurrentTechnique.Passes["CreateMask"];
              _blurPass = effect.CurrentTechnique.Passes["Blur"];
              _combinePass = effect.CurrentTechnique.Passes["Combine"];

              _downsampleFilter = graphicsService.GetDownsampleFilter();

              Scale = 1;
              LightDirection = new Vector3F(0, -1, 0);
              LightRadius = 0.2f;
              Intensity = new Vector3F(1, 1, 1);
              DownsampleFactor = 4;
              NumberOfSamples = 8;
              NumberOfPasses = 2;
              Softness = 1;
        }
        public ScatteringSkyRenderer(IGraphicsService graphicsService)
        {
            if (graphicsService == null)
            throw new ArgumentNullException("graphicsService");

              if (graphicsService.GraphicsDevice.GraphicsProfile == GraphicsProfile.Reach)
            throw new NotSupportedException("The ScatteringSkyRenderer does not support the Reach profile.");

              _effect = graphicsService.Content.Load<Effect>("DigitalRune/Sky/ScatteringSky");
              _parameterView = _effect.Parameters["View"];
              _parameterProjection = _effect.Parameters["Projection"];
              _parameterSunDirection = _effect.Parameters["SunDirection"];
              _parameterRadii = _effect.Parameters["Radii"];
              _parameterNumberOfSamples = _effect.Parameters["NumberOfSamples"];
              _parameterBetaRayleigh = _effect.Parameters["BetaRayleigh"];
              _parameterBetaMie = _effect.Parameters["BetaMie"];
              _parameterGMie = _effect.Parameters["GMie"];
              _parameterSunIntensity = _effect.Parameters["SunIntensity"];
              _parameterTransmittance = _effect.Parameters["Transmittance"];
              _parameterBaseHorizonColor = _effect.Parameters["BaseHorizonColor"];
              _parameterBaseZenithColor = _effect.Parameters["BaseZenithColor"];
              _passLinear = _effect.Techniques[0].Passes["Linear"];
              _passGamma = _effect.Techniques[0].Passes["Gamma"];
              _passLinearWithBaseColor = _effect.Techniques[0].Passes["LinearWithBaseColor"];
              _passGammaWithBaseColor = _effect.Techniques[0].Passes["GammaWithBaseColor"];

              _submesh = MeshHelper.GetBox(graphicsService);
        }
Exemple #7
0
        public MyGraphicsScreen(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            _meshRenderer = new MeshRenderer();

              var contentManager = ServiceLocator.Current.GetInstance<ContentManager>();
              var spriteFont = contentManager.Load<SpriteFont>("SpriteFont1");
              _debugRenderer = new DebugRenderer(graphicsService, spriteFont);

              Scene = new Scene();

              // Add a camera with a perspective projection.
              var projection = new PerspectiveProjection();
              projection.SetFieldOfView(
            ConstantsF.PiOver4,
            graphicsService.GraphicsDevice.Viewport.AspectRatio,
            0.1f,
            100.0f);
              CameraNode = new CameraNode(new Camera(projection))
              {
            Name = "CameraPerspective",
            PoseWorld = Pose.FromMatrix(Matrix44F.CreateLookAt(new Vector3F(10, 5, 10), new Vector3F(0, 1, 0), new Vector3F(0, 1, 0)).Inverse),
              };
              Scene.Children.Add(CameraNode);
        }
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="DepthOfFieldFilter"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public DepthOfFieldFilter(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            _effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/DepthOfFieldFilter");
              _screenSizeParameter = _effect.Parameters["ScreenSize"];
              _depthTextureParameter = _effect.Parameters["DepthTexture"];
              _nearBlurDistanceParameter = _effect.Parameters["NearBlurDistance"];
              _nearFocusDistanceParameter = _effect.Parameters["NearFocusDistance"];
              _farFocusDistanceParameter = _effect.Parameters["FarFocusDistance"];
              _farBlurDistanceParameter = _effect.Parameters["FarBlurDistance"];
              _farParameter = _effect.Parameters["Far"];
              _blurTextureParameter = _effect.Parameters["BlurTexture"];
              _downsampledDepthTextureParameter = _effect.Parameters["DownsampledDepthTexture"];
              _downsampledCocTextureParameter = _effect.Parameters["DownsampledCocTexture"];
              _offsetsParameter = _effect.Parameters["Offsets"];
              _weightsParameter = _effect.Parameters["Weights"];
              _sceneTextureParameter = _effect.Parameters["SceneTexture"];
              _circleOfConfusionPass = _effect.CurrentTechnique.Passes["CircleOfConfusion"];
              _blurPass = _effect.CurrentTechnique.Passes["Blur"];
              _depthOfFieldPass = _effect.CurrentTechnique.Passes["DepthOfField"];

              _downsampleFilter = PostProcessHelper.GetDownsampleFilter(graphicsService);

              _cocBlur = new Blur(graphicsService);
              _cocBlur.InitializeBoxBlur(5, false);

              NearBlurDistance = 2;
              NearFocusDistance = 5;
              FarFocusDistance = 6;
              FarBlurDistance = 10;
              _downsampleFactor = 2;
              BlurStrength = 1;
        }
Exemple #9
0
        public EditorBase(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            // Get services from the global service container.
            var services = (ServiceContainer)ServiceLocator.Current;
            UIContentManager = services.GetInstance<ContentManager>("UIContent");
            InputService = services.GetInstance<IInputService>();
            AnimationService = services.GetInstance<IAnimationService>();
            GraphicsService = services.GetInstance<IGraphicsService>();
            GameObjectService = services.GetInstance<IGameObjectService>();
            UIService = services.GetInstance<IUIService>();

            // Create a local service container which can be modified in samples:
            // The local service container is a child container, i.e. it inherits the
            // services of the global service container. Samples can add new services
            // or override existing entries without affecting the global services container
            // or other samples.
            Services = services.CreateChildContainer();

            // Load a UI theme, which defines the appearance and default values of UI controls.
            Theme theme = UIContentManager.Load<Theme>("BlendBlue/Theme");

            FigureRenderer = new FigureRenderer(GraphicsService, 2000);
            DebugRenderer = new DebugRenderer(GraphicsService, UIContentManager.Load<SpriteFont>("BlendBlue/Default"));
            UIRenderer = new UIRenderer(GraphicsService.GraphicsDevice, theme);

            UIScreen = new UIScreen("Main Screen", UIRenderer)
            {
                Background = Color.TransparentBlack,
            };

            UIService.Screens.Add(UIScreen);

            Scene = new Scene();
        }
Exemple #10
0
 //--------------------------------------------------------------
 public LightBufferRenderer(IGraphicsService graphicsService)
 {
     _graphicsService = graphicsService;
       LightRenderer = new LightRenderer(graphicsService);
       AmbientOcclusionType = AmbientOcclusionType.SSAO;
       _copyFilter = new CopyFilter(graphicsService);
 }
Exemple #11
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="EdgeFilter"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public EdgeFilter(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            _effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/EdgeFilter");
              _parameterViewportSize = _effect.Parameters["ViewportSize"];
              _parameterHalfEdgeWidth = _effect.Parameters["HalfEdgeWidth"];
              _parameterDepthThreshold = _effect.Parameters["DepthThreshold"];
              _parameterDepthSensitivity = _effect.Parameters["DepthSensitivity"];
              _parameterNormalThreshold = _effect.Parameters["NormalThreshold"];
              _parameterNormalSensitivity = _effect.Parameters["NormalSensitivity"];
              _parameterCameraBackward = _effect.Parameters["CameraBackward"];
              _parameterSourceTexture = _effect.Parameters["SourceTexture"];
              _parameterSilhouetteColor = _effect.Parameters["SilhouetteColor"];
              _parameterCreaseColor = _effect.Parameters["CreaseColor"];
              _parameterGBuffer0 = _effect.Parameters["GBuffer0"];
              _parameterGBuffer1 = _effect.Parameters["GBuffer1"];
              _passEdge = _effect.Techniques[0].Passes["Edge"];
              _passOnePixelEdge = _effect.Techniques[0].Passes["OnePixelEdge"];

              EdgeWidth = 2.0f;
              DepthThreshold = 0.001f;  // = minDistance / farPlaneDistance
              DepthSensitivity = 1000;  // = farPlaneDistance / (maxDistance - minDistance)
              NormalThreshold = 0.1f;
              NormalSensitivity = 2f;
              SilhouetteColor = new Vector4F(0, 0, 0, 1);
              CreaseColor = new Vector4F(0, 0, 0, 1);
        }
        public CloudMapRenderer(IGraphicsService graphicsService)
        {
            if (graphicsService == null)
            throw new ArgumentNullException("graphicsService");

              if (graphicsService.GraphicsDevice.GraphicsProfile == GraphicsProfile.Reach)
            throw new NotSupportedException("The CloudMapRenderer does not support the Reach profile.");

              // One 512x512 noise texture is used for all layers. Each layer which does not have
              // a user defined texture uses a part of this texture.
              _noiseTexture = NoiseHelper.GetGrainTexture(graphicsService, 512);

              _effect = graphicsService.Content.Load<Effect>("DigitalRune/Sky/CloudLayer");
              _parameterViewportSize = _effect.Parameters["ViewportSize"];
              _parameterTexture0Parameters = _effect.Parameters["Texture0Parameters"];
              _parameterTexture1Parameters = _effect.Parameters["Texture1Parameters"];
              _parameterLerp = _effect.Parameters["LerpParameter"];

              _parameterTextures = new EffectParameter[LayeredCloudMap.NumberOfTextures];
              _parameterDensities = new EffectParameter[LayeredCloudMap.NumberOfTextures];
              _parameterMatrices = new EffectParameter[LayeredCloudMap.NumberOfTextures];
              for (int i = 0; i < LayeredCloudMap.NumberOfTextures; i++)
              {
            _parameterTextures[i] = _effect.Parameters["NoiseTexture" + i];
            _parameterDensities[i] = _effect.Parameters["Density" + i];
            _parameterMatrices[i] = _effect.Parameters["Matrix" + i];
              }

              _parameterCoverage = _effect.Parameters["Coverage"];
              _parameterDensity = _effect.Parameters["Density"];

              _passLerp = _effect.Techniques[0].Passes["Lerp"];
              _passDensity = _effect.Techniques[0].Passes["Density"];
        }
Exemple #13
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="LuminanceFilter"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public LuminanceFilter(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            _effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/LuminanceFilter");
              _useGeometricMeanParameter = _effect.Parameters["UseGeometricMean"];
              _useAdaptionParameter = _effect.Parameters["UseAdaption"];
              _deltaTimeParameter = _effect.Parameters["DeltaTime"];
              _adaptionSpeedParameter = _effect.Parameters["AdaptionSpeed"];
              _lastLuminanceTextureParameter = _effect.Parameters["LastLuminanceTexture"];
              _textureParameter = _effect.Parameters["SourceTexture"];
              _sourceSizeParameter = _effect.Parameters["SourceSize"];
              _targetSizeParameter = _effect.Parameters["TargetSize"];
              _createPass = _effect.CurrentTechnique.Passes["Create"];
              _downsamplePass = _effect.CurrentTechnique.Passes["Downsample"];
              _finalPass = _effect.CurrentTechnique.Passes["Final"];

              _downsampleFilter = PostProcessHelper.GetDownsampleFilter(graphicsService);
              _copyFilter = PostProcessHelper.GetCopyFilter(graphicsService);

              UseGeometricMean = true;
              UseAdaption = true;
              AdaptionSpeed = 0.02f;

              DefaultTargetFormat = new RenderTargetFormat(1, 1, false, SurfaceFormat.HalfVector4, DepthFormat.None);
        }
        public FigurePickerObject(IGraphicsService graphicsService, Scene scene, Editor2DCameraObject cameraObject, DebugRenderer debugRenderer)
        {
            _cameraObject = cameraObject;
            _scene = scene;
            _debugRenderer = debugRenderer;

            // Create a collision domain which manages all collision objects used for
            // picking: the picking object and the collision objects for figure nodes.
            _collisionDomain = new CollisionDomain(new CollisionDetection());

            // Create the picking object:
            // The picking object represents the mouse cursor or the reticle. Usually 
            // a ray is used, but in this example we want to use a cylinder/cone. This 
            // allows to check which objects within a certain radius of the reticle. A 
            // picking cylinder/cone is helpful for touch devices where the picking is 
            // done with an imprecise input method like the human finger.

            // We want to pick objects in 10 pixel radius around the reticle. To determine 
            // the world space size of the required cylinder/cone, we can use the projection
            // and the viewport. 
            const float pickingRadius = 0.25f;
            var projection = _cameraObject.CameraNode.Camera.Projection;
            var viewport = graphicsService.GraphicsDevice.Viewport;

            Shape pickingShape;
            if (projection is OrthographicProjection)
            {
                // Use cylinder for orthographic projections:
                // The cylinder is centered at the camera position and reaches from the 
                // camera position to the camera far plane. A TransformedShape is used
                // to rotate and translate the cylinder.
                float radius = projection.Width / viewport.Width * pickingRadius;
                pickingShape = new TransformedShape(
                  new GeometricObject(
                    new CylinderShape(radius, projection.Far),
                    new Pose(new Vector3F(0, 0, -projection.Far / 2), Matrix33F.CreateRotationX(ConstantsF.PiOver2))));
            }
            else
            {
                // Use cone for perspective projections:
                // The cone tip is at the camera position and the cone base is at the 
                // camera far plane. 

                // Compute the radius at the far plane that projects to 10 pixels in screen space.
                float radius = viewport.Unproject(
                  new Vector3(viewport.Width / 2.0f + pickingRadius, viewport.Height / 2.0f, 1),
                  (Matrix)_cameraObject.CameraNode.Camera.Projection.ToMatrix44F(),
                  Matrix.Identity,
                  Matrix.Identity).X;

                // A transformed shape is used to rotate and translate the cone.
                pickingShape = new TransformedShape(
                  new GeometricObject(
                    new ConeShape(radius, projection.Far),
                    new Pose(new Vector3F(0, 0, -projection.Far), Matrix33F.CreateRotationX(ConstantsF.PiOver2))));
            }

            // Create collision object with the picking shape.
            _pickingObject = new CollisionObject(new GeometricObject(pickingShape, _cameraObject.CameraNode.PoseWorld));
        }
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectMotionBlur"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public ObjectMotionBlur(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            _effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/ObjectMotionBlur");
              _viewportSizeParameter = _effect.Parameters["ViewportSize"];
              _sourceTextureParameter = _effect.Parameters["SourceTexture"];
              _numberOfSamplesParameter = _effect.Parameters["NumberOfSamples"];
              _velocityTextureParameter = _effect.Parameters["VelocityTexture"];
              _velocityTexture2Parameter = _effect.Parameters["VelocityTexture2"];
              _maxBlurRadiusParameter = _effect.Parameters["MaxBlurRadius"];
              _sourceSizeParameter = _effect.Parameters["SourceSize"];
              _gBuffer0Parameter = _effect.Parameters["GBuffer0"];
              _jitterTextureParameter = _effect.Parameters["JitterTexture"];
              _softZExtentParameter = _effect.Parameters["SoftZExtent"];
              _singlePass = _effect.CurrentTechnique.Passes["Single"];
              _dualPass = _effect.CurrentTechnique.Passes["Dual"];
              _downsampleMaxParameter = _effect.CurrentTechnique.Passes["DownsampleMax"];
              _downsampleMaxFromFloatBufferParameter = _effect.CurrentTechnique.Passes["DownsampleMaxFromFloatBuffer"];
              _neighborMaxPass = _effect.CurrentTechnique.Passes["NeighborMax"];
              _softEdgePass = _effect.CurrentTechnique.Passes["SoftEdge"];
              _jitterTexture = NoiseHelper.GetGrainTexture(GraphicsService, 128);

              NumberOfSamples = 9;
              MaxBlurRadius = 20;
        }
        //--------------------------------------------------------------
        /// <overloads>
        /// <summary>
        /// Initializes a new instance of the <see cref="TerrainRoadLayer"/> class.
        /// </summary>
        /// </overloads>
        /// 
        /// <summary>
        /// Initializes a new instance of the <see cref="TerrainRoadLayer"/> class with the default
        /// material.
        /// </summary>
        /// <param name="graphicService">The graphic service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicService"/> is <see langword="null"/>.
        /// </exception>
        public TerrainRoadLayer(IGraphicsService graphicService)
        {
            if (graphicService == null)
            throw new ArgumentNullException("graphicService");

              var effect = graphicService.Content.Load<Effect>("DigitalRune/Terrain/TerrainRoadLayer");
              Material = new Material
              {
            { "Detail", new EffectBinding(graphicService, effect, null, EffectParameterHint.Material) }
              };

              FadeOutStart = int.MaxValue;
              FadeOutEnd = int.MaxValue;
              TileSize = 1;
              DiffuseColor = new Vector3F(1, 1, 1);
              SpecularColor = new Vector3F(1, 1, 1);
              SpecularPower = 10;
              Alpha = 1;
              DiffuseTexture = graphicService.GetDefaultTexture2DWhite();
              SpecularTexture = graphicService.GetDefaultTexture2DBlack();
              NormalTexture = graphicService.GetDefaultNormalTexture();
              HeightTextureScale = 1;
              HeightTexture = graphicService.GetDefaultTexture2DBlack();
              RoadLength = 1;
        }
        public GradientTextureSkyRenderer(IGraphicsService graphicsService)
        {
            if (graphicsService == null)
            throw new ArgumentNullException("graphicsService");

              if (graphicsService.GraphicsDevice.GraphicsProfile == GraphicsProfile.Reach)
            throw new NotSupportedException("The GradientTextureSkyRenderer does not support the Reach profile.");

              _effect = graphicsService.Content.Load<Effect>("DigitalRune/Sky/GradientTextureSky");
              _parameterView = _effect.Parameters["View"];
              _parameterProjection = _effect.Parameters["Projection"];
              _parameterSunDirection = _effect.Parameters["SunDirection"];
              _parameterTime = _effect.Parameters["Time"];
              _parameterColor = _effect.Parameters["Color"];
              _parameterFrontTexture = _effect.Parameters["FrontTexture"];
              _parameterBackTexture = _effect.Parameters["BackTexture"];
              _parameterAbcd = _effect.Parameters["Abcd"];
              _parameterEAndStrength = _effect.Parameters["EAndStrength"];
              _passLinear = _effect.Techniques[0].Passes["Linear"];
              _passGamma = _effect.Techniques[0].Passes["Gamma"];
              _passCieLinear = _effect.Techniques[0].Passes["CieLinear"];
              _passCieGamma = _effect.Techniques[0].Passes["CieGamma"];

              _submesh = MeshHelper.GetBox(graphicsService);
        }
Exemple #18
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="SsaoFilter"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public SaoFilter(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            Effect effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/SaoFilter");
              _frustumInfoParameter = effect.Parameters["FrustumInfo"];
              _numberOfAOSamplesParameter = effect.Parameters["NumberOfAOSamples"];
              _aoParameters0 = effect.Parameters["AOParameters0"];
              _aoParameters1 = effect.Parameters["AOParameters1"];
              _aoParameters2 = effect.Parameters["AOParameters2"];
              _sourceTextureParameter = effect.Parameters["SourceTexture"];
              _occlusionTextureParameter = effect.Parameters["OcclusionTexture"];
              _gBuffer0Parameter = effect.Parameters["GBuffer0"];
              //_viewParameter = _effect.Parameters["View"];
              //_gBuffer1Parameter = _effect.Parameters["GBuffer1"];
              _createAOPass = effect.CurrentTechnique.Passes["CreateAO"];
              _blurHorizontalPass = effect.CurrentTechnique.Passes["BlurHorizontal"];
              _blurVerticalPass = effect.CurrentTechnique.Passes["BlurVertical"];
              _blurVerticalAndCombinePass = effect.CurrentTechnique.Passes["BlurVerticalAndCombine"];

              Strength = 1;
              MaxOcclusion = 1;
              Radius = 0.5f;
              MinBias = 0.02f;
              Bias = 0.0004f;
              NumberOfSamples = 11;
              SampleDistribution = 7;
              BlurScale = 2;
              EdgeSoftness = 0.5f;
              CombineWithSource = true;
        }
        public CloudLayerRenderer(IGraphicsService graphicsService)
        {
            if (graphicsService == null)
            throw new ArgumentNullException("graphicsService");

              if (graphicsService.GraphicsDevice.GraphicsProfile == GraphicsProfile.Reach)
            throw new NotSupportedException("The CloudLayerRenderer does not support the Reach profile.");

              _effect = graphicsService.Content.Load<Effect>("DigitalRune/Sky/CloudLayer");
              _parameterView = _effect.Parameters["View"];
              _parameterProjection = _effect.Parameters["Projection"];
              _parameterSunDirection = _effect.Parameters["SunDirection"];
              _parameterSkyCurvature = _effect.Parameters["SkyCurvature"];
              _parameterTextureMatrix = _effect.Parameters["Matrix0"];
              _parameterNumberOfSamples = _effect.Parameters["NumberOfSamples"];
              _parameterSampleDistance = _effect.Parameters["SampleDistance"];
              _parameterScatterParameters = _effect.Parameters["ScatterParameters"];
              _parameterHorizonFade = _effect.Parameters["HorizonFade"];
              _parameterSunLight = _effect.Parameters["SunLight"];
              _parameterAmbientLight = _effect.Parameters["AmbientLight"];
              _parameterTexture = _effect.Parameters["NoiseTexture0"];
              _passCloudRgbLinear = _effect.Techniques[0].Passes["CloudRgbLinear"];
              _passCloudAlphaLinear = _effect.Techniques[0].Passes["CloudAlphaLinear"];
              _passCloudRgbGamma = _effect.Techniques[0].Passes["CloudRgbGamma"];
              _passCloudAlphaGamma = _effect.Techniques[0].Passes["CloudAlphaGamma"];
              _passOcclusionRgb = _effect.Techniques[0].Passes["OcclusionRgb"];
              _passOcclusionAlpha = _effect.Techniques[0].Passes["OcclusionAlpha"];

              // We render a spherical patch into the sky. But any mesh which covers the top
              // hemisphere works too.
              //_submesh = MeshHelper.CreateSpherePatch(graphicsService.GraphicsDevice, 1, 1.1f, 10);
              _submesh = MeshHelper.CreateBox(graphicsService.GraphicsDevice);

              _queryGeometry = new Vector3F[4];
        }
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="ProjectorLightRenderer"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public ProjectorLightRenderer(IGraphicsService graphicsService)
        {
            if (graphicsService == null)
            throw new ArgumentNullException("graphicsService");

              _effect = graphicsService.Content.Load<Effect>("DigitalRune/Deferred/ProjectorLight");
              _parameterWorldViewProjection = _effect.Parameters["WorldViewProjection"];
              _parameterViewportSize = _effect.Parameters["ViewportSize"];
              _parameterFrustumCorners = _effect.Parameters["FrustumCorners"];
              _parameterDiffuseColor = _effect.Parameters["ProjectorLightDiffuse"];
              _parameterSpecularColor = _effect.Parameters["ProjectorLightSpecular"];
              _parameterPosition = _effect.Parameters["ProjectorLightPosition"];
              _parameterRange = _effect.Parameters["ProjectorLightRange"];
              _parameterAttenuation = _effect.Parameters["ProjectorLightAttenuation"];
              _parameterTexture = _effect.Parameters["ProjectorLightTexture"];
              _parameterTextureMatrix = _effect.Parameters["ProjectorLightTextureMatrix"];
              _parameterGBuffer0 = _effect.Parameters["GBuffer0"];
              _parameterGBuffer1 = _effect.Parameters["GBuffer1"];
              _parameterShadowMaskChannel = _effect.Parameters["ShadowMaskChannel"];
              _parameterShadowMask = _effect.Parameters["ShadowMask"];
              _passClip = _effect.CurrentTechnique.Passes["Clip"];
              _passDefaultRgb = _effect.CurrentTechnique.Passes["DefaultRgb"];
              _passDefaultAlpha = _effect.CurrentTechnique.Passes["DefaultAlpha"];
              _passShadowedRgb = _effect.CurrentTechnique.Passes["ShadowedRgb"];
              _passShadowedAlpha = _effect.CurrentTechnique.Passes["ShadowedAlpha"];
        }
Exemple #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CopyFilter"/> class.
 /// </summary>
 /// <param name="graphicsService">The graphics service.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="graphicsService"/> is <see langword="null"/>.
 /// </exception>
 public CopyFilter(IGraphicsService graphicsService)
     : base(graphicsService)
 {
     _effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/CopyFilter");
       _sourceTextureParameter = _effect.Parameters["SourceTexture"];
       _viewportSizeParameter = _effect.Parameters["ViewportSize"];
 }
Exemple #22
0
 public MainMenuComponent(Microsoft.Xna.Framework.Game game, IServiceLocator services)
   : base(game)
 {
   _services = services;
   _inputService = services.GetInstance<IInputService>();
   _graphicsService = services.GetInstance<IGraphicsService>();
   _uiService = services.GetInstance<IUIService>();
 }
Exemple #23
0
 /// <summary>
 /// Draws the circle on the specified graphics context
 /// </summary>
 /// <param name="graphics"></param>
 public void Draw(IGraphicsService graphics)
 {
     if (graphics == null)
     {
         throw new ArgumentNullException("graphics");
     }
     graphics.FillEllipse(_brush, _mathService.GetCenterRect(CircleSize));
 }
Exemple #24
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="RenderContext"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public RenderContext(IGraphicsService graphicsService)
        {
            if (graphicsService == null)
            throw new ArgumentNullException("graphicsService");

              GraphicsService = graphicsService;
              Reset();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DelegateGraphicsScreen"/> class.
 /// </summary>
 /// <param name="graphicsService">The graphics service.</param>
 /// <param name="updateCallback">
 /// The update callback method. (Can be <see langword="null"/>.)
 /// </param>
 /// <param name="renderCallback">
 /// The render callback method. (Can be <see langword="null"/>.)
 /// </param>
 public DelegateGraphicsScreen(IGraphicsService graphicsService, 
     Action<GraphicsScreen, TimeSpan> updateCallback,
     Action<RenderContext> renderCallback)
     : base(graphicsService)
 {
     UpdateCallback = updateCallback;
       RenderCallback = renderCallback;
 }
Exemple #26
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="SsaoFilter"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public SsaoFilter(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            _effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/SsaoFilter");
              _farParameter = _effect.Parameters["Far"];
              _radiusParameter = _effect.Parameters["Radius"];
              _strengthParameter = _effect.Parameters["Strength"];
              _maxDistancesParameter = _effect.Parameters["MaxDistances"];
              _viewportSizeParameter = _effect.Parameters["ViewportSize"];
              _sourceTextureParameter = _effect.Parameters["SourceTexture"];
              _gBuffer0Parameter = _effect.Parameters["GBuffer0"];
              _occlusionTextureParameter = _effect.Parameters["OcclusionTexture"];
              _createLinesAPass = _effect.CurrentTechnique.Passes["CreateLinesA"];
              _createLinesBPass = _effect.CurrentTechnique.Passes["CreateLinesB"];
              _blurHorizontalPass = _effect.CurrentTechnique.Passes["BlurHorizontal"];
              _blurVerticalPass = _effect.CurrentTechnique.Passes["BlurVertical"];
              _combinePass = _effect.CurrentTechnique.Passes["Combine"];
              _copyPass = _effect.CurrentTechnique.Passes["Copy"];

              Radii = new Vector2F(0.01f, 0.02f);
              MaxDistances = new Vector2F(0.5f, 1.0f);
              Strength = 1f;
              NumberOfBlurPasses = 1;
              DownsampleFactor = 2;
              Quality = 2;
              Scale = new Vector2F(0.5f, 2f);
              CombineWithSource = true;

              _blur = new Blur(graphicsService);
              _blur.InitializeGaussianBlur(7, 7 / 3, true);

              _copyFilter = PostProcessHelper.GetCopyFilter(graphicsService);
              _downsampleFilter = PostProcessHelper.GetDownsampleFilter(graphicsService);

              Random random = new Random(123456);
              Vector3[] vectors = new Vector3[9];

              // 16 random vectors for Crytek-style point samples.
              //for (int i = 0; i < vectors.Length; i++)
              //  vectors[i] = (Vector3)random.NextQuaternionF().Rotate(Vector3F.One).Normalized;
              //    //* random.NextFloat(0.5f, 1) // Note: StarCraft 2 uses varying length to vary the sample offset length.

              // We create rotated random vectors with uniform distribution in 360°. Each random vector
              // is further rotated with small random angle.
              float jitterAngle = ConstantsF.TwoPi / vectors.Length / 4;
              for (int i = 0; i < vectors.Length; i++)
            vectors[i] = (Vector3)(Matrix33F.CreateRotationZ(ConstantsF.TwoPi * i / vectors.Length + random.NextFloat(-jitterAngle, jitterAngle)) * new Vector3F(1, 0, 0)).Normalized;

              // Permute randomVectors.
              for (int i = 0; i < vectors.Length; i++)
            MathHelper.Swap(ref vectors[i], ref vectors[random.Next(i, vectors.Length - 1)]);

              // Scale random vectors.
              for (int i = 0; i < vectors.Length; i++)
            vectors[i].Z = random.NextFloat(Scale.X, Scale.Y);

              _effect.Parameters["RandomVectors"].SetValue(vectors);
        }
        public CompositeShadowMaskRenderer(IGraphicsService graphicsService, IList<SceneNodeRenderer> shadowMaskRenderers)
        {
            if (graphicsService == null)
            throw new ArgumentNullException("graphicsService");
              if (shadowMaskRenderers == null)
            throw new ArgumentNullException("shadowMaskRenderers");

              _shadowMaskRenderers = shadowMaskRenderers;
        }
Exemple #28
0
        /// <summary>
        /// Draws the resize in a contrasting colour to the provided graphics context.
        /// </summary>
        /// <param name="graphics"></param>
        public void Draw(IGraphicsService graphics)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException("graphics");
            }

            ControlPaint.DrawSizeGrip(graphics.Graphics, _color, _mathService.ResizeRect);
        }
Exemple #29
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="PostProcessor"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        protected PostProcessor(IGraphicsService graphicsService)
        {
            if (graphicsService == null)
            throw new ArgumentNullException("graphicsService");

              GraphicsService = graphicsService;
              _enabled = true;  // Note: Virtual OnEnabled must not be called in constructor.
              DefaultTargetFormat = new RenderTargetFormat(null, null, false, null, DepthFormat.None);
        }
Exemple #30
0
        public GBufferRenderer(IGraphicsService graphicsService, SceneNodeRenderer sceneNodeRenderer, DecalRenderer decalRenderer)
        {
            _clearGBufferRenderer = new ClearGBufferRenderer(graphicsService);
              _sceneNodeRenderer = sceneNodeRenderer;
              _decalRenderer = decalRenderer;

              // This filter is used to downsample the depth buffer (GBuffer0).
              _downsampleFilter = PostProcessHelper.GetDownsampleFilter(graphicsService);
        }
    public static BasicEffect GetBasicEffect(this IGraphicsService graphicsService)
    {
      if (graphicsService == null)
        throw new ArgumentNullException("graphicsService");

      const string key = "__WrappedBasicEffect";
      object effect;
      graphicsService.Data.TryGetValue(key, out effect);
      var instance = effect as WrappedBasicEffect;
      if (instance == null)
      {
        instance = new WrappedBasicEffect(graphicsService.GraphicsDevice);
        graphicsService.Data[key] = instance;
      }
      return instance;
    }