opponent019

WavySphere shader

May 2nd, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.51 KB | None | 0 0
  1. Shader "Erika/WavyModified" {
  2.  
  3. // Shader made by Erika Moya. With @MatthewDBell 's help
  4. // Goes with this script: https://pastebin.com/jTYuRsSn
  5.  
  6. Properties {
  7. _Tess ("Tessellation", Range(1,32)) = 4
  8. _MainTex ("Base (RGB)", 2D) = "white" {}
  9. _Color ("Main color", Color) = (1, 1, 1, 0)
  10. _Glossiness ("Smoothness", Range(0,1)) = 0.5
  11. _Metallic ("Metallic", Range(0,1)) = 0.0
  12.  
  13. _DispTex1 ("Disp Texture 1", 2D) = "gray" {}
  14. _NormalMap1 ("Normalmap1", 2D) = "bump" {}
  15. _ScrollX1 ("Scroll X1", Range(-5, 5)) = 1
  16. _ScrollY1 ("Scroll Y1", Range(-5, 5)) = 1
  17.  
  18. _DispTex2 ("Disp Texture 2", 2D) = "gray" {}
  19. _NormalMap2 ("Normalmap2", 2D) = "bump" {}
  20. _ScrollX2 ("Scroll X2", Range(-5, 5)) = 1
  21. _ScrollY2 ("Scroll Y2", Range(-5, 5)) = 1
  22.  
  23. _DispPatch ("Disp Patch", 2D) = "gray" {} // For the poles of the sphere
  24. _NormalMapPatch ("Normalmap patch", 2D) = "bump" {}
  25.  
  26. _DispLogo ("Logo displacement", 2D) = "gray" {}
  27. _LogoNM ("Logo normal map", 2D) = "gray" {}
  28.  
  29. _NormalStrength ("Normal strength", Range (0, 5.0)) = 1.0
  30. _Displacement ("Displacement", Range(0, 1.0)) = 0.3
  31.  
  32. _DispBuildings ("Displacement for buildings", CUBE) = ""{}
  33. _Brightness ("Brightness of cubemap", float) = 1
  34.  
  35. _Blend ("Blend", Range(0,1)) = 0.0
  36.  
  37. }
  38. SubShader {
  39. Tags { "RenderType"="Opaque" }
  40. LOD 300
  41.  
  42. CGPROGRAM
  43. #pragma surface surf Standard addshadow fullforwardshadows vertex:disp tessellate:tessFixed nolightmap
  44. #pragma target 4.6
  45. #include "UnityCG.cginc"
  46.  
  47. struct appdata {
  48. float4 vertex : POSITION;
  49. float4 tangent : TANGENT;
  50. float3 normal : NORMAL;
  51. float2 texcoord : TEXCOORD0;
  52.  
  53. float4 color : COLOR;
  54. };
  55.  
  56. float _Tess;
  57.  
  58. float4 tessFixed()
  59. {
  60. return _Tess;
  61. }
  62.  
  63. // Displacement
  64. sampler2D _DispTex1;
  65. sampler2D _DispTex2;
  66. sampler2D _DispPatch;
  67. sampler2D _DispLogo;
  68. sampler2D _LogoNM;
  69. sampler2D _NormalMap1;
  70. sampler2D _NormalMap2;
  71. sampler2D _NormalMapPatch;
  72. float _Displacement;
  73.  
  74. // Scrolling texture effect
  75. float _ScrollX1;
  76. float _ScrollY1;
  77. float _ScrollX2;
  78. float _ScrollY2;
  79.  
  80. samplerCUBE _DispBuildings;
  81. uniform float4 _DispBuildings_TexelSize;
  82. half4 _DispBuildings_HDR;
  83. float _Brightness;
  84. half4 tex;
  85.  
  86. half _Blend;
  87.  
  88. void disp (inout appdata v)
  89. {
  90. _ScrollX1 *= _Time.x;
  91. _ScrollY1 *= _Time.x;
  92. _ScrollX2 *= _Time.x;
  93. _ScrollY2 *= _Time.x;
  94.  
  95. // Waves
  96. float d = ((tex2Dlod(_DispTex1, float4(v.texcoord.xy, 0, 0) + float4(_ScrollX1, _ScrollY1, 0, 0)).r
  97. + tex2Dlod(_DispTex2, float4(v.texcoord.xy, 0, 0) + float4(_ScrollX2, _ScrollY2, 0, 0)).r))
  98. * (-1 * _Displacement);
  99.  
  100. // Poles patch
  101. d *= tex2Dlod(_DispPatch, float4(v.texcoord.xy,0,0)).r;
  102. v.color = mul(unity_ObjectToWorld, v.vertex);
  103.  
  104. // Buildings
  105. d *= 1.0f - texCUBElod(_DispBuildings, float4(v.color.xyz, 0)).r * _Brightness;
  106. tex = texCUBElod(_DispBuildings, float4(v.color.xyz, 0)).r * _Brightness;
  107.  
  108. // Logo
  109. float dL = - tex2Dlod(_DispLogo, float4(v.texcoord.xy,0,0)) * _Displacement / 2;
  110.  
  111.  
  112. v.vertex.xyz += v.normal * lerp(d, dL, _Blend);
  113.  
  114. }
  115.  
  116. struct Input {
  117. float2 uv_MainTex;
  118. float2 uv_LogoNM;
  119. float2 uv_NormalMap1;
  120. float2 uv_NormalMap2;
  121. float3 worldRefl;
  122. float4 color : COLOR;
  123. INTERNAL_DATA
  124.  
  125. };
  126.  
  127. sampler2D _MainTex;
  128. sampler2D _NormalMap;
  129. float _NormalStrength;
  130. fixed4 _Color;
  131. half _Glossiness;
  132. half _Metallic;
  133.  
  134.  
  135. void surf (Input IN, inout SurfaceOutputStandard o) {
  136. o.Albedo = lerp (_Color, tex2D(_MainTex, IN.uv_MainTex).rgb, _Blend);
  137. o.Metallic = _Metallic;
  138. o.Smoothness = lerp (_Glossiness, 0, _Blend);
  139.  
  140. _ScrollX1 *= _Time.x;
  141. _ScrollY1 *= _Time.x;
  142. _ScrollX2 *= _Time.x;
  143. _ScrollY2 *= _Time.x;
  144.  
  145. // Cubemap normal map
  146. float3 cubemapNormal = float3(0,0,1);
  147.  
  148. float heightSampleCenter = texCUBE(_DispBuildings, IN.color.xyz).r;
  149. float heightSampleRight = texCUBE(_DispBuildings, IN.color.xyz + float3(_DispBuildings_TexelSize.x,0,0)).r;
  150. float heightSampleUp = texCUBE(_DispBuildings, IN.color.xyz + float3(0,_DispBuildings_TexelSize.y,0)).r;
  151.  
  152. float sampleDeltaRight = heightSampleRight - heightSampleCenter;
  153. float sampleDeltaUp = heightSampleUp - heightSampleCenter;
  154.  
  155. float _BumpStrength = 15.0f;
  156.  
  157. cubemapNormal = cross (float3(1, 0, sampleDeltaRight * _BumpStrength), float3(0,1, sampleDeltaUp * _BumpStrength));
  158.  
  159. // Normalmap
  160.  
  161. IN.uv_NormalMap1 += fixed2(_ScrollX1, _ScrollY1);
  162. IN.uv_NormalMap2 += fixed2(_ScrollX2, _ScrollY2);
  163.  
  164.  
  165. /* // Normal maps including waves and buildings
  166. float3 normal = (UnpackNormal(tex2D(_NormalMap1, IN.uv_NormalMap1))
  167. + UnpackNormal(tex2D(_NormalMap2, IN.uv_NormalMap2))
  168. + cubemapNormal)
  169. * UnpackNormal(tex2D(_NormalMapPatch, IN.uv_MainTex));
  170. normal.xy *= _NormalStrength;
  171. o.Normal = normalize(normal);
  172. */
  173. // Normal map for just the sphere
  174. float3 normalWaves = UnpackNormal(tex2D(_NormalMap1, IN.uv_NormalMap1)) + UnpackNormal(tex2D(_NormalMap2, IN.uv_NormalMap2));
  175. float3 normalLogo = UnpackNormal(tex2D(_LogoNM, IN.uv_LogoNM));
  176. float3 normal = lerp (normalWaves, normalLogo, _Blend);
  177.  
  178. normal.xy *= _NormalStrength;
  179. o.Normal = normalize (normal);
  180.  
  181. }
  182. ENDCG
  183. }
  184. FallBack "Diffuse"
  185. }
Add Comment
Please, Sign In to add comment