Exemple #1
0
        public void Read(string filename, BFRES bfres, AnimationGroupNode ThisAnimation, ModelContainer modelContainer)
        {
            Console.WriteLine("Reading Material Animations ...");

            ResFile b = new ResFile(filename);

            ThisAnimation.Text = "Material Animations";



            TreeNode dummy = new TreeNode()
            {
                Text = "Animation Set"
            };

            int i = 0;

            foreach (MaterialAnim vis in b.MaterialAnims)
            {
                modelContainer.BFRES_MTA = new BFRES_MTA(vis);


                ThisAnimation.Nodes.Add(modelContainer.BFRES_MTA);
            }
        }
Exemple #2
0
 public void DepthSortModels(Vector3 cameraPosition)
 {
     if (NUD != null)
     {
         NUD.DepthSortMeshes(cameraPosition);
     }
     if (BFRES != null)
     {
         BFRES.DepthSortMeshes(cameraPosition);
     }
 }
Exemple #3
0
        public void ReadBNTX(FileData f)
        {
            textures.Clear();

            BFRES b = new BFRES();

            temp = f.pos();

            f.skip(8); //Magic
            int Version        = f.readInt();
            int ByteOrderMark  = f.readShort();
            int FormatRevision = f.readShort();

            Text = f.readString(f.readInt() + temp, -1);
            f.skip(2);
            int strOffset   = f.readShort();
            int relocOffset = f.readInt();
            int FileSize    = f.readInt();

            f.skip(4); //NX Magic
            int TexturesCount   = f.readInt();
            int InfoPtrsOffset  = f.readInt();
            int DataBlockOffset = f.readInt();
            int DictOffset      = f.readInt();
            int strDictSize     = f.readInt();

            Text = Text + ".bntx";

            BNTXFile = f.getSection(temp, FileSize);

            for (int i = 0; i < TexturesCount; i++)
            {
                f.seek(InfoPtrsOffset + temp + i * 8);
                BRTIOffset = f.readInt();


                f.seek(BRTIOffset + temp);

                //  textures.Add(new BRTI(f));
                BRTI texture = new BRTI(f);

                if (!textured.ContainsKey(texture.Text))
                {
                    textured.Add(texture.Text, texture);
                }

                textures.Add(texture);
            }
            Nodes.AddRange(textures.ToArray());
        }
        public BfresMeshEditor(BFRES.Mesh p, BFRES.FMDL_Model mdl, BFRES b)
        {
            InitializeComponent();

            button1.Enabled      = false;
            textBox1.Text        = p.Text;
            VertCountlabel1.Text = VertCountlabel1.Text + " " + p.vertices.Count.ToString();
            PolyCountlabel3.Text = PolyCountlabel3.Text + " " + p.lodMeshes[p.DisplayLODIndex].displayFaceSize.ToString();
            skinCountLabel.Text  = skinCountLabel.Text + " " + p.VertexSkinCount.ToString();
            label3.Text          = label3.Text + " " + mdl.skeleton.bones[p.boneIndx].ToString();

            Mesh  = p;
            Model = mdl;
            bfres = b;


            foreach (var lod in p.lodMeshes)
            {
                LODcomboBox3.Items.Add(lod);
            }
            LODcomboBox3.SelectedIndex = p.DisplayLODIndex;

            List <string> attributes = new List <string>();

            foreach (Syroot.NintenTools.NSW.Bfres.GFX.AttribFormat attr in Enum.GetValues(typeof(Syroot.NintenTools.NSW.Bfres.GFX.AttribFormat)))
            {
                attributes.Add(attr.ToString());
            }
            attributes.Sort();
            foreach (string att in attributes)
            {
                comboBox2.Items.Add(att);
            }


            int Height = 2;

            foreach (BFRES.Mesh.VertexAttribute att in p.vertexAttributes)
            {
                comboBox1.Items.Add(att);
            }
        }
Exemple #5
0
        public static void BFRES2OBJ(string fname, BFRES bfres)
        {
            using (StreamWriter f = new StreamWriter(fname))
            {
                int FaceShift = 1;
                int CurMesh   = 0;
                foreach (BFRES.FMDL_Model mdl in bfres.models)
                {
                    foreach (BFRES.Mesh m in mdl.poly)
                    {
                        List <Vector3> VerticesN      = new List <Vector3>(); //a lot of normals are often shared
                        List <string>  ExportTextures = new List <string>();



                        f.WriteLine($"o {m.Text}");

                        foreach (BFRES.Vertex vtx in m.vertices)
                        {
                            f.WriteLine($"v {vtx.pos.X} {vtx.pos.Y} {vtx.pos.Z}");
                            f.WriteLine($"vn {vtx.nrm.X} {vtx.nrm.Y} {vtx.nrm.Z}");
                            VerticesN.Add(vtx.nrm);
                        }

                        Vector2 Scale    = new Vector2(1);
                        Vector2 Position = new Vector2(0);

                        if (m.material.matparam.ContainsKey("gsys_bake_st0"))
                        {
                            Vector4 uvShift = m.material.matparam["gsys_bake_st0"].Value_float4;
                            Scale    = uvShift.Xy;
                            Position = uvShift.Zw;
                        }

                        if (Scale != new Vector2(1) || Position != new Vector2(0))
                        {
                            foreach (BFRES.Vertex vtx in m.vertices)
                            {
                                Vector2 st = (vtx.uv1 * Scale) + Position;
                                st = new Vector2(st.X, 1 - st.Y);
                                f.WriteLine($"vt {st.X} {st.Y}");
                            }
                        }
                        else
                        {
                            foreach (BFRES.Vertex vtx in m.vertices)
                            {
                                f.WriteLine($"vt {vtx.uv0.X * Scale.X + Position.X} {vtx.uv0.Y * Scale.Y + Position.Y}");
                            }
                        }



                        f.WriteLine($"usemtl {m.material.Name}");
                        if (!ExportTextures.Contains(m.material.textures[0].Name))
                        {
                            ExportTextures.Add(m.material.textures[0].Name);
                        }
                        f.WriteLine($"s off");


                        var vert = m.CreateDisplayVertices();
                        for (int i = 0; i < m.display.Length; i++)
                        {
                            int[] verts = new int[3] {
                                (int)m.display[i++], (int)m.display[i++], (int)m.display[i]
                            };
                            int[] normals = new int[3] {
                                VerticesN.IndexOf(m.vertices[verts[0]].nrm),
                                VerticesN.IndexOf(m.vertices[verts[1]].nrm),
                                VerticesN.IndexOf(m.vertices[verts[2]].nrm)
                            };
                            f.WriteLine($"f {verts[0] + FaceShift}/{verts[0] + FaceShift}/{normals[0] + FaceShift} {verts[1] + FaceShift}/{verts[1] + FaceShift}/{normals[1] + FaceShift} {verts[2] + FaceShift}/{verts[2] + FaceShift}/{normals[2] + FaceShift}");
                        }

                        FaceShift += vert.Count;

                        Console.WriteLine(m.Text);
                        Console.WriteLine(m.vertices.Count);
                        Console.WriteLine(m.display.Length);

                        CurMesh++;
                    }
                }
            }
        }
Exemple #6
0
        public static AnimationGroupNode Read(string filename, ResFile TargetWiiUBFRES, BFRES bfres)
        {
            string path = filename;

            FileData f = new FileData(filename);


            int Magic = f.readInt();

            if (Magic == 0x59617A30) //YAZO compressed
            {
                using (FileStream input = new FileStream(path, System.IO.FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    Yaz0Compression.Decompress(path, TEMP_FILE);

                    path = TEMP_FILE;
                }
            }

            f = new FileData(path);

            f.seek(0);

            f.Endian = Endianness.Little;

            Console.WriteLine("Reading Animations ...");

            f.seek(4);                     // magic check
            int SwitchCheck = f.readInt(); //Switch version only has padded magic

            f.skip(4);


            //    SwitchAnim2WiiU(path); //Hacky auto convert switch anims to wii u


            Syroot.NintenTools.NSW.Bfres.ResFile b = new Syroot.NintenTools.NSW.Bfres.ResFile(path);

            AnimationGroupNode ThisAnimation = new AnimationGroupNode()
            {
                Text = "Bone Visual Animations"
            };

            TreeNode dummy = new TreeNode()
            {
                Text = "Animation Set"
            };

            int i = 0;

            foreach (Syroot.NintenTools.NSW.Bfres.VisibilityAnim vis in b.BoneVisibilityAnims)
            {
                Animation a = new Animation(vis.Name);

                ThisAnimation.Nodes.Add(a);

                a.FrameCount = vis.FrameCount;
                i++;

                int boneindx = 0;
                if (vis.Names != null)
                {
                    foreach (string nm in vis.Names) //Loop through every bone. Not all have base and curve data
                    {
                        Animation.KeyNode bone = new Animation.KeyNode("");
                        a.Bones.Add(bone);
                        bone.Text = vis.Names[boneindx];



                        if (boneindx < vis.BaseDataList.Length)
                        {
                            bool bas = vis.BaseDataList[boneindx];

                            if (bas == true)
                            {
                                bone.XSCA.Keys.Add(new Animation.KeyFrame()
                                {
                                    Frame = 0, Value = 1
                                });
                                bone.YSCA.Keys.Add(new Animation.KeyFrame()
                                {
                                    Frame = 0, Value = 1
                                });
                                bone.ZSCA.Keys.Add(new Animation.KeyFrame()
                                {
                                    Frame = 0, Value = 1
                                });
                            }
                            else
                            {
                                bone.XSCA.Keys.Add(new Animation.KeyFrame()
                                {
                                    Frame = 0, Value = 0
                                });
                                bone.YSCA.Keys.Add(new Animation.KeyFrame()
                                {
                                    Frame = 0, Value = 0
                                });
                                bone.ZSCA.Keys.Add(new Animation.KeyFrame()
                                {
                                    Frame = 0, Value = 0
                                });
                            }
                        }


                        if (vis.Curves.Count != 0)
                        {
                            if (boneindx < vis.Curves.Count)
                            {
                                Syroot.NintenTools.NSW.Bfres.AnimCurve cr = vis.Curves[boneindx];

                                Console.WriteLine($"{vis.Name} {vis.Names[boneindx]}");

                                int frm = 0;
                                foreach (bool bn in cr.KeyStepBoolData)
                                {
                                    Animation.KeyFrame frame = new Animation.KeyFrame();
                                    frame.InterType = Animation.InterpolationType.STEP;
                                    frame.Frame     = cr.Frames[frm];



                                    Console.WriteLine(vis.Name + " " + vis.Names[boneindx] + " " + bn);

                                    switch (bn)
                                    {
                                    case true:
                                        frame.Value = 1; bone.XSCA.Keys.Add(frame);
                                        frame.Value = 1; bone.YSCA.Keys.Add(frame);
                                        frame.Value = 1; bone.ZSCA.Keys.Add(frame);
                                        break;

                                    case false:
                                        frame.Value = 0; bone.XSCA.Keys.Add(frame);
                                        frame.Value = 0; bone.YSCA.Keys.Add(frame);
                                        frame.Value = 0; bone.ZSCA.Keys.Add(frame);
                                        break;
                                    }
                                    frm++;
                                }
                            }
                        }

                        boneindx++;
                    }
                }
            }
            return(ThisAnimation);
        }
        public static void WiiU2Switch(string FileName, int CurModel, BFRES b)
        {
            ResFile TargetWiiUBFRES = new ResFile(FileName);



            int CurMdl = 0;

            foreach (Model mdl in TargetWiiUBFRES.Models.Values)
            {
                int CurBn = 0;
                foreach (Syroot.NintenTools.Bfres.Bone bn in mdl.Skeleton.Bones.Values)
                {
                    Bone bone = b.models[CurMdl].skeleton.bones[CurBn];

                    bone.scale[0]    = bn.Scale.X;
                    bone.scale[1]    = bn.Scale.Y;
                    bone.scale[2]    = bn.Scale.Z;
                    bone.rotation[0] = bn.Rotation.X;
                    bone.rotation[1] = bn.Rotation.Y;
                    bone.rotation[2] = bn.Rotation.Z;
                    bone.rotation[3] = bn.Rotation.W;
                    bone.position[0] = bn.Position.X;
                    bone.position[1] = bn.Position.Y;
                    bone.position[2] = bn.Position.Z;
                    CurBn++;
                }
                b.models[CurMdl].skeleton.reset();

                int CurShape = 0;
                foreach (Shape shp in mdl.Shapes.Values)
                {
                    Mesh poly = b.models[CurMdl].poly[CurShape];

                    //Create a buffer instance which stores all the buffer data
                    // VertexBufferHelperAttrib uv1 = helper["_u1"];

                    int TotalCount = poly.vertices.Count;

                    int LODCount = 0;

                    uint   FaceCount    = FaceCount = shp.Meshes[LODCount].IndexCount;
                    uint[] indicesArray = shp.Meshes[LODCount].GetIndices().ToArray();


                    int TotalFaceCount = poly.lodMeshes[poly.DisplayLODIndex].faces.Count;

                    poly.lodMeshes[poly.DisplayLODIndex].faces.Clear();

                    for (int face = 0; face < FaceCount; face++)
                    {
                        poly.lodMeshes[poly.DisplayLODIndex].faces.Add((int)indicesArray[face] + (int)shp.Meshes[LODCount].FirstVertex);
                    }

                    if (TotalFaceCount != poly.lodMeshes[poly.DisplayLODIndex].faces.Count)
                    {
                        MessageBox.Show("Error F");
                    }

                    poly.vertices.Clear();


                    //Create a buffer instance which stores all the buffer data
                    VertexBufferHelper helper = new VertexBufferHelper(mdl.VertexBuffers[shp.VertexBufferIndex], TargetWiiUBFRES.ByteOrder);

                    //Set each array first from the lib if exist. Then add the data all in one loop
                    Syroot.Maths.Vector4F[] vec4Positions = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4Normals   = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4uv0       = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4uv1       = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4uv2       = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4c0        = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4t0        = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4b0        = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4w0        = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4i0        = new Syroot.Maths.Vector4F[0];


                    foreach (VertexAttrib att in mdl.VertexBuffers[shp.VertexBufferIndex].Attributes.Values)
                    {
                        Mesh.VertexAttribute attr = new Mesh.VertexAttribute();
                        attr.Name = att.Name;
                        // attr.Format = att.Format;

                        if (att.Name == "_p0")
                        {
                            vec4Positions = WiiUAttributeData(att, helper, "_p0");
                        }
                        if (att.Name == "_n0")
                        {
                            vec4Normals = WiiUAttributeData(att, helper, "_n0");
                        }
                        if (att.Name == "_u0")
                        {
                            vec4uv0 = WiiUAttributeData(att, helper, "_u0");
                        }
                        if (att.Name == "_u1")
                        {
                            vec4uv1 = WiiUAttributeData(att, helper, "_u1");
                        }
                        if (att.Name == "_u2")
                        {
                            vec4uv2 = WiiUAttributeData(att, helper, "_u2");
                        }
                        if (att.Name == "_c0")
                        {
                            vec4c0 = WiiUAttributeData(att, helper, "_c0");
                        }
                        if (att.Name == "_t0")
                        {
                            vec4t0 = WiiUAttributeData(att, helper, "_t0");
                        }
                        if (att.Name == "_b0")
                        {
                            vec4b0 = WiiUAttributeData(att, helper, "_b0");
                        }
                        if (att.Name == "_w0")
                        {
                            vec4w0 = WiiUAttributeData(att, helper, "_w0");
                        }
                        if (att.Name == "_i0")
                        {
                            vec4i0 = WiiUAttributeData(att, helper, "_i0");
                        }

                        poly.vertexAttributes.Add(attr);
                    }
                    for (int i = 0; i < vec4Positions.Length; i++)
                    {
                        Vertex v = new Vertex();
                        if (vec4Positions.Length > 0)
                        {
                            v.pos = new Vector3(vec4Positions[i].X, vec4Positions[i].Y, vec4Positions[i].Z);
                        }
                        if (vec4Normals.Length > 0)
                        {
                            v.nrm = new Vector3(vec4Normals[i].X, vec4Normals[i].Y, vec4Normals[i].Z);
                        }
                        if (vec4uv0.Length > 0)
                        {
                            v.uv0 = new Vector2(vec4uv0[i].X, vec4uv0[i].Y);
                        }
                        if (vec4uv1.Length > 0)
                        {
                            v.uv1 = new Vector2(vec4uv1[i].X, vec4uv1[i].Y);
                        }
                        if (vec4uv2.Length > 0)
                        {
                            v.uv2 = new Vector2(vec4uv2[i].X, vec4uv2[i].Y);
                        }
                        if (vec4w0.Length > 0)
                        {
                            v.boneWeights.Add(vec4w0[i].X);
                            v.boneWeights.Add(vec4w0[i].Y);
                            v.boneWeights.Add(vec4w0[i].Z);
                            v.boneWeights.Add(vec4w0[i].W);
                        }
                        if (vec4i0.Length > 0)
                        {
                            v.boneIds.Add((int)vec4i0[i].X);
                            v.boneIds.Add((int)vec4i0[i].Y);
                            v.boneIds.Add((int)vec4i0[i].Z);
                            v.boneIds.Add((int)vec4i0[i].W);
                        }
                        if (vec4t0.Length > 0)
                        {
                            v.tan = new Vector4(vec4t0[i].X, vec4t0[i].Y, vec4t0[i].Z, vec4t0[i].W);
                        }
                        if (vec4b0.Length > 0)
                        {
                            v.bitan = new Vector4(vec4b0[i].X, vec4b0[i].Y, vec4b0[i].Z, vec4b0[i].W);
                        }
                        if (vec4c0.Length > 0)
                        {
                            v.col = new Vector4(vec4c0[i].X, vec4c0[i].Y, vec4c0[i].Z, vec4c0[i].W);
                        }

                        poly.vertices.Add(v);
                    }

                    CurShape++;
                }
                CurMdl++;
            }
            b.UpdateVertexData();
        }
Exemple #8
0
        public void Render(Camera camera, int depthmap, Matrix4 lightMatrix, Matrix4 modelMatrix, bool specialWireFrame = false)
        {
            if (!Checked)
            {
                return;
            }

            Shader shader;

            if (Runtime.renderType != Runtime.RenderTypes.Shaded)
            {
                shader = Runtime.shaders["NUD_Debug"];
            }
            else
            {
                shader = Runtime.shaders["NUD"];
            }
            GL.UseProgram(shader.programID);

            int renderType = (int)Runtime.renderType;

            Matrix4 mvpMatrix = camera.mvpMatrix;

            GL.UniformMatrix4(shader.getAttribute("mvpMatrix"), false, ref mvpMatrix);

            // Perform the calculations here to reduce render times in shader
            Matrix4 modelViewMatrix = camera.modelViewMatrix;
            Matrix4 sphereMapMatrix = modelViewMatrix;

            sphereMapMatrix.Invert();
            sphereMapMatrix.Transpose();
            GL.UniformMatrix4(shader.getAttribute("modelViewMatrix"), false, ref modelViewMatrix);
            GL.UniformMatrix4(shader.getAttribute("sphereMapMatrix"), false, ref sphereMapMatrix);

            Matrix4 rotationMatrix = camera.rotationMatrix;

            GL.UniformMatrix4(shader.getAttribute("rotationMatrix"), false, ref rotationMatrix);

            shader = Runtime.shaders["MBN"];
            GL.UseProgram(shader.programID);

            if (Runtime.cameraLight)
            {
                GL.Uniform3(shader.getAttribute("difLightDirection"), Vector3.TransformNormal(new Vector3(0f, 0f, -1f), camera.mvpMatrix.Inverted()).Normalized());
            }
            else
            {
                GL.Uniform3(shader.getAttribute("difLightDirection"), Runtime.lightSetParam.characterDiffuse.direction);
            }

            shader = Runtime.shaders["DAT"];
            GL.UseProgram(shader.programID);

            LightColor diffuseColor = Runtime.lightSetParam.characterDiffuse.diffuseColor;
            LightColor ambientColor = Runtime.lightSetParam.characterDiffuse.ambientColor;

            GL.Uniform3(shader.getAttribute("difLightColor"), diffuseColor.R, diffuseColor.G, diffuseColor.B);
            GL.Uniform3(shader.getAttribute("ambLightColor"), ambientColor.R, ambientColor.G, ambientColor.B);


            if (BCH != null)
            {
                foreach (BCH_Model mo in BCH.Models.Nodes)
                {
                    mo.Render(camera.mvpMatrix);
                }
            }
            if (BFRES != null && Runtime.shaders["BFRES"].CompiledSuccessfully() && Runtime.shaders["BFRES_PBR"].CompiledSuccessfully())
            {
                if (Runtime.renderPhysicallyBasedRendering == true)
                {
                    shader = Runtime.shaders["BFRES_PBR"];
                    GL.UseProgram(shader.programID);

                    GL.Uniform3(shader.getAttribute("difLightColor"), diffuseColor.R, diffuseColor.G, diffuseColor.B);
                    GL.Uniform3(shader.getAttribute("ambLightColor"), ambientColor.R, ambientColor.G, ambientColor.B);
                }
                else
                {
                    shader = Runtime.shaders["BFRES"];
                    GL.UseProgram(shader.programID);

                    GL.Uniform3(shader.getAttribute("difLightColor"), diffuseColor.R, diffuseColor.G, diffuseColor.B);
                    GL.Uniform3(shader.getAttribute("ambLightColor"), ambientColor.R, ambientColor.G, ambientColor.B);
                }


                BFRES.Render(camera.mvpMatrix);
            }
            if (DAT_MELEE != null && Runtime.shaders["DAT"].CompiledSuccessfully())
            {
                DAT_MELEE.Render(camera.mvpMatrix);
            }

            if (NUD != null && Runtime.shaders["NUD"].CompiledSuccessfully() && Runtime.shaders["NUD_Debug"].CompiledSuccessfully())
            {
                if (Runtime.renderType != Runtime.RenderTypes.Shaded)
                {
                    shader = Runtime.shaders["NUD_Debug"];
                }
                else
                {
                    shader = Runtime.shaders["NUD"];
                }

                GL.UseProgram(shader.programID);

                SetRenderSettingsUniforms(shader);
                SetLightingUniforms(shader, camera);

                GL.ActiveTexture(TextureUnit.Texture2);
                GL.BindTexture(TextureTarget.TextureCubeMap, RenderTools.dummyTextures[NUD.DummyTextures.StageMapHigh]);
                GL.Uniform1(shader.getAttribute("cmap"), 2);

                GL.Uniform1(shader.getAttribute("renderType"), renderType);
                GL.Uniform1(shader.getAttribute("debugOption"), (int)Runtime.uvChannel);

                SetElapsedDirectUvTime(shader);

                GL.UniformMatrix4(shader.getAttribute("modelMatrix"), false, ref modelMatrix);

                if (specialWireFrame)
                {
                    Runtime.renderModelWireframe = true;
                    Runtime.renderModel          = false;
                }

                NUD.Render(VBN, camera);
            }
        }
Exemple #9
0
        public void Render(Camera camera, int depthMap, Matrix4 lightMatrix, Vector2 screenDimensions, bool drawShadow = false)
        {
            if (!Checked)
            {
                return;
            }

            Shader shader;

            // 3DS MBN
            shader = OpenTKSharedResources.shaders["Mbn"];
            shader.UseProgram();
            SetMbnUniforms(camera, shader);

            // Melee DAT
            shader = OpenTKSharedResources.shaders["Dat"];
            shader.UseProgram();
            SetDatUniforms(shader);

            if (BCH != null)
            {
                foreach (BCH_Model mo in BCH.Models.Nodes)
                {
                    mo.Render(camera.MvpMatrix);
                }
            }

            if (DatMelee != null && OpenTKSharedResources.shaders["Dat"].ProgramCreatedSuccessfully)
            {
                DatMelee.Render(camera.MvpMatrix);
            }

            LightColor diffuseColor = Runtime.lightSetParam.characterDiffuse.diffuseColor;
            LightColor ambientColor = Runtime.lightSetParam.characterDiffuse.ambientColor;

            if (KCL != null && OpenTKSharedResources.shaders["KCL"].ProgramCreatedSuccessfully)
            {
                shader = OpenTKSharedResources.shaders["KCL"];
                shader.UseProgram();

                shader.SetVector3("difLightColor", diffuseColor.R, diffuseColor.G, diffuseColor.B);
                shader.SetVector3("ambLightColor", ambientColor.R, ambientColor.G, ambientColor.B);

                KCL.Render(camera.MvpMatrix);
            }

            if (BFRES != null && OpenTKSharedResources.shaders["BFRES"].ProgramCreatedSuccessfully &&
                OpenTKSharedResources.shaders["BFRES_PBR"].ProgramCreatedSuccessfully)
            {
                if (Runtime.renderPhysicallyBasedRendering == true)
                {
                    shader = OpenTKSharedResources.shaders["BFRES_PBR"];
                }
                else
                {
                    shader = OpenTKSharedResources.shaders["BFRES"];
                }

                shader.UseProgram();

                shader.SetVector3("difLightColor", diffuseColor.R, diffuseColor.G, diffuseColor.B);
                shader.SetVector3("ambLightColor", ambientColor.R, ambientColor.G, ambientColor.B);

                Matrix4 invertedCamera = camera.MvpMatrix.Inverted();
                Vector3 lightDirection = new Vector3(0f, 0f, -1f);

                //Todo. Maybe change direction via AAMP file (configs shader data)
                shader.SetVector3("lightDirection", Vector3.TransformNormal(lightDirection, invertedCamera).Normalized());
                shader.SetVector3("specLightDirection", Vector3.TransformNormal(lightDirection, invertedCamera).Normalized());
                shader.SetVector3("difLightDirection", Vector3.TransformNormal(lightDirection, invertedCamera).Normalized());

                shader.SetInt("debugOption", (int)Runtime.uvChannel);

                // This cube map is for a quick test.
                shader.SetTexture("cmap", RenderTools.dummyTextures[NUD.DummyTextures.StageMapHigh].Id, TextureTarget.TextureCubeMap, 2);

                BFRES.Render(camera.MvpMatrix);
            }

            if (NUD != null && OpenTKSharedResources.shaders["Nud"].ProgramCreatedSuccessfully && OpenTKSharedResources.shaders["NudDebug"].ProgramCreatedSuccessfully)
            {
                // Choose the appropriate shader.
                if (drawShadow)
                {
                    shader = OpenTKSharedResources.shaders["Shadow"];
                }
                else if (Runtime.renderType != Runtime.RenderTypes.Shaded)
                {
                    shader = OpenTKSharedResources.shaders["NudDebug"];
                }
                else
                {
                    shader = OpenTKSharedResources.shaders["Nud"];
                }

                shader.UseProgram();

                // Matrices.
                Matrix4 lightMatrixRef = lightMatrix;
                shader.SetMatrix4x4("lightMatrix", ref lightMatrixRef);
                SetCameraMatrixUniforms(camera, shader);

                SetRenderSettingsUniforms(shader);
                SetLightingUniforms(shader, camera);

                shader.SetInt("renderType", (int)Runtime.renderType);
                shader.SetInt("debugOption", (int)Runtime.uvChannel);
                shader.SetBoolToInt("drawShadow", Runtime.drawModelShadow);

                shader.SetTexture("depthMap", depthMap, TextureTarget.Texture2D, 14);

                SetElapsedDirectUvTime(shader);

                NUD.Render(VBN, camera, drawShadow, Runtime.drawNudColorIdPass);
            }
        }