public void DrawDepthBuffer(GLFrameworkEngine.GLContext control, BfresRender parentRender)
        {
            if (disposed || !IsVisible)
            {
                return;
            }

            foreach (BfresMeshAsset mesh in this.Meshes)
            {
                if (!mesh.IsVisible || mesh.IsDepthShadow ||
                    mesh.IsCubeMap || mesh.UseColorBufferPass)
                {
                    continue;
                }

                RenderMesh(control, mesh, 1);
            }

            control.CurrentShader = null;

            GL.Enable(EnableCap.DepthTest);
            GL.Disable(EnableCap.TextureCubeMapSeamless);
            GL.Disable(EnableCap.AlphaTest);
            GL.Disable(EnableCap.Blend);
            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);
            GL.UseProgram(0);
        }
        public void DrawShadow(GLFrameworkEngine.GLContext control, BfresRender parentRender)
        {
            var shadowRender = GLFrameworkEngine.GlobalShaders.GetShader("SHADOW");

            control.CurrentShader = shadowRender;

            GL.Disable(EnableCap.CullFace);
            foreach (var mesh in this.Meshes)
            {
                if (!mesh.IsVisible || mesh.IsDepthShadow || mesh.IsCubeMap ||
                    !ModelData.Skeleton.Bones[mesh.BoneIndex].Visible)
                {
                    continue;
                }

                //Set light space matrix
                //   Matrix4 lightSpace = control.ShadowRenderer.getProjectionViewMatrix();
                //  shadowRender.SetMatrix4x4("lightSpaceMatrix", ref lightSpace);

                //Draw the mesh
                mesh.vao.Enable(shadowRender);
                mesh.Render(control, shadowRender);
            }
            GL.Enable(EnableCap.CullFace);
            GL.UseProgram(0);
        }
 //Temporary loader atm for map objects to cache quickly and easily
 public static BfresRender LoadFile(string filePath)
 {
     if (!DataCache.ModelCache.ContainsKey(filePath))
     {
         BFRES bfres = new BFRES()
         {
             FileInfo = new File_Info()
         };
         bfres.Load(System.IO.File.OpenRead(filePath));
         bfres.Renderer.Name = filePath;
         DataCache.ModelCache.Add(filePath, bfres.Renderer);
         return((BfresRender)bfres.Renderer);
     }
     else
     {
         var cached = (BfresRender)DataCache.ModelCache[filePath];
         var render = new BfresRender();
         render.Name = filePath;
         render.Models.AddRange(cached.Models);
         foreach (var tex in cached.Textures)
         {
             render.Textures.Add(tex.Key, tex.Value);
         }
         return(render);
     }
 }
Exemplo n.º 4
0
        public void Load(Stream stream)
        {
            Icon    = "/Images/Bfres.png";
            ResFile = new ResFile(stream);
            ReloadWrappers(ResFile);

            Renderer = new BfresRender();
            ((BfresRender)Renderer).Load(this);

            Tag = this;
        }
Exemplo n.º 5
0
        static void LoadMapObject(Obj obj, bool onlyLoadSkybox = false)
        {
            var resource = GetResourceName(obj);

            if (resource.Contains("Moon") || resource.Contains("Sun"))
            {
                return;
            }

            if (!resource.Contains("VR") && onlyLoadSkybox)
            {
                return;
            }

            string path = FindFilePath(resource);

            if (path == string.Empty)
            {
                return;
            }

            var render = BfresRender.LoadFile(path);

            //Use fustrum culling on non sky box objects
            if (!resource.Contains("VR"))
            {
                render.StayInFustrum = false;
            }
            else
            {
                render.IsSkybox = true;
            }

            if (render.IsSkybox)
            {
                //Temporary atm but disable the background as it has render conflicts with the skybox
                CafeStudio.UI.DrawableBackground.Display = false;
            }

            LoadBFRES(obj, render);
        }
        public void DrawShadowModel(GLFrameworkEngine.GLContext control, BfresRender parentRender)
        {
            if (disposed || !IsVisible)
            {
                return;
            }

            foreach (BfresMeshAsset mesh in this.Meshes)
            {
                if (!mesh.IsVisible || mesh.IsDepthShadow ||
                    mesh.IsCubeMap || mesh.UseColorBufferPass)
                {
                    continue;
                }

                var lightSpaceMatrix = control.Scene.ShadowRenderer.GetLightSpaceMatrix();

                var mtxMdl = this.ParentRender.Transform.TransformMatrix;
                control.CurrentShader.SetMatrix4x4("mtxMdl", ref mtxMdl);
                control.CurrentShader.SetMatrix4x4("lightSpaceMatrix", ref lightSpaceMatrix);

                DrawSolidColorMesh(control.CurrentShader, mesh);
            }
        }
        public void DrawGBuffer(GLContext control, BfresRender parentRender)
        {
            if (disposed || !IsVisible)
            {
                return;
            }

            foreach (BfresMeshAsset mesh in this.Meshes)
            {
                if (!mesh.IsVisible || mesh.IsDepthShadow || mesh.IsCubeMap)
                {
                    continue;
                }

                RenderMesh(control, mesh, 2);
            }

            GL.Enable(EnableCap.DepthTest);
            GL.Disable(EnableCap.TextureCubeMapSeamless);
            GL.Disable(EnableCap.AlphaTest);
            GL.Disable(EnableCap.Blend);
            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);
        }
        public BfresModelAsset(BFRES bfres, BfresRender render, FMDL model)
        {
            ParentRender = render;
            ModelData    = model;
            Name         = model.Name;

            List <Vector3> positons = new List <Vector3>();

            foreach (FSHP mesh in model.Meshes)
            {
                //Create a mesh asset for rendering onto
                var meshAsset = new BfresMeshAsset(mesh);
                Meshes.Add(meshAsset);

                foreach (var customRender in BfshaRenders)
                {
                    var materialRender = (ShaderRenderBase)Activator.CreateInstance(customRender);
                    if (materialRender.UseRenderer(
                            mesh.Material,
                            mesh.Material.ShaderArchive,
                            mesh.Material.ShaderModel))
                    {
                        materialRender.TryLoadShader(bfres, ResModel, mesh, meshAsset);
                        break;
                    }
                }

                //Check for the GX2 shader decompiler as needed for Wii U games
                if (System.IO.File.Exists("GFD\\gx2shader-decompiler.exe"))
                {
                    foreach (var customRender in SharcfbRenders)
                    {
                        var materialRender = (SharcFBRenderer)Activator.CreateInstance(customRender);
                        if (materialRender.UseRenderer(
                                mesh.Material,
                                mesh.Material.ShaderArchive,
                                mesh.Material.ShaderModel))
                        {
                            materialRender.TryLoadShader(bfres, ResModel, mesh, meshAsset);
                            break;
                        }
                    }
                }

                mesh.Material.MaterialAsset = (BfresMaterialAsset)meshAsset.MaterialAsset;

                ((BfresMaterialAsset)meshAsset.MaterialAsset).ParentRenderer = render;
                ((BfresMaterialAsset)meshAsset.MaterialAsset).ParentModel    = this.ResModel;

                //Calculate total boundings
                for (int i = 0; i < mesh.Vertices.Count; i++)
                {
                    positons.Add(mesh.Vertices[i].Position);
                }
            }
            SkeletonRenderer = new SkeletonRenderer(model.Skeleton);

            //Calculate the total bounding sphere
            BoundingSphere = GLFrameworkEngine.Utils.BoundingSphereGenerator.GenerateBoundingSphere(positons);
            positons.Clear();
        }
        public void Draw(GLContext control, GLFrameworkEngine.Pass pass, BfresRender parentRender)
        {
            if (disposed || !IsVisible)
            {
                return;
            }

            GL.Enable(EnableCap.TextureCubeMapSeamless);

            if (pass == GLFrameworkEngine.Pass.OPAQUE && Meshes.Any(x => x.IsSelected))
            {
                GL.Enable(EnableCap.StencilTest);
                GL.Clear(ClearBufferMask.StencilBufferBit);
                GL.ClearStencil(0);
                GL.StencilFunc(StencilFunction.Always, 0x1, 0x1);
                GL.StencilOp(StencilOp.Keep, StencilOp.Replace, StencilOp.Replace);
            }

            //Go through each mesh and map materials using shader programs
            var meshes = RenderLayer.Sort(this);

            foreach (var mesh in meshes)
            {
                if (mesh.Pass != pass || !mesh.IsVisible ||
                    mesh.IsDepthShadow || mesh.IsCubeMap || mesh.UseColorBufferPass)
                {
                    continue;
                }

                //Load the material data
                var material = (FMAT)mesh.Shape.Material;
                mesh.Material = material;
                //Update the parent renderer
                ((BfresMaterialAsset)mesh.MaterialAsset).ParentRenderer = parentRender;

                if (!ModelData.Skeleton.Bones[mesh.BoneIndex].Visible)
                {
                    continue;
                }

                RenderMesh(control, mesh);
            }

            GL.DepthMask(true);
            GL.BindTexture(TextureTarget.Texture2D, 0);
            GL.Enable(EnableCap.DepthTest);
            GL.Disable(EnableCap.TextureCubeMapSeamless);
            GL.Disable(EnableCap.AlphaTest);
            GL.Disable(EnableCap.Blend);
            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);

            if (meshes.Any(x => x.UseColorBufferPass))
            {
                ScreenBufferTexture.FilterScreen(control);
            }

            foreach (var mesh in meshes.Where(x => x.UseColorBufferPass))
            {
                if (pass != mesh.Pass || !mesh.IsVisible)
                {
                    continue;
                }

                //Load the material data
                var material = (FMAT)mesh.Shape.Material;
                mesh.Material = material;
                ((BfresMaterialAsset)mesh.MaterialAsset).ParentRenderer = parentRender;

                if (!ModelData.Skeleton.Bones[mesh.BoneIndex].Visible)
                {
                    continue;
                }

                RenderMesh(control, mesh);
            }

            if (Runtime.RenderSettings.WireframeOverlay)
            {
                DrawWireframeOutline(control);
            }

            if (pass == GLFrameworkEngine.Pass.TRANSPARENT)
            {
                DrawSelection(control, parentRender.IsSelected || this.IsSelected);
            }

            GL.DepthMask(true);
            GL.Enable(EnableCap.DepthTest);
            GL.Disable(EnableCap.TextureCubeMapSeamless);
            GL.Disable(EnableCap.AlphaTest);
            GL.Disable(EnableCap.Blend);
            GL.Enable(EnableCap.CullFace);
            GL.CullFace(CullFaceMode.Back);
        }