コード例 #1
0
 public virtual bool UseRenderer(string archive, string model, SHARCFB sharcFB)
 {
     return(false);
 }
コード例 #2
0
        /// <summary>
        /// Called once when the renderer can be loaded from a given shader model and mesh.
        /// </summary>
        public void OnLoad(SHARCFB sharcfb, FMDL model, FSHP mesh, BfresMeshAsset meshAsset)
        {
            ShaderModel = sharcfb.Programs.FirstOrDefault(x => x.Name == mesh.Material.ShaderModel);
            if (ShaderModel == null)
            {
                Console.WriteLine($"Failed to find program! {mesh.Material.ShaderModel}");
                return;
            }

            //Assign some necessary data
            meshAsset.MaterialAsset = this;

            //Force reload from material editing
            mesh.ShaderReload += delegate
            {
                Console.WriteLine($"Reloading shader program {meshAsset.Name}");
                this.ReloadRenderState(meshAsset);
                this.ReloadProgram(meshAsset);
                mesh.HasValidShader = this.HasValidProgram;

                Console.WriteLine($"Program Validation: {this.HasValidProgram}");
                this.UpdateShader = true;
            };

            MaterialData = mesh.Material;
            ParentModel  = model;
            //Load mesh function for loading the custom shader for the first time
            LoadMesh(meshAsset);
            ReloadRenderState(meshAsset);
            ReloadProgram(meshAsset);

            var gx2ShaderVertex = (GX2VertexShader)ShaderModel.GetGX2VertexShader(BinaryIndex);
            var bfresMaterial   = (FMAT)this.MaterialData;

            //Remap the vertex layouts from shader model attributes
            Dictionary <string, string> attributeLocations = new Dictionary <string, string>();

            for (int i = 0; i < gx2ShaderVertex.Attributes.Count; i++)
            {
                var symbol = ShaderModel.AttributeVariables.symbols.FirstOrDefault(
                    x => x.Name == gx2ShaderVertex.Attributes[i].Name);

                if (symbol == null)
                {
                    continue;
                }

                var attribVar   = gx2ShaderVertex.Attributes[i];
                var arrayCount  = Math.Max(1, attribVar.Count);
                var streamCount = attribVar.GetStreamCount();

                if (arrayCount > 1 || streamCount > 1)
                {
                    throw new Exception("Multiple attribute streams and variable counts not supported!");
                }

                attributeLocations.Add(symbol.SymbolName, $"{symbol.Name}_0_0");
            }

            meshAsset.UpdateVaoAttributes(attributeLocations);
        }
コード例 #3
0
 public ShaderProgram(SHARCFB shader)
 {
     ParentFile = shader;
 }