Esempio n. 1
0
        public MaterialShader(ShaderBlock shader, out ShaderPostprocessBitmapNewBlock[] bitmapBlocks)
        {
            CacheKey cacheKey;

            if (!shader.TryGetCacheKey(out cacheKey))
            {
                bitmapBlocks = new ShaderPostprocessBitmapNewBlock[0];
                return;
            }

            this.shader = shader;

            //  Load shader template class and load shader passes
            bitmapBlocks = shader.PostprocessDefinition[0].Bitmaps;

            var shaderTemplateIdent = ( TagIdent )shader.PostprocessDefinition[0].ShaderTemplateIndex;

            shaderTemplate = ( ShaderTemplateBlock )shaderTemplateIdent.Get(cacheKey);

            shaderPasses    = new ShaderPassBlock[shaderTemplate.PostprocessDefinition[0].Passes.Length];
            shaderPassPaths = new string[shaderTemplate.PostprocessDefinition[0].Passes.Length];
            for (var i = 0; i < shaderPasses.Length; ++i)
            {
                var item = shaderTemplate.PostprocessDefinition[0].Passes[i];
                shaderPasses[i]    = ( ShaderPassBlock )item.Pass.Get(cacheKey);
                shaderPassPaths[i] = item.Pass.ToString( );
            }
        }
Esempio n. 2
0
            private void Visit(ShaderBlock shaderBlock)
            {
                HasMixin = true;

                // Create a context associated with ShaderBlock
                currentContext = new ShaderBlockContext();
                shaderBlock.SetTag(BlockContextTag, currentContext);

                foreach (Statement statement in shaderBlock.Body.Statements)
                {
                    VisitDynamic(statement);
                }
                currentContext = null;
            }
Esempio n. 3
0
        protected virtual void Visit(ShaderBlock shaderBlock)
        {
            WriteLinkLine(shaderBlock);
            currentBlock = shaderBlock;

            VariableAsParameterKey = false;

            // Clear ParameterKey and Mixin references
            parameterKeysReferenced.Clear();
            mixinsReferenced.Clear();

            // Use a single internal class for all shader mixins
            Write("internal static partial class ShaderMixins");
            {
                OpenBrace();
                Write("internal partial class");
                Write(" ");
                Write(shaderBlock.Name);
                WriteSpace();
                Write(" : IShaderMixinBuilder");
                {
                    OpenBrace();
                    // Generate the main generate method for each shader block
                    Write("public void Generate(ShaderMixinSource mixin, ShaderMixinContext context)");
                    {
                        OpenBrace();
                        // Create a context associated with ShaderBlock
                        foreach (Statement statement in shaderBlock.Body.Statements)
                        {
                            VisitDynamic(statement);
                        }
                        CloseBrace();
                    }

                    WriteLine();
                    WriteLine("[ModuleInitializer]");
                    WriteLine("internal static void __Initialize__()");
                    {
                        OpenBrace();
                        Write("ShaderMixinManager.Register(\"").Write(shaderBlock.Name).Write("\", new ").Write(shaderBlock.Name).WriteLine("());");
                        CloseBrace();
                    }
                    CloseBrace();
                }
                CloseBrace();
            }

            VariableAsParameterKey = true;
            currentBlock           = null;
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            FileStream fs = new FileStream("D:\\bloomextract.bls", FileMode.Open, FileAccess.Read);

            try
            {
                string st     = "";
                byte[] buffur = new byte[fs.Length];
                fs.Read(buffur, 0, (int)fs.Length);
                foreach (byte b in buffur)
                {
                    st += b.ToString();
                }
                Console.WriteLine(st);
                //BLS p = new BLS(buffur);
                byte[] re = new ShaderBlock(buffur).Serialize();

                using (FileStream fs1 = new FileStream("D:\\bloom.bls", FileMode.OpenOrCreate, FileAccess.ReadWrite))
                {
                    byte[] buffur1 = re;
                    using (BinaryWriter bw = new BinaryWriter(fs1))
                    {
                        bw.Write(buffur1);
                        bw.Close();
                    }
                }
            }
            catch
            {
            }
            finally
            {
                if (fs != null)

                {
                    //关闭资源
                    fs.Close();
                }
            }


            Console.WriteLine("Hello World!");
            Console.ReadLine();
        }
Esempio n. 5
0
        private List <VertexConstantInfo> GetVertexConstants(ShaderBlock shaderBlock,
                                                             ShaderTemplateBlock shaderTemplateBlock,
                                                             ShaderPassBlock shaderPassBlock, TagDatum vrtxDatum, TagDatum spasDatum, TagDatum stemDatum,
                                                             TagDatum shaderDatum, CacheStream cache)
        {
            var vertexConstantInfos = new List <VertexConstantInfo>( );
            var passes =
                shaderTemplateBlock.PostprocessDefinition[0].Passes.Where(u => u.Pass.Ident == spasDatum.Identifier);

            foreach (var pass in passes)
            {
                for (int i = pass.Implementations.Index; i < pass.Implementations.Index + pass.Implementations.Length; i++)
                {
                    var index =
                        shaderTemplateBlock.PostprocessDefinition[0].Implementations[i].VertexConstants.Index;
                    var length =
                        shaderTemplateBlock.PostprocessDefinition[0].Implementations[i].VertexConstants.Length;
                    for (int j = index; j < index + length; j++)
                    {
                        var sourceIndex = shaderTemplateBlock.PostprocessDefinition[0].Remappings[j].SourceIndex;
                        var bytes       = shaderTemplateBlock.PostprocessDefinition[0].Remappings[j].fieldskip;

                        var vertexConstant = shaderBlock.PostprocessDefinition[0].VertexConstants[sourceIndex];

                        var info = new VertexConstantInfo
                        {
                            source   = sourceIndex,
                            bytes    = bytes,
                            value    = new Vector4(vertexConstant.Vector3, vertexConstant.W),
                            stringId = Halo2.Strings[new StringIdent(BitConverter.ToInt16(bytes, 0), 0)]
                        };
                        vertexConstantInfos.Add(info);
                    }
                }
            }
            return(vertexConstantInfos);
        }
Esempio n. 6
0
        public BLS(byte[] inData)
        {
            using (MemoryStream ms = new MemoryStream(inData))
            {
                using (BinaryReader br = new BinaryReader(ms))
                {
                    this.Header = new BLSHeader(br.ReadBytes(BLSHeader.GetSize()));

                    for (int i = 0; i < this.Header.ShaderBlockCount; ++i)
                    {
                        ShaderBlock shaderBlock = new ShaderBlock(br.ReadBytes(ShaderBlock.GetSize()));
                        shaderBlock.Data = br.ReadChars((int)shaderBlock.DataSize);

                        this.Shaders.Add(shaderBlock);

                        if ((ms.Position % 4) != 0)
                        {
                            long padCount = 4 - (ms.Position % 4);
                            ms.Position += padCount;
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        public static void GenerateOutputFields(FrontEndTranslator translator, ShaderType shaderType, ShaderInterfaceSet interfaceSet, ShaderBlock declarationBlock, ShaderBlock decorationsBlock)
        {
            if (interfaceSet.Fields.Count == 0)
            {
                return;
            }

            var outputsName = shaderType.mMeta.mName + "_Outputs";

            EntryPointGenerationShared.GenerateInterfaceGlobalFields(translator, interfaceSet.Fields, outputsName, "Out", StorageClass.Output);
            foreach (var inputField in interfaceSet)
            {
                var fieldOp = interfaceSet.GetFieldInstance(translator, inputField, null);
                declarationBlock.mLocalVariables.Add(fieldOp);
            }
            Decorations.LocationCallback locationCallback = (ShaderField field, out int location, out int component) =>
            {
                location = component = -1;
                var attribute = field.mMeta.mAttributes.FindFirstAttribute(typeof(Shader.StageOutput));
                if (attribute == null)
                {
                    return(false);
                }
                var parsedAttribute = AttributeExtensions.ParseStageOutput(attribute);
                location  = parsedAttribute.Location;
                component = parsedAttribute.Component;
                return(false);
            };
            Decorations.AddDecorationLocations(translator, shaderType, interfaceSet, locationCallback, decorationsBlock);
        }
Esempio n. 8
0
        public static ShaderOp GenerateOutputBlockStruct(FrontEndTranslator translator, ShaderType shaderType, ShaderInterfaceSet interfaceSet, ShaderBlock declarationBlock, ShaderBlock decorationsBlock)
        {
            var instanceOp = GenerateOutputStruct(translator, shaderType, interfaceSet, declarationBlock, decorationsBlock);

            if (instanceOp == null)
            {
                return(null);
            }

            var instanceType = instanceOp.mResultType.GetDereferenceType();

            Decorations.AddDecorationBlock(translator, instanceType, decorationsBlock);
            return(instanceOp);
        }
Esempio n. 9
0
        public static ShaderOp GenerateOutputStruct(FrontEndTranslator translator, ShaderType shaderType, ShaderInterfaceSet interfaceSet, ShaderBlock declarationBlock, ShaderBlock decorationsBlock)
        {
            if (interfaceSet.Fields.Count == 0)
            {
                return(null);
            }

            var typeName     = shaderType.mMeta.TypeName.CloneAsAppended("_Outputs");
            var instanceName = "Out";
            var instanceOp   = EntryPointGenerationShared.GenerateInterfaceStructAndOp(translator, interfaceSet.Fields, typeName, instanceName, StorageClass.Output);

            Decorations.AddDecorationLocation(translator, instanceOp, 0, decorationsBlock);
            declarationBlock.mLocalVariables.Add(instanceOp);
            return(instanceOp);
        }