示例#1
0
        /// <summary>
        ///
        /// </summary>
        public override void CreateDisplayResources()
        {
            base.CreateDisplayResources();

            backbufferColor = new RenderTarget2D(device, D3D.Texture2D.FromSwapChain <D3D.Texture2D>(swapChain, 0));
            backbufferDepth = new DepthStencil2D(device, DepthFormat.D24S8, backbufferColor.Width, backbufferColor.Height, backbufferColor.SampleCount);
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="singleShadowMapSize"></param>
        /// <param name="splitCount"></param>
        public CascadedShadowMap(GraphicsDevice device, int cascadeSize, int cascadeCount)
        {
            this.device       = device;
            this.cascadeCount = cascadeCount;
            this.cascadeSize  = cascadeSize;

            if (cascadeCount < 1 || cascadeCount > MaxCascadeCount)
            {
                throw new ArgumentOutOfRangeException("cascadeCount must be within range 1.." + MaxCascadeCount.ToString());
            }

            if (cascadeSize < 64 || cascadeSize > MaxCascadeSize)
            {
                throw new ArgumentOutOfRangeException("cascadeSize must be within range 64.." + MaxCascadeSize.ToString());
            }

            if (!MathUtil.IsPowerOfTwo(cascadeSize))
            {
                Log.Warning("CascadedShadowMap : splitSize is not power of 2");
            }

            csmColor  = new RenderTarget2D(device, ColorFormat.R32F, cascadeSize * cascadeCount, cascadeSize);
            csmDepth  = new DepthStencil2D(device, DepthFormat.D24S8, cascadeSize * cascadeCount, cascadeSize);
            prtShadow = new RenderTarget2D(device, ColorFormat.Rgba8_sRGB, cascadeSize * cascadeCount, cascadeSize);
        }
示例#3
0
            /// <summary>
            /// Dispose contained fields.
            /// </summary>
            public void Dispose()
            {
                if (SwapTexture != null)
                {
                    SwapTexture.Dispose();
                    SwapTexture = null;
                }

                if (Textures != null)
                {
                    foreach (var texture in Textures)
                    {
                        texture.Dispose();
                    }

                    Textures = null;
                }

                if (RenderTargets != null)
                {
                    foreach (var renderTargetView in RenderTargets)
                    {
                        renderTargetView.Dispose();
                    }

                    RenderTargets = null;
                }

                if (DepthStencil2D != null)
                {
                    DepthStencil2D.Dispose();

                    DepthStencil2D = null;
                }
            }
示例#4
0
        /// <summary>
        ///
        /// </summary>
        void CreateShadowMaps()
        {
            SafeDispose(ref cascadedShadowMap);

            SafeDispose(ref spotColor);
            SafeDispose(ref spotDepth);

            cascadedShadowMap = new CascadedShadowMap(Game.GraphicsDevice, CSMCascadeSize, CSMCascadeCount);

            spotColor = new RenderTarget2D(Game.GraphicsDevice, ColorFormat.R32F, SpotShadowSize * 4, SpotShadowSize * 4);
            spotDepth = new DepthStencil2D(Game.GraphicsDevice, DepthFormat.D24S8, SpotShadowSize * 4, SpotShadowSize * 4);
        }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        void CreateShadowMaps()
        {
            SafeDispose(ref csmColor);
            SafeDispose(ref csmDepth);

            SafeDispose(ref spotColor);
            SafeDispose(ref spotDepth);

            csmColor = new RenderTarget2D(Game.GraphicsDevice, ColorFormat.R32F, Config.CSMSize * 4, Config.CSMSize);
            csmDepth = new DepthStencil2D(Game.GraphicsDevice, DepthFormat.D24S8, Config.CSMSize * 4, Config.CSMSize);

            spotColor = new RenderTarget2D(Game.GraphicsDevice, ColorFormat.R32F, Config.SpotShadowSize * 4, Config.SpotShadowSize * 4);
            spotDepth = new DepthStencil2D(Game.GraphicsDevice, DepthFormat.D24S8, Config.SpotShadowSize * 4, Config.SpotShadowSize * 4);
        }
示例#6
0
		public HdrFrame ( Game game, int width, int height )
		{
			HdrBuffer			=	new RenderTarget2D( game.GraphicsDevice, ColorFormat.Rgba16F,		width,	height,	false, false );
			LightAccumulator	=	new RenderTarget2D( game.GraphicsDevice, ColorFormat.Rgba16F,		width,	height,	false, true );
			SSSAccumulator		=	new RenderTarget2D( game.GraphicsDevice, ColorFormat.Rgba16F,		width,	height,	false, true );
			DepthBuffer			=	new DepthStencil2D( game.GraphicsDevice, DepthFormat.D24S8,			width,	height,	1 );
			DiffuseBuffer		=	new RenderTarget2D( game.GraphicsDevice, ColorFormat.Rgba8_sRGB,	width,	height,	false, false );
			SpecularBuffer 		=	new RenderTarget2D( game.GraphicsDevice, ColorFormat.Rgba8_sRGB,	width,	height,	false, false );
			NormalMapBuffer		=	new RenderTarget2D( game.GraphicsDevice, ColorFormat.Rgb10A2,		width,	height,	false, false );
			ScatteringBuffer	=	new RenderTarget2D( game.GraphicsDevice, ColorFormat.Rgba8_sRGB,	width,	height,	false, false );
			SSAOBuffer			=	new RenderTarget2D( game.GraphicsDevice, ColorFormat.Rgba8,			width,	height, false, false );

			Clear();
		}
示例#7
0
        /// <summary>
        /// Creates GBuffer
        /// </summary>
        void CreateGBuffer()
        {
            SafeDispose(ref depthBuffer);
            SafeDispose(ref diffuseBuffer);
            SafeDispose(ref specularBuffer);
            SafeDispose(ref normalMapBuffer);
            SafeDispose(ref lightAccumBuffer);

            var vp = Game.GraphicsDevice.DisplayBounds;

            depthBuffer      = new DepthStencil2D(Game.GraphicsDevice, DepthFormat.D24S8, vp.Width, vp.Height);
            diffuseBuffer    = new RenderTarget2D(Game.GraphicsDevice, ColorFormat.Rgba8, vp.Width, vp.Height);
            specularBuffer   = new RenderTarget2D(Game.GraphicsDevice, ColorFormat.Rgba8, vp.Width, vp.Height);
            normalMapBuffer  = new RenderTarget2D(Game.GraphicsDevice, ColorFormat.Rgb10A2, vp.Width, vp.Height);
            lightAccumBuffer = new RenderTarget2D(Game.GraphicsDevice, ColorFormat.Rgba16F, vp.Width, vp.Height, true);
        }
示例#8
0
        /// <summary>
        /// Load stuff here
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            LoadContent();

            rt   = new RenderTarget2D(GraphicsDevice, ColorFormat.Rgba8, 256, 256, 1);
            rtMS = new RenderTarget2D(GraphicsDevice, ColorFormat.Rgba8, 256, 256, 4);
            dsMS = new DepthStencil2D(GraphicsDevice, DepthFormat.D24S8, 256, 256, 4);

            dynamicTexture = new Texture2D(GraphicsDevice, 64, 64, ColorFormat.Rgba8, false);

            Reloading += (s, e) => LoadContent();

            InputDevice.KeyDown += InputDevice_KeyDown;
        }
示例#9
0
        public HdrFrame(Game game, int width, int height)
        {
            int fbbw = FeedbackBufferWidth;
            int fbbh = FeedbackBufferHeight;

            FeedbackBufferRB = new FeedbackBuffer(game.GraphicsDevice, fbbw, fbbh);
            HdrBuffer        = new RenderTarget2D(game.GraphicsDevice, ColorFormat.Rgba16F, width, height, false, false);
            LightAccumulator = new RenderTarget2D(game.GraphicsDevice, ColorFormat.Rgba16F, width, height, false, true);
            DepthBuffer      = new DepthStencil2D(game.GraphicsDevice, DepthFormat.D24S8, width, height, 1);
            GBuffer0         = new RenderTarget2D(game.GraphicsDevice, ColorFormat.Rgba8_sRGB, width, height, false, false);
            GBuffer1         = new RenderTarget2D(game.GraphicsDevice, ColorFormat.Rgba8, width, height, false, false);
            SSAOBuffer       = new RenderTarget2D(game.GraphicsDevice, ColorFormat.Rgba8, width, height, false, false);
            FeedbackBuffer   = new RenderTarget2D(game.GraphicsDevice, ColorFormat.Rgb10A2, width, height, false, false);

            Clear();
        }
示例#10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="ds"></param>
        /// <param name="target"></param>
        public void DrawInRenderTarget(GameTime gameTime, DepthStencil2D ds, RenderTarget2D target, Viewport viewport)
        {
            UpdateProjectionMatrix(viewport.Width, viewport.Height);

            //Game.GraphicsDevice.ResetStates();
            Game.GraphicsDevice.SetTargets(ds, target);
            Game.GraphicsDevice.SetViewport(viewport.X, viewport.Y, viewport.Width, viewport.Height);

            vport = viewport;

            DrawInternal(gameTime);
            //Game.GraphicsDevice.RestoreBackbuffer();

            var sb = Game.GetService <SpriteBatch>();

            sb.Begin(SpriteBlend.ClearAlpha, SamplerState.LinearClamp, DepthStencilState.None);
            sb.Draw(sb.TextureWhite, new Rectangle(0, 0, target.Width, target.Height), new Color(1.0f, 1.0f, 1.0f, 1.0f));
            sb.End();
        }
示例#11
0
        /// <summary>
        ///
        /// </summary>
        public override void CreateDisplayResources()
        {
            base.CreateDisplayResources();

            backbufferColor = new RenderTarget2D(device, swapChain.GetBackBuffer <D3D.Texture2D>(0));

            int ms = backbufferColor.SampleCount;
            int w  = backbufferColor.Width;
            int h  = backbufferColor.Height;

            backbufferColor1 = new RenderTarget2D(device, ColorFormat.Rgba8, w, h, ms);
            backbufferDepth1 = new DepthStencil2D(device, DepthFormat.D24S8, w, h, ms);
            backbufferColor2 = new RenderTarget2D(device, ColorFormat.Rgba8, w, h, ms);
            backbufferDepth2 = new DepthStencil2D(device, DepthFormat.D24S8, w, h, ms);

            if (ms > 1)
            {
                backbufferColor1Resolved = new RenderTarget2D(device, ColorFormat.Rgba8, w, h);
                backbufferColor2Resolved = new RenderTarget2D(device, ColorFormat.Rgba8, w, h);
            }
        }
示例#12
0
		/// <summary>
		/// Performs good-old StretchRect to destination buffer with blending.
		/// </summary>
		/// <param name="dst"></param>
		/// <param name="src"></param>
		/// <param name="filter"></param>
		/// <param name="rect"></param>
		public void RenderSsao ( RenderTargetSurface ssaoDst, StereoEye stereoEye, Camera camera, DepthStencil2D depthSource, RenderTarget2D normalsSource )
		{
			SetDefaultRenderStates();

			using( new PixEvent("SSAO") ) {

				var ssaoParams = new SsaoParams();

				ssaoParams.View					=	camera.GetViewMatrix( stereoEye );	
				ssaoParams.Projection			=	camera.GetProjectionMatrix( stereoEye );	
				ssaoParams.InverseProjection	=	Matrix.Invert( ssaoParams.Projection );	
				paramsCB.SetData( ssaoParams );


				SetViewport( ssaoDst );
				device.SetTargets( null, ssaoDst );

				device.PipelineState			=	factory[ (int)(ShaderFlags.SSAO) ];

				device.VertexShaderResources[0] =	depthSource;
				device.PixelShaderResources[0]	=	depthSource;
				device.PixelShaderSamplers[0]	=	SamplerState.PointClamp;

				device.PixelShaderConstants[0]	=	paramsCB;
				device.PixelShaderConstants[1]	=	randomDirsCB;

				device.Draw( 3, 0 );
			}
			device.ResetStates();
		}
示例#13
0
		public void Free ( DepthStencil2D target )
		{
			throw new NotImplementedException();
		}
示例#14
0
		/// <summary>
		/// Load stuff here
		/// </summary>
		protected override void Initialize ()
		{
			base.Initialize();

			LoadContent();

			rt			=	new RenderTarget2D( GraphicsDevice, ColorFormat.Rgba8, 256,256, 1 );
			rtMS		=	new RenderTarget2D( GraphicsDevice, ColorFormat.Rgba8, 256,256, 4 );
			dsMS		=	new DepthStencil2D( GraphicsDevice, DepthFormat.D24S8, 256,256, 4 );

			dynamicTexture	=	new Texture2D( GraphicsDevice, 64,64, ColorFormat.Rgba8, false );

			Reloading += (s,e) => LoadContent();

			InputDevice.KeyDown += InputDevice_KeyDown;
		}
		/// <summary>
		/// 
		/// </summary>
		public override void CreateDisplayResources ()
		{
			base.CreateDisplayResources();

			backbufferColor = new RenderTarget2D(device, swapChain.GetBackBuffer<D3D.Texture2D>(0));

			int ms	= backbufferColor.SampleCount;
			int w	= backbufferColor.Width;
			int h	= backbufferColor.Height;

			backbufferColor1	=	new RenderTarget2D( device, ColorFormat.Rgba8, w, h, ms );
			backbufferDepth1	=	new DepthStencil2D( device, DepthFormat.D24S8, w, h, ms );
			backbufferColor2	=	new RenderTarget2D( device, ColorFormat.Rgba8, w, h, ms );
			backbufferDepth2	=	new DepthStencil2D( device, DepthFormat.D24S8, w, h, ms );

			if (ms>1) {
				backbufferColor1Resolved	=	new RenderTarget2D( device, ColorFormat.Rgba8, w, h );
				backbufferColor2Resolved	=	new RenderTarget2D( device, ColorFormat.Rgba8, w, h );
			}
		}
示例#16
0
		/// <summary>
		/// Analogue of SetTargets( depthStencil.Surface, renderTarget.Surface )
		/// </summary>
		/// <param name="depthStencil"></param>
		/// <param name="renderTarget"></param>
		public void SetTargets ( DepthStencil2D depthStencil, RenderTarget2D renderTarget )
		{
			SetTargets( depthStencil==null?null:depthStencil.Surface, renderTarget==null?null:renderTarget.Surface );
		}
        /// <summary>
        /// 
        /// </summary>
        public override void CreateDisplayResources()
        {
            base.CreateDisplayResources();

            backbufferColor = new RenderTarget2D(device, swapChain.GetBackBuffer<D3D.Texture2D>(0));

            // Configure Stereo settings.
            OVR.Sizei recommenedTex0Size = hmd.GetFovTextureSize(OVR.EyeType.Left, hmd.DefaultEyeFov[0], 1.0f);
            OVR.Sizei recommenedTex1Size = hmd.GetFovTextureSize(OVR.EyeType.Right, hmd.DefaultEyeFov[1], 1.0f);

            int ms	= backbufferColor.SampleCount;

            backbufferColor1	=	new RenderTarget2D( device, ColorFormat.Rgba8, recommenedTex0Size.Width, recommenedTex0Size.Height, ms );
            backbufferDepth1	=	new DepthStencil2D( device, DepthFormat.D24S8, recommenedTex0Size.Width, recommenedTex0Size.Height, ms );
            backbufferColor2	=	new RenderTarget2D( device, ColorFormat.Rgba8, recommenedTex1Size.Width, recommenedTex1Size.Height, ms );
            backbufferDepth2	=	new DepthStencil2D( device, DepthFormat.D24S8, recommenedTex1Size.Width, recommenedTex1Size.Height, ms );

            if (ms>1) {
                backbufferColor1Resolved	=	new RenderTarget2D( device, ColorFormat.Rgba8, recommenedTex0Size.Width, recommenedTex0Size.Height );
                backbufferColor2Resolved	=	new RenderTarget2D( device, ColorFormat.Rgba8, recommenedTex1Size.Width, recommenedTex1Size.Height );
            }

            OVR.FovPort[] eyeFov = new OVR.FovPort[]
            {
                hmd.DefaultEyeFov[0],
                hmd.DefaultEyeFov[1]
            };

            OVR.Sizei size1 = new OVR.Sizei(recommenedTex0Size.Width, recommenedTex0Size.Height);
            OVR.Sizei size2 = new OVR.Sizei(recommenedTex1Size.Width, recommenedTex1Size.Height);

            OVR.Recti[] eyeRenderViewport	= new OVR.Recti[2];
            eyeRenderViewport[0].Position	= new OVR.Vector2i(0, 0);
            eyeRenderViewport[0].Size		= size1;
            eyeRenderViewport[1].Position	= new OVR.Vector2i(0, 0); ;
            eyeRenderViewport[1].Size		= size2;

            // Query D3D texture data.
            eyeTexture = new OVR.D3D11.D3D11TextureData[2];
            eyeTexture[0].Header.API			= OVR.RenderAPIType.D3D11;
            eyeTexture[0].Header.TextureSize	= size1;
            eyeTexture[0].Header.RenderViewport = eyeRenderViewport[0];

            // Right eye uses the same texture, but different rendering viewport.
            eyeTexture[1] = eyeTexture[0];
            eyeTexture[1].Header.RenderViewport = eyeRenderViewport[1];

            if (ms > 1) {
                eyeTexture[0].Texture				= backbufferColor1Resolved.Surface.Resource.NativePointer;
                eyeTexture[0].ShaderResourceView	= backbufferColor1Resolved.SRV.NativePointer;

                eyeTexture[1].Texture				= backbufferColor2Resolved.Surface.Resource.NativePointer;
                eyeTexture[1].ShaderResourceView	= backbufferColor2Resolved.SRV.NativePointer;
            } else {
                eyeTexture[0].Texture				= backbufferColor1.Surface.Resource.NativePointer;
                eyeTexture[0].ShaderResourceView	= backbufferColor1.SRV.NativePointer;

                eyeTexture[1].Texture				= backbufferColor2.Surface.Resource.NativePointer;
                eyeTexture[1].ShaderResourceView	= backbufferColor2.SRV.NativePointer;
            }

            // Configure d3d11.
            OVR.D3D11.D3D11ConfigData d3d11cfg	= new OVR.D3D11.D3D11ConfigData();
            d3d11cfg.Header.API					= OVR.RenderAPIType.D3D11;
            d3d11cfg.Header.BackBufferSize		= new OVR.Sizei(hmd.Resolution.Width, hmd.Resolution.Height);
            d3d11cfg.Header.Multisample			= 1;
            d3d11cfg.Device						= d3dDevice.NativePointer;
            d3d11cfg.DeviceContext				= d3dDevice.ImmediateContext.NativePointer;
            d3d11cfg.BackBufferRenderTargetView = backbufferColor.Surface.RTV.NativePointer;
            d3d11cfg.SwapChain					= swapChain.NativePointer;

            eyeRenderDesc = hmd.ConfigureRendering(d3d11cfg, OVR.DistortionCaps.ovrDistortionCap_Chromatic | OVR.DistortionCaps.ovrDistortionCap_Vignette | OVR.DistortionCaps.ovrDistortionCap_TimeWarp | OVR.DistortionCaps.ovrDistortionCap_Overdrive, eyeFov);
            if (eyeRenderDesc == null) {
                throw new ArgumentNullException("eyeRenderDesc", "Achtung eyeRenderDesc = null");
            }

            // Specify which head tracking capabilities to enable.
            hmd.SetEnabledCaps(OVR.HmdCaps.LowPersistence /*| OVR.HmdCaps.DynamicPrediction*/);

            // Start the sensor which informs of the Rift's pose and motion
            hmd.ConfigureTracking(OVR.TrackingCaps.ovrTrackingCap_Orientation | OVR.TrackingCaps.ovrTrackingCap_MagYawCorrection | OVR.TrackingCaps.ovrTrackingCap_Position, OVR.TrackingCaps.None);
        }
示例#18
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="gameTime"></param>
		/// <param name="stereoEye"></param>
		/// <param name="viewport"></param>
		/// <param name="targetSurface"></param>
		protected void RenderGIS ( GameTime gameTime, StereoEye stereoEye, Viewport viewport, RenderTargetSurface targetSurface ) 
		{
			if (GisLayers.Any()) {

				if (GlobeDepthStencil == null) {
					GlobeDepthStencil = new DepthStencil2D(Game.GraphicsDevice, DepthFormat.D24S8, targetSurface.Width, targetSurface.Height, targetSurface.SampleCount);
				}
				else if (GlobeDepthStencil.Width != targetSurface.Width || GlobeDepthStencil.Height != targetSurface.Height) {
					
					GlobeDepthStencil.Dispose();
					GlobeDepthStencil = new DepthStencil2D(Game.GraphicsDevice, DepthFormat.D24S8, targetSurface.Width, targetSurface.Height, targetSurface.SampleCount);
				}

				rs.Device.Clear(GlobeDepthStencil.Surface);

				Game.GraphicsDevice.SetTargets(GlobeDepthStencil.Surface, targetSurface);
				
				GlobeCamera.Viewport = viewport;
				GlobeCamera.Update(gameTime);

				rs.Gis.Camera = GlobeCamera;
				rs.Gis.Draw(gameTime, stereoEye, GisLayers);
			}
		}
示例#19
0
 public void DrawInRenderTarget(GameTime gameTime, DepthStencil2D ds, RenderTarget2D target, Viewport viewport)
 {
     GlobeLayer.DrawInRenderTarget(gameTime, ds, target, viewport);
 }
示例#20
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="singleShadowMapSize"></param>
		/// <param name="splitCount"></param>
		public CascadedShadowMap ( GraphicsDevice device, int cascadeSize, int cascadeCount )
		{
			this.device			=	device;
			this.cascadeCount	=	cascadeCount;
			this.cascadeSize	=	cascadeSize;

			if (cascadeCount<1 || cascadeCount>MaxCascadeCount) {
				throw new ArgumentOutOfRangeException("cascadeCount must be within range 1.." + MaxCascadeCount.ToString());
			}

			if (cascadeSize<64 || cascadeSize > MaxCascadeSize) {
				throw new ArgumentOutOfRangeException("cascadeSize must be within range 64.." + MaxCascadeSize.ToString());
			}

			if (!MathUtil.IsPowerOfTwo( cascadeSize )) {
				Log.Warning("CascadedShadowMap : splitSize is not power of 2");
			}

			csmColor	=	new RenderTarget2D( device, ColorFormat.R32F,		cascadeSize * cascadeCount, cascadeSize );
			csmDepth	=	new DepthStencil2D( device, DepthFormat.D24S8,		cascadeSize * cascadeCount, cascadeSize );
			prtShadow	=	new RenderTarget2D( device, ColorFormat.Rgba8_sRGB,	cascadeSize * cascadeCount, cascadeSize );
		}
示例#21
0
        /// <summary>
        ///
        /// </summary>
        public override void CreateDisplayResources()
        {
            base.CreateDisplayResources();

            backbufferColor = new RenderTarget2D(device, swapChain.GetBackBuffer <D3D.Texture2D>(0));


            // Configure Stereo settings.
            OVR.Sizei recommenedTex0Size = hmd.GetFovTextureSize(OVR.EyeType.Left, hmd.DefaultEyeFov[0], 1.0f);
            OVR.Sizei recommenedTex1Size = hmd.GetFovTextureSize(OVR.EyeType.Right, hmd.DefaultEyeFov[1], 1.0f);

            int ms = backbufferColor.SampleCount;

            backbufferColor1 = new RenderTarget2D(device, ColorFormat.Rgba8, recommenedTex0Size.Width, recommenedTex0Size.Height, ms);
            backbufferDepth1 = new DepthStencil2D(device, DepthFormat.D24S8, recommenedTex0Size.Width, recommenedTex0Size.Height, ms);
            backbufferColor2 = new RenderTarget2D(device, ColorFormat.Rgba8, recommenedTex1Size.Width, recommenedTex1Size.Height, ms);
            backbufferDepth2 = new DepthStencil2D(device, DepthFormat.D24S8, recommenedTex1Size.Width, recommenedTex1Size.Height, ms);

            if (ms > 1)
            {
                backbufferColor1Resolved = new RenderTarget2D(device, ColorFormat.Rgba8, recommenedTex0Size.Width, recommenedTex0Size.Height);
                backbufferColor2Resolved = new RenderTarget2D(device, ColorFormat.Rgba8, recommenedTex1Size.Width, recommenedTex1Size.Height);
            }


            OVR.FovPort[] eyeFov = new OVR.FovPort[]
            {
                hmd.DefaultEyeFov[0],
                hmd.DefaultEyeFov[1]
            };

            OVR.Sizei size1 = new OVR.Sizei(recommenedTex0Size.Width, recommenedTex0Size.Height);
            OVR.Sizei size2 = new OVR.Sizei(recommenedTex1Size.Width, recommenedTex1Size.Height);

            OVR.Recti[] eyeRenderViewport = new OVR.Recti[2];
            eyeRenderViewport[0].Position = new OVR.Vector2i(0, 0);
            eyeRenderViewport[0].Size     = size1;
            eyeRenderViewport[1].Position = new OVR.Vector2i(0, 0);;
            eyeRenderViewport[1].Size     = size2;

            // Query D3D texture data.
            eyeTexture = new OVR.D3D11.D3D11TextureData[2];
            eyeTexture[0].Header.API            = OVR.RenderAPIType.D3D11;
            eyeTexture[0].Header.TextureSize    = size1;
            eyeTexture[0].Header.RenderViewport = eyeRenderViewport[0];


            // Right eye uses the same texture, but different rendering viewport.
            eyeTexture[1] = eyeTexture[0];
            eyeTexture[1].Header.RenderViewport = eyeRenderViewport[1];

            if (ms > 1)
            {
                eyeTexture[0].Texture            = backbufferColor1Resolved.Surface.Resource.NativePointer;
                eyeTexture[0].ShaderResourceView = backbufferColor1Resolved.SRV.NativePointer;

                eyeTexture[1].Texture            = backbufferColor2Resolved.Surface.Resource.NativePointer;
                eyeTexture[1].ShaderResourceView = backbufferColor2Resolved.SRV.NativePointer;
            }
            else
            {
                eyeTexture[0].Texture            = backbufferColor1.Surface.Resource.NativePointer;
                eyeTexture[0].ShaderResourceView = backbufferColor1.SRV.NativePointer;

                eyeTexture[1].Texture            = backbufferColor2.Surface.Resource.NativePointer;
                eyeTexture[1].ShaderResourceView = backbufferColor2.SRV.NativePointer;
            }

            // Configure d3d11.
            OVR.D3D11.D3D11ConfigData d3d11cfg = new OVR.D3D11.D3D11ConfigData();
            d3d11cfg.Header.API            = OVR.RenderAPIType.D3D11;
            d3d11cfg.Header.BackBufferSize = new OVR.Sizei(hmd.Resolution.Width, hmd.Resolution.Height);
            d3d11cfg.Header.Multisample    = 1;
            d3d11cfg.Device        = d3dDevice.NativePointer;
            d3d11cfg.DeviceContext = d3dDevice.ImmediateContext.NativePointer;
            d3d11cfg.BackBufferRenderTargetView = backbufferColor.Surface.RTV.NativePointer;
            d3d11cfg.SwapChain = swapChain.NativePointer;

            eyeRenderDesc = hmd.ConfigureRendering(d3d11cfg, OVR.DistortionCaps.ovrDistortionCap_Chromatic | OVR.DistortionCaps.ovrDistortionCap_Vignette | OVR.DistortionCaps.ovrDistortionCap_TimeWarp | OVR.DistortionCaps.ovrDistortionCap_Overdrive, eyeFov);
            if (eyeRenderDesc == null)
            {
                throw new ArgumentNullException("eyeRenderDesc", "Achtung eyeRenderDesc = null");
            }

            // Specify which head tracking capabilities to enable.
            hmd.SetEnabledCaps(OVR.HmdCaps.LowPersistence /*| OVR.HmdCaps.DynamicPrediction*/);

            // Start the sensor which informs of the Rift's pose and motion
            hmd.ConfigureTracking(OVR.TrackingCaps.ovrTrackingCap_Orientation | OVR.TrackingCaps.ovrTrackingCap_MagYawCorrection | OVR.TrackingCaps.ovrTrackingCap_Position, OVR.TrackingCaps.None);
        }
示例#22
0
        /// <summary>
        /// 
        /// </summary>
        public override void CreateDisplayResources()
        {
            base.CreateDisplayResources();

            backbufferColor	=	new RenderTarget2D( device, D3D.Texture2D.FromSwapChain<D3D.Texture2D>( swapChain, 0 ) );
            backbufferDepth	=	new DepthStencil2D( device, DepthFormat.D24S8, backbufferColor.Width, backbufferColor.Height, backbufferColor.SampleCount );
        }
示例#23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="view"></param>
        /// <param name="projection"></param>
        /// <param name="depthBuffer"></param>
        /// <param name="hdrTarget"></param>
        /// <param name="diffuse"></param>
        /// <param name="specular"></param>
        /// <param name="normalMap"></param>
        public void RenderGBuffer(Matrix view, Matrix projection, DepthStencil2D depthBuffer, RenderTarget2D hdrTarget, RenderTarget2D diffuse, RenderTarget2D specular, RenderTarget2D normals)
        {
            if (surfaceShader == null)
            {
                return;
            }

            var device = Game.GraphicsDevice;

            device.ResetStates();

            var cbData = new CBSurfaceData();

            var viewPosition   = Matrix.Invert(view).TranslationVector;
            var worldMatricies = new Matrix[scene.Nodes.Count];

            scene.CopyAbsoluteTransformsTo(worldMatricies);


            device.SetTargets(depthBuffer.Surface, hdrTarget.Surface, diffuse.Surface, specular.Surface, normals.Surface);


            device.PipelineState = factory[(int)SurfaceFlags.GBUFFER];

            for (int i = 0; i < scene.Nodes.Count; i++)
            {
                var node = scene.Nodes[i];

                if (node.MeshIndex == -1)
                {
                    continue;
                }

                var mesh = scene.Meshes[node.MeshIndex];

                cbData.Projection = projection;
                cbData.View       = view;
                cbData.World      = worldMatricies[i];
                cbData.ViewPos    = new Vector4(viewPosition, 0);

                constBuffer.SetData(cbData);

                device.PixelShaderConstants[0]  = constBuffer;
                device.VertexShaderConstants[0] = constBuffer;
                device.PixelShaderSamplers[0]   = SamplerState.AnisotropicWrap;

                device.SetupVertexInput(vertexBuffers[node.MeshIndex], indexBuffers[node.MeshIndex]);

                foreach (var subset in mesh.Subsets)
                {
                    var surf = surfaceProps[subset.MaterialIndex];

                    device.PixelShaderResources[0] = surf.Diffuse;
                    device.PixelShaderResources[1] = surf.Specular;
                    device.PixelShaderResources[2] = surf.NormalMap;
                    device.PixelShaderResources[3] = surf.Emission;

                    device.DrawIndexed(subset.PrimitiveCount * 3, subset.StartPrimitive * 3, 0);
                }
            }
        }
示例#24
0
		/// <summary>
		/// 
		/// </summary>
		void CreateShadowMaps ()
		{
			SafeDispose( ref cascadedShadowMap );

			SafeDispose( ref spotColor );
			SafeDispose( ref spotDepth );

			cascadedShadowMap	=	new CascadedShadowMap( Game.GraphicsDevice, CSMCascadeSize, CSMCascadeCount );

			spotColor			=	new RenderTarget2D( Game.GraphicsDevice, ColorFormat.R32F,  SpotShadowSize * 4, SpotShadowSize * 4 );
			spotDepth			=	new DepthStencil2D( Game.GraphicsDevice, DepthFormat.D24S8, SpotShadowSize * 4, SpotShadowSize * 4 );

		}