tonynogo

Demo 25 - Fixed tessellation

Jul 6th, 2017
3,997
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/FixedTessellation" {
  2.     Properties {
  3.         _MainTex ("Main Texture (Diffuse)", 2D) = "white" {}
  4.         _BumpTex ("Normal Map", 2D) = "bump" {}
  5.         _DispTex ("Displacement Map", 2D) = "gray" {}
  6.         _TexVal ("Tessellation value", Range(1,40)) = 1
  7.         _DispVal ("Displacement factor", Range (0, 1)) = 0
  8.     }
  9.     SubShader {
  10.         Tags { "RenderType"="Opaque" }
  11.        
  12.         CGPROGRAM
  13.         #pragma surface surf BlinnPhong vertex:vert tessellate:tess
  14.         #pragma target 4.6
  15.  
  16.         struct appdata {
  17.             float4 vertex : POSITION;
  18.             float3 normal : NORMAL;
  19.             float4 tangent : TANGENT;
  20.             float2 texcoord : TEXCOORD0;
  21.         };
  22.  
  23.         float _TexVal;
  24.  
  25.         float4 tess() {
  26.             return _TexVal;
  27.         }
  28.  
  29.         sampler2D _DispTex;
  30.         float _DispVal;
  31.  
  32.         void vert(inout appdata v) {
  33.             float val = tex2Dlod(_DispTex, float4(v.texcoord.xy, 0, 0)).r * _DispVal;
  34.             v.vertex.xyz += v.normal * val;
  35.         }
  36.  
  37.         struct Input {
  38.             float2 uv_MainTex;
  39.         };
  40.  
  41.         sampler2D _MainTex;
  42.         sampler2D _BumpTex;
  43.  
  44.         void surf (Input IN, inout SurfaceOutput o) {
  45.             half4 c = tex2D (_MainTex, IN.uv_MainTex);
  46.             o.Albedo = c.rgb;
  47.             o.Normal = UnpackNormal(tex2D(_BumpTex, IN.uv_MainTex));
  48.         }
  49.         ENDCG
  50.     }
  51.     FallBack "Diffuse"
  52. }
Advertisement
Add Comment
Please, Sign In to add comment