public Planet(Camera c, CubemapTexture elevationMap) { myCamera = c; myNoiseTexture = elevationMap; for (int i = 0; i < MAX_TRI; i++) { myTris.Add(new Tri()); } myFov = MathHelper.DegreesToRadians(myCamera.fieldOfView); mySinFov = (float)Math.Sin(myFov); myCosFov = (float)Math.Cos(myFov); init(); myTextureManager.init(); //setup the shader List <ShaderDescriptor> desc = new List <ShaderDescriptor>(); desc.Add(new ShaderDescriptor(ShaderType.VertexShader, "Test IcoPlanet.shaders.draw-planet-vs.glsl")); //desc.Add(new ShaderDescriptor(ShaderType.GeometryShader, "Test IcoPlanet.shaders.draw-planet-gs.glsl")); desc.Add(new ShaderDescriptor(ShaderType.FragmentShader, "Test IcoPlanet.shaders.draw-planet-ps.glsl")); ShaderProgramDescriptor sd = new ShaderProgramDescriptor(desc); ShaderProgram shader = Renderer.resourceManager.getResource(sd) as ShaderProgram; myRenderPlanetCommand = new StatelessDrawElementsCommand(PrimitiveType.Triangles, (int)myIndexCount, 0, IndexBufferObject.IndexBufferDatatype.UnsignedInt); myRenderPlanetCommand.pipelineState.shaderState.shaderProgram = shader; myRenderPlanetCommand.pipelineState.vaoState.vao = new VertexArrayObject(); myRenderPlanetCommand.pipelineState.vaoState.vao.bindVertexFormat(shader, V3F1.bindings()); myRenderPlanetCommand.pipelineState.generateId(); desc.Clear(); desc.Add(new ShaderDescriptor(ShaderType.VertexShader, "Test IcoPlanet.shaders.planet-water-vs.glsl")); desc.Add(new ShaderDescriptor(ShaderType.FragmentShader, "Test IcoPlanet.shaders.planet-water-ps.glsl")); sd = new ShaderProgramDescriptor(desc); shader = Renderer.resourceManager.getResource(sd) as ShaderProgram; myRenderWaterCommand = new StatelessDrawElementsCommand(PrimitiveType.Triangles, (int)myIndexCount, 0, IndexBufferObject.IndexBufferDatatype.UnsignedInt); myRenderWaterCommand.pipelineState.shaderState.shaderProgram = shader; myRenderWaterCommand.pipelineState.vaoState.vao = new VertexArrayObject(); myRenderWaterCommand.pipelineState.vaoState.vao.bindVertexFormat(shader, V3F1.bindings()); myRenderWaterCommand.pipelineState.blending.enabled = true; myRenderWaterCommand.pipelineState.generateId(); myHeightTexture = new Texture("../data/textures/EarthLookupTable.png"); }
void subdivideTri(Tri t) { if (shouldSplit(t) == false) { return; } Vector3d v1, v2, v3; Vector3d t1, t2, t3; uint i12, i23, i31; V3F1 v12 = new V3F1(); V3F1 v23 = new V3F1(); V3F1 v31 = new V3F1(); //get existing verts v1 = myVerts[t.i1].Position; v2 = myVerts[t.i2].Position; v3 = myVerts[t.i3].Position; //work with normalized positions v1.Normalize(); v2.Normalize(); v3.Normalize(); //new verts between the existing verts t1 = (v1 + v2) / 2; t2 = (v2 + v3) / 2; t3 = (v3 + v1) / 2; //push out to unit sphere t1.Normalize(); t2.Normalize(); t3.Normalize(); v12.Position = t1 * myScale; v23.Position = t2 * myScale; v31.Position = t3 * myScale; //set the height v12.Depth = (float)t.id.depth; //TextureManager.heightAt(v12.Position); v23.Depth = (float)t.id.depth; //TextureManager.heightAt(v23.Position); v31.Depth = (float)t.id.depth; //TmyTextureManager.heightAt(v31.Position); //get the new vertex indexes i12 = myVertCount++; i23 = myVertCount++; i31 = myVertCount++; //add new verts to vert buffer at the new indexes myVerts[i12] = v12; myVerts[i23] = v23; myVerts[i31] = v31; //create new triangles t.c1 = createTriangle(t, 0, i12, i23, i31); t.c2 = createTriangle(t, 1, t.i1, i12, i31); t.c3 = createTriangle(t, 2, i12, t.i2, i23); t.c4 = createTriangle(t, 3, i23, t.i3, i31); mySplitQueue.Enqueue(t.c1); mySplitQueue.Enqueue(t.c2); mySplitQueue.Enqueue(t.c3); mySplitQueue.Enqueue(t.c4); }