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(); }
public void Write(ShaderGenerationContext context) { if (!IsDefault) { context.WriteLine("HLSLINCLUDE"); context.WriteLine("#define _NormalMap"); context.WriteLine("ENDHLSL"); } }
public override void Write(ShaderGenerationContext context) { context.WriteLine("#define UNITY_SHADER_NO_UPGRADE 1"); context.LogShaderSection("Vertex Shader"); context.WriteIndented(WriteInnerVertexShader); context.WriteLine("}"); }
internal void GeneratePasses(ShaderGenerationContext context) { context.WriteLine("SubShader{"); var passes = GetShaderModel(); context.WriteIndented(passes.Write); context.WriteLine("}"); }
public virtual void Write(ShaderGenerationContext context) { if (IsDefault || !context.CurrentPass.IsMainPass) { return; } context.LogShaderSection("FinalColor Code Block"); context.WriteLine("float4 finalColor = __color;"); context.WriteLine(_parsedCode); context.WriteLine("__color = finalColor;"); }
public void Write(ShaderGenerationContext context) { context.WriteLine($"#define __SAMPLETEXTURE{Name.ToUpper()}(uv) "); if (KeywordProperty.HasProperty(context, PropertyType.Texture, Name)) { context.Write($"tex2D({Name}, uv)"); context.WriteLine($"#define __HASETEXTURE{Name.ToUpper()} True"); } else { context.Write($" float4({DefaultValue.x}, {DefaultValue.y}, {DefaultValue.z}, {DefaultValue.w})"); } }
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("}"); }
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)); } }
private void WriteInnerVertexShader(ShaderGenerationContext context) { context.WriteLine("Varyings vert(Attributes input){"); context.WriteLine(" Varyings output = (Varyings)0;"); context.WriteLine("VertexPositionInputs __vertexPositionInputs = GetVertexPositionInputs(input.__ATTRIBUTESPOSITION);"); InitializeVaryingsWithDefaultValues(context); context.WriteLine(context.CurrentPass.GetVertexShaderHeader()); base.Write(context); context.WriteLine(context.CurrentPass.GetVertexShaderFooter()); context.WriteLine("output.__VARYINGSPOSITION = __vertexPositionInputs.positionCS;"); context.WriteLine(" return output;"); }
public void WriteAttributeDefinition(ShaderGenerationContext context, int attributeIndex, bool isFragmentShader) { context.WriteLine($"{DataTypeAndDimensionsString} {Name} : "); if (AttributeType == AttributeType.Anonymous) { context.Write($"COLOR1{attributeIndex}"); } else { if (isFragmentShader && AttributeType == AttributeType.Position) { context.Write("SV_POSITION"); } else { context.Write(AttributeType.ToString().ToUpper()); } } context.Write(";"); }
private void WriteFragmentShaderHeader(ShaderGenerationContext context) { context.WriteLine(context.CurrentPass.GetFragmentShaderHeader()); context.Newine(); }
public virtual void Write(ShaderGenerationContext context) { context.LogShaderSection("User Written Code"); context.WriteLine(_parsedCode); }
public void Write(ShaderGenerationContext context) { context.WriteLine($"Tags{{\"Queue\" = \"{FirstLineArguments}\"}}"); }
public void Write(ShaderGenerationContext context) { context.WriteLine($"#define {FirstLineArguments}"); }
public void Write(ShaderGenerationContext context, bool propertyDefinition) { if (IsDefault) { return; } if (propertyDefinition) { switch (_propertyType) { case PropertyType.Texture: context.WriteLine($"{_propertyName} (\"{_propertyName}\", 2D) = \"\"{{}}"); break; case PropertyType.Float: context.WriteLine($"{_propertyName} (\"{_propertyName}\", Float) = {_defaultValue}"); break; case PropertyType.Float2: case PropertyType.Float3: case PropertyType.Float4: context.WriteLine($"{_propertyName} (\"{_propertyName}\", Vector) = {_defaultValue}"); break; case PropertyType.Color: context.WriteLine($"{_propertyName} (\"{_propertyName}\", Color) = {_defaultValue}"); break; default: throw new ArgumentOutOfRangeException(); } } else { switch (_propertyType) { case PropertyType.Texture: context.WriteLine($"sampler2D {_propertyName};"); break; case PropertyType.Float: context.WriteLine($"float {_propertyName};"); break; case PropertyType.Float2: context.WriteLine($"float2 {_propertyName};"); break; case PropertyType.Float3: context.WriteLine($"float3 {_propertyName};"); break; case PropertyType.Float4: case PropertyType.Color: context.WriteLine($"float4 {_propertyName};"); break; default: throw new ArgumentOutOfRangeException(); } } }
internal override void WritePass(ShaderGenerationContext context, ShaderModel config, SourceMap.ShaderPassSource passSpecificCode) { context.WriteLine($"UsePass \"{_passName}\""); }
internal override void Write(ShaderGenerationContext context) { context.WriteLine($"{Name} True"); }