Search Unity

Adding Single Pass Rendering to a modified Standard Shader

Discussion in 'Shaders' started by zulaman, May 26, 2020.

  1. zulaman

    zulaman

    Joined:
    May 12, 2017
    Posts:
    26
    I've modified the most basic Unity Standard Shader to add Tesselation and it's working great except in VR (when using single pass rendering).
    I'm trying to find a good example to add Single Pass Rendering but all the examples are for vertex/fragment shaders , nothing for Unity Standard shaders.
    Does anyone has a link I can follow to a working sample?
    Here's my current shader:
    Thank you.

    Shader "Custom/StandardTesselation"
    {
    Properties{
    _MainTex("Base (RGB)", 2D) = "white" {}
    _Color("Color", color) = (1,1,1,0)
    _SpecularColor("Specular Color", color) = (0.5, 0.5, 0.5, 1)
    _Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5
    _GlossMap("Gloss Map", 2D) = "gloss" {}
    _BumpMap("Bumpmap", 2D) = "bump" {}
    _BumpMapDetailScale("BumpmapDetailScale", Range(0.0, 1.0)) = 1
    _BumpMapDetail("BumpmapDetail", 2D) = "bump" {}
    _EdgeLength("Edge length", Range(2,50)) = 5
    _Phong("Phong Strengh", Range(0,1)) = 0.5
    }
    CGINCLUDE
    #define _GLOSSYENV 1
    #define UNITY_SETUP_BRDF_INPUT MetallicSetup
    ENDCG

    SubShader{
    Tags { "RenderType" = "Opaque" }
    LOD 300

    CGPROGRAM
    #pragma surface surf StandardSpecular vertex:dispNone tessellate:tessEdge tessphong:_Phong nolightmap
    #include "Tessellation.cginc"
    #include "UnityPBSLighting.cginc"

    struct appdata {
    float4 vertex : POSITION;
    float4 tangent : TANGENT;
    float3 normal : NORMAL;
    float2 texcoord : TEXCOORD0;
    };

    void dispNone(inout appdata v) { }

    float _Phong;
    float _EdgeLength;

    float4 tessEdge(appdata v0, appdata v1, appdata v2)
    {
    return UnityEdgeLengthBasedTess(v0.vertex, v1.vertex, v2.vertex, _EdgeLength);
    }

    struct Input {
    float2 uv_MainTex;
    float2 uv_BumpMap;
    float2 uv_GlossMap;
    };

    fixed4 _Color;
    fixed4 _SpecularColor;
    sampler2D _MainTex;
    //half _Metallic;
    half _Smoothness;
    sampler2D _GlossMap;
    sampler2D _BumpMap;
    sampler2D _BumpMapDetail;
    half _BumpMapDetailScale;

    void surf(Input IN, inout SurfaceOutputStandardSpecular o) {
    half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    o.Albedo = c.rgb;
    o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)) + UnpackNormal(tex2D(_BumpMapDetail, IN.uv_BumpMap)) * _BumpMapDetailScale;
    o.Alpha = c.a;
    o.Specular = tex2D(_GlossMap, IN.uv_GlossMap).rgb *_SpecularColor.rgb;
    o.Smoothness = _Smoothness;
    }

    ENDCG
    }
    FallBack "Diffuse"
    }
     
unityunity