123456806 发表于 2020-12-22 17:40

Vscode for Unity Shader 用户代码片段(持续更新)

使用方法:打开vscode,文件→首选项→用户片段,输入shaderlab,复制粘贴即可{
    // Place your snippets for shaderlab here. Each snippet is defined under a snippet name and has a prefix, body and
    // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
    // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
    // same ids are connected.
    // Example:
    // "Print to console": {
    //"prefix": "log",
    //"body": [
    //      "console.log('$1');",
    //      "$2"
    //],
    //"description": "Log output to console"
    // }

    "Unity3D Shaderlab": {
      "prefix": "shaderlab",
      "body":[
            "Shader \"${1:New Shader}\"",
            "{",
                "\tProperties",
                "\t{",
                  "\t\t_MainTex (\"Texture\", 2D) = \"white\" {}",
                "\t}",
                "\tSubShader",
                "\t{",
                  "\t\tTags { \"RenderType\"=\"${2:Opaque}\" }\n",
                  "\t\tPass",
                  "\t\t{",
                  "\t\t\t$3",
                  "\t\t}",
                "\t}",
            "}"
      ],
      "description": "Unity3D Shaderlab"
    },
    "Unity3D SurfaceShader":{
      "prefix": "surfaceShader",
      "body": [
            "Shader \"${1:New Shader}\"",
                "{",
                  "\tProperties",
                  "\t{\n",
                                          
                  "\t}",
                  "\tSubShader",
                  "\t{",
                        "\t\tTags { \"RenderType\"=\"${2:Opaque}\" \"Queue\"=\"${3:Geometry}\" }\n",
                        "\t\tCGPROGRAM",
                        "\t\t#pragma surface surf Standard\n",
                        "\t\tstruct Input{\n",

                        "\t\t};\n\n",
                        
                        "\t\tvoid surf(Input IN,inout SurfaceOutput o) {\n",
                        
                        "\t\t}",
                        "\t\tENDCG",
                  "\t}",
                  "\tFallBack \"Diffuse\"",
                "}"         
            
      ],
    },
    "CGPROGRAM": {
      "prefix": "cg",
      "body": [
            "CGPROGRAM",
            "#pragma vertex vert",
            "#pragma fragment frag\n",
            "#include \"UnityCG.cginc\"\n",
            "struct appdata",
            "{",
                "\tfloat4 vertex : POSITION;",
                "\tfloat2 uv : TEXCOORD0;",
            "};\n",
            "struct v2f",
            "{",
                "\tfloat2 uv : TEXCOORD0;",
                "\tfloat4 vertex : SV_POSITION;",
            "};\n",
            "sampler2D _MainTex;\n",
            "v2f vert(appdata v)",
            "{",
                "\tv2f o;",
                "\to.vertex = UnityObjectToClipPos(v.vertex);",
                "\to.uv = TRANSFORM_TEX(v.uv, _MainTex);\n",
            
                "\treturn o;",
            "}\n",
            
            "fixed4 frag(v2f i) : SV_Target",
            "{",
                "\t// sample the texture",
                "\tfixed4 col = tex2D(_MainTex, i.uv);",
                "\treturn col;",
            "}",
            "ENDCG"
      ],
      "description": "Unity3D Shaderlab CGPROGRAM"
    },

    "Multi Lighting Control":{
      "prefix": "multi_compile_fwdbase",
      "body": [
            "multi_compile_fwdbase",
            
      ],
      "description": "instructs Unity to compile all variants necessary for forward base rendering"
    },

    "Shadow Caster":{
      "prefix": "multi_compile_shadowcaster",
      "body": [
            "multi_compile_shadowcaster",
            
      ],
      "description": "ensures that the shader compiles all necessary variants required for shadow casting"
    },

    "SHADOW_ATTENUTATION":{
      "prefix": "SHADOW_ATTENUATION",
      "body": [
            "SHADOW_ATTENUATION($0)",
      ],
      "description": "a macro that returns a value between 0 and 1, where 0 indicates no shadow and 1 is fully shadowed"
    },

    "Camera Depth Texture":{
      "prefix": "_CameraDepthTexture",
      "body": "_CameraDepthTexture",
      "description": "the depth buffer globally available that Unity provides"
    },

    "Linear Eye Depth":{
      "prefix": "LinearEyeDepth",
      "body": "LinearEyeDepth($0)",
      "description": " convert the raw value to the linear depth"
    },

    "SAMPLE_DEPTH_TEXTURE":{
      "prefix": "SAMPLE_DEPTH_TEXTURE",
      "body": "SAMPLE_DEPTH_TEXTURE(_CamperaDepthTexture,${float2:uv})",
      "description": "a macro that for sampling the background depth"
    },

    "UNITY_Z_0_FAR_FROM_CLIPSPACE":{
      "prefix": "UNITY_Z_0_FAR_FROM_CLIPSPACE",
      "body": "UNITY_Z_0_FAR_FROM_CLIPSPACE($0)",
      "description": "a macro that takes the Z component of screenPos—which is the interpolated clip space depth—and converts it to linear depth"
    },

    "Check Top-To-Bottom":{
      "prefix": "CheckTopToBottom",
      "body": [
            "#if Unity_UV_STARTS_AT_TOP",
            "\tif(_CameraDepthTexture_TexelSize.y <0){",
            "\t\tuv.y = 1 - uv.y;",
            "\t}"   ,
            "#endif"
      ],
      "description": "check if our platforms work with top-to-bottom coordinates"
    },

    "SHADOW_CASTER_FRAGMENT":{
      "prefix": "SHADOW_CASTER_FRAGMENT",
      "body": "SHADOW_CASTER_FRAGMENT($0)",
      "description": "shadow caster"
    },

    "UnityApplyLinearShadowBias":{
      "prefix": "UnityApplyLinearShadowBias",
      "body": "UnityApplyLinearShadowBias($0);",
      "description": "Applying the bias prevents artifacts from appearing on the surface"

    },
    "Toggle":{
      "prefix": "Toggle",
      "body": "Toggle",
      "description": "Make a toggle visual on the panel"
    },

    "UNITY_PROJ_COORD":{
      "prefix":"UNITY_PROJ_COORD",
      "body": "UNITY_PROJ_COORD($0)",
      "description": "处理平台差异,一般直接返回输入的值"
    }
}使用示例:
页: [1]
查看完整版本: Vscode for Unity Shader 用户代码片段(持续更新)