Exemplo n.º 1
0
        public static (string name, string lightMode) NameAndLightMode(this ShaderPassType pass, RenderPipeline rp)
        {
            switch (pass)
            {
            case ShaderPassType.Render:
                switch (rp)
                {
                case RenderPipeline.URP:  return("Pass", "SRPDefaultUnlit");

                case RenderPipeline.HDRP: return("ForwardOnly", "ForwardOnly");

                default:                  throw new ArgumentOutOfRangeException(nameof(rp), rp, null);
                }

            case ShaderPassType.Picking:   return("Picking", "Picking");

            case ShaderPassType.Selection: return("Selection", "SceneSelectionPass");

            case ShaderPassType.DepthOnly:
                switch (rp)
                {
                case RenderPipeline.URP:  return("DepthOnly", "DepthOnly");

                case RenderPipeline.HDRP: return("DepthForwardOnly", "DepthForwardOnly");

                default:                  throw new ArgumentOutOfRangeException(nameof(rp), rp, null);
                }

            default: throw new ArgumentOutOfRangeException(nameof(pass), pass, null);
            }
        }
Exemplo n.º 2
0
        void AppendPass(ShaderPassType pass, RenderPipeline rp)
        {
            using (Scope("Pass")) {
                // Name & LightMode
                bool isLegacyMainRenderPass = rp == RenderPipeline.Legacy && pass == ShaderPassType.Render;
                if (isLegacyMainRenderPass == false)
                {
                    (string passName, string lightMode) = pass.NameAndLightMode(rp);
                    AppendLine($"Name \"{passName}\"");
                    AppendLine("Tags { " + (ShaderTag)("LightMode", lightMode) + " }");
                }

                using (Scope("Stencil")) {
                    AppendLine("Comp [_StencilComp]");
                    AppendLine("Pass [_StencilOpPass]");
                    AppendLine("Ref [_StencilID]");
                    AppendLine("ReadMask [_StencilReadMask]");
                    AppendLine("WriteMask [_StencilWriteMask]");
                }

                // culling/blend mode
                if (pass == ShaderPassType.Render)
                {
                    AppendLines(blendMode.GetPassRenderStates());
                }
                else
                {
                    AppendLine("Cull Off");                       // todo: might be incorrect for DepthOnly
                }
                // hlsl program
                AppendHlslProgram(pass, rp);
            }
        }
Exemplo n.º 3
0
        public void AppendCGPROGRAM(ShaderPassType passType)
        {
            AppendLine("CGPROGRAM");
            indentLevel++;
            AppendLine("#pragma vertex vert");
            AppendLine("#pragma fragment frag");
            AppendLine("#pragma multi_compile_instancing");
            if (shaderKeywords.ContainsKey(shaderName))
            {
                AppendLines(shaderKeywords[shaderName].Select(x => x.ToString()));
            }
            AppendLine($"#define {blendMode.BlendShaderDefine()}");
            if (passType == ShaderPassType.Picking || passType == ShaderPassType.Selection)
            {
                AppendLine("#pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap");
                if (passType == ShaderPassType.Picking)
                {
                    AppendLine("#define SCENE_VIEW_PICKING");
                }
                else if (passType == ShaderPassType.Selection)
                {
                    AppendLine("#define SCENE_VIEW_OUTLINE_MASK");
                }
            }

            AppendLine($"#include \"../../Core/{shaderName} Core.cginc\"");
            indentLevel--;
            AppendLine("ENDCG");
        }
Exemplo n.º 4
0
        void AppendHlslProgram(ShaderPassType passType, RenderPipeline rp)
        {
            AppendLine("HLSLPROGRAM");
            indentLevel++;
            AppendLine("#pragma vertex vert");
            AppendLine("#pragma fragment frag");
            AppendLine("#pragma multi_compile_instancing");
            if (rp != RenderPipeline.Legacy)
            {
                AppendLine("#pragma prefer_hlslcc gles");
                AppendLine("#pragma exclude_renderers d3d11_9x");
                AppendLine("#pragma target 2.0");
            }

            if (shaderKeywords.ContainsKey(shaderName))
            {
                AppendLines(shaderKeywords[shaderName].Select(x => x.ToString()));
            }
            AppendLine($"#define {blendMode.BlendShaderDefine()}");
            if (passType == ShaderPassType.Picking || passType == ShaderPassType.Selection)
            {
                AppendLine("#pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap");
                if (passType == ShaderPassType.Picking)
                {
                    AppendLine("#define SCENE_VIEW_PICKING");
                }
                else if (passType == ShaderPassType.Selection)
                {
                    AppendLine("#define SCENE_VIEW_OUTLINE_MASK");
                }
            }

            AppendLine($"#include \"../../Core/{shaderName} Core.cginc\"");
            indentLevel--;
            AppendLine("ENDHLSL");
        }