public void PostProcessShader(string[] features, StringBuilder sb, MicroSplatShaderGUI.MicroSplatCompiler compiler, MicroSplatShaderGUI.MicroSplatCompiler.AuxShader auxShader) { StringBuilder temp = new StringBuilder(); compiler.WriteFeatures(features, temp); if (auxShader != null && auxShader.trigger == "_TERRAINBLENDING") { temp.AppendLine(" #define _SRPTERRAINBLEND 1"); } StringBuilder cbuffer = new StringBuilder(); compiler.WritePerMaterialCBuffer(features, cbuffer); if (auxShader != null && auxShader.trigger == "_TERRAINBLENDING") { cbuffer.AppendLine(terrainBlendCBuffer.text); } sb = sb.Replace("//MS_DEFINES", temp.ToString()); sb = sb.Replace("//MS_ADAPTER", adapter.ToString()); sb = sb.Replace("//MS_SHARED_INC", sharedInc.text); sb = sb.Replace("//MS_SHARED_HD", sharedHD.text); sb = sb.Replace("//MS_TERRAIN_BODY", terrainBody.text); sb = sb.Replace("//MS_VERTEXMOD", vertex.text); sb = sb.Replace("//MS_MAINFUNC", mainFunc.text); sb = sb.Replace("//MS_CBUFFER", cbuffer.ToString()); sb = sb.Replace("//MS_PASS_DEPTHONLY", vertMesh.text + "\n" + pass_depthonly.text); sb = sb.Replace("//MS_PASS_GBUFFER", vertMesh.text + "\n" + pass_gbuffer.text); sb = sb.Replace("//MS_PASS_FORWARD", vertMesh.text + "\n" + pass_forward.text); sb = sb.Replace("//MS_PASS_LIGHTTRANSPORT", vertMesh.text + "\n" + pass_lighttransport.text); sb = sb.Replace("//MS_PASS_DECAL", vertMesh.text + "\n" + pass_decal.text); if (auxShader != null && auxShader.trigger == "_TERRAINBLENDING") { sb = sb.Replace("//MS_BLENDABLE", terrainBlendBody.text); sb = sb.Replace("Blend [_SrcBlend] [_DstBlend], [_AlphaSrcBlend] [_AlphaDstBlend]", "Blend SrcAlpha OneMinusSrcAlpha"); } // extentions StringBuilder ext = new StringBuilder(); compiler.WriteExtensions(features, ext); sb = sb.Replace("//MS_EXTENSIONS", ext.ToString()); ext = new StringBuilder(); foreach (var e in compiler.extensions) { e.WriteAfterVetrexFunctions(ext); } sb = sb.Replace("//MS_AFTERVERTEX", ext.ToString()); // HD fixup sb = sb.Replace("fixed", "half"); sb = sb.Replace("unity_ObjectToWorld", "GetObjectToWorldMatrix()"); sb = sb.Replace("unity_WorldToObject", "GetWorldToObjectMatrix()"); sb = sb.Replace("_ObjectToWorld", "GetObjectToWorldMatrix()"); sb = sb.Replace("_WorldToObject", "GetWorldToObjectMatrix()"); sb = sb.Replace("UNITY_MATRIX_M", "GetObjectToWorldMatrix()"); sb = sb.Replace("UNITY_MATRIX_I_M", "GetWorldToObjectMatrix()"); sb = sb.Replace("UNITY_MATRIX_VP", "GetWorldToHClipMatrix()"); sb = sb.Replace("UNITY_MATRIX_V", "GetWorldToViewMatrix()"); sb = sb.Replace("UNITY_MATRIX_P", "GetViewToHClipMatrix()"); if (features.Contains("_USESPECULARWORKFLOW")) { sb = sb.Replace("// #define _MATERIAL_FEATURE_SPECULAR_COLOR 1", "#define _MATERIAL_FEATURE_SPECULAR_COLOR 1"); } if (features.Contains("_TESSDISTANCE")) { sb = sb.Replace("#pragma vertex Vert", "#pragma hull hull\n#pragma domain domain\n#pragma vertex tessvert\n#pragma require tessellation tessHW\n"); } }
public Blocks GetShaderBlocks(string[] features, MicroSplatShaderGUI.MicroSplatCompiler compiler, MicroSplatShaderGUI.MicroSplatCompiler.AuxShader auxShader) { StringBuilder defines = new StringBuilder(); compiler.WriteDefines(features, defines); if (auxShader != null && auxShader.trigger == "_TERRAINBLENDING") { defines.AppendLine(" #define _SRPTERRAINBLEND 1"); } if (features.Contains("_USESPECULARWORKFLOW")) { defines.AppendLine(" #define _SPECULAR_SETUP"); } if (features.Contains("_MICROTERRAIN") && !features.Contains("_TERRAINBLENDABLESHADER")) // digger? mesh terrain? { defines.AppendLine("#pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap forwardadd"); } StringBuilder cbuffer = new StringBuilder(); compiler.WritePerMaterialCBuffer(features, cbuffer); if (auxShader != null && auxShader.trigger == "_TERRAINBLENDING") { cbuffer.AppendLine(terrainBlendCBuffer.text); } StringBuilder options = new StringBuilder(); WriteOptions(features, options, compiler, auxShader, null); StringBuilder properties = new StringBuilder(); compiler.WriteProperties(features, properties, auxShader); StringBuilder ext = new StringBuilder(); compiler.WriteExtensions(features, ext); StringBuilder afterVertex = new StringBuilder(); foreach (var e in compiler.extensions) { e.WriteAfterVetrexFunctions(afterVertex); } StringBuilder code = new StringBuilder(100000); code.AppendLine(adapter.text); code.AppendLine(sharedInc.text); code.AppendLine(StripVertexWorkflow(features)); code.AppendLine((StripMegaSplat(features))); if (features.Contains("_PLANETVECTORS") && planetData != null) { code.AppendLine(planetData.text); } code.AppendLine(sharedHD.text); code.AppendLine(ext.ToString()); code.AppendLine(terrainBody.text); code.AppendLine(vertex.text); if (auxShader != null && auxShader.trigger == "_TERRAINBLENDING") { code.AppendLine(terrainBlendBody.text); } code.AppendLine(mainFunc.text); code.AppendLine(afterVertex.ToString()); Blocks b = new Blocks(); b.code = code.ToString(); b.cbuffer = cbuffer.ToString(); b.properties = properties.ToString(); b.defines = defines.ToString(); b.options = options.ToString(); return(b); }