Advertisement
tonynogo

Demo 35 - Deform with bezier curve

Jul 6th, 2017
4,645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/BezierCurve"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Texture", 2D) = "white" {}
  6.         _ControlPoint ("Control point", vector) = (1, 1, 1, 1)
  7.     }
  8.     SubShader
  9.     {
  10.         Tags { "RenderType"="Opaque" }
  11.  
  12.         Pass
  13.         {
  14.             CGPROGRAM
  15.             #pragma vertex vert
  16.             #pragma fragment frag
  17.            
  18.             #include "UnityCG.cginc"
  19.  
  20.             struct v2f
  21.             {
  22.                 float4 pos : SV_POSITION;
  23.                 float2 uv : TEXCOORD0;
  24.             };
  25.  
  26.             sampler2D _MainTex;
  27.             float4 _MainTex_ST;
  28.             float4 _ControlPoint;
  29.  
  30.  
  31.             v2f vert (appdata_base v)
  32.             {
  33.                 v2f o;
  34.                 float3 begin = float3(-0.5, v.vertex.y, v.vertex.z);
  35.                 float3 end = float3(0.5, v.vertex.y, v.vertex.z);
  36.  
  37.                 float vertX = v.vertex.x + 0.5;
  38.  
  39.                 v.vertex.xyz = (1 - vertX) * (1 - vertX) * begin.xyz
  40.                 + 2.0 * (1 - vertX) * vertX * _ControlPoint.xyz;
  41.                 + vertX * vertX * end.xyz;
  42.  
  43.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  44.                 o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  45.                 return o;
  46.             }
  47.            
  48.             fixed4 frag (v2f i) : SV_Target
  49.             {
  50.                 return tex2D(_MainTex, i.uv);
  51.             }
  52.             ENDCG
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement