Ejemplo n.º 1
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();
		}
Ejemplo n.º 2
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();
		}
Ejemplo n.º 3
0
		public void Free ( DepthStencil2D target )
		{
			throw new NotImplementedException();
		}
Ejemplo n.º 4
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 );
			}
		}
Ejemplo n.º 6
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 );
		}
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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 );
        }
Ejemplo n.º 9
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);
			}
		}
Ejemplo n.º 10
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 );
		}
Ejemplo n.º 11
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 );

		}