public GenShader(RenderPipeline rp, RenderingMode rm, EnabledFeatures enabledFeatures) { m_RenderingMode = rm; m_EnabledFeatures = enabledFeatures; switch (rp) { case RenderPipeline.BuiltIn: AddPass(CullMode.Front); if (rm == RenderingMode.MultiPass) { AddPass(CullMode.Back); } m_RenderPipeline = SRPHelper.RenderPipeline.BuiltIn; break; case RenderPipeline.URP: AddPass(CullMode.Front); m_RenderPipeline = SRPHelper.RenderPipeline.URP; break; case RenderPipeline.HDRP: AddPass(CullMode.Front); m_RenderPipeline = SRPHelper.RenderPipeline.HDRP; break; } }
string GetRenderPipelineInclude(SRPHelper.RenderPipeline rp) { switch (rp) { case SRPHelper.RenderPipeline.BuiltIn: return("ShaderSpecificBuiltin.cginc"); case SRPHelper.RenderPipeline.HDRP: return("ShaderSpecificHDRP.hlsl"); case SRPHelper.RenderPipeline.LWRP: case SRPHelper.RenderPipeline.URP: return("ShaderSpecificURP.cginc"); } return(null); }
static ShaderLangage GetShaderLangage(SRPHelper.RenderPipeline rp) { switch (rp) { case SRPHelper.RenderPipeline.BuiltIn: case SRPHelper.RenderPipeline.LWRP: return(ShaderLangage.CG); case SRPHelper.RenderPipeline.URP: case SRPHelper.RenderPipeline.HDRP: return(ShaderLangage.HLSL); } return(ShaderLangage.CG); }
TextAsset GetTextAssetIncludes(SRPHelper.RenderPipeline rp) { switch (rp) { case SRPHelper.RenderPipeline.BuiltIn: return(textAssetIncludesBuiltin); case SRPHelper.RenderPipeline.LWRP: case SRPHelper.RenderPipeline.URP: return(textAssetIncludesURP); case SRPHelper.RenderPipeline.HDRP: return(textAssetIncludesHDRP); } return(null); }
public string Generate(SRPHelper.RenderPipeline rp, RenderingMode rm, EnabledFeatures enabledFeatures, int passID, int passCount) { var code = LoadText(Instance.textAssetPass); code = code.Replace("{VLB_GEN_CULLING}", m_CullMode.ToString()); code = code.Replace("{VLB_GEN_PRAGMA_INSTANCING}", rm == RenderingMode.GPUInstancing ? "#pragma multi_compile_instancing" : ""); code = code.Replace("{VLB_GEN_PRAGMA_FOG}", IsFogSupported(rp) ? "#pragma multi_compile_fog" : ""); string multiCompileVariants = ""; AppendMultiCompile(ref multiCompileVariants, true, ShaderKeywords.AlphaAsBlack); if (enabledFeatures.noise3D) { AppendMultiCompile(ref multiCompileVariants, true, ShaderKeywords.Noise3D); } if (enabledFeatures.depthBlend) { AppendMultiCompile(ref multiCompileVariants, true, ShaderKeywords.DepthBlend); } switch (enabledFeatures.colorGradient) { case FeatureEnabledColorGradient.HighOnly: AppendMultiCompile(ref multiCompileVariants, true, ShaderKeywords.ColorGradientMatrixHigh); break; case FeatureEnabledColorGradient.HighAndLow: AppendMultiCompile(ref multiCompileVariants, true, ShaderKeywords.ColorGradientMatrixHigh, ShaderKeywords.ColorGradientMatrixLow); break; } if (enabledFeatures.dynamicOcclusion) { AppendMultiCompile(ref multiCompileVariants, true, ShaderKeywords.OcclusionClippingPlane, ShaderKeywords.OcclusionDepthTexture); } if (enabledFeatures.meshSkewing) { AppendMultiCompile(ref multiCompileVariants, true, ShaderKeywords.MeshSkewing); } if (enabledFeatures.shaderAccuracyHigh) { AppendMultiCompile(ref multiCompileVariants, true, ShaderKeywords.ShaderAccuracyHigh); } code = code.Replace("{VLB_GEN_PRAGMA_MULTI_COMPILE_VARIANTS}", multiCompileVariants); var lang = GetShaderLangage(rp); code = code.Replace("{VLB_GEN_PROGRAM_PRE}", GetShaderLangagePre(lang)); code = code.Replace("{VLB_GEN_PROGRAM_POST}", GetShaderLangagePost(lang)); var passPre = ""; if (passCount > 1) { code = code.Replace("{VLB_GEN_INPUT_VS}", string.Format("{0}", passID)); code = code.Replace("{VLB_GEN_INPUT_FS}", string.Format("{0}", passID)); } else { code = code.Replace("{VLB_GEN_INPUT_VS}", string.Format("{0}", "v.texcoord.y")); code = code.Replace("{VLB_GEN_INPUT_FS}", string.Format("{0}", "i.cameraPosObjectSpace_outsideBeam.w")); passPre += " #define VLB_PASS_OUTSIDEBEAM_FROM_VS_TO_FS 1" + System.Environment.NewLine; } if (rp != SRPHelper.RenderPipeline.BuiltIn) { passPre += " #define VLB_SRP_API 1" + System.Environment.NewLine; if (rm == RenderingMode.SRPBatcher) { passPre += " #define VLB_SRP_BATCHER 1" + System.Environment.NewLine; if (rp == SRPHelper.RenderPipeline.URP) { // force enable constant buffers to fix SRP Batcher support on Android passPre += " #pragma enable_cbuffer" + System.Environment.NewLine; } } } if (enabledFeatures.dithering) { passPre += " #define VLB_DITHERING 1" + System.Environment.NewLine; } passPre += LoadText(Instance.GetTextAssetIncludes(rp)); code = code.Replace("{VLB_GEN_PRE}", passPre); return(code); }
static bool IsFogSupported(SRPHelper.RenderPipeline rp) { return(rp != SRPHelper.RenderPipeline.HDRP); }