public ProjectedShadowSample(Microsoft.Xna.Framework.Game game) : base(game) { SampleFramework.IsMouseVisible = false; var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = Render, }; GraphicsService.Screens.Insert(0, delegateGraphicsScreen); // Create a new empty scene. _scene = new Scene(); Services.Register(typeof(IScene), null, _scene); // Add a custom game object which controls the camera. _cameraObject = new CameraObject(Services); _cameraObject.ResetPose(new Vector3F(-8, 6, 8), -ConstantsF.PiOver4, -0.4f); GameObjectService.Objects.Add(_cameraObject); // Add a default light setup (ambient light + 3 directional lights). var defaultLightsObject = new DefaultLightsObject(Services); GameObjectService.Objects.Add(defaultLightsObject); // Get the main directional light. _mainDirectionalLightNode = ((LightNode)_scene.GetSceneNode("KeyLight")); // Add a ground plane model to the scene graph. var grid = ContentManager.Load<ModelNode>("Ground/Ground").Clone(); grid.ScaleLocal = new Vector3F(0.3f); _scene.Children.Add(grid); // Add a tank model to the scene graph. var tank = ContentManager.Load<ModelNode>("Tank/tank").Clone(); _scene.Children.Add(tank); // Remember the mesh nodes of tank node. _tankMeshNodes = tank.GetSubtree().Where(n => n is MeshNode).ToArray(); // Create the renderers. _meshRenderer = new MeshRenderer(); var spriteFont = UIContentManager.Load<SpriteFont>("UI Themes/BlendBlue/Default"); _debugRenderer = new DebugRenderer(GraphicsService, spriteFont); _projectedShadowRenderer = new ProjectedShadowRenderer(GraphicsService) { // The plane onto which the shadows are projected. It is positioned a bit above the ground // plane to avoid z-fighting. ShadowedPlane = new Plane(new Vector3F(0, 1, 0), 0.01f), // The shadow color is a transparent black. ShadowColor = new Vector4F(0, 0, 0, 0.4f), // The light position is set in Update(). //LightPosition = ... }; }
public ProjectedShadowSample2(Microsoft.Xna.Framework.Game game) : base(game) { SampleFramework.IsMouseVisible = false; var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = Render, }; GraphicsService.Screens.Insert(0, delegateGraphicsScreen); // The dude model uses a new ProjectedShadowSkinned.fx effect. This effect contains new // parameters 'ShadowMatrix' and 'ShadowColor' which are not yet supported. When an mesh is // loaded via the content manager, effect bindings are automatically created. This is done // by effect interpreters and effect binders. The graphics service uses several predefined // effect interpreter and binder classes to support the most common effect parameters. E.g. // the SceneEffectInterpreter and SceneEffectBinder handle parameters like 'World', 'View', // 'ViewProjection', 'CameraPosition', 'FogColor', etc. (see also class // SceneEffectParameterSemantics). // We can add new effect interpreters/binders or we can add an entry to an existing // interpreter/binder. Let's add entries to the standard SceneEffectInterpreter which creates // meta-data for the new parameters: var sceneEffectInterpreter = GraphicsService.EffectInterpreters.OfType<SceneEffectInterpreter>().First(); sceneEffectInterpreter.ParameterDescriptions.Add( "ShadowMatrix", (parameter, index) => new EffectParameterDescription(parameter, "ShadowMatrix", index, EffectParameterHint.Global)); sceneEffectInterpreter.ParameterDescriptions.Add( "ShadowColor", (parameter, index) => new EffectParameterDescription(parameter, "ShadowColor", index, EffectParameterHint.Global)); // Add entries to the standard SceneEffectBinder which create DelegateParameterBindings for // the new parameters. The delegate bindings use callback methods to compute the parameter // value. var sceneEffectBinder = GraphicsService.EffectBinders.OfType<SceneEffectBinder>().First(); sceneEffectBinder.MatrixBindings.Add( "ShadowMatrix", (effect, parameter, data) => new DelegateParameterBinding<Matrix>(effect, parameter, GetShadowMatrix)); sceneEffectBinder.Vector4Bindings.Add( "ShadowColor", (effect, parameter, data) => new DelegateParameterBinding<Vector4>(effect, parameter, GetShadowColor)); // Create a new empty scene. _scene = new Scene(); Services.Register(typeof(IScene), null, _scene); // Add a custom game object which controls the camera. _cameraObject = new CameraObject(Services); _cameraObject.ResetPose(new Vector3F(-2, 2, 2), -ConstantsF.PiOver4, -0.4f); GameObjectService.Objects.Add(_cameraObject); // Add a default light setup (ambient light + 3 directional lights). var defaultLightsObject = new DefaultLightsObject(Services); GameObjectService.Objects.Add(defaultLightsObject); // Get the main directional light. _mainDirectionalLightNode = ((LightNode)_scene.GetSceneNode("KeyLight")); // Add a ground plane model to the scene graph. var grid = ContentManager.Load<ModelNode>("Ground/Ground").Clone(); grid.ScaleLocal = new Vector3F(0.3f); _scene.Children.Add(grid); // Add a dude model to the scene graph. var dude = ContentManager.Load<ModelNode>("DudeWithProjectedShadow/Dude").Clone(); dude.PoseWorld = new Pose(Matrix33F.CreateRotationY(ConstantsF.Pi)); SampleHelper.EnablePerPixelLighting(dude); _scene.Children.Add(dude); // Start walk animation. StartDudeAnimation(dude); // Create the renderers. _meshRenderer = new MeshRenderer(); _shadowColor = new Vector4(0, 0, 0, 0.4f); }
public ProjectedShadowSample2(Microsoft.Xna.Framework.Game game) : base(game) { SampleFramework.IsMouseVisible = false; var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = Render, }; GraphicsService.Screens.Insert(0, delegateGraphicsScreen); // The dude model uses a new ProjectedShadowSkinned.fx effect. This effect contains new // parameters 'ShadowMatrix' and 'ShadowColor' which are not yet supported. When an mesh is // loaded via the content manager, effect bindings are automatically created. This is done // by effect interpreters and effect binders. The graphics service uses several predefined // effect interpreter and binder classes to support the most common effect parameters. E.g. // the SceneEffectInterpreter and SceneEffectBinder handle parameters like 'World', 'View', // 'ViewProjection', 'CameraPosition', 'FogColor', etc. (see also class // SceneEffectParameterSemantics). // We can add new effect interpreters/binders or we can add an entry to an existing // interpreter/binder. Let's add entries to the standard SceneEffectInterpreter which creates // meta-data for the new parameters: var sceneEffectInterpreter = GraphicsService.EffectInterpreters.OfType <SceneEffectInterpreter>().First(); sceneEffectInterpreter.ParameterDescriptions.Add( "ShadowMatrix", (parameter, index) => new EffectParameterDescription(parameter, "ShadowMatrix", index, EffectParameterHint.Global)); sceneEffectInterpreter.ParameterDescriptions.Add( "ShadowColor", (parameter, index) => new EffectParameterDescription(parameter, "ShadowColor", index, EffectParameterHint.Global)); // Add entries to the standard SceneEffectBinder which create DelegateParameterBindings for // the new parameters. The delegate bindings use callback methods to compute the parameter // value. var sceneEffectBinder = GraphicsService.EffectBinders.OfType <SceneEffectBinder>().First(); sceneEffectBinder.MatrixBindings.Add( "ShadowMatrix", (effect, parameter, data) => new DelegateParameterBinding <Matrix>(effect, parameter, GetShadowMatrix)); sceneEffectBinder.Vector4Bindings.Add( "ShadowColor", (effect, parameter, data) => new DelegateParameterBinding <Vector4>(effect, parameter, GetShadowColor)); // Create a new empty scene. _scene = new Scene(); Services.Register(typeof(IScene), null, _scene); // Add a custom game object which controls the camera. _cameraObject = new CameraObject(Services); _cameraObject.ResetPose(new Vector3(-2, 2, 2), -ConstantsF.PiOver4, -0.4f); GameObjectService.Objects.Add(_cameraObject); // Add a default light setup (ambient light + 3 directional lights). var defaultLightsObject = new DefaultLightsObject(Services); GameObjectService.Objects.Add(defaultLightsObject); // Get the main directional light. _mainDirectionalLightNode = ((LightNode)_scene.GetSceneNode("KeyLight")); // Add a ground plane model to the scene graph. var grid = ContentManager.Load <ModelNode>("Ground/Ground").Clone(); grid.ScaleLocal = new Vector3(0.3f); _scene.Children.Add(grid); // Add a dude model to the scene graph. var dude = ContentManager.Load <ModelNode>("DudeWithProjectedShadow/Dude").Clone(); dude.PoseWorld = new Pose(Matrix.CreateRotationY(ConstantsF.Pi)); SampleHelper.EnablePerPixelLighting(dude); _scene.Children.Add(dude); // Start walk animation. StartDudeAnimation(dude); // Create the renderers. _meshRenderer = new MeshRenderer(); _shadowColor = new Vector4(0, 0, 0, 0.4f); }
public ProjectedShadowSample(Microsoft.Xna.Framework.Game game) : base(game) { SampleFramework.IsMouseVisible = false; var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = Render, }; GraphicsService.Screens.Insert(0, delegateGraphicsScreen); // Create a new empty scene. _scene = new Scene(); Services.Register(typeof(IScene), null, _scene); // Add a custom game object which controls the camera. _cameraObject = new CameraObject(Services); _cameraObject.ResetPose(new Vector3F(-8, 6, 8), -ConstantsF.PiOver4, -0.4f); GameObjectService.Objects.Add(_cameraObject); // Add a default light setup (ambient light + 3 directional lights). var defaultLightsObject = new DefaultLightsObject(Services); GameObjectService.Objects.Add(defaultLightsObject); // Get the main directional light. _mainDirectionalLightNode = ((LightNode)_scene.GetSceneNode("KeyLight")); // Add a ground plane model to the scene graph. var grid = ContentManager.Load <ModelNode>("Ground/Ground").Clone(); grid.ScaleLocal = new Vector3F(0.3f); _scene.Children.Add(grid); // Add a tank model to the scene graph. var tank = ContentManager.Load <ModelNode>("Tank/tank").Clone(); _scene.Children.Add(tank); // Remember the mesh nodes of tank node. _tankMeshNodes = tank.GetSubtree().Where(n => n is MeshNode).ToArray(); // Create the renderers. _meshRenderer = new MeshRenderer(); var spriteFont = UIContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default"); _debugRenderer = new DebugRenderer(GraphicsService, spriteFont); _projectedShadowRenderer = new ProjectedShadowRenderer(GraphicsService) { // The plane onto which the shadows are projected. It is positioned a bit above the ground // plane to avoid z-fighting. ShadowedPlane = new Plane(new Vector3F(0, 1, 0), 0.01f), // The shadow color is a transparent black. ShadowColor = new Vector4F(0, 0, 0, 0.4f), // The light position is set in Update(). //LightPosition = ... }; }