public virtual void Write(ShaderGenerationContext context)
        {
            AddPassRequiredAttributes(GetRequiredPassAttributes(context));
            AddPassKeywords(GetRequiredPassKeywords(context));

            context.LogShaderSection($"Generated Data Struct {AttributeStructName}");

            context.WriteLine($"struct {AttributeStructName}");
            context.WriteLine("{");

            context.WriteIndented((c) =>
            {
                for (int i = 0; i < _attributes.Count; i++)
                {
                    AttributeConfig config = _attributes[i];
                    if (config.AttributeType != AttributeType.Anonymous)
                    {
                        c.WriteLine($"#define __{AttributeStructName.ToUpper()}{config.AttributeType.ToString().ToUpper()}  {config.Name}");
                    }

                    config.WriteAttributeDefinition(c, i, this is KeywordFragmentInput);
                }
            });

            foreach (string keyword in _keywords)
            {
                context.WriteLine(keyword);
            }

            context.WriteLine("};");
            context.Newine();
        }
Esempio n. 2
0
        public override void Write(ShaderGenerationContext context)
        {
            context.LogShaderSection("Fragment Shader");

            //todo it migh be more performant to only output a float3 for opaque shaders
            context.WriteLine($"{context.CurrentPass.FragmentReturnFormat} frag(Varyings input) : COLOR{{");

            context.WriteIndented(WriteFragmentShaderHeader);

            base.Write(context);

            context.WriteIndented(WriteFragmentShaderFooter);

            context.KeywordMap.GetKeyword <KeywordModifyFinalColor>().Write(context);

            context.WriteLineIndented("return __color;");

            context.WriteLine("}");
        }
Esempio n. 3
0
        public override void Write(ShaderGenerationContext context)
        {
            context.WriteLine("#define UNITY_SHADER_NO_UPGRADE 1");

            context.LogShaderSection("Vertex Shader");

            context.WriteIndented(WriteInnerVertexShader);

            context.WriteLine("}");
        }
Esempio n. 4
0
        internal void GeneratePasses(ShaderGenerationContext context)
        {
            context.WriteLine("SubShader{");

            var passes = GetShaderModel();

            context.WriteIndented(passes.Write);

            context.WriteLine("}");
        }
Esempio n. 5
0
        public void Write(ShaderGenerationContext context)
        {
            context.KeywordMap.GetKeyword <KeywordQueue>().Write(context);
            //todo workaround for now
            context.KeywordMap.GetKeyword <KeywordHasNormalMap>().Write(context);

            context.WriteLine("HLSLINCLUDE");

            context.WriteLine("#include \"Packages/com.henningboat.thshader/ShaderLibrary/Common.cginc\"");

            foreach (ShaderModelTexture modelTexture in OptionalShaderModelTextures)
            {
                modelTexture.Write(context);
            }

            context.KeywordMap.GetMultiKeywords <KeywordDefine>().ForEach(keyword => keyword.Write(context));
            context.KeywordMap.GetMultiKeywords <KeywordProperty>().ForEach(keyword => keyword.Write(context, false));

            context.WriteLine(ShaderPass.ReadSourceFile(context, SubShaderHeader));

            context.WriteLine("ENDHLSL");

            GeneratePasses(context, out ShaderPass mainPass, out List <ShaderPass> additionalPasses);

            if (context.SourceMap.CustomPasses.Count > 0)
            {
                foreach (SourceMap.ShaderPassSource customPass in context.SourceMap.CustomPasses)
                {
                    context.WriteIndented(buildContext => mainPass.WritePass(buildContext, this, customPass));
                }
            }
            else
            {
                context.WriteIndented(buildContext => mainPass.WritePass(buildContext, this, null));
            }

            foreach (ShaderPass pass in additionalPasses)
            {
                context.WriteIndented(buildContext => pass.WritePass(buildContext, this, null));
            }
        }