Пример #1
0
		/// <summary>
		/// Gets time lag between client and server. Sum???
		/// </summary>
		/// <param name="clientSnapshotID"></param>
		/// <param name="currentGameTime"></param>
		/// <returns>Lag in seconds. Returned val</returns>
		public float GetLag ( uint clientSnapshotID, GameTime currentGameTime)
		{
			foreach ( var snapshot in queue ) {
				if (snapshot.Frame==clientSnapshotID) {
					var lag = currentGameTime.Total - snapshot.Timestamp;

					return Math.Min(1, (float)lag.TotalSeconds );
				}
			}

			return 1;
		}
Пример #2
0
		public override void Draw(GameTime gameTime, ConstantBuffer constBuffer)
		{
			Game.GraphicsDevice.VertexShaderConstants[0]	= constBuffer;
			Game.GraphicsDevice.PipelineState				= factory[(int)(DebugFlags.DRAW_LINES)];

			if (isDirty) {
				isDirty = false;

				buf.SetData(lines.ToArray(), 0, Math.Min(lines.Count, buf.Capacity));
			}

			if (lines.Any()) {
				Game.GraphicsDevice.SetupVertexInput(buf, null);
				Game.GraphicsDevice.Draw(lines.Count, 0);
			}
		}
Пример #3
0
			public override void Update ( GameTime gameTime )
			{
				loader.Update(gameTime);

				//	sleep a while to get 
				//	other threads more time.
				Thread.Sleep(1);

				if (loader.IsCompleted) {
					if (disconnectReason!=null) {
						gameClient.SetState( new Disconnected(gameClient, disconnectReason) );
					} else {
						gameClient.FinalizeLoad( loader );
						gameClient.SetState( new Awaiting(gameClient) );
					}
				}
			}
Пример #4
0
		public override void Update(GameTime gameTime)
		{

			//Console.Clear();
			//Console.WriteLine("Current Zoom Level: " + CurrentLevel);
			//
			//for(int i = 0; i < 15; i++)
			//	Console.WriteLine("Zoom: " + i + "\tError: " + GetLevelScreenSpaceError(i, camera.CameraDistance - camera.EarthRadius));
			//
			//Console.WriteLine(camera.FinalCamPosition);

			CurrentMapSource.Update(gameTime);			

			DetermineTiles();

			//Console.WriteLine();
			//Console.WriteLine("Tiles to render: " + tilesToRender.Count);
			//Console.WriteLine("Free tiles:		" + tilesFree.Count);
		}
Пример #5
0
		public override void Draw(GameTime gameTime, ConstantBuffer constBuffer)
		{
			var dev = Game.GraphicsDevice;

			dev.VertexShaderConstants[0]	= constBuffer;
			dev.PixelShaderSamplers[0]		= SamplerState.AnisotropicClamp;
			dev.PixelShaderResources[1]		= frame;

			//dev.PipelineState = factory[(int)(TileFlags.SHOW_FRAMES)];
			dev.PipelineState = factory[0];


			foreach (var globeTile in tilesToRender) {
				var tex = CurrentMapSource.GetTile(globeTile.Value.X, globeTile.Value.Y, globeTile.Value.Z).Tile;
				
				dev.PixelShaderResources[0] = tex;

				dev.SetupVertexInput(globeTile.Value.VertexBuf, globeTile.Value.IndexBuf);
				dev.DrawIndexed(globeTile.Value.IndexBuf.Capacity, 0, 0);
			}
		}
Пример #6
0
		public void Update(GameTime gameTime, GlobeCamera camera = null)
		{
			if (TextureAtlas == null) return;

			var curCamera = camera ?? Game.RenderSystem.Gis.Camera;

			dotsData.View				= curCamera.ViewMatrixFloat;
			dotsData.Proj				= curCamera.ProjMatrixFloat;
			dotsData.AtlasSizeImgSize	= new Vector4(TextureAtlas.Width, TextureAtlas.Height, ImageSizeInAtlas.X, ImageSizeInAtlas.Y);
			dotsData.SizeMult			= new Vector4(SizeMultiplier);


			DotsBuffer.SetData(dotsData);
		}
Пример #7
0
		public override void Draw(GameTime gameTime, ConstantBuffer constBuffer)
		{
			if (TextureAtlas == null) return;

			Update(gameTime);

			var dev = Game.GraphicsDevice;

			//dev.ResetStates();

			dev.PipelineState = factory[Flags];

			dev.VertexShaderConstants[0]	= constBuffer;
			dev.GeometryShaderConstants[0]	= constBuffer;

			dev.VertexShaderConstants[1]	= DotsBuffer;
			dev.GeometryShaderConstants[1]	= DotsBuffer;

			dev.GeometryShaderConstants[2]	= ColorBuffer;


			dev.PixelShaderResources[0]	= TextureAtlas;
			dev.PixelShaderSamplers[0]	= SamplerState.LinearClamp;


			dev.SetupVertexInput(currentBuffer, null);
			dev.Draw(PointsCountToDraw, PointsDrawOffset);
		}
Пример #8
0
		public override void Draw(GameTime gameTime, ConstantBuffer constBuffer)
		{
			Game.GraphicsDevice.VertexShaderConstants[0] = constBuffer;
			Game.GraphicsDevice.PipelineState = factory[(int)(PointFlags.DRAW_TEXTURED_POLY)];

			Game.GraphicsDevice.PixelShaderResources[0] = TextureAtlas;
			Game.GraphicsDevice.PixelShaderSamplers[0]	= SamplerState.LinearClamp;

			if (PointsCpu.Any()) {
				Game.GraphicsDevice.SetupVertexInput(currentBuffer, indBuf);
				Game.GraphicsDevice.DrawIndexed(indeces.Length, 0, 0);
			}
		}
Пример #9
0
		/// <summary>
		/// Executes enqueued commands. Updates delayed commands.
		/// </summary>
		/// <param name="gameTime"></param>
		public void ExecuteQueue ( GameTime gameTime, CommandAffinity affinity, bool forceDelayed = false )
		{
			var delta = (int)gameTime.Elapsed.TotalMilliseconds;

			lock (lockObject) {

				delayed.Clear();

				while (queue.Any()) {
					
					var cmd = queue.Dequeue();

					if ( cmd.Affinity == affinity ) {

						if ( cmd.Delay<=0 || forceDelayed ) {
							//	execute :
							cmd.Execute();

							if (cmd.Result!=null) {
								Log.Message( "// Result: {0} //", cmd.GetStringResult() );
							}

							//	push to history :
							if (!cmd.NoRollback && cmd.Affinity==CommandAffinity.Default) {
								history.Push( cmd );
							}

						} else {

							cmd.Delay -= delta;

							delayed.Enqueue( cmd );

						}

					} else {
						
						delayed.Enqueue( cmd );

					}

				}

				Misc.Swap( ref delayed, ref queue );
			}
		}
Пример #10
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="gameTime"></param>
		internal void Render ( GameTime gameTime, Camera camera, StereoEye stereoEye, HdrFrame viewFrame )
		{
			var device	=	Game.GraphicsDevice;
			device.ResetStates();

			device.SetTargets( viewFrame.DepthBuffer, viewFrame.HdrBuffer );
			device.SetViewport( 0,0,viewFrame.HdrBuffer.Width, viewFrame.HdrBuffer.Height );

			int	w	=	device.DisplayBounds.Width;
			int h	=	device.DisplayBounds.Height;

			//var map	=	"SV_POSITION.xyzw;COLOR0.xyzw;COLOR1.xyzw;TEXCOORD0.xyzw;TEXCOORD1.xyzw;TEXCOORD2.xyzw";

			Params param = new Params();
			//param.View			=	Matrix.Identity;
			//param.Projection	=	Matrix.OrthoOffCenterRH(0, w, h, 0, -9999, 9999);
			param.View			=	camera.GetViewMatrix( stereoEye );
			param.Projection	=	camera.GetProjectionMatrix( stereoEye );
			param.MaxParticles	=	100;
			param.DeltaTime		=	gameTime.ElapsedSec;

			paramsCB.SetData( param );



			device.VertexShaderConstants[0]		= paramsCB ;
			device.GeometryShaderConstants[0]	= paramsCB ;
			device.PixelShaderConstants[0]		= paramsCB ;
			
			device.PixelShaderSamplers[0]		= SamplerState.LinearWrap ;


			//
			//	Simulate :
			//
			device.PipelineState	=	factory[ (int)Flags.SIMULATION ];

			device.SetupVertexInput( simulationSrcVB, null );
			device.SetupVertexOutput( simulationDstVB, 0 );
		
			device.DrawAuto();

			//
			//	Inject :
			//
			injectionVB.SetData( injectionBufferCPU );

			device.PipelineState	=	factory[ (int)Flags.INJECTION ];

			device.SetupVertexInput( injectionVB, null );
			device.SetupVertexOutput( simulationDstVB, -1 );
		
			device.Draw(injectionCount, 0 );

			SwapParticleBuffers();	

			//
			//	Render
			//
			paramsCB.SetData( param );
			device.VertexShaderConstants[0]		= paramsCB ;
			device.GeometryShaderConstants[0]	= paramsCB ;
			device.PixelShaderConstants[0]		= paramsCB ;

			device.PipelineState	=	factory[ (int)Flags.RENDER ];

			device.PixelShaderResources[0]	=	null;

			device.SetupVertexOutput( null, 0 );
			device.SetupVertexInput( simulationSrcVB, null );

			//device.Draw( Primitive.PointList, injectionCount, 0 );

			device.DrawAuto();
			//device.Draw( Primitive.PointList, MaxSimulatedParticles, 0 );


			ClearParticleBuffer();
		}
Пример #11
0
		/// <summary>
		/// Called on each frame until GameLoader returns IsCompleted..
		/// </summary>
		/// <param name="gameTime"></param>
		abstract public void Update ( GameTime gameTime );
Пример #12
0
		/// <summary>
		/// 
		/// </summary>
		void RenderGeneric ( string passName, GameTime gameTime, Camera camera, Viewport viewport, Matrix view, Matrix projection, RenderTargetSurface colorTarget, DepthStencilSurface depthTarget, ShaderResource depthValues, Flags flags )
		{
			var device	=	Game.GraphicsDevice;

			if (rs.SkipParticles) {
				return;
			}


			using ( new PixEvent(passName) ) {

				device.ResetStates();

				//
				//	Setup images :
				//
				if (Images!=null && !Images.IsDisposed) {
					imagesCB.SetData( Images.GetNormalizedRectangles( MaxImages ) );
				}

				SetupGPUParameters( 0, renderWorld, view, projection, flags );
				device.ComputeShaderConstants[0] = paramsCB ;

				//
				//	Render
				//
				using (new PixEvent("Drawing")) {

					device.ResetStates();
	
					//	target and viewport :
					device.SetTargets( depthTarget, colorTarget );
					device.SetViewport( viewport );

					//	params CB :			
					device.ComputeShaderConstants[0]	= paramsCB ;
					device.VertexShaderConstants[0]		= paramsCB ;
					device.GeometryShaderConstants[0]	= paramsCB ;
					device.PixelShaderConstants[0]		= paramsCB ;

					//	atlas CB :
					device.VertexShaderConstants[1]		= imagesCB ;
					device.GeometryShaderConstants[1]	= imagesCB ;
					device.PixelShaderConstants[1]		= imagesCB ;

					//	sampler & textures :
					device.PixelShaderSamplers[0]		=	SamplerState.LinearClamp4Mips ;

					device.PixelShaderResources[0]		=	Images==null? rs.WhiteTexture.Srv : Images.Texture.Srv;
					device.PixelShaderResources[5]		=	depthValues;
					device.GeometryShaderResources[1]	=	simulationBuffer ;
					device.GeometryShaderResources[2]	=	simulationBuffer ;
					device.GeometryShaderResources[3]	=	sortParticlesBuffer;
					device.GeometryShaderResources[4]	=	particleLighting;

					//	setup PS :
					device.PipelineState	=	factory[ (int)flags ];

					//	GPU time : 0.81 ms	-> 0.91 ms
					device.Draw( MaxSimulatedParticles, 0 );
				}
			}
		}
Пример #13
0
		/// <summary>
		/// Updates sound world.
		/// </summary>
		/// <param name="gameTime"></param>
		internal void Update ( GameTime gameTime, int operationSet )
		{
			foreach ( var e in emitters ) {
				if (!e.LocalSound) {
					e.Apply3D( Listener, operationSet );
				}
			}


		}
Пример #14
0
		public override void Draw(GameTime gameTime, ConstantBuffer constBuffer)
		{
			var dev = Game.GraphicsDevice;

			if (((LineFlags) Flags).HasFlag(LineFlags.THIN_LINE)) {
				dev.PipelineState = thinFactory[Flags];
			}
			else {
				dev.PipelineState = factory[Flags];
			}

			if (isDirty) {
				linesConstantBuffer.SetData(linesConstData);
				isDirty = false;
			}

			dev.GeometryShaderConstants[0]	= constBuffer;
			dev.VertexShaderConstants[0]	= constBuffer;
			dev.PixelShaderConstants[0]		= constBuffer;
			dev.PixelShaderConstants[1]		= linesConstantBuffer;

			dev.PixelShaderResources[0] = Texture;
			dev.PixelShaderSamplers[0]	= SamplerState.AnisotropicWrap;


			dev.SetupVertexInput(currentBuffer, null);
			dev.Draw(currentBuffer.Capacity, 0);
		}
Пример #15
0
		/// <summary>
		/// Updates particle properties.
		/// </summary>
		/// <param name="gameTime"></param>
		internal void Simulate ( GameTime gameTime, Camera camera )
		{
			var device	=	Game.GraphicsDevice;

			var view		=	camera.GetViewMatrix( StereoEye.Mono );
			var projection	=	camera.GetProjectionMatrix( StereoEye.Mono );


			timeAccumulator	+=	gameTime.ElapsedSec;


			using ( new PixEvent("Particle Simulation") ) {

				device.ResetStates();

				//
				//	Inject :
				//
				using (new PixEvent("Injection")) {

					injectionBuffer.SetData( injectionBufferCPU );

					device.ComputeShaderResources[1]	= injectionBuffer ;
					device.SetCSRWBuffer( 0, simulationBuffer,		0 );
					device.SetCSRWBuffer( 1, deadParticlesIndices, -1 );

					SetupGPUParameters( 0, renderWorld, view, projection, Flags.INJECTION );
					device.ComputeShaderConstants[0]	= paramsCB ;

					device.PipelineState	=	factory[ (int)Flags.INJECTION ];
			
					//	GPU time ???? -> 0.0046
					device.Dispatch( MathUtil.IntDivUp( MaxInjectingParticles, BlockSize ) );

					ClearParticleBuffer();
				}


				//
				//	Simulate :
				//
				using (new PixEvent("Simulation")) {

					if (!renderWorld.IsPaused && !rs.SkipParticlesSimulation) {
	
						device.SetCSRWBuffer( 0, simulationBuffer,		0 );
						device.SetCSRWBuffer( 1, deadParticlesIndices, -1 );
						device.SetCSRWBuffer( 2, sortParticlesBuffer, 0 );

						float stepTime = SimulationStepTime;

						while ( timeAccumulator > stepTime ) {

							SetupGPUParameters( stepTime, renderWorld, view, projection, Flags.SIMULATION);
							device.ComputeShaderConstants[0] = paramsCB ;

							device.PipelineState	=	factory[ (int)Flags.SIMULATION ];
	
							/// GPU time : 1.665 ms	 --> 0.38 ms
							device.Dispatch( MathUtil.IntDivUp( MaxSimulatedParticles, BlockSize ) );//*/

							timeAccumulator -= stepTime;
						}
					}
				}

				//
				//	Sort :
				//
				using (new PixEvent("Sort")) {
					rs.BitonicSort.Sort( sortParticlesBuffer );
				}


				if (rs.ShowParticles) {
					rs.Counters.DeadParticles	=	deadParticlesIndices.GetStructureCount();
				}
			}
		}
Пример #16
0
		public override void Update(GameTime gameTime)
		{
			//UpdateText();
		}
Пример #17
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);
			}
		}
Пример #18
0
		/*-----------------------------------------------------------------------------------------
		 * 
		 *	Rendering :
		 * 
		-----------------------------------------------------------------------------------------*/


		/// <summary>
		/// Renders view
		/// </summary>
		internal virtual void Render ( GameTime gameTime, StereoEye stereoEye )
		{
			var targetSurface = (Target == null) ? rs.Device.BackbufferColor.Surface : Target.RenderTarget.Surface;

			//	clear target buffer if necassary :
			if (Clear) {
				rs.Device.Clear( targetSurface, ClearColor );
			}

			var viewport	=	new Viewport( 0,0, targetSurface.Width, targetSurface.Height );

			//	Render GIS stuff :
			RenderGIS( gameTime, stereoEye, viewport, targetSurface );

			//	draw debug stuff :
			//  ...

			//	draw sprites :
			rs.SpriteEngine.DrawSprites( gameTime, stereoEye, targetSurface, SpriteLayers );

			rs.Filter.FillAlphaOne( targetSurface );
		}
Пример #19
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="gameTime"></param>
		/// <param name="stereoEye"></param>
		internal void Draw ( GameTime gameTime, StereoEye stereoEye )
		{
			Counters.Reset();

			Gis.Update(gameTime);
			//GIS.Draw(gameTime, StereoEye.Mono);

			RenderLayer[] layersToDraw;

			lock (viewLayers) {
				layersToDraw = viewLayers
					.OrderBy( c1 => c1.Order )
					.Where( c2 => c2.Visible )
					.ToArray();
			}

			foreach ( var viewLayer in layersToDraw ) {
				viewLayer.Render( gameTime, stereoEye );
			}

			if (ShowCounters) {
				Counters.PrintCounters();
			}
		}
Пример #20
0
		/// <summary>
		/// Updates sound.
		/// </summary>
		internal void Update ( GameTime gameTime )
		{
			SoundWorld.Update( gameTime, OperationSetCounter );

			Device.CommitChanges( OperationSetCounter );
			Interlocked.Increment( ref operationSetCounter );
		}
Пример #21
0
		/// <summary>
		/// 
		/// </summary>
		/// 
		public void Render ( GameTime gameTime, StereoEye stereoEye, bool suppress )
		{
			if (!vertexDataAccum.Any()) {
				return;
			}

			if (suppress) {
				vertexDataAccum.Clear();
			}

			var dev = Game.GraphicsDevice;


			if (RenderTarget!=null) {
				if (DepthStencil==null) {	
					throw new InvalidOperationException("Both RenderTarget and DepthStencil must be set.");
				}
				dev.SetTargets( DepthStencil, RenderTarget );
			}


			constData.Transform = View * Projection;
			constBuffer.SetData(constData);

			dev.SetupVertexInput( vertexBuffer, null );
			dev.VertexShaderConstants[0]	=	constBuffer ;
			dev.PipelineState				=	factory[0];


			int numDPs = MathUtil.IntDivUp(vertexDataAccum.Count, vertexBufferSize);

			for (int i = 0; i < numDPs; i++) {

				int numVerts = i < numDPs - 1 ? vertexBufferSize : vertexDataAccum.Count % vertexBufferSize;

				if (numVerts == 0) {
					break;
				}

				vertexDataAccum.CopyTo(i * vertexBufferSize, vertexArray, 0, numVerts);

				vertexBuffer.SetData(vertexArray, 0, numVerts);

				dev.Draw( numVerts, 0);

			}

			vertexDataAccum.Clear();
		}
Пример #22
0
		public void PlayAnimation(GameTime gameTime)
		{
			if(cameraAnimTrackStates == null) return;

			freezeFreeCamRotation = true;

			var state = cameraAnimTrackStates[curStateInd];


			curTime += 0.016f; //gameTime.ElapsedSec;
			
			if (curTime < state.WaitTime || curStateInd >= cameraAnimTrackStates.Count - 1) {
				SetState(state);

				if (curStateInd >= cameraAnimTrackStates.Count - 1)
					StopAnimation();

				return;
			}

			float time		= curTime - state.WaitTime;
			float amount	= time/state.TransitionTime;

			float	factor = MathUtil.SmoothStep(amount);
					factor = MathUtil.Clamp(factor, 0.0f, 1.0f);

			var nextState = cameraAnimTrackStates[curStateInd+1];

			var curPos		= DVector3.Lerp(state.FreeSurfacePosition, nextState.FreeSurfacePosition, factor);
			var curFreeRot	= DQuaternion.Slerp(state.FreeRotation, nextState.FreeRotation, factor);

			freeSurfaceRotation = curFreeRot;

			CameraPosition = FreeSurfacePosition = curPos;

			var newLonLat = GetCameraLonLat();
			Yaw		= newLonLat.X;
			Pitch	= -newLonLat.Y;
			
			if (curTime > state.WaitTime + state.TransitionTime) {
				curStateInd++;
				curTime = 0;
			}
		}
Пример #23
0
		/// <summary>
		/// Performs luminance measurement, tonemapping, applies bloom.
		/// </summary>
		/// <param name="target">LDR target.</param>
		/// <param name="hdrImage">HDR source image.</param>
		public void Render ( GameTime gameTime, RenderTargetSurface target, ShaderResource hdrImage, RenderWorld viewLayer )
		{
			var device	=	Game.GraphicsDevice;
			var filter	=	Game.RenderSystem.Filter;

			var settings	=	viewLayer.HdrSettings;

			//
			//	Rough downsampling of source HDR-image :
			//
			filter.StretchRect( averageLum.Surface, hdrImage, SamplerState.PointClamp );
			averageLum.BuildMipmaps();

			//
			//	Make bloom :
			//
			filter.StretchRect( viewLayer.Bloom0.Surface, hdrImage, SamplerState.LinearClamp );
			viewLayer.Bloom0.BuildMipmaps();

			filter.GaussBlur( viewLayer.Bloom0, viewLayer.Bloom1, settings.GaussBlurSigma, 0 );
			filter.GaussBlur( viewLayer.Bloom0, viewLayer.Bloom1, settings.GaussBlurSigma, 1 );
			filter.GaussBlur( viewLayer.Bloom0, viewLayer.Bloom1, settings.GaussBlurSigma, 2 );
			filter.GaussBlur( viewLayer.Bloom0, viewLayer.Bloom1, settings.GaussBlurSigma, 3 );

			//
			//	Setup parameters :
			//
			var paramsData	=	new Params();
			paramsData.AdaptationRate		=	1 - (float)Math.Pow( 0.5f, gameTime.ElapsedSec / settings.AdaptationHalfLife );
			paramsData.LuminanceLowBound	=	settings.LuminanceLowBound;
			paramsData.LuminanceHighBound	=	settings.LuminanceHighBound;
			paramsData.KeyValue				=	settings.KeyValue;
			paramsData.BloomAmount			=	settings.BloomAmount;
			paramsData.DirtMaskLerpFactor	=	settings.DirtMaskLerpFactor;
			paramsData.DirtAmount			=	settings.DirtAmount;

			paramsCB.SetData( paramsData );
			device.PixelShaderConstants[0]	=	paramsCB;

			//
			//	Measure and adapt :
			//
			device.SetTargets( null, viewLayer.MeasuredNew );

			device.PixelShaderResources[0]	=	averageLum;
			device.PixelShaderResources[1]	=	viewLayer.MeasuredOld;

			device.PipelineState		=	factory[ (int)(Flags.MEASURE_ADAPT) ];
				
			device.Draw( 3, 0 );


			//
			//	Tonemap and compose :
			//
			device.SetTargets( null, target );

			device.PixelShaderResources[0]	=	hdrImage;// averageLum;
			device.PixelShaderResources[1]	=	viewLayer.MeasuredNew;// averageLum;
			device.PixelShaderResources[2]	=	viewLayer.Bloom0;// averageLum;
			device.PixelShaderResources[3]	=	settings.DirtMask1==null ? whiteTex.Srv : settings.DirtMask1.Srv;
			device.PixelShaderResources[4]	=	settings.DirtMask2==null ? whiteTex.Srv : settings.DirtMask2.Srv;
			device.PixelShaderSamplers[0]	=	SamplerState.LinearClamp;

			Flags op = Flags.LINEAR;
			if (settings.TonemappingOperator==TonemappingOperator.Filmic)   { op = Flags.FILMIC;   }
			if (settings.TonemappingOperator==TonemappingOperator.Linear)   { op = Flags.LINEAR;	 }
			if (settings.TonemappingOperator==TonemappingOperator.Reinhard) { op = Flags.REINHARD; }

			device.PipelineState		=	factory[ (int)(Flags.TONEMAPPING|op) ];
				
			device.Draw( 3, 0 );
			
			device.ResetStates();


			//	swap luminanice buffers :
			Misc.Swap( ref viewLayer.MeasuredNew, ref viewLayer.MeasuredOld );
		}
Пример #24
0
		/// <summary>
		/// Updates particle properties.
		/// </summary>
		/// <param name="gameTime"></param>
		internal void Simulate ( GameTime gameTime )
		{
		}
Пример #25
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="gameTime"></param>
		internal void Render ( GameTime gameTime, Camera camera, StereoEye stereoEye, HdrFrame viewFrame )
		{
			var view		=	camera.GetViewMatrix( stereoEye );
			var projection	=	camera.GetProjectionMatrix( stereoEye );

			var colorTarget	=	viewFrame.HdrBuffer.Surface;
			var depthTarget	=	viewFrame.DepthBuffer.Surface;

			var viewport	=	new Viewport( 0, 0, colorTarget.Width, colorTarget.Height );

			RenderGeneric( "Particles", gameTime, camera, viewport, view, projection, colorTarget, null, viewFrame.DepthBuffer, Flags.DRAW );
		}
Пример #26
0
		public override void Draw(GameTime gameTime, ConstantBuffer constBuffer)
		{
			UpdateText();
		}
Пример #27
0
		public void Update(GameTime gameTime)
		{
			UpdateProjectionMatrix();

			CameraPosition	= DVector3.Transform(new DVector3(0, 0, CameraDistance), Rotation);
			ViewMatrix		= DMatrix.LookAtRH(CameraPosition, DVector3.Zero, DVector3.UnitY);

			ViewMatrixWithTranslation		= ViewMatrix;
			ViewMatrix.TranslationVector	= DVector3.Zero;
			FinalCamPosition				= CameraPosition;


			if (CameraState == CameraStates.ViewToPoint) {
				var mat = CalculateBasisOnSurface();

				DVector3	lookAtPoint = mat.Up * EarthRadius;
				double		length		= CameraDistance - EarthRadius;

				var quat	= DQuaternion.RotationAxis(DVector3.UnitY, ViewToPointYaw) * DQuaternion.RotationAxis(DVector3.UnitX, ViewToPointPitch);
				var qRot	= DMatrix.RotationQuaternion(quat);
				var matrix	= qRot * mat;

				var pointOffset = DVector3.Transform(new DVector3(0, 0, length), matrix);
				var camPoint	= new DVector3(pointOffset.X, pointOffset.Y, pointOffset.Z) + lookAtPoint;

				FinalCamPosition = camPoint;

				ViewMatrix					= DMatrix.LookAtRH(camPoint, lookAtPoint, mat.Up);
				ViewMatrixWithTranslation	= ViewMatrix;

				ViewMatrix.TranslationVector = DVector3.Zero;
			} else if (CameraState == CameraStates.FreeSurface) {
				var mat = CalculateBasisOnSurface();
				
				#region Input
					// Update surface camera yaw and pitch
					//if (input.IsKeyDown(Keys.RightButton)) {
					//	FreeSurfaceYaw		+= input.RelativeMouseOffset.X*0.0003;
					//	FreeSurfacePitch	-= input.RelativeMouseOffset.Y*0.0003;
					//
					//	input.IsMouseCentered	= false;
					//	input.IsMouseHidden		= true;
					//}
					//else {
					//	input.IsMouseCentered	= false;
					//	input.IsMouseHidden		= false;
					//}


					//if (Game.Keyboard.IsKeyDown(Input.Keys.Left))		FreeSurfaceYaw		-= gameTime.ElapsedSec * 0.7;
					//if (Game.Keyboard.IsKeyDown(Input.Keys.Right))	FreeSurfaceYaw		+= gameTime.ElapsedSec * 0.7;
					//if (Game.Keyboard.IsKeyDown(Input.Keys.Up))		FreeSurfacePitch	-= gameTime.ElapsedSec * 0.7;
					//if (Game.Keyboard.IsKeyDown(Input.Keys.Down))		FreeSurfacePitch	+= gameTime.ElapsedSec * 0.7;


					//FreeSurfaceYaw = DMathUtil.Clamp(FreeSurfaceYaw, -DMathUtil.PiOverTwo, DMathUtil.PiOverTwo);
					if (FreeSurfaceYaw > DMathUtil.TwoPi)	FreeSurfaceYaw -= DMathUtil.TwoPi;
					if (FreeSurfaceYaw < -DMathUtil.TwoPi)	FreeSurfaceYaw += DMathUtil.TwoPi;

					// Calculate free cam rotation matrix

					if (!freezeFreeCamRotation)
						freeSurfaceRotation = DQuaternion.RotationAxis(DVector3.UnitY, FreeSurfaceYaw) * DQuaternion.RotationAxis(DVector3.UnitX, FreeSurfacePitch);

					var quat	= freeSurfaceRotation;
					var qRot	= DMatrix.RotationQuaternion(quat);
					var matrix	= qRot * mat;

					var velDir = matrix.Forward * velocityDirection.X + mat.Up * velocityDirection.Y + matrix.Right * velocityDirection.Z;

					if (velDir.Length() != 0) {
						velDir.Normalize();
					}
				
				#endregion

				double fac = ((CameraDistance - EarthRadius) - Parameters.MinDistVelocityThreshold) / (Parameters.MaxDistVelocityThreshold - Parameters.MinDistVelocityThreshold);
				fac = DMathUtil.Clamp(fac, 0.0, 1.0);

				FreeSurfaceVelocityMagnitude = DMathUtil.Lerp(Parameters.MinVelocityFreeSurfCam, Parameters.MaxVelocityFreeSurfCam, fac);

				// Update camera position
				FinalCamPosition	= FreeSurfacePosition = FreeSurfacePosition + velDir * FreeSurfaceVelocityMagnitude * gameTime.ElapsedSec;
				CameraPosition		= FinalCamPosition;


				velocityDirection = DVector3.Zero;


				//Calculate view matrix
				ViewMatrix = DMatrix.LookAtRH(FinalCamPosition, FinalCamPosition + matrix.Forward, matrix.Up);
				ViewMatrixWithTranslation		= ViewMatrix;
				ViewMatrix.TranslationVector	= DVector3.Zero;

				// Calculate new yaw and pitch
				CameraDistance = CameraPosition.Length();

				var newLonLat = GetCameraLonLat();
				Yaw		= newLonLat.X;
				Pitch	= -newLonLat.Y;
			}

			ViewMatrixFloat = DMatrix.ToFloatMatrix(ViewMatrix);
			ProjMatrixFloat = DMatrix.ToFloatMatrix(ProjMatrix);

			//var viewDir = CameraPosition / CameraPosition.Length();
		}
Пример #28
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="gameTime"></param>
		internal void RenderShadow ( GameTime gameTime, Viewport viewport, Matrix view, Matrix projection, RenderTargetSurface particleShadow, DepthStencilSurface depthBuffer )
		{
			var colorTarget	=	particleShadow;
			var depthTarget	=	depthBuffer;

			RenderGeneric( "Particles Shadow", gameTime, null, viewport, view, projection, colorTarget, depthTarget, null, Flags.DRAW_SHADOW );
		}
			public override void Update ( GameTime gameTime )
			{
				//	fall immediatly to stand-by mode:
				gameClient.SetState( new StandBy( gameClient ) );
			}
Пример #30
0
		/// <summary>
		/// Runs one step of server-side world simulation.
		/// <remarks>Due to delta compression of snapshot keep data aligned. 
		/// Even small layout change will cause significiant increase of sending data</remarks>
		/// </summary>
		/// <param name="gameTime"></param>
		/// <returns>Snapshot bytes</returns>
		public abstract byte[] Update ( GameTime gameTime );