public void BindTexturesAndSamplers() { GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, _diffuse); Samplers.BindFramebufferTextureSampler(0); GL.ActiveTexture(TextureUnit.Texture1); GL.BindTexture(TextureTarget.Texture2D, _normal); Samplers.BindFramebufferTextureSampler(1); GL.ActiveTexture(TextureUnit.Texture2); GL.BindTexture(TextureTarget.Texture2D, _depth); Samplers.BindFramebufferTextureSampler(2); }
private static void DrawGeometryFramebuffer(WorldServer world, Camera camera, Matrix4 projection, Frustum viewFrustum) { var chunksToDraw = new List <Chunk>(1024); var transparentSortedChunks = new List <Chunk>(1024); var transparentChunks = new List <Chunk>(1024); foreach (var entry in world.LoadedChunks) { //Check if chunk is in player view frustum var chunkMiddle = (entry.Key * Chunk.Size + new Vector3i(Chunk.Size / 2)).ToVector3(); if (!viewFrustum.SpehereIntersection(chunkMiddle, Chunk.Radius)) { continue; } var lengthSq = (camera.Position - chunkMiddle).LengthSquared; if (lengthSq > RenderDistanceSq) { continue; } if (entry.Value.HasTransparency) { if (lengthSq < SortDistanceSq) { entry.Value.SortTransparentFaces(); transparentSortedChunks.Add(entry.Value); } else { transparentChunks.Add(entry.Value); } } else { chunksToDraw.Add(entry.Value); } } //Sort transparent chunks and append to draw list var cameraPos = camera.Position; transparentSortedChunks.Sort((chunk1, chunk2) => (int)((cameraPos - chunk2.Middle).LengthSquared * 1000 - (cameraPos - chunk1.Middle).LengthSquared * 1000)); transparentChunks.AddRange(transparentSortedChunks); chunksToDraw.AddRange(transparentChunks); GL.Enable(EnableCap.CullFace); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); //Grass fix ClientResources.GeometryFramebuffer.Bind(); ClientResources.GeometryFramebuffer.Clear(Color4.DarkBlue); //ClientResources.GeometryFramebuffer.Clear(Color4.Transparent); Breaks transparency ClientResources.WorldGeometryShader.Bind(); GL.UniformMatrix4(4, false, ref camera.View); GL.UniformMatrix4(8, false, ref projection); GL.Uniform1(12, 1); BlockTextureManager.Bind(); Samplers.BindBlockTextureSampler(); //Draw opaque blocks front to back foreach (var chunk in chunksToDraw) { var worldMat = Matrix4.CreateTranslation(chunk.Position.X * Chunk.Size, chunk.Position.Y * Chunk.Size, chunk.Position.Z * Chunk.Size); GL.UniformMatrix4(0, false, ref worldMat); chunk.Draw(); } GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Uniform1(12, 0); //Draw transparent blocks back to front foreach (var chunk in transparentChunks) { var worldMat = Matrix4.CreateTranslation(chunk.Position.X * Chunk.Size, chunk.Position.Y * Chunk.Size, chunk.Position.Z * Chunk.Size); GL.UniformMatrix4(0, false, ref worldMat); chunk.DrawTransparent(); } GL.Disable(EnableCap.Blend); //TODO: Entities PlayerController.Render(camera, projection); ClientResources.GeometryFramebuffer.Unbind(ClientResources.Window.Width, ClientResources.Window.Height); }