public MainVisual(IRenderState renderState, IContentLoader contentLoader) { renderState.Set(BoolState <IDepthState> .Enabled); shaderProgram = contentLoader.Load <IShaderProgram>("shader.*"); var mesh = contentLoader.Load <DefaultMesh>("suzanne.obj"); geometry = VAOLoader.FromMesh(mesh, shaderProgram); //per instance attributes var rnd = new Random(12); float Rnd01() => (float)rnd.NextDouble(); float RndCoord() => (Rnd01() - 0.5f) * 2.0f; var instancePositions = new Vector3[instanceCount]; var velocities = new Vector3[instanceCount]; for (int i = 0; i < instanceCount; ++i) { instancePositions[i] = new Vector3(RndCoord(), RndCoord(), RndCoord() + 1); velocities[i] = new Vector3(RndCoord(), RndCoord(), 0.0f).Normalized() * Rnd01(); } geometry.SetAttribute(shaderProgram.GetResourceLocation(ShaderResourceType.Attribute, "instancePosition"), instancePositions, VertexAttribPointerType.Float, 3, true); geometry.SetAttribute(shaderProgram.GetResourceLocation(ShaderResourceType.Attribute, "velocity"), velocities, VertexAttribPointerType.Float, 3, true); //TODO students: add per instance attribute speed here }
public View(IRenderState renderState, IContentLoader contentLoader) { this.contentLoader = contentLoader; renderer = new PBRRenderer(renderState, contentLoader); cam = new Camera(); currScene = new List <GameObject>(); GameObject weapon = GetPBRModelWithMapPostfix("ceberus", "Cerberus", ".jpg"); currScene.Add(weapon); sceneList.Add(currScene); sceneList.Add(GetSphereSampleScene()); List <GameObject> lighterList = new List <GameObject>(); GameObject lighter = GetPBRModelWithMapPostfix("lighterModel", "Lighter", ".png"); lighter.transform.scale = new Vector3(0.05f); lighter.transform.rotation = new Vector3(-90, 0, 0); lighterList.Add(lighter); sceneList.Add(lighterList); renderer.AddIBLMap("Content/Textures/hdr/Alexs_Apt_2k.hdr"); renderer.AddIBLMap("Content/Textures/hdr/Arches_E_PineTree_3k.hdr"); renderer.AddIBLMap("Content/Textures/hdr/BasketballCourt_3k.hdr"); renderer.SetIBLMap(0); cam.transform.position = new Vector3(0, 0, 1); cam.clippingNear = 0.01f; cam.clippingFar = 10000.0f; cam.fov = 90; cam.projectionMode = Camera.ProjectionMode.Perspective; //fCam = new Camera<FirstPerson, Perspective>(new FirstPerson(new Vector3(0, 0, 1)), new Perspective(farClip:1000.0f)); //fCam.Projection.FieldOfViewY = 60; MouseState mState = Mouse.GetState(); lastMousePos = new Vector2(mState.X, mState.Y); keyStates = new Dictionary <Key, bool>(); }
public View(IContentLoader contentLoader, IRenderState renderState, Dictionary <int, string> tileSprites, List <Grid <int> > gridLayers) { if (contentLoader == null) { throw new ArgumentNullException(nameof(contentLoader)); } if (renderState == null) { throw new ArgumentNullException(nameof(renderState)); } if (tileSprites == null) { throw new ArgumentNullException(nameof(tileSprites)); } renderState.Set(BlendStates.AlphaBlend); foreach (var sprite in tileSprites) { var tex = contentLoader.Load <ITexture2D>(sprite.Value); tex.WrapFunction = TextureWrapFunction.ClampToEdge; tex.Filter = TextureFilterMode.Nearest; texTileSets[sprite.Key] = tex; } layerGrid = gridLayers ?? throw new ArgumentNullException(nameof(gridLayers)); var grid = layerGrid[0]; gridSize = new Vector2(grid.Width, grid.Height); }
public MainVisual(IRenderState renderState, IContentLoader contentLoader) { renderState.Set(new ClearColorState(1, 1, 1, 1)); renderState.Set(new DepthTest(true)); renderState.Set(new FaceCullingModeState(FaceCullingMode.BACK_SIDE)); var envMap = contentLoader.Load <ITexture2D>("beach"); envMap.WrapFunction = TextureWrapFunction.MirroredRepeat; envMap.Filter = TextureFilterMode.Linear; var textureBinding = new TextureBinding[] { new TextureBinding(nameof(envMap), envMap) }; var sphere = Meshes.CreateSphere(1f, 4); var skySphere = sphere.Transform(Transformation.Scale(200f)).SwitchTriangleMeshWinding(); var shaderBackground = contentLoader.Load <IShaderProgram>("background.*"); visuals.Add(new MeshVisual(skySphere, shaderBackground, textureBinding)); #if SOLUTION var shaderEnvMap = contentLoader.Load <IShaderProgram>("envMapping.*"); var visSphere = new MeshVisual(sphere, shaderEnvMap, textureBinding); visSphere.SetUniform("reflective", 1f); visuals.Add(visSphere); var suzanne = contentLoader.Load <DefaultMesh>("suzanne"); var visSuzanne = new MeshVisual(suzanne.Transform(Transformation.Translation(0, -1.5f, 0)), shaderEnvMap, textureBinding); visSuzanne.SetUniform("reflective", 0.4f); visuals.Add(visSuzanne); #endif }
private void DrawShadowSurface(IRenderState renderState, Vector3 lightDirection, ITransformation lightCamera, ITransformation camera, Dictionary <Enums.EntityType, int> instanceCounts, List <Enums.EntityType> disableBackFaceCulling) { _outputSurface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _shadowShader.Activate(); _depthSurface.Texture.WrapFunction = TextureWrapFunction.ClampToEdge; _depthSurface.Texture.Activate(); _shadowShader.Uniform("lightDirection", lightDirection); _shadowShader.Uniform("lightCamera", lightCamera); _shadowShader.Uniform("camera", camera); GL.Uniform1(_shadowShader.GetResourceLocation(ShaderResourceType.Uniform, "lightDepth"), 0); foreach (var type in _geometriesDepth.Keys) { if (disableBackFaceCulling.Contains(type)) { renderState.Set(new BackFaceCulling(false)); } _geometriesShadow[type].Draw(instanceCounts[type]); renderState.Set(new BackFaceCulling(true)); } _depthSurface.Texture.Deactivate(); _shadowShader.Deactivate(); _outputSurface.Deactivate(); }
public UIRenderer(IContentLoader contentLoader, IRenderState renderstate) { this.contentLoader = contentLoader; this.renderstate = renderstate; sceneShader = contentLoader.Load <IShaderProgram>("FullQuad.*"); uiShader = contentLoader.Load <IShaderProgram>("UIElement.*"); }
public Visual(IRenderState renderState) { this.renderState = renderState ?? throw new ArgumentNullException(nameof(renderState)); renderState.Set(BlendStates.AlphaBlend); renderState.Set(new LineSmoothing(true)); GL.Enable(EnableCap.PointSmooth); }
public void Draw(IRenderState renderState, ITexture2D depth, float mipmapLevel = 0) { _geometries[_entity.Type].SetAttribute(_environmentMapProgram.GetResourceLocation(ShaderResourceType.Attribute, "transform"), new[] { _entity.Transform }, true); GL.ClearColor(Color.FromArgb(0, 0, 0, 0)); _outputSurface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _environmentMapProgram.Activate(); _environmentMapProgram.ActivateTexture("cubeMap", 0, _cubeFbo.Texture); _environmentMapProgram.ActivateTexture("depth", 1, depth); _environmentMapProgram.Uniform("camera", _camera); Matrix4x4.Invert(_camera.Matrix, out var invert); _environmentMapProgram.Uniform("camPos", invert.Translation / invert.M44); _environmentMapProgram.Uniform("mipmapLevel", mipmapLevel); _geometries[_entity.Type].Draw(); _environmentMapProgram.DeactivateTexture(0, _cubeFbo.Texture); _environmentMapProgram.DeactivateTexture(1, depth); _environmentMapProgram.Deactivate(); _outputSurface.Deactivate(); GL.ClearColor(Color.FromArgb(0, 0, 0, 1)); }
public void Draw(IRenderState renderState, ITransformation camera, Dictionary <Enums.EntityType, int> instanceCounts, Dictionary <Enums.EntityType, ITexture2D> textures, Dictionary <Enums.EntityType, ITexture2D> normalMaps, List <Enums.EntityType> disableBackFaceCulling) { _outputSurface.Activate(); renderState.Set(new DepthTest(true)); GL.ClearColor(System.Drawing.Color.FromArgb(0, 0, 0, 0)); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.ClearBuffer(ClearBuffer.Color, 2, new float[] { 1000 }); GL.DrawBuffers(4, new[] { DrawBuffersEnum.ColorAttachment0, DrawBuffersEnum.ColorAttachment1, DrawBuffersEnum.ColorAttachment2, DrawBuffersEnum.ColorAttachment3 }); _deferredProgram.Activate(); _deferredProgram.Uniform("camera", camera); Matrix4x4.Invert(camera.Matrix, out var invert); _deferredProgram.Uniform("camPos", invert.Translation / invert.M44); foreach (var type in _geometries.Keys) { if (instanceCounts[type] == 0) { continue; } if (normalMaps.ContainsKey(type)) { _deferredProgram.ActivateTexture("normalMap", 1, normalMaps[type]); } else { _deferredProgram.ActivateTexture("normalMap", 1, _defaultMap); _deferredProgram.Uniform("normalMapping", 0f); _deferredProgram.Uniform("paralaxMapping", 0f); } if (textures.ContainsKey(type)) { _deferredProgram.ActivateTexture("tex", 0, textures[type]); _deferredProgram.Uniform("textured", 1f); } else { _deferredProgram.Uniform("materialColor", System.Drawing.Color.LightGray); _deferredProgram.Uniform("textured", 0f); } renderState.Set(disableBackFaceCulling.Contains(type) ? new BackFaceCulling(false) : new BackFaceCulling(true)); _geometries[type].Draw(instanceCounts[type]); if (textures.ContainsKey(type)) { _deferredProgram.DeactivateTexture(0, textures[type]); } } renderState.Set(new DepthTest(false)); renderState.Set(new BackFaceCulling(true)); _outputSurface.Deactivate(); }
public MainVisual(IRenderState renderState, IContentLoader contentLoader) { renderState.Set(BoolState <IDepthState> .Enabled); renderState.Set(BoolState <IBackfaceCullingState> .Enabled); renderState.Set(BlendStates.AlphaBlend); shaderProgram = contentLoader.Load <IShaderProgram>("phong.*"); var mesh = new DefaultMesh(); var roomSize = 8; //off-center plane var plane = Meshes.CreatePlane(roomSize, roomSize, 2, 2).Transform(new Translation3D(0, -roomSize / 2, 0)); mesh.Add(plane); //rotate plane to create box mesh.Add(plane.Transform(new Rotation3D(Axis.Z, 90f))); mesh.Add(plane.Transform(new Rotation3D(Axis.Z, 180f))); mesh.Add(plane.Transform(new Rotation3D(Axis.Z, 270f))); mesh.Add(plane.Transform(new Rotation3D(Axis.X, 90f))); mesh.Add(plane.Transform(new Rotation3D(Axis.X, -90f))); var sphere = Meshes.CreateSphere(1); sphere.SetConstantUV(new Vector2(0, 0)); mesh.Add(sphere); var suzanne = contentLoader.Load <DefaultMesh>("suzanne"); mesh.Add(suzanne.Transform(new Translation3D(2, 2, -2))); geometry = VAOLoader.FromMesh(mesh, shaderProgram); }
public Renderer(IRenderState renderState, IContentLoader contentLoader) { rendererPoints = new RendererPoints(contentLoader); renderState.Set(BlendStates.Additive); renderState.Set(new PointSprite(true)); renderState.Set(new ShaderPointSize(true)); }
public DeferredRenderer(IContentLoader contentLoader, IRenderState renderState) { renderState.Set <DepthTest>(new DepthTest(true)); GL.Enable(EnableCap.CullFace); GL.Enable(EnableCap.Blend); GL.CullFace(CullFaceMode.Back); this.renderState = renderState; this.contentLoader = contentLoader; deferredParticleShader = contentLoader.Load <IShaderProgram>("deferred_particle.*"); shadowMapShaderParticle = contentLoader.Load <IShaderProgram>("shadowMapParticle.*"); shadowLightViewShaderParticle = contentLoader.Load <IShaderProgram>("shadowLightViewParticle.*"); deferredGeometryShader = contentLoader.Load <IShaderProgram>("deferred_geometry.*"); deferredPost = contentLoader.LoadPixelShader("deferred_post"); pointLightShader = contentLoader.Load <IShaderProgram>("def_pointLight.*"); shadowMapShader = contentLoader.Load <IShaderProgram>("shadowMap.*"); shadowLightViewShader = contentLoader.Load <IShaderProgram>("shadowLightView.*"); var lmesh = Meshes.CreateSphere(1, 2); pointLightSphere = VAOLoader.FromMesh(lmesh, pointLightShader); }
public MainVisual(IRenderState renderState, IContentLoader contentLoader) { renderState.Set(new DepthTest(true)); renderState.Set(new FaceCullingModeState(FaceCullingMode.BACK_SIDE)); shaderProgramPhong = contentLoader.Load <IShaderProgram>("phong.*"); var mesh = new DefaultMesh(); var roomSize = 8; //off-center plane var plane = Meshes.CreatePlane(roomSize, roomSize, 2, 2).Transform(Transformation.Translation(0, -roomSize / 2, 0)); mesh.Add(plane); //rotate plane to create box mesh.Add(plane.Transform(Transformation.Rotation(90f, Axis.Z))); mesh.Add(plane.Transform(Transformation.Rotation(180f, Axis.Z))); mesh.Add(plane.Transform(Transformation.Rotation(270f, Axis.Z))); mesh.Add(plane.Transform(Transformation.Rotation(90f, Axis.X))); mesh.Add(plane.Transform(Transformation.Rotation(-90f, Axis.X))); var sphere = Meshes.CreateSphere(1); sphere.SetConstantUV(Vector2.Zero); //all other meshes have texture coordinates mesh.Add(sphere); var suzanne = contentLoader.Load <DefaultMesh>("suzanne"); mesh.Add(suzanne.Transform(Transformation.Translation(2, 2, -2))); geometryPhong = VAOLoader.FromMesh(mesh, shaderProgramPhong); shaderProgramToon = contentLoader.Load <IShaderProgram>("toon.*"); geometryToon = VAOLoader.FromMesh(suzanne.Transform(Transformation.Translation(2, 0, 0)), shaderProgramToon); }
private MyVisual(IRenderState renderState) { renderState.Set(new DepthTest(true)); //for query to work queryA = new QueryObject(); queryB = new QueryObject(); }
public View(IContentLoader contentLoader, IRenderState renderState, string spriteSheetName) { renderState.Set(BlendStates.AlphaBlend); GL.Enable(EnableCap.Texture2D); texTileSet = contentLoader.Load <ITexture2D>(spriteSheetName); texTileSet.Filter = TextureFilterMode.Nearest; texTileSet.WrapFunction = TextureWrapFunction.ClampToEdge; }
public VisualPlane(IRenderState renderState, IContentLoader contentLoader) { shdPlane = contentLoader.Load <IShaderProgram>("plane.*"); var mesh = Meshes.CreatePlane(2, 2, 1, 1); plane = VAOLoader.FromMesh(mesh, shdPlane); this.renderState = renderState; }
public MainVisual(IRenderState renderState, IContentLoader contentLoader) { renderState.Set(new DepthTest(true)); plane = new VisualPlane(renderState, contentLoader); visualSmoke = new VisualSmoke(Vector3.Zero, new Vector3(.2f, 0, 0), renderState, contentLoader); visualWaterfall = new VisualWaterfall(new Vector3(-.5f, 1, -.5f), renderState, contentLoader); }
public MyVisual(IRenderState renderState, IContentLoader contentLoader) { renderState.Set(new ClearColorState(1, 1, 1, 1)); //background clear color renderState.Set(BlendStates.AlphaBlend); //for transparency in textures we use blending GL.Enable(EnableCap.Texture2D); //TODO: only for non shader pipeline relevant -> remove at some point texBird = contentLoader.Load <ITexture2D>("bird1"); }
public BlendingExample([Import] IRenderState renderState) { //background clear color renderState.Set(new ClearColorState(1, 1, 1, 1)); //setup blending equation Color = Color_new · alpha + Color_before · (1 - alpha) renderState.Set(new BlendState(BlendOperator.Add, BlendParameter.SourceAlpha, BlendParameter.OneMinusSourceAlpha)); //renderState.Set(BlendStates.AlphaBlend); // does the same }
public MainVisual(IRenderState renderState, IContentLoader contentLoader) { InitParticles(); renderState.Set(BlendStates.AlphaBlend); renderState.Set(new ShaderPointSize(true)); renderState.Set(new PointSprite(true)); shaderProgram = contentLoader.Load <IShaderProgram>("particle.*"); }
private MyVisual(IRenderState renderState, IContentLoader contentLoader) { renderState.Set(BlendStates.AlphaBlend); // for transparency in textures we use blending texShip = contentLoader.Load <ITexture2D>("Example.Content.redship4.png"); // fully qualified resource name of the content file texBackground = contentLoader.Load <ITexture2D>("water"); // the short case-insensitive version is also found GL.Enable(EnableCap.Texture2D); }
public RendererGL4(IRenderState renderState, IContentLoader contentLoader) { //for transparency in textures we use blending renderState.Set(BlendStates.AlphaBlend); levelVisual = new VisualLevel(contentLoader); font = new FontGL(contentLoader); }
public PBRRenderer(IRenderState renderState, IContentLoader contentLoader) { iblMapList = new List <IBLSetup>(); GL.Enable(EnableCap.DebugOutput); GL.Enable(EnableCap.TextureCubeMapSeamless); this.renderState = renderState; GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.TextureCubeMap); renderState.Set(new DepthTest(true)); //pbrShader = contentLoader.Load<IShaderProgram>("PBRLightingBasic.*"); pbrShader = contentLoader.Load <IShaderProgram>("PBRLighting.*"); //pbrShader = contentLoader.Load<IShaderProgram>("PBRReference.*"); skyboxShader = contentLoader.Load <IShaderProgram>("Skybox.*"); cubeProjectionShader = contentLoader.Load <IShaderProgram>("CubeMapProjection.*"); textureTest = contentLoader.Load <IShaderProgram>("DisplayTexture2D.*"); irradianceMapShader = contentLoader.Load <IShaderProgram>("IrradianceMap.*"); prefilterMapShader = contentLoader.Load <IShaderProgram>("PrefilterIBLMap.*"); integrationMapShader = contentLoader.Load <IShaderProgram>("BRDFIntegration.*"); dLight = new DirectionalLight(); dLight.direction = new Vector3(0, 1, -1); dLight.color = new Vector3(10); dLight.position = new Vector3(0, 1, -1); Vector3 startPos = new Vector3(0, 0, 0.5f); pointLights = new PointLight[4]; for (int i = 0; i < 4; i++) { pointLights[i] = new PointLight(); pointLights[i].color = new Vector3(1); pointLights[i].radius = 1; pointLights[i].position = startPos; } pointLights[0].position = new Vector3(-1, 1, 0.5f); pointLights[1].position = new Vector3(-1, -1, 0.5f); pointLights[2].position = new Vector3(1, -1, 0.5f); pointLights[3].position = new Vector3(1, 1, 0.5f); int size = System.Runtime.InteropServices.Marshal.SizeOf(typeof(PointLight)) * pointLights.Length; //Generate buffer and allocate memory ubo = GL.GenBuffer(); GL.BindBuffer(BufferTarget.UniformBuffer, ubo); GL.BufferData(BufferTarget.UniformBuffer, size, pointLights, BufferUsageHint.DynamicDraw); //Assign Buffer Block to ubo int uniformID = GL.GetUniformBlockIndex(pbrShader.ProgramID, "BufferPointLights"); GL.UniformBlockBinding(pbrShader.ProgramID, uniformID, 0); GL.BindBufferBase(BufferRangeTarget.UniformBuffer, 0, ubo); DefaultMesh cubeMesh = Meshes.CreateCubeWithNormals(); unitCube = VAOLoader.FromMesh(cubeMesh, cubeProjectionShader); renderState.Set(new FaceCullingModeState(FaceCullingMode.BACK_SIDE)); }
/// <summary> /// Default constructor /// </summary> public SpherePlanetRingRenderer( ) { ITexture2d texture = ( ITexture2d )AssetManager.Instance.Load( "Rings\\ring1.jpg" ); m_Texture = Graphics.Factory.CreateTexture2dSampler( ); m_Texture.Texture = texture; m_State = Graphics.Factory.CreateRenderState( ); m_State.Enable2dTextures = true; }
public MainVisual(IRenderState renderState, IContentLoader contentLoader) { renderState.Set(BlendStates.Additive); renderState.Set(new ShaderPointSize(true)); renderState.Set(new PointSprite(true)); shaderProgram = contentLoader.Load <IShaderProgram>("shader.*"); UpdateGeometry(shaderProgram); }
public MainVisual(IRenderState renderState, IContentLoader contentLoader) { renderState.Set(BlendStates.Additive); renderState.Set(BoolState <IShaderPointSizeState> .Enabled); renderState.Set(BoolState <IPointSpriteState> .Enabled); shaderProgram = contentLoader.Load <IShaderProgram>("shader.*"); UpdateGeometry(shaderProgram); }
public GameVisual(IRenderState renderState, IContentLoader contentLoader) { texBackground = contentLoader.Load <ITexture2D>("background"); texBird = contentLoader.Load <ITexture2D>("bird"); //for transparency in textures we use blending renderState.Set(BlendStates.AlphaBlend); GL.Enable(EnableCap.Texture2D); //TODO: only for non shader pipeline relevant -> remove at some point }
public MainVisual(IRenderState renderState, IContentLoader contentLoader) { renderState.Set(new DepthTest(true)); renderState.Set(new FaceCullingModeState(FaceCullingMode.BACK_SIDE)); shaderProgram = contentLoader.Load <IShaderProgram>("shader.*"); var mesh = contentLoader.Load <DefaultMesh>("suzanne"); geometryBody = VAOLoader.FromMesh(mesh, shaderProgram); }
public TextureExample([Import] IRenderState renderState, [Import] IContentLoader contentLoader) { renderState.Set(BlendStates.AlphaBlend); // for transparency in textures we use blending texShip = contentLoader.Load <ITexture2D>("ExampleBrowser.Content.redship4.png"); // fully qualified resource name of the content file texBackground = contentLoader.Load <ITexture2D>("water"); // the short case-insensitive version is also found texChecker = CreaterCheckerTex(); GL.Enable(EnableCap.Texture2D); }
public MainVisual(IRenderState renderState, IContentLoader contentLoader) { renderState.Set(new DepthTest(true)); shader = contentLoader.Load <IShaderProgram>("TerrainTessellation.*"); shader.Activate(); GL.PatchParameter(PatchParameterInt.PatchVertices, 4); }
public MainVisual(IRenderState renderState, IContentLoader contentLoader) { renderState.Set(BoolState <IDepthState> .Enabled); plane = new VisualPlane(renderState, contentLoader); visualSmoke = new VisualSmoke(Vector3.Zero, new Vector3(.2f, 0, 0), renderState, contentLoader); visualWaterfall = new VisualWaterfall(new Vector3(-.5f, 1, -.5f), renderState, contentLoader); visualExplosion = new VisualExplosion(new Vector3(0f, 1, 0f), renderState, contentLoader); }
public TextureForm( string filePath ) { InitializeComponent( ); m_RenderState = Graphics.Factory.CreateRenderState( ); m_RenderState.Enable2dTextures = true; m_RenderState.Enable2dTextureUnit( 0, true ); m_RenderState.Colour = Color.Red; m_FilePath = filePath; }
/// <summary> /// Setup constructor /// </summary> /// <param name="fontData">Font data</param> public OpenGlFont( FontData fontData ) { m_RenderState = Graphics.Factory.CreateRenderState( ); m_RenderState.DepthTest = false; m_RenderState.Blend = true; m_RenderState.SourceBlend = BlendFactor.SrcAlpha; m_RenderState.DestinationBlend = BlendFactor.OneMinusSrcAlpha; m_RenderState.FaceRenderMode = PolygonRenderMode.Fill; m_RenderState.Enable2dTextures = true; m_RenderState.Lighting = false; Setup( fontData.Font, fontData.Characters ); }
public PlanetTerrainRenderer( ) { IEffect effect = ( IEffect )AssetManager.Instance.Load( "Effects/Planets/terrestrialPlanetTerrain.cgfx" ); TechniqueSelector selector = new TechniqueSelector( effect, "DefaultTechnique" ); m_PlanetTerrainTechnique = selector; float hDim = 1; Point3[] cubePoints = new Point3[] { new Point3( -hDim, -hDim, -hDim ), new Point3( +hDim, -hDim, -hDim ), new Point3( +hDim, +hDim, -hDim ), new Point3( -hDim, +hDim, -hDim ), new Point3( -hDim, -hDim, +hDim ), new Point3( +hDim, -hDim, +hDim ), new Point3( +hDim, +hDim, +hDim ), new Point3( -hDim, +hDim, +hDim ), }; int res = 3; int defaultLodLevel = 0; CubeSide[] sides = new CubeSide[ ] { new CubeSide( res, cubePoints[ 0 ], cubePoints[ 1 ], cubePoints[ 3 ], defaultLodLevel, true ), // -z new CubeSide( res, cubePoints[ 7 ], cubePoints[ 6 ], cubePoints[ 4 ], defaultLodLevel, true ), // +z new CubeSide( res, cubePoints[ 4 ], cubePoints[ 5 ], cubePoints[ 0 ], defaultLodLevel, true ), // +y new CubeSide( res, cubePoints[ 6 ], cubePoints[ 7 ], cubePoints[ 2 ], defaultLodLevel, true ), // -y new CubeSide( res, cubePoints[ 0 ], cubePoints[ 3 ], cubePoints[ 4 ], defaultLodLevel, true ), // -x new CubeSide( res, cubePoints[ 5 ], cubePoints[ 6 ], cubePoints[ 1 ], defaultLodLevel, true ) // +x }; foreach ( CubeSide side in sides ) { side.PreBuild( m_Builder ); foreach ( TerrainPatch patch in side.TerrainPatches ) { m_Patches.Add( patch ); } } // Arrange patches in a spiral, with the centre patch on side -y at position 0 //int ringSize = 1; //CubeSide bottomSide = sides[ 3 ]; //for ( int offsetFromCentre = 0; offsetFromCentre < res; ++offsetFromCentre ) //{ // if ( offsetFromCentre == 0 ) // { // continue; // } // int start = ( res / 2 ) - offsetFromCentre; // ringSize += 2; //} //int[] cubeSides = new int[] // { // 0, 1, 3, // -z // 7, 6, 4, // +z // 4, 5, 0, // +y // 6, 7, 2, // -y // 0, 3, 4, // -x // 5, 6, 1 // +x // }; //int[] sideConnections = new int[] // { // // Left Top Right Bottom // 4, 2, 5, 3, // Side 0 (-z) // // 0, 0, 0, 0, // Side 1 (+z) // // 0, 0, 0, 0, // Side 2 (+y) // // 0, 0, 0, 0, // Side 3 (-y) // // 0, 0, 0, 0, // Side 4 (-x) // // 0, 0, 0, 0, // Side 5 (+x) // }; // for ( int side = 0; side < cubeSides.Length / 3; ++side ) //for ( int side = 0; side < 1; ++side ) //{ // CubeSide leftSide = sides[ sideConnections[ side * 4 ] ]; // CubeSide topSide = sides[ sideConnections[ side * 4 + 1 ] ]; // CubeSide rightSide = sides[ sideConnections[ side * 4 + 2 ] ]; // CubeSide bottomSide = sides[ sideConnections[ side * 4 + 3 ] ]; // sides[ side ].Link( leftSide, topSide, rightSide, bottomSide ); //} foreach ( CubeSide side in sides ) { side.Build( m_Builder ); } m_PatchRenderState = Graphics.Factory.CreateRenderState( ); m_PatchRenderState.DepthTest = true; m_PatchRenderState.DepthWrite = true; m_PatchRenderState.CullBackFaces = true; m_PatchRenderState.FaceRenderMode = PolygonRenderMode.Lines; }
/// <summary> /// Pushes a new render state, and applies it /// </summary> public void PushRenderState( IRenderState state ) { m_RenderStates.Add( state ); state.Begin( ); }
/// <summary> /// Renders the grid as a texture /// </summary> private void RenderTexture( ) { if ( m_TextureState == null ) { m_TextureState = Graphics.Factory.CreateRenderState( ); m_TextureState.Lighting = false; m_TextureState.Enable2dTextures = true; m_TextureState.Enable2dTextureUnit(0, true ); ITexture2d texture = Graphics.Factory.CreateTexture2d( ); texture.Load( GridSquareBitmap, true, TextureUsage.Normal ); m_Sampler = Graphics.Factory.CreateTexture2dSampler( ); m_Sampler.Texture = texture; m_Sampler.Mode = TextureMode.Replace; m_Sampler.MinFilter = TextureFilter.NearestTexelLinearMipMap; m_Sampler.MagFilter = TextureFilter.NearestTexelLinearMipMap; m_Sampler.WrapS = TextureWrap.Repeat; m_Sampler.WrapT = TextureWrap.Repeat; } // For the moment, let's just render a giant quad with a texture :( // TODO: AP: Render a grid of quads centered on the camera position projected onto the ground plane Graphics.Renderer.PushRenderState( m_TextureState ); m_Sampler.Begin( ); Gl.glBegin( Gl.GL_QUADS ); Gl.glTexCoord2f( MinU, MinV ); Gl.glVertex3f( MinX, Y, MinZ ); Gl.glTexCoord2f( MaxU, MinV ); Gl.glVertex3f( MaxX, Y, MinZ ); Gl.glTexCoord2f( MaxU, MaxV ); Gl.glVertex3f( MaxX, Y, MaxZ ); Gl.glTexCoord2f( MinU, MaxV ); Gl.glVertex3f( MinX, Y, MaxZ ); Gl.glEnd( ); m_Sampler.End( ); Graphics.Renderer.PopRenderState( ); }