Пример #1
0
		protected override void SetupContent()
		{
			//Setup default effects values.
			this.curLightingModel = ShaderSystemLightingModel.PerVertexLighting;
			this.perPixelFogEnable = false;
			this.specularEnable = false;
			this.reflectionMapEnable = false;
			this.reflectionMapSubRS = null;
			this.layerBlendSubRS = null;

			this.rayQuery = SceneManager.CreateRayQuery( new Ray() );
			this.targetObj = null;

			//Set ambient
			SceneManager.AmbientLight = new ColorEx( 0.2f, 0.2f, 0.2f );

			SceneManager.SetSkyBox( true, "Examples/SceneCubeMap2", 10000 );

			MeshManager.Instance.CreatePlane( "Myplane", ResourceGroupManager.DefaultResourceGroupName,
			                                  new Plane( Vector3.UnitY, 0 ),
			                                  1500, 1500, 25, 25, true, 1, 60, 60, Vector3.UnitZ );

			Entity planeEnt = SceneManager.CreateEntity( "plane", "Myplane" );
			planeEnt.MaterialName = "Examples/Rockwall";
			planeEnt.CastShadows = false;
			SceneManager.RootSceneNode.CreateChildSceneNode( Vector3.Zero ).AttachObject( planeEnt );

			//Load sample meshes an generate tangent vectors.
			for ( int i = 0; i < this.meshArray.Length; i++ )
			{
				string curMeshName = this.meshArray[ i ];

				Mesh mesh = MeshManager.Instance.Load( curMeshName, ResourceGroupManager.DefaultResourceGroupName,
				                                       BufferUsage.DynamicWriteOnly, BufferUsage.StaticWriteOnly );

				//Build tangent vectors, all our meshes use only 1 texture coordset
				//Note we can build into ves_tangent now (sm2+)
				short src, dst;
				if ( !mesh.SuggestTangentVectorBuildParams( out src, out dst ) )
				{
					mesh.BuildTangentVectors( src, dst );
				}
			}

			Entity entity;
			SceneNode childNode;

			//Create the main entity and mark it as the current target object
			entity = SceneManager.CreateEntity( MainEntityName, MainEntityMesh );
			this.targetEntities.Add( entity );
			childNode = SceneManager.RootSceneNode.CreateChildSceneNode();
			childNode.AttachObject( entity );
			this.targetObj = entity;
			childNode.ShowBoundingBox = true;

			//Create reflection entity that will show the exported material.
			string mainExportedMaterial = SceneManager.GetEntity( MainEntityName ).GetSubEntity( 0 ).MaterialName +
			                              "_RTSS_Export";
			var matMainEnt = (Material)MaterialManager.Instance.GetByName( mainExportedMaterial );

			entity = SceneManager.CreateEntity( "ExportedMaterialEntity", MainEntityMesh );
			entity.GetSubEntity( 0 ).Material = matMainEnt;
			childNode = SceneManager.RootSceneNode.CreateChildSceneNode();
			childNode.Position = new Vector3( 0, 200, -200 );
			childNode.AttachObject( entity );

			//Create texture layer blending demonstration entity
			this.layeredBlendingEntity = SceneManager.CreateEntity( "LayeredBlendingMaterialEntity", MainEntityMesh );
			this.layeredBlendingEntity.MaterialName = "RTSS/LayeredBlending";
			this.layeredBlendingEntity.GetSubEntity( 0 ).SetCustomParameter( 2, Vector4.Zero );
			childNode = SceneManager.RootSceneNode.CreateChildSceneNode();
			childNode.Position = new Vector3( 300, 200, -200 );
			childNode.AttachObject( this.layeredBlendingEntity );

			//Grab the render state of the material
			RenderState renderState = ShaderGenerator.Instance.GetRenderState( ShaderGenerator.DefaultSchemeName, "RTSS/LayeredBlending", 0 );

			if ( renderState != null )
			{
				var subRenderStateList = renderState.TemplateSubRenderStateList;

				for ( int i = 0; i < subRenderStateList.Count; i++ )
				{
					SubRenderState curSubRenderState = subRenderStateList[ i ];

					if ( curSubRenderState.Type == FFPTexturing.FFPType )
					{
						this.layerBlendSubRS = curSubRenderState as LayeredBlending;
						break;
					}
				}
			}
			//Create per pixel lighting demo entity
			entity = SceneManager.CreateEntity( "PerPixelEntity", "knot.mesh" );
			entity.MaterialName = "RTSS/PerPixel_SinglePass";
			childNode = SceneManager.RootSceneNode.CreateChildSceneNode();
			childNode.Position = new Vector3( 300, 100, -100 );
			childNode.AttachObject( entity );

			//Create normal map lighting demo entity
			entity = SceneManager.CreateEntity( "NormalMapEntity", "knot.mesh" );
			entity.MaterialName = "RTSS/NormalMapping_SinglePass";
			childNode = SceneManager.RootSceneNode.CreateChildSceneNode();
			childNode.Position = new Vector3( -300, 100, -100 );
			childNode.AttachObject( entity );

			//OpenGL ES 2.0 does not support texture atlases
			if ( !Root.Instance.RenderSystem.Name.Contains( "OpenGL ES 2" ) )
			{
				RenderState mainRenderState =
					ShaderGenerator.Instance.CreateOrRetrieveRenderState( ShaderGenerator.DefaultSchemeName ).Item1;
				mainRenderState.AddTemplateSubRenderState(
					ShaderGenerator.Instance.CreateSubRenderState( TextureAtlasSampler.SGXType ) );

				//Create texture atlas object and node
				ManualObject atlasObject = CreateTextureAtlasObject();
				childNode = SceneManager.RootSceneNode.CreateChildSceneNode();
				childNode.AttachObject( atlasObject );
			}

			CreateDirectionalLight();
			CreatePointLight();
			CreateSpotLight();

			RenderState schemeRenderState = ShaderGenerator.Instance.GetRenderState( ShaderGenerator.DefaultSchemeName );

			//take responsibility for updating the light count manually
			schemeRenderState.LightCountAutoUpdate = false;

			SetupUI();

			Camera.Position = new Vector3( 0, 300, 450 );

			Viewport.MaterialScheme = ShaderGenerator.DefaultSchemeName;

			//Mark system as on
			DetailsPanel.SetParamValue( 11, "On" );

			// a friendly reminder
			var names = new List<string>();
			names.Add( "Help" );
			TrayManager.CreateParamsPanel( TrayLocation.TopLeft, "Help", 100, names ).SetParamValue( 0, "H/F1" );
			UpdateSystemShaders();
		}
Пример #2
0
		private void UpdateLayerBlendingCaption( LayeredBlending.BlendMode nextBlendMode )
		{
			this.layerBlendLabel.Caption = nextBlendMode.ToString();
		}