Dissolve.shader 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Upgrade NOTE: upgraded instancing buffer 'Props' to new syntax.
  2. Shader "Custom/Dissolve" {
  3. Properties {
  4. _Color ("Color", Color) = (1,1,1,1)
  5. [HDR]_Emission ("Emission", Color) = (0,0,0,0)
  6. _MainTex ("Albedo", 2D) = "white" {}
  7. _Normal ("Normal", 2D) = "bump" {}
  8. _MetallicSmooth ("Metallic (RGB) Smooth (A)", 2D) = "white" {}
  9. _AO ("AO", 2D) = "white" {}
  10. [HDR]_EdgeColor1 ("Edge Color", Color) = (1,1,1,1)
  11. _Noise ("Noise", 2D) = "white" {}
  12. [Toggle] _Use_Gradient ("Use Gradient?", Float) = 1
  13. _Gradient ("Gradient", 2D) = "white" {}
  14. _Glossiness ("Smoothness", Range(0,1)) = 0.5
  15. _Metallic ("Metallic", Range(0,1)) = 0.0
  16. [PerRendererData]_Cutoff ("Cutoff", Range(0,1)) = 0.0
  17. _EdgeSize ("EdgeSize", Range(0,1)) = 0.2
  18. _NoiseStrength ("Noise Strength", Range(0,1)) = 0.4
  19. _DisplaceAmount ("Displace Amount", Float) = 1.5
  20. _cutoff ("cutoff", Range(0,1)) = 0.0
  21. }
  22. SubShader {
  23. Tags { "Queue"="AlphaTest" "RenderType"="TransparentCutout" "IgnoreProjector"="True" }
  24. Cull Off
  25. LOD 200
  26. CGPROGRAM
  27. // Physically based Standard lighting model, and enable shadows on all light types
  28. #pragma surface surf Standard fullforwardshadows vertex:vert addshadow
  29. // Use shader model 3.0 target, to get nicer looking lighting
  30. #pragma target 3.0
  31. #pragma multi_compile __ _USE_GRADIENT_ON
  32. sampler2D _MainTex;
  33. sampler2D _Noise;
  34. sampler2D _Gradient;
  35. sampler2D _Normal;
  36. sampler2D _MetallicSmooth;
  37. sampler2D _AO;
  38. struct Input {
  39. float2 uv_Noise;
  40. float2 uv_MainTex;
  41. fixed4 color : COLOR0;
  42. float3 worldPos;
  43. };
  44. half _Glossiness, _Metallic, _Cutoff, _EdgeSize, _NoiseStrength, _DisplaceAmount;
  45. half _cutoff;
  46. half4 _Color, _EdgeColor1, _Emission;
  47. void vert (inout appdata_full v, out Input o) {
  48. UNITY_INITIALIZE_OUTPUT(Input,o);
  49. float3 pos = mul((float3x3)unity_ObjectToWorld, v.vertex.xyz);
  50. //pos.x += _cutoff*5;
  51. float4 tex = tex2Dlod(_Noise, float4(pos, 0)*0.5);
  52. float4 Gradient = tex2Dlod (_Gradient, float4(v.texcoord.xy,0,0));
  53. float mask = smoothstep(_Cutoff, _Cutoff - 0.3, 1-Gradient);
  54. float displacementAmount = lerp(0, _DisplaceAmount, _cutoff);
  55. //v.vertex.xyz += mul((float3x3)unity_WorldToObject, float3(0, vertexOffset, 0));
  56. //v.vertex.xyz = lerp(v.vertex.xyz , float3(0,0,0), clamp(_cutoff * (tex.r+0.1) * displacementAmount, 0, 1));
  57. }
  58. // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
  59. // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
  60. // #pragma instancing_options assumeuniformscaling
  61. UNITY_INSTANCING_BUFFER_START(Props)
  62. // put more per-instance properties here
  63. UNITY_INSTANCING_BUFFER_END(Props)
  64. void surf (Input IN, inout SurfaceOutputStandard o) {
  65. half3 Noise = tex2D (_Noise, IN.uv_Noise);
  66. Noise.r = lerp(0, 1, Noise.r);
  67. half4 MetallicSmooth = tex2D (_MetallicSmooth, IN.uv_MainTex);
  68. _cutoff = lerp(0, _cutoff + _EdgeSize, _cutoff);
  69. #if _USE_GRADIENT_ON
  70. half3 Gradient = tex2D (_Gradient, IN.uv_MainTex);
  71. half Edge = smoothstep(_Cutoff, _Cutoff - _EdgeSize, 1-(Gradient + Noise.r*(1-Gradient)*_NoiseStrength));
  72. #else
  73. half Edge = smoothstep(_cutoff + _EdgeSize, _cutoff, clamp(Noise.r, _EdgeSize, 1));
  74. #endif
  75. fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
  76. fixed3 EmissiveCol = c.a * _Emission;
  77. o.Albedo = _Color;
  78. o.Occlusion = tex2D (_AO, IN.uv_MainTex);
  79. o.Emission = EmissiveCol + _EdgeColor1 * Edge;
  80. o.Normal = UnpackNormal (tex2D (_Normal, IN.uv_MainTex));
  81. o.Metallic = MetallicSmooth.r * _Metallic;
  82. o.Smoothness = MetallicSmooth.a * _Glossiness;
  83. clip(Noise - _cutoff);
  84. }
  85. ENDCG
  86. }
  87. FallBack "Diffuse"
  88. }