Exemplo n.º 1
0
        private void LookupTexture(ref TextureResourceHande handle, FlverMaterial dest, IFlverTexture matparam, string mtd)
        {
            var path = matparam.Path;

            if (matparam.Path == "")
            {
                var mtdstring = Path.GetFileNameWithoutExtension(mtd);
                if (MtdBank.Mtds.ContainsKey(mtdstring))
                {
                    var tex = MtdBank.Mtds[mtdstring].Textures.Find(x => (x.Type == matparam.Type));
                    if (tex == null || !tex.Extended || tex.Path == "")
                    {
                        return;
                    }
                    path = tex.Path;
                }
            }
            handle = ResourceManager.GetTextureResource(TexturePathToVirtual(path.ToLower()));
            handle.Acquire();
            handle.AddResourceEventListener(dest);
        }
Exemplo n.º 2
0
        private bool LoadInternalDeS(AccessLevel al, GameType type)
        {
            if (al == AccessLevel.AccessFull || al == AccessLevel.AccessGPUOptimizedOnly)
            {
                GPUMeshes    = new FlverSubmesh[FlverDeS.Meshes.Count()];
                GPUMaterials = new FlverMaterial[FlverDeS.Materials.Count()];
                Bounds       = new BoundingBox();
                Bones        = FlverDeS.Bones;

                for (int i = 0; i < FlverDeS.Materials.Count(); i++)
                {
                    GPUMaterials[i] = new FlverMaterial();
                    ProcessMaterial(FlverDeS.Materials[i], GPUMaterials[i], type);
                }

                for (int i = 0; i < FlverDeS.Meshes.Count(); i++)
                {
                    GPUMeshes[i] = new FlverSubmesh();
                    ProcessMesh(FlverDeS.Meshes[i], GPUMeshes[i]);
                    if (i == 0)
                    {
                        Bounds = GPUMeshes[i].Bounds;
                    }
                    else
                    {
                        Bounds = BoundingBox.Combine(Bounds, GPUMeshes[i].Bounds);
                    }
                }
            }

            if (al == AccessLevel.AccessGPUOptimizedOnly)
            {
                Flver = null;
            }
            //return false;
            return(true);
        }
Exemplo n.º 3
0
        unsafe private void ProcessMaterial(IFlverMaterial mat, FlverMaterial dest, GameType type)
        {
            dest.MaterialName   = Path.GetFileNameWithoutExtension(mat.MTD);
            dest.MaterialBuffer = Scene.Renderer.MaterialBufferAllocator.Allocate((uint)sizeof(Scene.Material), sizeof(Scene.Material));
            dest.MaterialData   = new Scene.Material();

            if (!CFG.Current.EnableTexturing)
            {
                dest.ShaderName              = @"SimpleFlver";
                dest.LayoutType              = MeshLayoutType.LayoutSky;
                dest.VertexLayout            = MeshLayoutUtils.GetLayoutDescription(dest.LayoutType);
                dest.VertexSize              = MeshLayoutUtils.GetLayoutVertexSize(dest.LayoutType);
                dest.SpecializationConstants = new SpecializationConstant[0];
                return;
            }

            bool blend         = false;
            bool blendMask     = false;
            bool hasNormal2    = false;
            bool hasSpec2      = false;
            bool hasShininess2 = false;

            foreach (var matparam in mat.Textures)
            {
                string paramNameCheck;
                if (matparam.Type == null)
                {
                    paramNameCheck = "G_DIFFUSE";
                }
                else
                {
                    paramNameCheck = matparam.Type.ToUpper();
                }
                if (paramNameCheck == "G_DIFFUSETEXTURE2" || paramNameCheck == "G_DIFFUSE2" || paramNameCheck.Contains("ALBEDO_2"))
                {
                    LookupTexture(ref dest.AlbedoTextureResource2, dest, matparam, mat.MTD);
                    blend = true;
                }
                else if (paramNameCheck == "G_DIFFUSETEXTURE" || paramNameCheck == "G_DIFFUSE" || paramNameCheck.Contains("ALBEDO"))
                {
                    LookupTexture(ref dest.AlbedoTextureResource, dest, matparam, mat.MTD);
                }
                else if (paramNameCheck == "G_BUMPMAPTEXTURE2" || paramNameCheck == "G_BUMPMAP2" || paramNameCheck.Contains("NORMAL_2"))
                {
                    LookupTexture(ref dest.NormalTextureResource2, dest, matparam, mat.MTD);
                    blend      = true;
                    hasNormal2 = true;
                }
                else if (paramNameCheck == "G_BUMPMAPTEXTURE" || paramNameCheck == "G_BUMPMAP" || paramNameCheck.Contains("NORMAL"))
                {
                    LookupTexture(ref dest.NormalTextureResource, dest, matparam, mat.MTD);
                }
                else if (paramNameCheck == "G_SPECULARTEXTURE2" || paramNameCheck == "G_SPECULAR2" || paramNameCheck.Contains("SPECULAR_2"))
                {
                    LookupTexture(ref dest.SpecularTextureResource2, dest, matparam, mat.MTD);
                    blend    = true;
                    hasSpec2 = true;
                }
                else if (paramNameCheck == "G_SPECULARTEXTURE" || paramNameCheck == "G_SPECULAR" || paramNameCheck.Contains("SPECULAR"))
                {
                    LookupTexture(ref dest.SpecularTextureResource, dest, matparam, mat.MTD);
                }
                else if (paramNameCheck == "G_SHININESSTEXTURE2" || paramNameCheck == "G_SHININESS2" || paramNameCheck.Contains("SHININESS2"))
                {
                    LookupTexture(ref dest.ShininessTextureResource2, dest, matparam, mat.MTD);
                    blend         = true;
                    hasShininess2 = true;
                }
                else if (paramNameCheck == "G_SHININESSTEXTURE" || paramNameCheck == "G_SHININESS" || paramNameCheck.Contains("SHININESS"))
                {
                    LookupTexture(ref dest.ShininessTextureResource, dest, matparam, mat.MTD);
                }
                else if (paramNameCheck.Contains("BLENDMASK"))
                {
                    LookupTexture(ref dest.BlendmaskTextureResource, dest, matparam, mat.MTD);
                    blendMask = true;
                }
            }

            if (blendMask)
            {
                dest.ShaderName = @"FlverShader\FlverShader_blendmask";
                dest.LayoutType = MeshLayoutType.LayoutUV2;
            }
            else if (blend)
            {
                dest.ShaderName = @"FlverShader\FlverShader_blend";
                dest.LayoutType = MeshLayoutType.LayoutUV2;
            }
            else
            {
                dest.ShaderName = @"FlverShader\FlverShader";
                dest.LayoutType = MeshLayoutType.LayoutStandard;
            }

            List <SpecializationConstant> specConstants = new List <SpecializationConstant>();

            specConstants.Add(new SpecializationConstant(0, (uint)type));
            if (blend || blendMask)
            {
                specConstants.Add(new SpecializationConstant(1, hasNormal2));
                specConstants.Add(new SpecializationConstant(2, hasSpec2));
                specConstants.Add(new SpecializationConstant(3, hasShininess2));
            }

            dest.SpecializationConstants = specConstants.ToArray();
            dest.VertexLayout            = MeshLayoutUtils.GetLayoutDescription(dest.LayoutType);
            dest.VertexSize = MeshLayoutUtils.GetLayoutVertexSize(dest.LayoutType);

            dest.UpdateMaterial();
        }