public void RenderClouds() { if (!TheClient.CVars.r_clouds.ValueB) { if (Cl_Pos.Count > 0) { Cl_Pos = new List <Vector3>(); Cl_Norm = new List <Vector3>(); Cl_TC = new List <Vector2>(); Cl_Ind = new List <uint>(); } return; } if (ReClouds) { bool forceset = false; if (Cl_VAO == -1) { Cl_VAO = GL.GenVertexArray(); Cl_VBO_Pos = GL.GenBuffer(); Cl_VBO_Norm = GL.GenBuffer(); Cl_VBO_TC = GL.GenBuffer(); Cl_VBO_Tang = GL.GenBuffer(); Cl_VBO_Ind = GL.GenBuffer(); Cl_VBO_Col = GL.GenBuffer(); Cl_VBO_BID1 = GL.GenBuffer(); Cl_VBO_BID2 = GL.GenBuffer(); Cl_VBO_BWE1 = GL.GenBuffer(); Cl_VBO_BWE2 = GL.GenBuffer(); forceset = true; } Cl_Pos.Clear(); Cl_Norm.Clear(); Cl_TC.Clear(); Cl_Ind.Clear(); foreach (Cloud cloud in Clouds) { Location relang = Utilities.VectorToAngles(cloud.Position - TheClient.MainWorldView.CameraPos); Matrix4 mat = Matrix4.CreateRotationY((float)((relang.Y - 90) * Utilities.PI180)) * Matrix4.CreateRotationZ((float)(relang.Z * Utilities.PI180)) * Matrix4.CreateTranslation(ClientUtilities.Convert(cloud.Position)); for (int i = 0; i < cloud.Points.Count; i++) { Matrix4 pmat = Matrix4.CreateTranslation(-0.5f, -0.5f, 0f) * Matrix4.CreateScale(cloud.Sizes[i]) * mat * Matrix4.CreateTranslation(ClientUtilities.Convert(cloud.Points[i])); Matrix4 nmat = pmat; nmat[3, 0] = 0; nmat[3, 1] = 0; nmat[3, 2] = 0; for (uint n = 0; n < 6; n++) { Cl_Ind.Add((uint)Cl_Ind.Count); Cl_Col.Add(Vector4.One); Cl_Norm.Add(Vector4.Transform(nmat, new Vector4(0, 0, 1, 1)).Xyz); Vector4 p = Vector4.Transform(new Vector4(Cl_Vecer[n], 1f), pmat); Cl_Pos.Add(p.Xyz / p.W); Cl_TC.Add(Cl_TCer[n]); } } } Vector3[] pos = Cl_Pos.ToArray(); Vector3[] norm = Cl_Norm.ToArray(); Vector2[] tc = Cl_TC.ToArray(); Vector3[] tang = VBO.TangentsFor(pos, norm, tc); Vector4[] col = Cl_Col.ToArray(); uint[] ind = Cl_Ind.ToArray(); Vector4[] bdata = new Vector4[pos.Length]; for (int i = 0; i < bdata.Length; i++) { bdata[i] = new Vector4(0f, 0f, 0f, 0f); } BufferUsageHint BufferMode = BufferUsageHint.StreamDraw; GL.BindBuffer(BufferTarget.ArrayBuffer, Cl_VBO_Pos); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(pos.Length * Vector3.SizeInBytes), pos, BufferMode); GL.BindBuffer(BufferTarget.ArrayBuffer, Cl_VBO_Norm); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(norm.Length * Vector3.SizeInBytes), norm, BufferMode); GL.BindBuffer(BufferTarget.ArrayBuffer, Cl_VBO_TC); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(tc.Length * Vector2.SizeInBytes), tc, BufferMode); GL.BindBuffer(BufferTarget.ArrayBuffer, Cl_VBO_Tang); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(tang.Length * Vector3.SizeInBytes), tang, BufferMode); GL.BindBuffer(BufferTarget.ArrayBuffer, Cl_VBO_Col); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(col.Length * Vector4.SizeInBytes), col, BufferMode); GL.BindBuffer(BufferTarget.ArrayBuffer, Cl_VBO_BWE1); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(bdata.Length * Vector4.SizeInBytes), bdata, BufferMode); GL.BindBuffer(BufferTarget.ArrayBuffer, Cl_VBO_BID1); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(bdata.Length * Vector4.SizeInBytes), bdata, BufferMode); GL.BindBuffer(BufferTarget.ArrayBuffer, Cl_VBO_BWE2); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(bdata.Length * Vector4.SizeInBytes), bdata, BufferMode); GL.BindBuffer(BufferTarget.ArrayBuffer, Cl_VBO_BID2); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(bdata.Length * Vector4.SizeInBytes), bdata, BufferMode); GL.BindBuffer(BufferTarget.ElementArrayBuffer, Cl_VBO_Ind); GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(ind.Length * sizeof(uint)), ind, BufferMode); if (forceset) { GL.BindVertexArray(Cl_VAO); GL.BindBuffer(BufferTarget.ArrayBuffer, Cl_VBO_Pos); GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 0, 0); GL.BindBuffer(BufferTarget.ArrayBuffer, Cl_VBO_Norm); GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, false, 0, 0); GL.BindBuffer(BufferTarget.ArrayBuffer, Cl_VBO_TC); GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, 0, 0); GL.BindBuffer(BufferTarget.ArrayBuffer, Cl_VBO_Tang); GL.VertexAttribPointer(3, 3, VertexAttribPointerType.Float, false, 0, 0); GL.BindBuffer(BufferTarget.ArrayBuffer, Cl_VBO_Col); GL.VertexAttribPointer(4, 4, VertexAttribPointerType.Float, false, 0, 0); GL.BindBuffer(BufferTarget.ArrayBuffer, Cl_VBO_BWE1); GL.VertexAttribPointer(5, 4, VertexAttribPointerType.Float, false, 0, 0); GL.BindBuffer(BufferTarget.ArrayBuffer, Cl_VBO_BID1); GL.VertexAttribPointer(6, 4, VertexAttribPointerType.Float, false, 0, 0); GL.BindBuffer(BufferTarget.ArrayBuffer, Cl_VBO_BWE2); GL.VertexAttribPointer(7, 4, VertexAttribPointerType.Float, false, 0, 0); GL.BindBuffer(BufferTarget.ArrayBuffer, Cl_VBO_BID2); GL.VertexAttribPointer(8, 4, VertexAttribPointerType.Float, false, 0, 0); GL.EnableVertexAttribArray(0); GL.EnableVertexAttribArray(1); GL.EnableVertexAttribArray(2); GL.EnableVertexAttribArray(3); GL.EnableVertexAttribArray(4); GL.EnableVertexAttribArray(5); GL.EnableVertexAttribArray(6); GL.EnableVertexAttribArray(7); GL.EnableVertexAttribArray(8); GL.BindBuffer(BufferTarget.ElementArrayBuffer, Cl_VBO_Ind); } //ReClouds = false; } TheClient.SetEnts(); TheClient.Textures.GetTexture("effects/clouds/cloud1").Bind(); // TODO: Cache! TheClient.MainWorldView.SetMatrix(2, Matrix4d.Identity); Matrix4 identity = Matrix4.Identity; GL.UniformMatrix4(40, false, ref identity); GL.BindVertexArray(Cl_VAO); GL.DrawElements(PrimitiveType.Triangles, Cl_Ind.Count, DrawElementsType.UnsignedInt, IntPtr.Zero); }