public void SeedMonotouchAheadOfTimeCompile() { ParticleSystem system = null; system.playbackSpeed++; system.startLifetime++; system.startSpeed++; system.startDelay++; system.startRotation++; system.emissionRate++; RenderToTexture texture = null; texture.m_ObjectToRender = null; texture.m_RealtimeRender &= true; texture.enabled &= true; FullScreenEffects effects = null; effects.BlendToColorAmount++; effects.VignettingEnable &= true; effects.VignettingIntensity++; MeshFilter filter = null; filter.mesh = null; RotateOverTime time = null; time.RotateSpeedX++; time.RotateSpeedY++; time.RotateSpeedZ++; }
void Awake() { rtt = GetComponent <RenderToTexture>(); audios = GetComponent <AudioSource>(); uisprites = GetComponent <Sprites>(); FaceunityWorker.OnInitOK += InitApplication; }
//-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="PlanarReflectionNode" /> class. /// </summary> /// <param name="renderToTexture">The render texture target.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="renderToTexture"/> is <see langword="null"/>. /// </exception> public PlanarReflectionNode(RenderToTexture renderToTexture) : base(renderToTexture) { CameraNode = new CameraNode(new Camera(new PerspectiveProjection())); FieldOfViewScale = 1; _normalLocal = new Vector3F(0, 0, 1); }
//-------------------------------------------------------------- #region Creation & Cleanup //-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="PlanarReflectionNode" /> class. /// </summary> /// <param name="renderToTexture">The render texture target.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="renderToTexture"/> is <see langword="null"/>. /// </exception> public PlanarReflectionNode(RenderToTexture renderToTexture) : base(renderToTexture) { CameraNode = new CameraNode(new Camera(new PerspectiveProjection())); FieldOfViewScale = 1; _normalLocal = new Vector3F(0, 0, 1); }
public void Initialize() { // <Rant> // OpenTK has a great fuckup in its design here. It's absolutly nohm it possible to create // a render context for offscreen rendering without creating an OpenTK window. // before. // Passing Utilities.CreateDummyWindowInfo() or anything else will cause an invalid cast exception // Using Utilities.CreateWindowsWindowInfo(IntPtr.Zero) binds the code to windows only // Really great, why do i need to have a window in order to render to memory? -_- //</Rant> _window = new NativeWindow { Visible = false }; _context = new GraphicsContext(GraphicsMode.Default, _window.WindowInfo, 2, 0, GraphicsContextFlags.Default); _context.MakeCurrent(_window.WindowInfo); _context.LoadAll(); // create offscreen rendertarget with high precision _rtt = new RenderToTexture(1, 1, false, 4, typeof(float)); int precision; int range; GL.GetShaderPrecisionFormat(OpenTK.Graphics.OpenGL.ShaderType.FragmentShader, ShaderPrecisionType.HighFloat, out range, out precision); Debug.WriteLine("Precision: {0}, Range {1}", precision, range); // init SL# Bindings.OpenTK.SLSharp.Init(); }
//-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="RenderToTextureNode" /> class. /// </summary> /// <param name="renderToTexture">The render texture target.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="renderToTexture"/> is <see langword="null"/>. /// </exception> protected RenderToTextureNode(RenderToTexture renderToTexture) { if (renderToTexture == null) throw new ArgumentNullException("renderToTexture"); _renderToTexture = renderToTexture; Shape = Geometry.Shapes.Shape.Infinite; }
} // Dispose(someObject) /// <summary> /// Dispose /// </summary> /// <param name="someObject">Some object</param> public static void Dispose(ref RenderToTexture someObject) { if (someObject != null) { someObject.Dispose(); } someObject = null; } // Dispose(someObject)
//-------------------------------------------------------------- #region Creation & Cleanup //-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="RenderToTextureNode" /> class. /// </summary> /// <param name="renderToTexture">The render texture target.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="renderToTexture"/> is <see langword="null"/>. /// </exception> protected RenderToTextureNode(RenderToTexture renderToTexture) { if (renderToTexture == null) { throw new ArgumentNullException("renderToTexture"); } _renderToTexture = renderToTexture; Shape = Geometry.Shapes.Shape.Infinite; }
private void DoGetObject() { GameObject ownerDefaultTarget = base.Fsm.GetOwnerDefaultTarget(this.gameObject); if (ownerDefaultTarget != null) { RenderToTexture component = ownerDefaultTarget.GetComponent <RenderToTexture>(); if (component == null) { this.LogError("Missing RenderToTexture component!"); } else { this.renderObject.Value = component.GetRenderToObject(); } } }
public TwistHandler(GLControl glControl, System.Action status, Settings settings, RenderToTexture renderToTexture) { m_glControl = glControl; m_status = status; m_settings = settings; m_renderToTexture = renderToTexture; m_timer = new System.Timers.Timer(30); m_timer.SynchronizingObject = glControl; m_timer.Enabled = false; m_timer.Elapsed += new System.Timers.ElapsedEventHandler(TimerTick); m_setupMoves = new SetupMoves(); m_workingMacro = new Macro(); m_rotation = 0; this.Solving = false; }
/// <summary> /// Konstruktor, spusti inicializaci D3D /// </summary> /// <param name="form">Objekt tridy Form, kam se ma vykreslovat</param> /// <param name="windowed">Je true, pokud aplikace bude spusteni v okenim rezimu, jinak bude spustena ve fullscreenu</param> public GraphicCore(Program form, bool windowed) { Logger.AddInfo("Graphic core init"); this.windowed = windowed; this.form = form; form.Size = this.WindowResolution; initializator = new Initializator(form); initializator.SetResolution(false, form.Size.Width, form.Size.Height); if (currentDetail == SceneManager.DetailLevel.High || currentDetail == SceneManager.DetailLevel.UltraHigh || Settings.Default.ForceVSync) { initializator.SetVSync(true); } initializator.ReInit(); device = initializator.GetDevice(); Microsoft.DirectX.Direct3D.AdapterDetails adapter = new Microsoft.DirectX.Direct3D.AdapterDetails(); Logger.AddInfo("Info: " + System.Environment.OSVersion.ToString() + "<br/> " + this.device.DisplayMode + "<br/>" + adapter.ToString()); sceneManager = new SceneManager(device, Camera.GetCameraInstance()); #region Nastaveni kvality shadow map int shadowMapDimension = Settings.Default.MediumShadowMapDimension; if (currentDetail == SceneManager.DetailLevel.Low) { shadowMapDimension = (int)(shadowMapDimension * 0.5f); } else if (currentDetail == SceneManager.DetailLevel.High) { shadowMapDimension *= 2; } #endregion shadowMap = new RenderToTexture(device, shadowMapDimension, shadowMapDimension, Format.R32F, true, DepthFormat.D24X8); collisionMap = new RenderToTexture(device, 128, 128, Format.A8R8G8B8, true, DepthFormat.D16); DeviceReset(); }
public SceneRenderTargetListener(RenderToTexture owner) { this.owner = owner; }
public PlanarReflectionSample(Microsoft.Xna.Framework.Game game) : base(game) { SampleFramework.IsMouseVisible = false; // Create a graphics screen. This screen has to call the PlanarReflectionRenderer // to handle the PlanarReflectionNodes! _graphicsScreen = new DeferredGraphicsScreen(Services) { DrawReticle = true }; GraphicsService.Screens.Insert(0, _graphicsScreen); GameObjectService.Objects.Add(new DeferredGraphicsOptionsObject(Services)); Services.Register(typeof(DebugRenderer), null, _graphicsScreen.DebugRenderer); Services.Register(typeof(IScene), null, _graphicsScreen.Scene); // Add gravity and damping to the physics Simulation. Simulation.ForceEffects.Add(new Gravity()); Simulation.ForceEffects.Add(new Damping()); // Add a custom game object which controls the camera. var cameraGameObject = new CameraObject(Services); GameObjectService.Objects.Add(cameraGameObject); _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode; // More standard objects. GameObjectService.Objects.Add(new GrabObject(Services)); GameObjectService.Objects.Add(new ObjectCreatorObject(Services)); GameObjectService.Objects.Add(new StaticSkyObject(Services)); GameObjectService.Objects.Add(new GroundObject(Services)); GameObjectService.Objects.Add(new DudeObject(Services)); GameObjectService.Objects.Add(new DynamicObject(Services, 1)); GameObjectService.Objects.Add(new DynamicObject(Services, 2)); GameObjectService.Objects.Add(new DynamicObject(Services, 5)); GameObjectService.Objects.Add(new DynamicObject(Services, 6)); GameObjectService.Objects.Add(new DynamicObject(Services, 7)); GameObjectService.Objects.Add(new FogObject(Services)); GameObjectService.Objects.Add(new LavaBallsObject(Services)); // Add a few palm trees. Random random = new Random(12345); for (int i = 0; i < 10; i++) { Vector3F position = new Vector3F(random.NextFloat(-3, -8), 0, random.NextFloat(0, -5)); Matrix33F orientation = Matrix33F.CreateRotationY(random.NextFloat(0, ConstantsF.TwoPi)); float scale = random.NextFloat(0.5f, 1.2f); GameObjectService.Objects.Add(new StaticObject(Services, "PalmTree/palm_tree", scale, new Pose(position, orientation))); } #if MONOGAME // ----- Workaround for missing effect parameter semantics in MonoGame. // The effect used by the reflecting ground object defines some new effect // parameters and sets the EffectParameterHint to "PerInstance", e.g.: // texture ReflectionTexture < string Hint = "PerInstance"; >; // "PerInstance" means that each mesh instance which uses the effect can // have an individual parameter value, i.e. if there are two instances // each instance needs a different ReflectionTexture. // MonoGame does not yet support effect parameter annotations in shader // code. But we can add the necessary effect parameter descriptions here: var effectInterpreter = GraphicsService.EffectInterpreters.OfType <DefaultEffectInterpreter>().First(); if (!effectInterpreter.ParameterDescriptions.ContainsKey("ReflectionTexture")) { effectInterpreter.ParameterDescriptions.Add("ReflectionTexture", (parameter, index) => new EffectParameterDescription(parameter, "ReflectionTexture", index, EffectParameterHint.PerInstance)); effectInterpreter.ParameterDescriptions.Add("ReflectionTextureSize", (parameter, index) => new EffectParameterDescription(parameter, "ReflectionTextureSize", index, EffectParameterHint.PerInstance)); effectInterpreter.ParameterDescriptions.Add("ReflectionMatrix", (parameter, index) => new EffectParameterDescription(parameter, "ReflectionMatrix", index, EffectParameterHint.PerInstance)); effectInterpreter.ParameterDescriptions.Add("ReflectionNormal", (parameter, index) => new EffectParameterDescription(parameter, "ReflectionNormal", index, EffectParameterHint.PerInstance)); } #endif // Get a ground model which can render a planar reflection. See // GroundReflective/MaterialReflective.fx. var groundModel = ContentManager.Load <ModelNode>("GroundReflective/Ground"); // Use the reflective mesh as the ground. var groundMesh = groundModel.GetSubtree().OfType <MeshNode>().First().Clone(); groundMesh.PoseWorld = new Pose(new Vector3F(0, 0.01f, 0)); // Small y offset to draw above the default ground model from GroundObject. _graphicsScreen.Scene.Children.Add(groundMesh); // Use another instance of the mesh as a wall. var wallMesh = groundMesh.Clone(); wallMesh.ScaleLocal = new Vector3F(0.2f, 1, 0.1f); wallMesh.PoseWorld = new Pose(new Vector3F(5, 2, -5), Matrix33F.CreateRotationY(-0.7f) * Matrix33F.CreateRotationX(ConstantsF.PiOver2)); _graphicsScreen.Scene.Children.Add(wallMesh); // Create a PlanarReflectionNode and add it to the children of the first ground mesh. // The RenderToTexture class defines the render target for the reflection. var renderToTexture0 = new RenderToTexture { Texture = new RenderTarget2D( GraphicsService.GraphicsDevice, 1024, 1024, false, // No mipmaps. Mipmaps can reduce reflection quality. SurfaceFormat.HdrBlendable, DepthFormat.Depth24Stencil8), }; _planarReflectionNode0 = new PlanarReflectionNode(renderToTexture0) { // The reflection is limited to the bounding shape of the ground mesh. Shape = groundMesh.Shape, // The normal of the reflection plane. NormalLocal = new Vector3F(0, 1, 0), }; groundMesh.Children = new SceneNodeCollection(1) { _planarReflectionNode0 }; // Add another PlanarReflectionNode to the wall. var renderToTexture1 = new RenderToTexture { Texture = new RenderTarget2D( GraphicsService.GraphicsDevice, 1024, 1024, false, SurfaceFormat.HdrBlendable, DepthFormat.Depth24Stencil8), }; _planarReflectionNode1 = new PlanarReflectionNode(renderToTexture1) { Shape = groundMesh.Shape, NormalLocal = new Vector3F(0, 1, 0), }; wallMesh.Children = new SceneNodeCollection(1) { _planarReflectionNode1 }; // Now we have to use the texture that contains the reflection. // We use effect parameter bindings to use the reflection texture in the shader of the meshes. SetReflectionEffectParameters(groundMesh, _planarReflectionNode0); SetReflectionEffectParameters(wallMesh, _planarReflectionNode1); }
/// <summary> /// Dispose /// </summary> /// <param name="someObject">Some object</param> public static void Dispose(ref RenderToTexture someObject) { if (someObject != null) someObject.Dispose(); someObject = null; }
//-------------------------------------------------------------- #region Methods //-------------------------------------------------------------- protected override void OnLoad() { // Get services. _inputService = _services.GetInstance <IInputService>(); _graphicsService = _services.GetInstance <IGraphicsService>(); _scene = _services.GetInstance <IScene>(); var content = _services.GetInstance <ContentManager>(); var gameObjectService = _services.GetInstance <IGameObjectService>(); // Get camera game object. _cameraObject = (CameraObject)gameObjectService.Objects["Camera"]; // Create SkyNodes. InitializeSky(content); // Create LightNodes InitializeLights(); // Optionally, the sky is captured into a cube map and the cube map is added // to the scene instead of all the sky nodes. if (_cacheSky) { // We use a SceneCaptureNode to create the cube map. // The cube map uses RGBM encoding to store HDR values. var renderToTexture = new RenderToTexture { Texture = new RenderTargetCube( _graphicsService.GraphicsDevice, 1024, false, SurfaceFormat.Color, DepthFormat.None), }; var projection = new PerspectiveProjection(); projection.SetFieldOfView(ConstantsF.PiOver2, 1, 1, 10); _sceneCaptureNode = new SceneCaptureNode(renderToTexture) { // Note: The scene is captured at the origin (0, 0, 0). CameraNode = new CameraNode(new Camera(projection)), }; SkyboxNode = new SkyboxNode { Encoding = ColorEncoding.Rgbm, Texture = (TextureCube)renderToTexture.Texture, }; _scene.Children.Add(SkyboxNode); } // The Ephemeris class computes the positions of the sun and the moon as seen // from any place on the earth. _ephemeris = new Ephemeris { // Seattle, Washington //Latitude = 47, //Longitude = 122, //Altitude = 100 // Vienna //Latitude = 48, //Longitude = -16, //Altitude = 0 // Equator Latitude = 0, Longitude = 90, Altitude = 0 }; #if XBOX _time = DateTime.Now; #else _time = DateTimeOffset.Now; #endif // Update the positions of sky objects and the lights. UpdateSky(); // Create cube map. if (_cacheSky) { UpdateCubeMap(TimeSpan.Zero); } }
public SceneCapture2DSample(Microsoft.Xna.Framework.Game game) : base(game) { // Create a graphics screen. This screen has to call the SceneCaptureRenderer // to handle the SceneCaptureNodes! _graphicsScreen = new DeferredGraphicsScreen(Services) { DrawReticle = true }; GraphicsService.Screens.Insert(0, _graphicsScreen); Services.Register(typeof(DebugRenderer), null, _graphicsScreen.DebugRenderer); Services.Register(typeof(IScene), null, _graphicsScreen.Scene); // We are going to modify the material of the TV mesh. These changes should not // affect other samples. Therefore, we add a new content manager, which is only // used in this sample. _contentManager = new ContentManager(Services, ContentManager.RootDirectory); Services.Register(typeof(ContentManager), null, _contentManager); // Add gravity and damping to the physics Simulation. Simulation.ForceEffects.Add(new Gravity()); Simulation.ForceEffects.Add(new Damping()); // Add a custom game object which controls the camera. var cameraGameObject = new CameraObject(Services); GameObjectService.Objects.Add(cameraGameObject); _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode; // More standard objects. GameObjectService.Objects.Add(new GrabObject(Services)); GameObjectService.Objects.Add(new ObjectCreatorObject(Services)); GameObjectService.Objects.Add(new StaticSkyObject(Services)); GameObjectService.Objects.Add(new GroundObject(Services)); GameObjectService.Objects.Add(new DudeObject(Services)); GameObjectService.Objects.Add(new DynamicObject(Services, 1)); GameObjectService.Objects.Add(new DynamicObject(Services, 2)); GameObjectService.Objects.Add(new DynamicObject(Services, 4)); GameObjectService.Objects.Add(new DynamicObject(Services, 5)); GameObjectService.Objects.Add(new DynamicObject(Services, 6)); GameObjectService.Objects.Add(new DynamicObject(Services, 7)); GameObjectService.Objects.Add(new FogObject(Services)); GameObjectService.Objects.Add(new LavaBallsObject(Services)); // Add a few palm trees. Random random = new Random(12345); for (int i = 0; i < 10; i++) { Vector3F position = new Vector3F(random.NextFloat(-3, -8), 0, random.NextFloat(0, -5)); Matrix33F orientation = Matrix33F.CreateRotationY(random.NextFloat(0, ConstantsF.TwoPi)); float scale = random.NextFloat(0.5f, 1.2f); GameObjectService.Objects.Add(new StaticObject(Services, "PalmTree/palm_tree", scale, new Pose(position, orientation))); } // Add an options window. GameObjectService.Objects.Add(new OptionsObject(Services)); // Create another camera which defines the view that should be captured. _sceneCaptureCameraNode = cameraGameObject.CameraNode.Clone(); // Define the target for the render-to-texture operations. _renderToTexture = new RenderToTexture { Texture = new RenderTarget2D( GraphicsService.GraphicsDevice, 1280 / 2, 720 / 2, #if !MONOGAME && !XBOX true, #else false, // MonoGame has not yet implemented render target mipmap support. #endif SurfaceFormat.Color, DepthFormat.Depth24Stencil8) }; // Add a few TV objects. for (int i = 0; i < 10; i++) { GameObjectService.Objects.Add(new DynamicObject(Services, 3)); } // Attach a SceneCaptureNode to each TV mesh. The SceneCaptureNodes share the // same RenderToTexture instance, which means that all TVs show the same image. // The SceneCaptureNode has the same bounding shape as the TV mesh. This shape // is used for culling: The texture is only updated when at least one TV is // within the player's view. foreach (var meshNode in _graphicsScreen.Scene.GetDescendants().OfType <MeshNode>().Where(n => n.Name == "TV")) { if (meshNode.Children == null) { meshNode.Children = new SceneNodeCollection(); } meshNode.Children.Add(new SceneCaptureNode(_renderToTexture) { CameraNode = _sceneCaptureCameraNode, // For culling: Assign TV shape to SceneCaptureNode. Shape = meshNode.Shape, }); } // Get the material of the TV mesh. var tvModel = _graphicsScreen.Scene .GetDescendants() .OfType <ModelNode>() .First(n => n.Name == "TVBox"); var tvMesh = (MeshNode)tvModel.Children[0]; var tvScreenMaterial = tvMesh.Mesh .Materials .First(m => m.Name == "TestCard"); // Use the texture on the TV screen. tvScreenMaterial["Material"].Set("EmissiveTexture", _renderToTexture.Texture); tvScreenMaterial["Material"].Set("Exposure", 0.5f); // Also assign the texture to the light projected by the TV screen. var lightNode = (LightNode)tvModel.Children[1]; var projectorLight = (ProjectorLight)lightNode.Light; projectorLight.Texture = (Texture2D)_renderToTexture.Texture; }
public OceanSample(Microsoft.Xna.Framework.Game game) : base(game) { SampleFramework.IsMouseVisible = false; _graphicsScreen = new DeferredGraphicsScreen(Services); _graphicsScreen.DrawReticle = true; GraphicsService.Screens.Insert(0, _graphicsScreen); GameObjectService.Objects.Add(new DeferredGraphicsOptionsObject(Services)); Services.Register(typeof(DebugRenderer), null, _graphicsScreen.DebugRenderer); Services.Register(typeof(IScene), null, _graphicsScreen.Scene); // Add gravity and damping to the physics Simulation. Simulation.ForceEffects.Add(new Gravity()); Simulation.ForceEffects.Add(new Damping()); // Add a custom game object which controls the camera. var cameraGameObject = new CameraObject(Services); GameObjectService.Objects.Add(cameraGameObject); _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode; // More standard objects. GameObjectService.Objects.Add(new GrabObject(Services)); GameObjectService.Objects.Add(new ObjectCreatorObject(Services)); //GameObjectService.Objects.Add(new StaticSkyObject(Services)); var dynamicSkyObject = new DynamicSkyObject(Services, true, false, true); GameObjectService.Objects.Add(dynamicSkyObject); // Add an island model. GameObjectService.Objects.Add(new StaticObject(Services, "Island/Island", new Vector3F(30), new Pose(new Vector3F(0, 0.75f, 0)), true, true)); GameObjectService.Objects.Add(new DynamicObject(Services, 1)); GameObjectService.Objects.Add(new DynamicObject(Services, 2)); GameObjectService.Objects.Add(new DynamicObject(Services, 5)); GameObjectService.Objects.Add(new DynamicObject(Services, 6)); GameObjectService.Objects.Add(new DynamicObject(Services, 7)); GameObjectService.Objects.Add(new FogObject(Services) { AttachToCamera = true }); // The LavaBalls class controls all lava ball instances. var lavaBalls = new LavaBallsObject(Services); GameObjectService.Objects.Add(lavaBalls); // Add a few palm trees. Random random = new Random(12345); for (int i = 0; i < 20; i++) { Vector3F position = new Vector3F(random.NextFloat(-7, 4), 0, random.NextFloat(13, 18)); Matrix33F orientation = Matrix33F.CreateRotationY(random.NextFloat(0, ConstantsF.TwoPi)); float scale = random.NextFloat(0.8f, 1.2f); GameObjectService.Objects.Add(new StaticObject(Services, "PalmTree/palm_tree", scale, new Pose(position, orientation))); } // Define the appearance of the water. var waterOcean = new Water { SpecularColor = new Vector3F(20f), SpecularPower = 500, NormalMap0 = null, NormalMap1 = null, RefractionDistortion = 0.1f, ReflectionColor = new Vector3F(0.2f), RefractionColor = new Vector3F(0.6f), // Water is scattered in high waves and this makes the wave crests brighter. // ScatterColor defines the intensity of this effect. ScatterColor = new Vector3F(0.05f, 0.1f, 0.1f), // Foam is automatically rendered where the water intersects geometry and // where wave are high. FoamMap = ContentManager.Load <Texture2D>("Water/Foam"), FoamMapScale = 5, FoamColor = new Vector3F(1), FoamCrestMin = 0.3f, FoamCrestMax = 0.8f, // Approximate underwater caustics are computed in real-time from the waves. CausticsSampleCount = 3, CausticsIntensity = 3, CausticsPower = 100, }; // If we do not specify a shape in the WaterNode constructor, we get an infinite // water plane. _waterNode = new WaterNode(waterOcean, null) { PoseWorld = new Pose(new Vector3F(0, 0.5f, 0)), SkyboxReflection = _graphicsScreen.Scene.GetDescendants().OfType <SkyboxNode>().First(), // ExtraHeight must be set to a value greater than the max. wave height. ExtraHeight = 2, }; _graphicsScreen.Scene.Children.Add(_waterNode); // OceanWaves can be set to displace water surface using a displacement map. // The displacement map is computed by the WaterWaveRenderer (see DeferredGraphicsScreen) // using FFT and a statistical ocean model. _waterNode.Waves = new OceanWaves { TextureSize = 256, HeightScale = 0.004f, Wind = new Vector3F(10, 0, 10), Directionality = 1, Choppiness = 1, TileSize = 20, // If we enable CPU queries, we can call OceanWaves.GetDisplacement() // (see Update() method below). EnableCpuQueries = true, }; // Optional: Use a planar reflection instead of the skybox reflection. // We add a PlanarReflectionNode as a child of the WaterNode. var renderToTexture = new RenderToTexture { Texture = new RenderTarget2D(GraphicsService.GraphicsDevice, 512, 512, false, SurfaceFormat.HdrBlendable, DepthFormat.None), }; var planarReflectionNode = new PlanarReflectionNode(renderToTexture) { Shape = _waterNode.Shape, NormalLocal = new Vector3F(0, 1, 0), IsEnabled = false, }; _waterNode.PlanarReflection = planarReflectionNode; _waterNode.Children = new SceneNodeCollection(1) { planarReflectionNode }; // To let rigid bodies swim, we add a Buoyancy force effect. This force effect // computes buoyancy of a flat water surface. Simulation.ForceEffects.Add(new Buoyancy { Surface = new Plane(new Vector3F(0, 1, 0), _waterNode.PoseWorld.Position.Y), Density = 1500, AngularDrag = 0.3f, LinearDrag = 3, }); }
//-------------------------------------------------------------- #region Methods //-------------------------------------------------------------- protected override void OnLoad() { // Get services. _inputService = _services.GetInstance <IInputService>(); _graphicsService = _services.GetInstance <IGraphicsService>(); _scene = _services.GetInstance <IScene>(); var content = _services.GetInstance <ContentManager>(); var gameObjectService = _services.GetInstance <IGameObjectService>(); // Get camera game object. _cameraObject = (CameraObject)gameObjectService.Objects["Camera"]; // Create SkyNodes. InitializeSky(content); // Create LightNodes InitializeLights(); // Optionally, the sky is captured into a cube map and the cube map is added // to the scene instead of all the sky nodes. if (_cacheSky) { // We use a SceneCaptureNode to create the cube map. // The cube map uses RGBM encoding to store HDR values. var renderToTexture = new RenderToTexture { Texture = new RenderTargetCube( _graphicsService.GraphicsDevice, #if XBOX 512, #else 1024, #endif true, SurfaceFormat.Color, DepthFormat.None), }; var projection = new PerspectiveProjection(); projection.SetFieldOfView(ConstantsF.PiOver2, 1, 1, 10); _sceneCaptureNode = new SceneCaptureNode(renderToTexture) { // Note: The scene is captured at the origin (0, 0, 0). CameraNode = new CameraNode(new Camera(projection)), }; SkyboxNode = new SkyboxNode { Encoding = ColorEncoding.Rgbm, Texture = (TextureCube)renderToTexture.Texture, }; _scene.Children.Add(SkyboxNode); } // The Ephemeris class computes the positions of the sun and the moon as seen // from any place on the earth. _ephemeris = new Ephemeris { // Seattle, Washington //Latitude = 47, //Longitude = 122, //Altitude = 100 // Vienna //Latitude = 48, //Longitude = -16, //Altitude = 0 // Equator Latitude = 0, Longitude = 0, Altitude = 0 }; // Update the positions of sky objects and the lights. UpdateSky(); // Create cube map. if (_cacheSky) { UpdateCubeMap(TimeSpan.Zero); } // Add GUI controls to the Options window. var sampleFramework = _services.GetInstance <SampleFramework>(); var optionsPanel = sampleFramework.AddOptions("Game Objects"); var panel = SampleHelper.AddGroupBox(optionsPanel, "DynamicSkyObject"); SampleHelper.AddSlider( panel, "Time", "F2", 0, 24, (float)Time.TimeOfDay.TotalHours, value => { var time = Time; time = time.Subtract(time.TimeOfDay).Add(TimeSpan.FromHours(value)); Time = time; }); SampleHelper.AddCheckBox( panel, "Enable ambient light", EnableAmbientLight, isChecked => EnableAmbientLight = isChecked); SampleHelper.AddSlider( panel, "Fog sample angle", "F2", 0, ConstantsF.PiOver2, FogSampleAngle, value => FogSampleAngle = value); SampleHelper.AddSlider( panel, "Fog saturation", "F2", 0, 1, FogSaturation, value => FogSaturation = value); //SampleHelper.AddSlider( // panel, // "Fog scattering symmetry R", // "F2", // 0, // 1, // FogScatteringSymmetry.X, // value => FogScatteringSymmetry = new Vector3F(value, FogScatteringSymmetry.Y, FogScatteringSymmetry.Z)); //SampleHelper.AddSlider( // panel, // "Fog scattering symmetry G", // "F2", // 0, // 1, // FogScatteringSymmetry.Y, // value => FogScatteringSymmetry = new Vector3F(FogScatteringSymmetry.X, value, FogScatteringSymmetry.Z)); //SampleHelper.AddSlider( // panel, // "Fog scattering symmetry B", // "F2", // 0, // 1, // FogScatteringSymmetry.Z, // value => FogScatteringSymmetry = new Vector3F(FogScatteringSymmetry.X, FogScatteringSymmetry.Y, value)); }
/// <summary> /// Renders the environment maps for the image-based lights. /// </summary> /// <remarks> /// This method uses the current DeferredGraphicsScreen to render new environment maps at /// runtime. The DeferredGraphicsScreen has a SceneCaptureRenderer which we can use to /// capture environment maps of the current scene. /// To capture new environment maps the flag _updateEnvironmentMaps must be set to true. /// When this flag is set, SceneCaptureNodes are added to the scene. When the graphics /// screen calls the SceneCaptureRenderer the next time, the new environment maps will be /// captured. /// The flag _updateEnvironmentMaps remains true until the new environment maps are available. /// This method checks the SceneCaptureNode.LastFrame property to check if new environment maps /// have been computed. Usually, the environment maps will be available in the next frame. /// (However, the XNA Game class can skip graphics rendering if the game is running slowly. /// Then we would have to wait more than 1 frame.) /// When environment maps are being rendered, the image-based lights are disabled to capture /// only the scene with ambient and directional lights. Dynamic objects are also disabled /// to capture only the static scene. /// </remarks> private void UpdateEnvironmentMaps() { if (!_updateEnvironmentMaps) { return; } // One-time initializations: if (_sceneCaptureNodes[0] == null) { // Create cube maps and scene capture nodes. // (Note: A cube map size of 256 is enough for surfaces with a specular power // in the range [0, 200000].) for (int i = 0; i < _sceneCaptureNodes.Length; i++) { var renderTargetCube = new RenderTargetCube( GraphicsService.GraphicsDevice, 256, true, SurfaceFormat.Color, DepthFormat.None); var renderToTexture = new RenderToTexture { Texture = renderTargetCube }; var projection = new PerspectiveProjection(); projection.SetFieldOfView(ConstantsF.PiOver2, 1, 1, 100); _sceneCaptureNodes[i] = new SceneCaptureNode(renderToTexture) { CameraNode = new CameraNode(new Camera(projection)) { PoseWorld = _lightNodes[i].PoseWorld, }, }; _imageBasedLights[i].Texture = renderTargetCube; } // We use a ColorEncoder to encode a HDR image in a normal Color texture. _colorEncoder = new ColorEncoder(GraphicsService) { SourceEncoding = ColorEncoding.Rgb, TargetEncoding = ColorEncoding.Rgbm, }; // The SceneCaptureRenderer has a render callback which defines what is rendered // into the scene capture render targets. _graphicsScreen.SceneCaptureRenderer.RenderCallback = context => { var graphicsDevice = GraphicsService.GraphicsDevice; var renderTargetPool = GraphicsService.RenderTargetPool; // Get scene nodes which are visible by the current camera. CustomSceneQuery sceneQuery = context.Scene.Query <CustomSceneQuery>(context.CameraNode, context); // The final image has to be rendered into this render target. var ldrTarget = context.RenderTarget; // Use an intermediate HDR render target with the same resolution as the final target. var format = new RenderTargetFormat(ldrTarget) { SurfaceFormat = SurfaceFormat.HdrBlendable, DepthStencilFormat = DepthFormat.Depth24Stencil8 }; var hdrTarget = renderTargetPool.Obtain2D(format); graphicsDevice.SetRenderTarget(hdrTarget); context.RenderTarget = hdrTarget; // Render scene (without post-processing, without lens flares, no debug rendering, no reticle). _graphicsScreen.RenderScene(sceneQuery, context, false, false, false, false); // Convert the HDR image to RGBM image. context.SourceTexture = hdrTarget; context.RenderTarget = ldrTarget; _colorEncoder.Process(context); context.SourceTexture = null; // Clean up. renderTargetPool.Recycle(hdrTarget); context.RenderTarget = ldrTarget; }; } if (_sceneCaptureNodes[0].Parent == null) { // Add the scene capture nodes to the scene. for (int i = 0; i < _sceneCaptureNodes.Length; i++) { _graphicsScreen.Scene.Children.Add(_sceneCaptureNodes[i]); } // Remember the old time stamp of the nodes. _oldEnvironmentMapTimeStamp = _sceneCaptureNodes[0].LastFrame; // Disable all lights except ambient and directional lights. // We do not capture the image-based lights or any other lights (e.g. point lights) // in the cube map. foreach (var lightNode in _graphicsScreen.Scene.GetDescendants().OfType <LightNode>()) { lightNode.IsEnabled = (lightNode.Light is AmbientLight) || (lightNode.Light is DirectionalLight); } // Disable dynamic objects. foreach (var node in _graphicsScreen.Scene.GetDescendants()) { if (node is MeshNode || node is LodGroupNode) { if (!node.IsStatic) { node.IsEnabled = false; } } } } else { // The scene capture nodes are part of the scene. Check if they have been // updated. if (_sceneCaptureNodes[0].LastFrame != _oldEnvironmentMapTimeStamp) { // We have new environment maps. Restore the normal scene. for (int i = 0; i < _sceneCaptureNodes.Length; i++) { _graphicsScreen.Scene.Children.Remove(_sceneCaptureNodes[i]); } _updateEnvironmentMaps = false; foreach (var lightNode in _graphicsScreen.Scene.GetDescendants().OfType <LightNode>()) { lightNode.IsEnabled = true; } foreach (var node in _graphicsScreen.Scene.GetDescendants()) { if (node is MeshNode || node is LodGroupNode) { if (!node.IsStatic) { node.IsEnabled = true; } } } } } }
public WaterSample(Microsoft.Xna.Framework.Game game) : base(game) { SampleFramework.IsMouseVisible = false; _graphicsScreen = new DeferredGraphicsScreen(Services); _graphicsScreen.DrawReticle = true; GraphicsService.Screens.Insert(0, _graphicsScreen); GameObjectService.Objects.Add(new DeferredGraphicsOptionsObject(Services)); Services.Register(typeof(DebugRenderer), null, _graphicsScreen.DebugRenderer); Services.Register(typeof(IScene), null, _graphicsScreen.Scene); // Add gravity and damping to the physics Simulation. Simulation.ForceEffects.Add(new Gravity()); Simulation.ForceEffects.Add(new Damping()); // Add a custom game object which controls the camera. var cameraGameObject = new CameraObject(Services); GameObjectService.Objects.Add(cameraGameObject); _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode; // More standard objects. GameObjectService.Objects.Add(new GrabObject(Services)); GameObjectService.Objects.Add(new ObjectCreatorObject(Services)); //GameObjectService.Objects.Add(new StaticSkyObject(Services)); var dynamicSkyObject = new DynamicSkyObject(Services, true, false, true); GameObjectService.Objects.Add(dynamicSkyObject); // Add a ground plane with some detail to see the water refractions. Simulation.RigidBodies.Add(new RigidBody(new PlaneShape(new Vector3(0, 1, 0), 0))); GameObjectService.Objects.Add(new StaticObject(Services, "Gravel/Gravel", 1, new Pose(new Vector3(0, 0.001f, 0)))); GameObjectService.Objects.Add(new DudeObject(Services)); GameObjectService.Objects.Add(new DynamicObject(Services, 1)); GameObjectService.Objects.Add(new DynamicObject(Services, 2)); GameObjectService.Objects.Add(new DynamicObject(Services, 5)); GameObjectService.Objects.Add(new DynamicObject(Services, 6)); GameObjectService.Objects.Add(new DynamicObject(Services, 7)); GameObjectService.Objects.Add(new FogObject(Services) { AttachToCamera = true }); // The LavaBalls class controls all lava ball instances. var lavaBalls = new LavaBallsObject(Services); GameObjectService.Objects.Add(lavaBalls); // Add a few palm trees. var random = new Random(12345); for (int i = 0; i < 10; i++) { Vector3 position = new Vector3(random.NextFloat(-3, -8), 0, random.NextFloat(0, -5)); Matrix orientation = Matrix.CreateRotationY(random.NextFloat(0, ConstantsF.TwoPi)); float scale = random.NextFloat(0.5f, 1.2f); GameObjectService.Objects.Add(new StaticObject(Services, "PalmTree/palm_tree", scale, new Pose(position, orientation))); } // Define the appearance of the water. var water = new Water { SpecularColor = new Vector3(10f), // Small water ripples/waves are created using scrolling normal maps. NormalMap0 = ContentManager.Load <Texture2D>("Water/Wave0"), NormalMap1 = ContentManager.Load <Texture2D>("Water/Wave1"), NormalMap0Scale = 1.8f, NormalMap1Scale = 2.2f, NormalMap0Velocity = new Vector3(-0.02f, 0, 0.03f), NormalMap1Velocity = new Vector3(0.02f, 0, -0.03f), NormalMap0Strength = 0.5f, NormalMap1Strength = 0.5f, ReflectionDistortion = 0.2f, ReflectionColor = new Vector3(0.7f), RefractionDistortion = 0.05f, }; // Create a box-shaped body of water. // We use a TransformedShape containing a BoxShape because the top of the // water body must be at height 0. var shape = new TransformedShape(new GeometricObject( new BoxShape(10, 1, 20), new Pose(new Vector3(0, -0.5f, 0)))); _waterNode0 = new WaterNode(water, shape) { PoseWorld = new Pose(new Vector3(-1, 0.5f, 0), Matrix.CreateRotationY(0.1f)), SkyboxReflection = _graphicsScreen.Scene.GetDescendants().OfType <SkyboxNode>().First(), DepthBufferWriteEnable = true, }; _graphicsScreen.Scene.Children.Add(_waterNode0); // Optional: Create a WaterFlow to move the water using a flow texture. _waterFlow0 = new WaterFlow { FlowMapSpeed = 0.5f, FlowMap = GenerateFlowMap(), CycleDuration = 3f, NoiseMapStrength = 0.1f, NoiseMapScale = 0.5f, }; _waterNode0.Flow = _waterFlow0; // Optional: Use a planar reflection instead of the skybox reflection. // We add a PlanarReflectionNode as a child of the WaterNode. var renderToTexture = new RenderToTexture { Texture = new RenderTarget2D(GraphicsService.GraphicsDevice, 512, 512, false, SurfaceFormat.HdrBlendable, DepthFormat.None), }; var planarReflectionNode = new PlanarReflectionNode(renderToTexture) { // Same shape as WaterNode. Shape = _waterNode0.Shape, // Reflection plane is horizontal. NormalLocal = new Vector3(0, 1, 0), }; _waterNode0.PlanarReflection = planarReflectionNode; _waterNode0.Children = new SceneNodeCollection(1) { planarReflectionNode }; // Create a short river with an inclined water surface. // Using a WaterFlow with a SurfaceSlopeSpeed, the water automatically flows // down the inclined surface. _waterNode1 = new WaterNode(water, GetSpiralShape()) { PoseWorld = new Pose(new Vector3(10, 1.5f, 0), Matrix.CreateRotationY(0.1f)), EnableUnderwaterEffect = false, SkyboxReflection = _graphicsScreen.Scene.GetDescendants().OfType <SkyboxNode>().First(), Flow = new WaterFlow { SurfaceSlopeSpeed = 0.5f, CycleDuration = 2f, NoiseMapStrength = 0.1f, NoiseMapScale = 1, } }; _graphicsScreen.Scene.Children.Add(_waterNode1); }
private void Init(bool forceRender) { if (!this.m_Init || forceRender) { if (this.m_Actor == null) { this.m_Actor = SceneUtils.FindComponentInThisOrParents <Actor>(base.gameObject); if (this.m_Actor == null) { Debug.LogError(string.Format("{0} Ghost card effect failed to find Actor!", base.transform.root.name)); base.enabled = false; return; } } this.m_CardMesh = this.m_Actor.m_cardMesh; this.m_CardFrontIdx = this.m_Actor.m_cardFrontMatIdx; this.m_PremiumRibbonIdx = this.m_Actor.m_premiumRibbon; this.m_PortraitMesh = this.m_Actor.m_portraitMesh; this.m_PortraitFrameIdx = this.m_Actor.m_portraitFrameMatIdx; this.m_NameMesh = this.m_Actor.m_nameBannerMesh; this.m_DescriptionMesh = this.m_Actor.m_descriptionMesh; this.m_DescriptionTrimMesh = this.m_Actor.m_descriptionTrimMesh; this.m_RarityFrameMesh = this.m_Actor.m_rarityFrameMesh; if (this.m_Actor.m_attackObject != null) { Renderer component = this.m_Actor.m_attackObject.GetComponent <Renderer>(); if (component != null) { this.m_AttackMesh = component.gameObject; } if (this.m_AttackMesh == null) { foreach (Renderer renderer2 in this.m_Actor.m_attackObject.GetComponentsInChildren <Renderer>()) { if (renderer2.GetComponent <UberText>() == null) { this.m_AttackMesh = renderer2.gameObject; } } } } if (this.m_Actor.m_healthObject != null) { Renderer renderer3 = this.m_Actor.m_healthObject.GetComponent <Renderer>(); if (renderer3 != null) { this.m_HealthMesh = renderer3.gameObject; } if (this.m_HealthMesh == null) { foreach (Renderer renderer4 in this.m_Actor.m_healthObject.GetComponentsInChildren <Renderer>()) { if (renderer4.GetComponent <UberText>() == null) { this.m_HealthMesh = renderer4.gameObject; } } } } this.m_ManaCostMesh = this.m_Actor.m_manaObject; this.m_RacePlateMesh = this.m_Actor.m_racePlateObject; this.m_EliteMesh = this.m_Actor.m_eliteObject; this.StoreOrgMaterials(); this.m_R2T_BaseCard = base.GetComponent <RenderToTexture>(); this.m_R2T_BaseCard.m_ObjectToRender = this.m_Actor.GetRootObject(); if ((this.m_R2T_BaseCard.m_Material != null) && this.m_R2T_BaseCard.m_Material.HasProperty("_Seed")) { this.m_R2T_BaseCard.m_Material.SetFloat("_Seed", UnityEngine.Random.Range((float)0f, (float)1f)); } this.m_Init = true; } }
//-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="SceneCaptureNode" /> class. /// </summary> /// <param name="renderToTexture">The render texture target.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="renderToTexture"/> is <see langword="null"/>. /// </exception> public SceneCaptureNode(RenderToTexture renderToTexture) : base(renderToTexture) { }
/// <summary> /// Initializes a new instance of the <see cref="SceneCaptureNode" /> class. /// </summary> /// <param name="renderToTexture">The render texture target.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="renderToTexture"/> is <see langword="null"/>. /// </exception> public SceneCaptureNode(RenderToTexture renderToTexture) : base(renderToTexture) { }
public SceneRenderTargetListener(RenderToTexture owner) { this.owner = owner; }
public SceneCaptureCubeSample(Microsoft.Xna.Framework.Game game) : base(game) { SampleFramework.IsMouseVisible = false; // Create a graphics screen. This screen has to call the SceneCaptureRenderer // to handle the SceneCaptureNodes! _graphicsScreen = new DeferredGraphicsScreen(Services) { DrawReticle = true }; GraphicsService.Screens.Insert(0, _graphicsScreen); GameObjectService.Objects.Add(new DeferredGraphicsOptionsObject(Services)); Services.Register(typeof(DebugRenderer), null, _graphicsScreen.DebugRenderer); Services.Register(typeof(IScene), null, _graphicsScreen.Scene); // Add gravity and damping to the physics Simulation. Simulation.ForceEffects.Add(new Gravity()); Simulation.ForceEffects.Add(new Damping()); // Add a custom game object which controls the camera. var cameraGameObject = new CameraObject(Services); GameObjectService.Objects.Add(cameraGameObject); _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode; // More standard objects. GameObjectService.Objects.Add(new GrabObject(Services)); GameObjectService.Objects.Add(new ObjectCreatorObject(Services)); //GameObjectService.Objects.Add(new StaticSkyObject(Services)); GameObjectService.Objects.Add(new DynamicSkyObject(Services, true, false, true)); GameObjectService.Objects.Add(new GroundObject(Services)); GameObjectService.Objects.Add(new DudeObject(Services)); GameObjectService.Objects.Add(new DynamicObject(Services, 1)); GameObjectService.Objects.Add(new DynamicObject(Services, 2)); GameObjectService.Objects.Add(new DynamicObject(Services, 5)); GameObjectService.Objects.Add(new DynamicObject(Services, 6)); GameObjectService.Objects.Add(new DynamicObject(Services, 7)); GameObjectService.Objects.Add(new FogObject(Services) { AttachToCamera = true }); GameObjectService.Objects.Add(new LavaBallsObject(Services)); // Add a few palm trees. Random random = new Random(12345); for (int i = 0; i < 10; i++) { Vector3F position = new Vector3F(random.NextFloat(-3, -8), 0, random.NextFloat(0, -5)); Matrix33F orientation = Matrix33F.CreateRotationY(random.NextFloat(0, ConstantsF.TwoPi)); float scale = random.NextFloat(0.5f, 1.2f); GameObjectService.Objects.Add(new StaticObject(Services, "PalmTree/palm_tree", scale, new Pose(position, orientation))); } // Load the "Bubble" mesh and place it at a fixed position in the scene. var modelNode = ContentManager.Load <ModelNode>("Bubble/Bubble"); var meshNode = modelNode.GetDescendants().OfType <MeshNode>().First().Clone(); meshNode.PoseWorld = new Pose(new Vector3F(0, 1, 0)); _graphicsScreen.Scene.Children.Add(meshNode); // Surface of the mesh should reflect the scene in real-time. Reflections are // created using environment mapping: The scene is rendered into a cube map, // which is then applied to the mesh. // To render the scene into a cube map, we need to define a CameraNode and a // SceneCaptureNode: The CameraNode defines the point from where the scene is // captured. The SceneCaptureNode defines where and in which format the captured // image is needed. // Attach a camera to the center of the mesh. var projection = new PerspectiveProjection(); projection.SetFieldOfView(ConstantsF.PiOver2, 1, 0.1f, 20); var captureCameraNode = new CameraNode(new Camera(projection)); meshNode.Children = new SceneNodeCollection { captureCameraNode }; // Attach a SceneCaptureNode with a cube map render target to the mesh. var renderToTexture = new RenderToTexture { Texture = new RenderTargetCube( GraphicsService.GraphicsDevice, 256, true, SurfaceFormat.Color, DepthFormat.None), }; var sceneCaptureNode = new SceneCaptureNode(renderToTexture) { Shape = meshNode.Shape, CameraNode = captureCameraNode, }; meshNode.Children.Add(sceneCaptureNode); // The bubble model uses a special effect and is rendered in the "AlphaBlend" // render pass. Let's modify the effect parameters to use the created cube map // as the reflection map of the bubble. var effectBinding = meshNode.Mesh.Materials[0]["AlphaBlend"]; effectBinding.Set("ReflectionStrength", 0.5f); effectBinding.Set("RefractionStrength", 0.0f); effectBinding.Set("FresnelBias", 1.0f); effectBinding.Set("BlendMode", 1.0f); effectBinding.Set("Alpha", 1.0f); effectBinding.Set("CustomEnvironmentMap", (TextureCube)renderToTexture.Texture); }