Esempio n. 1
0
        private void InitializeVaryingsWithDefaultValues(ShaderGenerationContext context)
        {
            var vertexInput   = context.KeywordMap.GetKeyword <KeywordVertexInput>();
            var fragmentInput = context.KeywordMap.GetKeyword <KeywordFragmentInput>();

            bool hasDefinedFragmentShader = !IsDefault;

            var attributesToInit = new List <AttributeConfig>();

            var vertexAttributes = vertexInput.GetAttributes();

            foreach (var fragmentAttribute in fragmentInput.GetAttributes())
            {
                if (fragmentAttribute.AttributeType == AttributeType.Anonymous || fragmentAttribute.AttributeType == AttributeType.Position)
                {
                    continue;
                }

                if (vertexAttributes.Any(vertexAttribute => fragmentAttribute == vertexAttribute))
                {
                    attributesToInit.Add(fragmentAttribute);
                }
            }

            foreach (AttributeConfig config in attributesToInit)
            {
                context.WriteLineIndented($"output.__VARYINGS{config.AttributeType.ToString().ToUpper()} = input.__ATTRIBUTES{config.AttributeType.ToString().ToUpper()};");
            }
        }
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("}");
        }