public void Render(Vector4[] frustumPlanes, AssetShader shader) { foreach (var node in Nodes) { node.Render(shader, frustumPlanes); } }
public void Render(AssetShader shader, Vector4[] frustum) { if (!Frustum.CubeInFrustum(frustum, worldPosition, worldSize)) { return; } if (assetsInNode.Count > AssetConfig.SplitCount) { foreach (var node in children) { if (node != null) { node.Render(shader, frustum); } } return; } foreach (var model in AssetConfig.Models) { var placedAssets = assetsInNode.Where(a => a.Model == model.Key).ToList(); if (placedAssets.Any()) { renderAsset(shader, placedAssets.First().Model, placedAssets.Count); } } }
public AssetRenderer() { AssetConfig.Models = new Dictionary <string, Model>(); initializeModels(); shader = new AssetShader(); shadowShader = new ShadowShader(); random = new Random(); assetQuadTree = new AssetQuadTree(); }
private void renderAsset(AssetShader shader, string key, int count) { var model = AssetConfig.Models[key]; foreach (var mesh in model.Meshes) { if (mesh.Material.DoubleSided) { GL.Disable(EnableCap.CullFace); } else { GL.Enable(EnableCap.CullFace); } GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, mesh.Material.BaseColorTexture.TextureId); GL.Uniform1(shader.BaseColorTexture, 0); if (mesh.Material.NormalTexture != null) { GL.ActiveTexture(TextureUnit.Texture1); GL.BindTexture(TextureTarget.Texture2D, mesh.Material.NormalTexture.TextureId); GL.Uniform1(shader.NormalTexture, 1); } if (mesh.Material.RoughnessTexture != null) { GL.ActiveTexture(TextureUnit.Texture2); GL.BindTexture(TextureTarget.Texture2D, mesh.Material.RoughnessTexture.TextureId); GL.Uniform1(shader.RoughnessTexture, 2); GL.Uniform1(shader.Roughness, -1.0f); } else { GL.Uniform1(shader.Roughness, mesh.Material.Roughness); } GL.BindVertexArray(mesh.VaoId); GL.EnableVertexAttribArray(0); GL.EnableVertexAttribArray(1); GL.EnableVertexAttribArray(2); GL.EnableVertexAttribArray(3); GL.EnableVertexAttribArray(4); GL.EnableVertexAttribArray(5); GL.EnableVertexAttribArray(6); GL.BindBuffer(BufferTarget.ArrayBuffer, positionBuffer); GL.VertexAttribPointer(4, 3, VertexAttribPointerType.Float, false, Vector3.SizeInBytes, 0); GL.VertexAttribDivisor(4, 1); GL.BindBuffer(BufferTarget.ArrayBuffer, rotationBuffer); GL.VertexAttribPointer(5, 1, VertexAttribPointerType.Float, false, sizeof(float), 0); GL.VertexAttribDivisor(5, 1); GL.BindBuffer(BufferTarget.ArrayBuffer, scaleBuffer); GL.VertexAttribPointer(6, 1, VertexAttribPointerType.Float, false, sizeof(float), 0); GL.VertexAttribDivisor(6, 1); GL.BindBuffer(BufferTarget.ElementArrayBuffer, mesh.IndexBuffer); GL.DrawElementsInstanced(PrimitiveType.Triangles, mesh.IndexCount, DrawElementsType.UnsignedShort, IntPtr.Zero, count); } GL.Enable(EnableCap.CullFace); GL.BindVertexArray(0); }