public GLSLPassTemplate(TranslatedMaterialGraph graph) { Graph = graph; VertexShaderGenerator = new GLSLCodeGen(this); VertexShaderUniformsAndFunctions = new UniformsAndFunctions( graph.Script.Nodes.Where(_ => _.Extra != null && !_.Extra.RequiredInPixelShader), graph.VertexShaderUniforms, VertexShaderGenerator); PixelShaderGenerator = new GLSLCodeGen(this); PixelShaderUniformsAndFunctions = new UniformsAndFunctions( graph.Script.Nodes.Where(_ => _.Extra != null && _.Extra.RequiredInPixelShader), graph.PixelShaderUniforms, PixelShaderGenerator); }
public GLSLPassTemplate(TranslatedMaterialGraph graph) { Graph = graph; VertexShaderGenerator = new GLSLCodeGen(this); VertexShaderUniformsAndFunctions = new UniformsAndFunctions( graph.Script.Nodes.Where(_ => _.Extra?.Attribution == TranslatedMaterialGraph.NodeAttribution.VertexShader), graph.VertexShaderUniforms, VertexShaderGenerator); PixelShaderGenerator = new GLSLCodeGen(this); PixelShaderUniformsAndFunctions = new UniformsAndFunctions( graph.Script.Nodes.Where(_ => _.Extra?.Attribution == TranslatedMaterialGraph.NodeAttribution.PixelShader), graph.PixelShaderUniforms, PixelShaderGenerator); }
/// <summary> /// Create the template output /// </summary> public virtual string TransformText() { #line 6 "D:\Arhiv\projects\CSharp\GitHub\Urho3DMaterialGraphEditor\src\Urho3DMaterialEditor\Model\Templates\GLSLPassTemplate.tt" foreach (var define in Graph.Defines) { WriteLine("#if !defined(" + define + ")"); WriteLine("#define " + define); WriteLine("#endif"); } foreach (var undefine in Graph.Undefines) { WriteLine("#if defined(" + undefine + ")"); WriteLine("#undef " + undefine); WriteLine("#endif"); } #line default #line hidden this.Write(@" // ------------------- Vertex Shader --------------- #if defined(DIRLIGHT) && (!defined(GL_ES) || defined(WEBGL)) #define NUMCASCADES 4 #else #define NUMCASCADES 1 #endif #ifdef COMPILEVS // Silence GLSL 150 deprecation warnings #ifdef GL3 #define attribute in #define varying out #endif "); #line 40 "D:\Arhiv\projects\CSharp\GitHub\Urho3DMaterialGraphEditor\src\Urho3DMaterialEditor\Model\Templates\GLSLPassTemplate.tt" foreach (var uniform in Graph.VertexShaderAttributes) { if (uniform.Type == NodeTypes.VertexData) { throw new InvalidOperationException(); } var type = GLSLCodeGen.GetType(uniform.OutputPins[0].Type); if (uniform.Name == "BlendIndices") { type = "vec4"; } uniform.Extra.Define.WriteLineIfDef(this, "attribute " + type + " i" + uniform.Name + GLSLCodeGen.GetArraySize(uniform.OutputPins[0].Type) + ";"); } foreach (var uniform in VertexShaderUniformsAndFunctions.Uniforms) { uniform.Extra.Define.WriteLineIfDef(this, "uniform " + GLSLCodeGen.GetType(uniform.Type) + " " + uniform.Name + GLSLCodeGen.GetArraySize(uniform.Type) + ";"); }// "uniform highp " foreach (var varyingGroup in Graph.VertexShaderVaryings.ToLookup(_ => _.Extra.Define.GetExpression())) { foreach (var varying in varyingGroup) { WriteLine(varyingGroup.Key, "varying " + GLSLCodeGen.GetType(GLSLCodeGen.GetVaryingType(varying.InputPins[0].Type)) + " v" + varying.Value + GLSLCodeGen.GetArraySize(varying.InputPins[0].Type) + ";"); } } this.WriteLine(null, ""); #line default #line hidden this.Write("\r\nattribute float iObjectIndex;\r\n\r\n\r\n"); #line 69 "D:\Arhiv\projects\CSharp\GitHub\Urho3DMaterialGraphEditor\src\Urho3DMaterialEditor\Model\Templates\GLSLPassTemplate.tt" foreach (var function in VertexShaderUniformsAndFunctions.Functions) { WriteLine("// --- " + function + " ---"); WriteLine(VertexShaderGenerator.GetFunction(function)); } this.WriteLine(null, ""); #line default #line hidden this.Write("\r\nvoid VS()\r\n{\r\n"); #line 80 "D:\Arhiv\projects\CSharp\GitHub\Urho3DMaterialGraphEditor\src\Urho3DMaterialEditor\Model\Templates\GLSLPassTemplate.tt" foreach (var varying in Graph.VertexShaderVaryings) { VertexShaderGenerator.GenerateCode(varying); } this.WriteLine(null, ""); var ret = VertexShaderGenerator.GenerateCode(Graph.OutputPosition); WriteLine("vec4 ret = " + ret + ";"); this.WriteLine(null, ""); #line default #line hidden this.Write(@" // While getting the clip coordinate, also automatically set gl_ClipVertex for user clip planes #if !defined(GL_ES) && !defined(GL3) gl_ClipVertex = ret; #elif defined(GL3) gl_ClipDistance[0] = dot(cClipPlane, ret); #endif gl_Position = ret; } #else // ------------------- Pixel Shader --------------- "); #line 101 "D:\Arhiv\projects\CSharp\GitHub\Urho3DMaterialGraphEditor\src\Urho3DMaterialEditor\Model\Templates\GLSLPassTemplate.tt" foreach (var uniform in PixelShaderUniformsAndFunctions.Uniforms) { // WriteIfDef(uniform); if (uniform.Type == PinTypes.LightMatrices) { uniform.Extra.Define.WriteLineIfDef(this, @" #if !defined(GL_ES) || defined(WEBGL) uniform mat4 cLightMatrices[4]; #else uniform highp mat4 cLightMatrices[2]; #endif "); } else { uniform.Extra.Define.WriteLineIfDef(this, "uniform " + GLSLCodeGen.GetType(uniform.Type) + " " + uniform.Name + ";"); } // WriteEndIf(uniform); //uniform highp } foreach (var uniform in Graph.Samplers) { if (uniform.Name == SamplerNodeFactory.ShadowMap) { uniform.Extra.Define.WriteLineIfDef(this, @" #ifndef GL_ES #ifdef VSM_SHADOW uniform sampler2D sShadowMap; #else uniform sampler2DShadow sShadowMap; #endif #else uniform highp sampler2D sShadowMap; #endif " ); } else { uniform.Extra.Define.WriteLineIfDef(this, "uniform " + GLSLCodeGen.GetType(uniform.OutputPins[0]) + " " + GLSLCodeGen.GetSamplerName(uniform) + ";"); } } foreach (var varyingGroup in Graph.PixelShaderVaryings.ToLookup(_ => _.Extra.Define.GetExpression())) { foreach (var varying in varyingGroup) { WriteLine(varyingGroup.Key, "varying " + GLSLCodeGen.GetType(GLSLCodeGen.GetVaryingType(varying.OutputPins[0].Type)) + " v" + varying.Value + GLSLCodeGen.GetArraySize(varying.OutputPins[0].Type) + ";"); } } this.WriteLine(null, ""); #line default #line hidden this.Write("\r\n"); #line 153 "D:\Arhiv\projects\CSharp\GitHub\Urho3DMaterialGraphEditor\src\Urho3DMaterialEditor\Model\Templates\GLSLPassTemplate.tt" foreach (var function in PixelShaderUniformsAndFunctions.Functions) { WriteLine("// --- " + function + " ---"); WriteLine(PixelShaderGenerator.GetFunction(function)); } this.WriteLine(null, ""); #line default #line hidden this.Write("\r\nvoid PS()\r\n{\r\n"); #line 164 "D:\Arhiv\projects\CSharp\GitHub\Urho3DMaterialGraphEditor\src\Urho3DMaterialEditor\Model\Templates\GLSLPassTemplate.tt" foreach (var discard in Graph.Discards) { PixelShaderGenerator.GenerateCode(discard); } foreach (var rt in Graph.RenderTargets) { PixelShaderGenerator.GenerateCode(rt); } this.WriteLine(null, ""); #line default #line hidden this.Write("}\r\n#endif"); return(this.GenerationEnvironment.ToString()); }