private void DrawModel(GLControl control, SOBJWrapper m, CMDLWrapper mdl, ShaderProgram shader, bool drawSelection) { if (m.lodMeshes[m.DisplayLODIndex].faces.Count <= 3) { return; } SetUniforms(m.MaterialWrapper, shader, m, m.DisplayId); SetUniformBlocks(m.MaterialWrapper, shader, m, m.DisplayId); SetBoneUniforms(control, shader, mdl, m); SetVertexAttributes(m, shader); SetTextureUniforms(m.MaterialWrapper, m, shader); if ((m.IsSelected)) { DrawModelSelection(m, shader); } else { if (Runtime.RenderModels) { GL.DrawElements(PrimitiveType.Triangles, m.lodMeshes[m.DisplayLODIndex].displayFaceSize, DrawElementsType.UnsignedInt, m.Offset); } } }
private static void SetTextureUniforms(MTOBWrapper mat, SOBJWrapper m, ShaderProgram shader) { SetDefaultTextureAttributes(mat, shader); GL.ActiveTexture(TextureUnit.Texture0 + 1); GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.RenderableTex.TexID); GL.Uniform1(shader["debugOption"], 2); GL.ActiveTexture(TextureUnit.Texture11); GL.Uniform1(shader["weightRamp1"], 11); GL.BindTexture(TextureTarget.Texture2D, RenderTools.BoneWeightGradient.Id); GL.ActiveTexture(TextureUnit.Texture12); GL.Uniform1(shader["weightRamp2"], 12); GL.BindTexture(TextureTarget.Texture2D, RenderTools.BoneWeightGradient2.Id); GL.ActiveTexture(TextureUnit.Texture10); GL.Uniform1(shader["UVTestPattern"], 10); GL.BindTexture(TextureTarget.Texture2D, RenderTools.uvTestPattern.RenderableTex.TexID); foreach (STGenericMatTexture matex in mat.TextureMaps) { if (matex.Type == STGenericMatTexture.TextureType.Diffuse) { TextureUniform(shader, mat, true, "DiffuseMap", matex); } } }
public void LoadModel(Model model, BCRES bcres) { BcresParent = bcres; Model = model; Text = model.Name; var MaterialFolder = new TreeNode("Materials"); var MeshFolder = new TreeNode("Meshes"); Skeleton = new CRESSkeletonWrapper(); Skeleton.Text = "Skeleton"; Checked = true; Nodes.Add(MeshFolder); Nodes.Add(MaterialFolder); Nodes.Add(Skeleton); if (model.HasSkeleton) { Skeleton.Load(model.Skeleton, bcres); } int Index = 0; foreach (var material in model.Materials.Values) { var matWrapper = new MTOBWrapper(); matWrapper.Load(bcres, material); if (matWrapper.Text == string.Empty) { matWrapper.Text = $"Material {Index++}"; } MaterialFolder.Nodes.Add(matWrapper); Materials.Add(matWrapper); } Index = 0; foreach (var mesh in model.Meshes) { var meshWrapper = new SOBJWrapper(this, mesh) { BcresParent = bcres }; MeshFolder.Nodes.Add(meshWrapper); if (meshWrapper.Text == string.Empty) { meshWrapper.Text = $"Mesh {Index++}"; } Shapes.Add(meshWrapper); } }
private void SetVertexAttributes(SOBJWrapper m, ShaderProgram shader) { GL.BindBuffer(BufferTarget.ArrayBuffer, vbo_position); GL.VertexAttribPointer(shader.GetAttribute("vPosition"), 3, VertexAttribPointerType.Float, false, SOBJWrapper.DisplayVertex.Size, 0); //+12 GL.VertexAttribPointer(shader.GetAttribute("vNormal"), 3, VertexAttribPointerType.Float, false, SOBJWrapper.DisplayVertex.Size, 12); //+12 GL.VertexAttribPointer(shader.GetAttribute("vTangent"), 3, VertexAttribPointerType.Float, false, SOBJWrapper.DisplayVertex.Size, 24); //+12 GL.VertexAttribPointer(shader.GetAttribute("vUV0"), 2, VertexAttribPointerType.Float, false, SOBJWrapper.DisplayVertex.Size, 36); //+8 GL.VertexAttribPointer(shader.GetAttribute("vColor"), 4, VertexAttribPointerType.Float, false, SOBJWrapper.DisplayVertex.Size, 44); //+16 GL.VertexAttribIPointer(shader.GetAttribute("vBone"), 4, VertexAttribIntegerType.Int, SOBJWrapper.DisplayVertex.Size, new IntPtr(60)); //+16 GL.VertexAttribPointer(shader.GetAttribute("vWeight"), 4, VertexAttribPointerType.Float, false, SOBJWrapper.DisplayVertex.Size, 76); //+16 GL.VertexAttribPointer(shader.GetAttribute("vUV1"), 2, VertexAttribPointerType.Float, false, SOBJWrapper.DisplayVertex.Size, 92); //+8 GL.VertexAttribPointer(shader.GetAttribute("vUV2"), 2, VertexAttribPointerType.Float, false, SOBJWrapper.DisplayVertex.Size, 100); //+8 GL.BindBuffer(BufferTarget.ElementArrayBuffer, ibo_elements); }
private void SetUniformBlocks(MTOBWrapper mat, ShaderProgram shader, SOBJWrapper m, int id) { /* shader.UniformBlockBinding("TexCoord1", 3); * GL.GetActiveUniformBlock(shader.program, * shader.GetUniformBlockIndex("TexCoord1"), * ActiveUniformBlockParameter.UniformBlockBinding, out int binding);*/ /* GL.BindBuffer(BufferTarget.UniformBuffer, TexCoord1Buffer); * GL.BufferData(BufferTarget.UniformBuffer, * (IntPtr)MTOBWrapper.TexCoord1.Size, * ref mat.TexCoord1Buffer, * BufferUsageHint.StaticDraw); * GL.BindBuffer(BufferTarget.UniformBuffer, 0); * GL.BindBufferRange(BufferRangeTarget.UniformBuffer, 0, TexCoord1Buffer, (IntPtr)0, * MTOBWrapper.TexCoord1.Size); * GL.BindBuffer(BufferTarget.UniformBuffer, TexCoord1Buffer); * GL.BINDBUFFER*/ }
private static void SetBoneUniforms(ShaderProgram shader, CMDLWrapper fmdl, SOBJWrapper fshp) { foreach (var FaceGroup in fshp.Shape.FaceGroups) { if (FaceGroup.BoneIndexList == null) { continue; } for (int i = 0; i < FaceGroup.BoneIndexList.Length; i++) { GL.Uniform1(GL.GetUniformLocation(shader.program, String.Format("boneIds[{0}]", i)), FaceGroup.BoneIndexList[i]); Matrix4 transform = fmdl.Skeleton.Renderable.bones[(int)FaceGroup.BoneIndexList[i]].invert * fmdl.Skeleton.Renderable.bones[(int)FaceGroup.BoneIndexList[i]].Transform; GL.UniformMatrix4(GL.GetUniformLocation(shader.program, String.Format("bones[{0}]", i)), false, ref transform); } } }
private static void SetUniforms(MTOBWrapper mat, ShaderProgram shader, SOBJWrapper m, int id) { shader.SetBoolToInt("RigidSkinning", m.Shape.FaceGroups[0].SkinnningMode == BcresLibrary.Enums.SkinnningMode.Rigid); shader.SetBoolToInt("NoSkinning", m.Shape.FaceGroups[0].SkinnningMode == BcresLibrary.Enums.SkinnningMode.None); }