Skip to content

Instantly share code, notes, and snippets.

@yCatDev
Forked from phi-lira/UnlitTexture.shader
Last active September 29, 2021 17:59
Show Gist options
  • Save yCatDev/21cb4b483d6de4ebaa72323d9989b224 to your computer and use it in GitHub Desktop.
Save yCatDev/21cb4b483d6de4ebaa72323d9989b224 to your computer and use it in GitHub Desktop.

Revisions

  1. yCatDev revised this gist Sep 29, 2021. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion UnlitTexture.shader
    Original file line number Diff line number Diff line change
    @@ -9,10 +9,11 @@ Shader "Custom/UnlitTexture"
    // Universal Render Pipeline subshader. If URP is installed this will be used.
    SubShader
    {
    Tags { "RenderType"="Opaque" "RenderPipeline"="UniversalRenderPipeline"}
    Tags { "RenderType"="Fade" "RenderPipeline"="UniversalRenderPipeline"}

    Pass
    {
    ZWrite On
    Tags { "LightMode"="UniversalForward" }

    HLSLPROGRAM
  2. yCatDev revised this gist Sep 29, 2021. No changes.
  3. @phi-lira phi-lira revised this gist Jul 28, 2020. 1 changed file with 55 additions and 1 deletion.
    56 changes: 55 additions & 1 deletion UnlitTexture.shader
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,12 @@
    Shader "Universal Render Pipeline/Custom/UnlitTexture"
    Shader "Custom/UnlitTexture"
    {
    Properties
    {
    [MainColor] _BaseColor("BaseColor", Color) = (1,1,1,1)
    [MainTexture] _BaseMap("BaseMap", 2D) = "white" {}
    }

    // Universal Render Pipeline subshader. If URP is installed this will be used.
    SubShader
    {
    Tags { "RenderType"="Opaque" "RenderPipeline"="UniversalRenderPipeline"}
    @@ -55,4 +56,57 @@ Shader "Universal Render Pipeline/Custom/UnlitTexture"
    ENDHLSL
    }
    }

    // Built-in pipeline subshader. This is fallback subshader in case URP is not being used.
    SubShader
    {
    Tags { "RenderType"="Opaque"}
    LOD 100

    Pass
    {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    // make fog work
    #pragma multi_compile_fog

    #include "UnityCG.cginc"

    struct appdata
    {
    float4 vertex : POSITION;
    float2 uv : TEXCOORD0;
    };

    struct v2f
    {
    float2 uv : TEXCOORD0;
    UNITY_FOG_COORDS(1)
    float4 vertex : SV_POSITION;
    };

    sampler2D _MainTex;
    float4 _MainTex_ST;

    v2f vert (appdata v)
    {
    v2f o;
    o.vertex = UnityObjectToClipPos(v.vertex);
    o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    UNITY_TRANSFER_FOG(o,o.vertex);
    return o;
    }

    fixed4 frag (v2f i) : SV_Target
    {
    // sample the texture
    fixed4 col = tex2D(_MainTex, i.uv);
    // apply fog
    UNITY_APPLY_FOG(i.fogCoord, col);
    return col;
    }
    ENDCG
    }
    }
    }
  4. @phi-lira phi-lira created this gist Apr 22, 2020.
    58 changes: 58 additions & 0 deletions UnlitTexture.shader
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    Shader "Universal Render Pipeline/Custom/UnlitTexture"
    {
    Properties
    {
    [MainColor] _BaseColor("BaseColor", Color) = (1,1,1,1)
    [MainTexture] _BaseMap("BaseMap", 2D) = "white" {}
    }

    SubShader
    {
    Tags { "RenderType"="Opaque" "RenderPipeline"="UniversalRenderPipeline"}

    Pass
    {
    Tags { "LightMode"="UniversalForward" }

    HLSLPROGRAM
    #pragma vertex vert
    #pragma fragment frag

    #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

    struct Attributes
    {
    float4 positionOS : POSITION;
    float2 uv : TEXCOORD0;
    };

    struct Varyings
    {
    float2 uv : TEXCOORD0;
    float4 positionHCS : SV_POSITION;
    };

    TEXTURE2D(_BaseMap);
    SAMPLER(sampler_BaseMap);

    CBUFFER_START(UnityPerMaterial)
    float4 _BaseMap_ST;
    half4 _BaseColor;
    CBUFFER_END

    Varyings vert(Attributes IN)
    {
    Varyings OUT;
    OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
    OUT.uv = TRANSFORM_TEX(IN.uv, _BaseMap);
    return OUT;
    }

    half4 frag(Varyings IN) : SV_Target
    {
    return SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, IN.uv) * _BaseColor;
    }
    ENDHLSL
    }
    }
    }