Search Unity

Question Looking for help with bumpy glass shader conversion to Shader Graph

Discussion in 'Shader Graph' started by webster, May 4, 2021.

  1. webster

    webster

    Joined:
    Jun 8, 2013
    Posts:
    21
    I have this glass shader I modified for my purposes. It does not work in URP of course, so I'd like to re-do it in Shader Graph. I'm brand new to Shader Graph. I actually have most of this figured out, but these three COMMENTED lines, I have no idea what the analog is in SG. Anyone help?

    Code (CSharp):
    1. Shader "Custom/Glass-Seethrough Alpha" {
    2.     Properties{
    3.         _Color("Main Color", Color) = (1,1,1,1)
    4.         _SpecColor("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
    5.         _Shininess("Shininess", Range(0.03, 1)) = 0.3
    6.         _MainTex("Base (RGB)", 2D) = "white" {}
    7.         _BumpMap("Normalmap", 2D) = "bump" {}
    8.         _AlphaMap("Alphamap", 2D) = "black" {}
    9.         _DistAmt("Distortion", range(0,256)) = 100
    10.     }
    11.         SubShader{
    12.             GrabPass { }
    13.  
    14.             Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Opaque" }
    15.             LOD 200
    16.  
    17.             CGPROGRAM
    18.             #pragma target 3.0
    19.             #pragma exclude_renderers gles
    20.             #pragma vertex vert
    21.             #pragma surface surf BlinnPhong alpha
    22.             #include "UnityCG.cginc"
    23.  
    24.             float4 _Color;
    25.             float _Shininess;
    26.             sampler2D _MainTex;
    27.             sampler2D _BumpMap;
    28.             sampler2D _AlphaMap;
    29.             sampler2D _GrabTexture;
    30.             float _DistAmt;
    31.             float4 _GrabTexture_TexelSize;
    32.  
    33.             struct Input {
    34.                 float2 uv_MainTex;
    35.                 float2 uv_BumpMap;
    36.                 float2 uv_AlphaMap;
    37.                 float4 proj : TEXCOORD;
    38.             };
    39.  
    40.             void vert(inout appdata_full v, out Input o) {
    41.                 UNITY_INITIALIZE_OUTPUT(Input, o);
    42.                 float4 oPos = UnityObjectToClipPos(v.vertex);
    43.                 #if UNITY_UV_STARTS_AT_TOP
    44.                     float scale = -1.0;
    45.                 #else
    46.                     float scale = 1.0;
    47.                 #endif
    48.                 o.proj.xy = (float2(oPos.x, oPos.y * scale) + oPos.w) * 0.5;
    49.                 o.proj.zw = oPos.zw;
    50.             }
    51.  
    52.             void surf(Input IN, inout SurfaceOutput o) {
    53.                 half3 tint = tex2D(_MainTex, IN.uv_MainTex);
    54.                 half3 nor = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    55.                 half3 alpha = tex2D(_AlphaMap, IN.uv_AlphaMap);
    56.  
    57.                 float2 offset = nor * _DistAmt * _GrabTexture_TexelSize.xy; // HOW TO USE TEXEL SIZE?
    58.                 IN.proj.xy = offset * IN.proj.z + IN.proj.xy;  // HOW TO USE TEXCOORDS HERE?
    59.                 half4 col = tex2Dproj(_GrabTexture, UNITY_PROJ_COORD(IN.proj)); // COMPLETELY LOST!!!
    60.                 half3 tinted = col * tint * _Color;
    61.  
    62.                 o.Albedo = lerp(col, tinted, alpha);
    63.                 o.Normal = nor.rgb;
    64.                 o.Specular = _Shininess;
    65.                 o.Gloss = col.a;
    66.                 o.Alpha = alpha.r;
    67.             }
    68.             ENDCG
    69.         }
    70.         FallBack "Diffuse"
    71. }
     
    DaveA likes this.