private void RenderSky(EffectWrapper pEffect, EffectPass pEffectPass) { ModelMeshPart meshPart = m_pSkyDomeModel.Meshes[0].MeshParts[0]; pEffect.GraphicsDevice.Indices = meshPart.IndexBuffer; pEffect.GraphicsDevice.SetVertexBuffer(meshPart.VertexBuffer, meshPart.VertexOffset); pEffect.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, meshPart.VertexOffset, 0, meshPart.NumVertices, meshPart.StartIndex, meshPart.PrimitiveCount); }
protected override void LoadContent() { m_pGraphicsDevice = this.GraphicsDevice; m_pEffect = new EffectWrapper(this.Game, m_pGraphicsDevice, @"Effects\Terrain"); m_pElevationData = new ElevationData(this.Game, m_pGraphicsDevice, @"Content\Terrains\SimpleLoop"); for (int i = 0, length = m_pLevels.Length; i < length; i++) { Level pLevel = m_pLevels[i]; Level pNextFinerLevel = null, pNextCoarserLevel = null; if (i != length - 1) pNextFinerLevel = m_pLevels[i + 1]; if (i > 0) pNextCoarserLevel = m_pLevels[i - 1]; pLevel.Create(m_pGraphicsDevice, pNextFinerLevel, pNextCoarserLevel, (IntVector2) m_pViewer.Position2D); } foreach (Level pLevel in m_pLevels) { pLevel.Create2(m_pGraphicsDevice); } m_pSky.Create(m_pGraphicsDevice); m_pTextFont = Game.Content.Load<SpriteFont>(@"Fonts\LucidaConsole"); m_pLevelHeightMap = new SpriteBatch(m_pGraphicsDevice); m_pGrassTexture = Game.Content.Load<Texture2D>(@"Terrains\Grass"); base.LoadContent(); }
private void RenderInteriorTrim(EffectWrapper pEffect, EffectPass pEffectPass) { pEffect.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, // base vertex 0, // min vertex index Settings.INTERIOR_TRIM_NUM_VERTICES, // total num vertices - note that is NOT just vertices that are indexed, but all vertices 0, // start index Settings.INTERIOR_TRIM_NUM_PRIMITIVES); // primitive count }
public override void Render(EffectWrapper pEffect) { pEffect.GraphicsDevice.SetVertexBuffer(m_pSharedVertexBuffers[(int) m_eActiveInteriorTrim]); pEffect.GraphicsDevice.Indices = m_pSharedIndexBuffer; // set offset (scaling should be done in level) pEffect.SetValue("ScaleFactor", m_tScaleFactor); pEffect.Render(new RenderCallback(RenderInteriorTrim)); }
public void Create(GraphicsDevice pGraphicsDevice) { m_pSkyDomeModel = AssetLoader.LoadAsset<Model>(@"Models\SkyUnitDome", m_pGame, pGraphicsDevice); m_pEffect = new EffectWrapper(m_pGame, pGraphicsDevice, @"Effects\Sky"); }
public override void Render(EffectWrapper pEffect) { pEffect.GraphicsDevice.SetVertexBuffer(m_pSharedVertexBuffer); pEffect.GraphicsDevice.Indices = m_pSharedIndexBuffer; // set offset (scaling should be done in level) pEffect.SetValue("ScaleFactor", m_tScaleFactor); pEffect.Render(new RenderCallback(RenderRingFixups)); }
public void Render(EffectWrapper pEffect, EffectPass pEffectPass) { if (m_bVisible) { pEffect.SetValue("FineBlockOrig", m_tFineBlockOrig); pEffect.SetValue("FineBlockOrig2", m_tFineBlockOrig2); pEffect.SetValue("ScaleFactor", m_tScaleFactor); pEffectPass.Apply(); // render pEffect.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, // base vertex 0, // min vertex index Settings.BLOCK_NUM_VERTICES, // total num vertices - note that is NOT just vertices that are indexed, but all vertices 0, // start index Settings.BLOCK_NUM_PRIMITIVES); // primitive count } }
public abstract void Render(EffectWrapper pEffect);
private void RenderCentreBlocks(EffectWrapper pEffect, EffectPass pEffectPass) { foreach (Block pBlock in m_pCentreBlocks) { pBlock.Render(pEffect, pEffectPass); } }
public void Render(EffectWrapper pEffect) { // apply vertex texture pEffect.SetValue("ElevationTexture", m_pElevationTexture); pEffect.SetValue("ViewerPos", (m_pParentTerrain.Viewer.Position2D - m_tPositionMin) / m_nGridSpacing); pEffect.SetValue("AlphaOffset", Settings.AlphaOffset); pEffect.SetValue("OneOverWidth", Settings.TransitionWidthInverse); pEffect.SetValue("GridSize", Settings.GRID_SIZE_N); pEffect.SetValue("GrassTexture", m_pParentTerrain.GrassTexture); pEffect.SetValue("NormalMapTexture", m_pNormalMapTexture); Vector2 tCoarserGridPosMin = new Vector2(); if (m_pNextCoarserLevel != null) tCoarserGridPosMin = m_pNextCoarserLevel.InteriorTrim.CoarserGridPosMin; pEffect.SetValue("CoarserNormalMapTextureOffset", tCoarserGridPosMin); pEffect.SetValue("CoarserNormalMapTexture", (m_pNextCoarserLevel != null) ? m_pNextCoarserLevel.NormalMapTexture : null); pEffect.SetValue("NormalMapTextureSizeInverse", Settings.NORMAL_MAP_TEXTURE_SIZE_INVERSE); pEffect.SetValue("NormalMapTextureSize", Settings.NORMAL_MAP_TEXTURE_SIZE); pEffect.SetValue("LightDirection", Vector3.Normalize(new Vector3(0.0f, 0.0f, 1))); Vector2 tToroidalOriginScaled = (Vector2) m_tToroidalOrigin / (float) Settings.ELEVATION_TEXTURE_SIZE; Vector2 tGridSizeScaled = new Vector2(((float) Settings.GRID_SIZE_N / (float) Settings.ELEVATION_TEXTURE_SIZE)); pEffect.SetValue("ToroidalOffsets", new Vector4(tToroidalOriginScaled, tGridSizeScaled.X, tGridSizeScaled.Y)); pEffect.SetValue("ElevationTextureSize", Settings.ELEVATION_TEXTURE_SIZE); #region Render blocks pEffect.SetValue("Shading", new Vector4(0.7f, 0.0f, 0.0f, 1.0f)); // we set the vertices and indices here because they are the same for all blocks pEffect.GraphicsDevice.SetVertexBuffer(Block.SharedVertexBuffer); pEffect.GraphicsDevice.Indices = Block.SharedIndexBuffer; pEffect.Render(new RenderCallback(RenderBlocks)); #endregion #region Render ring fix-ups pEffect.SetValue("FineBlockOrig", new Vector4(Settings.ELEVATION_TEXTURE_SIZE_INVERSE, Settings.ELEVATION_TEXTURE_SIZE_INVERSE, 0.0f, 0.0f)); pEffect.SetValue("FineBlockOrig2", Vector2.Zero); pEffect.SetValue("Shading", new Vector4(0.0f, 0.7f, 0.0f, 1.0f)); m_pRingFixups.Render(pEffect); #endregion #region Render interior trim pEffect.SetValue("FineBlockOrig", new Vector4(Settings.ELEVATION_TEXTURE_SIZE_INVERSE, Settings.ELEVATION_TEXTURE_SIZE_INVERSE, 0.0f, 0.0f)); pEffect.SetValue("FineBlockOrig2", Vector2.Zero); pEffect.SetValue("Shading", new Vector4(0.0f, 0.0f, 0.7f, 1.0f)); m_pInteriorTrim.Render(pEffect); #endregion #region Render centre blocks for finest level if (m_bFinestLevel) { pEffect.SetValue("Shading", new Vector4(0.7f, 0.7f, 0.0f, 1.0f)); // we set the vertices and indices here because they are the same for all blocks pEffect.GraphicsDevice.SetVertexBuffer(Block.SharedVertexBuffer); pEffect.GraphicsDevice.Indices = Block.SharedIndexBuffer; pEffect.Render(new RenderCallback(RenderCentreBlocks)); pEffect.SetValue("FineBlockOrig", new Vector4(Settings.ELEVATION_TEXTURE_SIZE_INVERSE, Settings.ELEVATION_TEXTURE_SIZE_INVERSE, 0.0f, 0.0f)); pEffect.SetValue("FineBlockOrig2", Vector2.Zero); pEffect.SetValue("Shading", new Vector4(0.0f, 0.0f, 0.7f, 1.0f)); m_pCentreInteriorTrim.Render(pEffect); } #endregion #region Render edge stitches pEffect.SetValue("FineBlockOrig", new Vector4(Settings.ELEVATION_TEXTURE_SIZE_INVERSE, Settings.ELEVATION_TEXTURE_SIZE_INVERSE, 0.0f, 0.0f)); pEffect.SetValue("FineBlockOrig2", Vector2.Zero); pEffect.SetValue("Shading", new Vector4(0.7f, 0.7f, 0.0f, 1.0f)); m_pEdgeStitches.Render(pEffect); #endregion }
private void RenderNormalMapTexture(EffectWrapper pEffect, EffectPass pEffectPass) { float fMinVertexX = 0.0f; float fMaxVertexX = Settings.NORMAL_MAP_TEXTURE_SIZE - 1; float fMinVertexY = fMaxVertexX; float fMaxVertexY = 0.0f; TextureVertex[] pVertices = new TextureVertex[4]; // (-1, -1) pVertices[0] = new TextureVertex(new Vector2(fMinVertexX, fMinVertexY)); // (-1, 1) pVertices[1] = new TextureVertex(new Vector2(fMinVertexX, fMaxVertexY)); // (1, -1) pVertices[2] = new TextureVertex(new Vector2(fMaxVertexX, fMinVertexY)); // (1, 1) pVertices[3] = new TextureVertex(new Vector2(fMaxVertexX, fMaxVertexY)); pEffect.GraphicsDevice.DrawUserPrimitives<TextureVertex>( PrimitiveType.TriangleStrip, pVertices, 0, 2); }
private static void RenderElevationTexture(EffectWrapper pEffect, EffectPass pEffectPass) { float fMinVertexX = 0.0f; float fMaxVertexX = Settings.ELEVATION_TEXTURE_SIZE; float fMinVertexY = Settings.ELEVATION_TEXTURE_SIZE; float fMaxVertexY = 0.0f; TextureVertex[] pVertices = new TextureVertex[4]; // (-1, -1) pVertices[0] = new TextureVertex(new Vector2(fMinVertexX, fMinVertexY)); // (-1, 1) pVertices[1] = new TextureVertex(new Vector2(fMinVertexX, fMaxVertexY)); // (1, -1) pVertices[2] = new TextureVertex(new Vector2(fMaxVertexX, fMinVertexY)); // (1, 1) pVertices[3] = new TextureVertex(new Vector2(fMaxVertexX, fMaxVertexY)); pEffect.GraphicsDevice.DrawUserPrimitives<TextureVertex>( PrimitiveType.TriangleStrip, pVertices, 0, 2); }
public void Create(GraphicsDevice pGraphicsDevice, Level pNextFinerLevel, Level pNextCoarserLevel, IntVector2 tViewerPosition2D) { foreach (Block pBlock in m_pBlocks) { pBlock.Create(pGraphicsDevice); } m_pRingFixups.Create(pGraphicsDevice); m_pInteriorTrim.Create(pGraphicsDevice); foreach (Block pBlock in m_pCentreBlocks) { pBlock.Create(pGraphicsDevice); } m_pCentreInteriorTrim.Create(pGraphicsDevice); m_pEdgeStitches.Create(pGraphicsDevice); m_pNextFinerLevel = pNextFinerLevel; m_pNextCoarserLevel = pNextCoarserLevel; // set initial min position of level IntVector2 tViewerPosGridCoords = (tViewerPosition2D - m_tPositionMin) / m_nGridSpacing; IntVector2 tDeltaPositionTemp1 = tViewerPosGridCoords - Settings.CentralSquareMin; IntVector2 tDeltaPositionTemp2 = new IntVector2(Math.Abs(tDeltaPositionTemp1.X), Math.Abs(tDeltaPositionTemp1.Y)); IntVector2 tDeltaPositionTemp3 = tDeltaPositionTemp1 - (tDeltaPositionTemp2 % 2); m_tPositionMin += tDeltaPositionTemp3 * m_nGridSpacing; m_pElevationTexture = new RenderTarget2D(pGraphicsDevice, Settings.ELEVATION_TEXTURE_SIZE, Settings.ELEVATION_TEXTURE_SIZE, false, SurfaceFormat.Vector2, DepthFormat.None); m_pNormalMapTexture = new RenderTarget2D(pGraphicsDevice, Settings.NORMAL_MAP_TEXTURE_SIZE, Settings.NORMAL_MAP_TEXTURE_SIZE, false, SurfaceFormat.HalfVector2, DepthFormat.None); m_pNormalMapUpdateEffect = new EffectWrapper(m_pParentTerrain.ParentGame, pGraphicsDevice, @"Effects\ComputeNormals"); m_pElevationUpdateEffect = new EffectWrapper(m_pParentTerrain.ParentGame, pGraphicsDevice, @"Effects\UpdateElevation"); }