Exemplo n.º 1
0
        /// <summary>
        /// Selects colorspace in ubershader.
        /// </summary>
        /// <param name="flags"></param>
        /// <param name="settings"></param>
        void ApplyColorSpace(ref SkyFlags flags, SkySettings settings)
        {
            switch (settings.RgbSpace)
            {
            case RgbSpace.CIE_RGB: flags |= SkyFlags.CIERGB;     break;

            case RgbSpace.sRGB: flags |= SkyFlags.SRGB;       break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Renders sky with specified technique
        /// </summary>
        /// <param name="rendCtxt"></param>
        /// <param name="techName"></param>
        internal void Render(Camera camera, StereoEye stereoEye, HdrFrame frame, SkySettings settings)
        {
            using (new PixEvent("Sky Rendering")) {
                var scale    = Matrix.Scaling(settings.SkySphereSize);
                var rotation = Matrix.Identity;

                var sunPos   = settings.SunPosition;
                var sunColor = settings.SunGlowColor;

                device.ResetStates();

                //rs.DepthStencilState = depthBuffer==null? DepthStencilState.None : DepthStencilState.Default ;

                device.SetTargets(frame.DepthBuffer.Surface, frame.HdrBuffer.Surface);

                var viewMatrix = camera.GetViewMatrix(stereoEye);
                var projMatrix = camera.GetProjectionMatrix(stereoEye);

                skyConstsData.MatrixWVP    = scale * rotation * MathUtil.Transformation(viewMatrix.Right, viewMatrix.Up, viewMatrix.Backward) * projMatrix;
                skyConstsData.SunPosition  = sunPos;
                skyConstsData.SunColor     = sunColor;
                skyConstsData.Turbidity    = settings.SkyTurbidity;
                skyConstsData.Temperature  = Temperature.Get(settings.SunTemperature);
                skyConstsData.SkyIntensity = settings.SkyIntensity;

                skyConstsCB.SetData(skyConstsData);

                device.VertexShaderConstants[0] = skyConstsCB;
                device.PixelShaderConstants[0]  = skyConstsCB;


                //
                //	Sky :
                //
                SkyFlags flags = SkyFlags.SKY;

                ApplyColorSpace(ref flags, settings);

                device.PipelineState = factory[(int)flags];

                device.SetupVertexInput(skyVB, null);
                device.Draw(skyVB.Capacity, 0);

                device.ResetStates();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Renders fog look-up table
        /// </summary>
        internal void RenderFogTable(SkySettings settings)
        {
            using (new PixEvent("Fog Table")) {
                var sunPos   = settings.SunPosition;
                var sunColor = settings.SunLightColor;

                var rotation   = Matrix.Identity;
                var projection = MathUtil.ComputeCubemapProjectionMatrixLH(0.125f, 10.0f);
                var cubeWVPS   = MathUtil.ComputeCubemapViewMatriciesLH(Vector3.Zero, rotation, projection);

                var flags = SkyFlags.FOG;

                ApplyColorSpace(ref flags, settings);

                device.PipelineState = factory[(int)flags];
                //			rs.DepthStencilState = DepthStencilState.None ;

                skyConstsData.SunPosition  = sunPos;
                skyConstsData.SunColor     = sunColor;
                skyConstsData.Turbidity    = settings.SkyTurbidity;
                skyConstsData.Temperature  = Temperature.Get(settings.SunTemperature);
                skyConstsData.SkyIntensity = settings.SkyIntensity;

                for (int i = 0; i < 6; ++i)
                {
                    device.SetTargets(null, SkyCube.GetSurface(0, (CubeFace)i));

                    SkyCube.SetViewport();

                    skyConstsData.MatrixWVP = cubeWVPS[i];

                    skyConstsCB.SetData(skyConstsData);
                    device.VertexShaderConstants[0] = skyConstsCB;
                    device.PixelShaderConstants[0]  = skyConstsCB;


                    device.SetupVertexInput(skyVB, null);
                    device.Draw(skyVB.Capacity, 0);
                }

                device.ResetStates();

                SkyCube.BuildMipmaps();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates ViewLayerHDR instance
        /// </summary>
        /// <param name="Game">Game engine</param>
        /// <param name="width">Target width.</param>
        /// <param name="height">Target height.</param>
        public RenderWorld(Game game, int width, int height)
        {
            Game    = game;
            this.rs = Game.RenderSystem;

            Camera = new Camera();

            var vp = Game.GraphicsDevice.DisplayBounds;

            if (width <= 0)
            {
                width = vp.Width;
            }
            if (height <= 0)
            {
                height = vp.Height;
            }

            HdrSettings = new HdrSettings();
            SkySettings = new SkySettings();
            DofSettings = new DofSettings();
            FogSettings = new FogSettings();

            Instances = new List <MeshInstance>();
            LightSet  = new LightSet(Game.RenderSystem);

            debug = new DebugRender(Game);

            particleSystem = new ParticleSystem(Game.RenderSystem, this);

            MeasuredOld = new RenderTarget2D(Game.GraphicsDevice, ColorFormat.Rgba32F, 1, 1);
            MeasuredNew = new RenderTarget2D(Game.GraphicsDevice, ColorFormat.Rgba32F, 1, 1);

            radianceFrame = new HdrFrame(Game, 512, 512);

            Radiance      = new RenderTargetCube(Game.GraphicsDevice, ColorFormat.Rgba16F, RenderSystem.EnvMapSize, true);
            RadianceCache = new TextureCubeArray(Game.GraphicsDevice, 128, RenderSystem.MaxEnvLights, ColorFormat.Rgba16F, true);

            Resize(width, height);
        }
Exemplo n.º 5
0
		/// <summary>
		/// Renders sky with specified technique
		/// </summary>
		/// <param name="rendCtxt"></param>
		/// <param name="techName"></param>
		internal void Render( Camera camera, StereoEye stereoEye, HdrFrame frame, SkySettings settings )
		{
			var scale		=	Matrix.Scaling( settings.SkySphereSize );
			var rotation	=	Matrix.Identity;

			var	sunPos		=	settings.SunPosition;
			var sunColor	=	settings.SunGlowColor;

			rs.ResetStates();

			//rs.DepthStencilState = depthBuffer==null? DepthStencilState.None : DepthStencilState.Default ;

			rs.SetTargets( frame.DepthBuffer.Surface, frame.HdrBuffer.Surface );

			var viewMatrix = camera.GetViewMatrix( stereoEye );
			var projMatrix = camera.GetProjectionMatrix( stereoEye );

			skyConstsData.MatrixWVP		= scale * rotation * MathUtil.Transformation( viewMatrix.Right, viewMatrix.Up, viewMatrix.Backward ) * projMatrix;
			skyConstsData.SunPosition	= sunPos;
			skyConstsData.SunColor		= sunColor;
			skyConstsData.Turbidity		= settings.SkyTurbidity;
			skyConstsData.Temperature	= Temperature.Get( settings.SunTemperature ); 
			skyConstsData.SkyIntensity	= settings.SkyIntensity;
	
			skyConstsCB.SetData( skyConstsData );
			
			rs.VertexShaderConstants[0] = skyConstsCB;
			rs.PixelShaderConstants[0] = skyConstsCB;


			//
			//	Sky :
			//
			SkyFlags flags = SkyFlags.SKY;

			ApplyColorSpace( ref flags, settings );
				
			rs.PipelineState	=	factory[(int)flags];
						
			rs.SetupVertexInput( skyVB, null );
			rs.Draw( skyVB.Capacity, 0 );

			rs.ResetStates();
		}
Exemplo n.º 6
0
		/// <summary>
		/// Renders fog look-up table
		/// </summary>
		internal void RenderFogTable( SkySettings settings )
		{
			var	sunPos		= settings.SunPosition;
			var sunColor	= settings.SunLightColor;

			var rotation	=	Matrix.Identity;
			var projection	=	MathUtil.ComputeCubemapProjectionMatrixLH( 0.125f, 10.0f );
			var cubeWVPS	=	MathUtil.ComputeCubemapViewMatriciesLH( Vector3.Zero, rotation, projection );

			var flags		=	SkyFlags.FOG;

			ApplyColorSpace( ref flags, settings );
				
			rs.PipelineState	=	factory[(int)flags];
//			rs.DepthStencilState = DepthStencilState.None ;

			skyConstsData.SunPosition	= sunPos;
			skyConstsData.SunColor		= sunColor;
			skyConstsData.Turbidity		= settings.SkyTurbidity;
			skyConstsData.Temperature	= Temperature.Get( settings.SunTemperature ); 
			skyConstsData.SkyIntensity	= settings.SkyIntensity;

			for( int i = 0; i < 6; ++i ) {
				rs.SetTargets( null, SkyCube.GetSurface(0, (CubeFace)i ) );

				SkyCube.SetViewport();

				skyConstsData.MatrixWVP = cubeWVPS[i];
	
				skyConstsCB.SetData( skyConstsData );
				rs.VertexShaderConstants[0] = skyConstsCB;
				rs.PixelShaderConstants[0] = skyConstsCB;


				rs.SetupVertexInput( skyVB, null );
				rs.Draw( skyVB.Capacity, 0 );
			}

			rs.ResetStates();

			SkyCube.BuildMipmaps();
		}
Exemplo n.º 7
0
		/// <summary>
		/// Selects colorspace in ubershader.
		/// </summary>
		/// <param name="flags"></param>
		/// <param name="settings"></param>
		void ApplyColorSpace ( ref SkyFlags flags, SkySettings settings )
		{	
			switch (settings.RgbSpace) {
				case RgbSpace.CIE_RGB	: flags |= SkyFlags.CIERGB;	break;
				case RgbSpace.sRGB		: flags |= SkyFlags.SRGB;	break;
			}
		}
Exemplo n.º 8
0
		/// <summary>
		/// Creates ViewLayerHDR instance
		/// </summary>
		/// <param name="Game">Game engine</param>
		/// <param name="width">Target width.</param>
		/// <param name="height">Target height.</param>
		public RenderWorld ( Game game, int width, int height ) : base( game )
		{
			var vp	=	Game.GraphicsDevice.DisplayBounds;

			if (width<=0) {
				width	=	vp.Width;
			}
			if (height<=0) {
				height	=	vp.Height;
			}

			HdrSettings		=	new HdrSettings();
			SkySettings		=	new SkySettings();
			DofSettings		=	new DofSettings();

			Instances		=	new List<MeshInstance>();
			LightSet		=	new LightSet( Game.RenderSystem );

			debug			=	new DebugRender( Game );
			
			particleSystem	=	new ParticleSystem( Game.RenderSystem, this );

			MeasuredOld		=	new RenderTarget2D( Game.GraphicsDevice, ColorFormat.Rgba32F,   1,  1 );
			MeasuredNew		=	new RenderTarget2D( Game.GraphicsDevice, ColorFormat.Rgba32F,   1,  1 );

			radianceFrame	=	new HdrFrame( Game, 512,512 );

			Radiance		=	new RenderTargetCube( Game.GraphicsDevice, ColorFormat.Rgba16F, RenderSystem.EnvMapSize, true );
			RadianceCache	=	new TextureCubeArray( Game.GraphicsDevice, 128, RenderSystem.MaxEnvLights, ColorFormat.Rgba16F, true );

			Resize( width, height );
		}