Ejemplo n.º 1
0
        private static void SetUniforms(GFLXMaterialData mat, ShaderProgram shader, GFLXMesh m, int id)
        {
            // Texture Maps

            /*  shader.SetBoolToInt("useColorTex", false);
             * shader.SetBoolToInt("EmissionMaskUse", false);
             * shader.SetBoolToInt("SwitchPriority", false);
             * shader.SetBoolToInt("Layer1Enable", false);
             * shader.SetBoolToInt("AmbientMapEnable", false);
             * shader.SetBoolToInt("NormalMapEnable", false);
             * shader.SetBoolToInt("LightTableEnable", false);
             * shader.SetBoolToInt("BaseColorAddEnable", false);
             * shader.SetBoolToInt("SphereMapEnable", false);
             * shader.SetBoolToInt("EffectVal", false);*/

            //Switch UVs
            shader.SetBoolToInt("SwitchEmissionMaskTexUV", false);
            shader.SetBoolToInt("SwitchAmbientTexUV", false);
            shader.SetBoolToInt("SwitchNormalMapUV", false);

            //UV Scale
            shader.SetFloat("ColorUVScaleU", 1);
            shader.SetFloat("ColorUVScaleV", 1);

            //UV Translate
            shader.SetFloat("ColorUVTranslateU", 0);
            shader.SetFloat("ColorUVTranslateV", 0);

            SetUniformData(mat, shader, "ColorUVScaleU");
            SetUniformData(mat, shader, "ColorUVScaleV");
            SetUniformData(mat, shader, "ColorUVTranslateU");
            SetUniformData(mat, shader, "ColorUVTranslateV");
        }
Ejemplo n.º 2
0
        private void DrawModel(GLControl control, GFLXMesh m, ShaderProgram shader)
        {
            foreach (var group in m.PolygonGroups)
            {
                if (group.faces.Count <= 3)
                {
                    return;
                }

                var Material = m.ParentModel.GenericMaterials[group.MaterialIndex];

                SetUniforms(m.GetMaterial(group), shader, m, m.DisplayId);
                SetUniformBlocks(m.GetMaterial(group), shader, m, m.DisplayId);
                SetBoneUniforms(control, shader, m);
                SetVertexAttributes(m, shader);
                SetTextureUniforms(m.GetMaterial(group), m, shader);

                if (m.IsSelected)
                {
                    DrawModelSelection(group, shader);
                }
                else
                {
                    if (Runtime.RenderModels)
                    {
                        GL.DrawElements(PrimitiveType.Triangles, group.displayFaceSize, DrawElementsType.UnsignedInt, group.Offset);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private static void SetBoneUniforms(GLControl control, ShaderProgram shader, GFLXMesh mesh)
        {
            int i = 0;

            foreach (var bone in mesh.ParentModel.Skeleton.bones)
            {
                Matrix4 transform = bone.invert * bone.Transform;

                GL.UniformMatrix4(GL.GetUniformLocation(shader.programs[control], String.Format("bones[{0}]", i++)), false, ref transform);
            }

            /*  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.programs[control], 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.programs[control], String.Format("bones[{0}]", i)), false, ref transform);
             *    }
             * }*/
        }
Ejemplo n.º 4
0
        private static void SetTextureUniforms(GFLXMaterialData mat, GFLXMesh m, ShaderProgram shader)
        {
            if (!mat.HasVertexColors())
            {
                shader.SetBoolToInt("renderVertColor", false);
            }
            else
            {
                shader.SetBoolToInt("renderVertColor", Runtime.renderVertColor);
            }

            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);

            shader.SetInt("RedChannel", 0);
            shader.SetInt("GreenChannel", 1);
            shader.SetInt("BlueChannel", 2);
            shader.SetInt("AlphaChannel", 3);

            LoadPBRMaps(shader);

            foreach (STGenericMatTexture matex in mat.TextureMaps)
            {
                if (matex.Type == STGenericMatTexture.TextureType.Diffuse)
                {
                    shader.SetBoolToInt("HasDiffuse", true);
                    TextureUniform(shader, mat, true, "DiffuseMap", matex);
                }
                if (matex.Type == STGenericMatTexture.TextureType.Normal)
                {
                    shader.SetBoolToInt("HasNormalMap", true);
                    TextureUniform(shader, mat, true, "NormalMap", matex);
                }
                if (matex.Type == STGenericMatTexture.TextureType.AO)
                {
                    shader.SetBoolToInt("HasAmbientMap", true);
                    TextureUniform(shader, mat, true, "AmbientMap", matex);
                }
            }
        }
Ejemplo n.º 5
0
 private void SetVertexAttributes(GFLXMesh m, ShaderProgram shader)
 {
     GL.BindBuffer(BufferTarget.ArrayBuffer, vbo_position);
     GL.VertexAttribPointer(shader.GetAttribute("vPosition"), 3, VertexAttribPointerType.Float, false, GFLXMesh.DisplayVertex.Size, 0);   //+12
     GL.VertexAttribPointer(shader.GetAttribute("vNormal"), 3, VertexAttribPointerType.Float, false, GFLXMesh.DisplayVertex.Size, 12);    //+12
     GL.VertexAttribPointer(shader.GetAttribute("vTangent"), 3, VertexAttribPointerType.Float, false, GFLXMesh.DisplayVertex.Size, 24);   //+12
     GL.VertexAttribPointer(shader.GetAttribute("vUV0"), 2, VertexAttribPointerType.Float, false, GFLXMesh.DisplayVertex.Size, 36);       //+8
     GL.VertexAttribPointer(shader.GetAttribute("vColor"), 4, VertexAttribPointerType.Float, false, GFLXMesh.DisplayVertex.Size, 44);     //+16
     GL.VertexAttribIPointer(shader.GetAttribute("vBone"), 4, VertexAttribIntegerType.Int, GFLXMesh.DisplayVertex.Size, new IntPtr(60));  //+16
     GL.VertexAttribPointer(shader.GetAttribute("vWeight"), 4, VertexAttribPointerType.Float, false, GFLXMesh.DisplayVertex.Size, 76);    //+16
     GL.VertexAttribPointer(shader.GetAttribute("vUV1"), 2, VertexAttribPointerType.Float, false, GFLXMesh.DisplayVertex.Size, 92);       //+8
     GL.VertexAttribPointer(shader.GetAttribute("vUV2"), 2, VertexAttribPointerType.Float, false, GFLXMesh.DisplayVertex.Size, 100);      //+8
     GL.VertexAttribPointer(shader.GetAttribute("vBinormal"), 3, VertexAttribPointerType.Float, false, GFLXMesh.DisplayVertex.Size, 108); //+12
     GL.BindBuffer(BufferTarget.ElementArrayBuffer, ibo_elements);
 }
Ejemplo n.º 6
0
        public static byte[] CreateVertexDataBuffer(GFLXMesh mesh)
        {
            var meshData = mesh.MeshData;

            //Get all the bones from model and create skin index list
            List <int> SkinningIndices = new List <int>();

            foreach (GFLXBone bone in mesh.ParentModel.Skeleton.bones)
            {
                if (bone.HasSkinning)
                {
                    SkinningIndices.Add(mesh.ParentModel.Skeleton.bones.IndexOf(bone));
                }
            }

            return(CreateVertexDataBuffer(mesh, SkinningIndices, mesh.MeshData.Attributes));
        }
Ejemplo n.º 7
0
        private void SetUniformBlocks(GFLXMaterialData mat, ShaderProgram shader, GFLXMesh 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*/
        }
Ejemplo n.º 8
0
        public void LoadFile(Model model, GFBMDL file, GFBMDL_Render Renderer)
        {
            Model      = model;
            ParentFile = file;

            Renderer.Meshes.Clear();

            for (int m = 0; m < Model.Materials?.Count; m++)
            {
                GenericMaterials.Add(new GFLXMaterialData(this, Model.Materials[m]));
            }

            List <int> SkinningIndices = new List <int>();

            for (int b = 0; b < Model.Bones?.Count; b++)
            {
                var bone = Model.Bones[b];
                Skeleton.bones.Add(new GFLXBone(this, bone));

                if (bone.RigidCheck == null)
                {
                    SkinningIndices.Add(b);
                }
            }

            Skeleton.reset();
            Skeleton.update();

            for (int g = 0; g < Model.Groups?.Count; g++)
            {
                var group = Model.Groups[g];
                var mesh  = Model.Meshes[g];

                OpenTK.Matrix4 transform = OpenTK.Matrix4.Identity;

                GFLXMesh genericMesh = new GFLXMesh(this, group, mesh);
                genericMesh.Checked          = true;
                genericMesh.ImageKey         = "model";
                genericMesh.SelectedImageKey = "model";

                int boneIndex = (int)group.BoneIndex;
                if (boneIndex < Skeleton.bones.Count && boneIndex > 0)
                {
                    genericMesh.BoneIndex = boneIndex;
                    transform             = Skeleton.bones[boneIndex].Transform;

                    genericMesh.Text = Skeleton.bones[boneIndex].Text;
                }

                //   if (group.MeshID < Skeleton.bones.Count && group.MeshID > 0)
                //       genericMesh.Text = Skeleton.bones[(int)group.MeshID].Text;

                Renderer.Meshes.Add(genericMesh);
                GenericMeshes.Add(genericMesh);

                //Load the vertex data
                genericMesh.Transform = transform;
                genericMesh.vertices  = GFLXMeshBufferHelper.LoadVertexData(mesh, transform, SkinningIndices);
                genericMesh.FlipUvsVertical();

                //Load faces
                for (int p = 0; p < mesh.Polygons?.Count; p++)
                {
                    var poly = mesh.Polygons[p];

                    var polygonGroup = new STGenericPolygonGroup();
                    polygonGroup.MaterialIndex = (int)poly.MaterialIndex;
                    genericMesh.PolygonGroups.Add(polygonGroup);

                    if (GenericMaterials.Count > poly.MaterialIndex)
                    {
                        polygonGroup.Material = GenericMaterials[(int)poly.MaterialIndex];
                    }

                    for (int f = 0; f < poly.Faces?.Count; f++)
                    {
                        polygonGroup.faces.Add((int)poly.Faces[f]);
                    }
                }
            }
        }