Advertisement
dnnkeeper

UnityDissolveBounds shader

Dec 13th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. Shader "Custom/Dissolve/BoundsWorld/Opaque" {
  2. Properties{
  3. _Color("Color", Color) = (1,1,1,1)
  4. _MainTex("Albedo (RGB)", 2D) = "white" {}
  5. _Glossiness("Smoothness", Range(0,1)) = 0.5
  6.  
  7. [NoScaleOffset] _MetallicGlossMap("Metallic", 2D) = "white" {}
  8. [Gamma] _Metallic ("Metallic", Range(0.000000,1.000000)) = 0.000000
  9. _BoxCenter("Box Center", Vector) = (0,0,0,0)
  10. _BoxSize("Box Size", Vector) = (0,0,0,0)
  11. _Distance("Dissolve Distance", Float) = 1
  12. _Interpolation("Dissolve Interpolation", Range(0,5)) = 1
  13. _DissTexture("Dissolve Texture", 2D) = "white" {}
  14. [HDR]_DissolveColor("Dissolve Color", Color) = (0,1,0,1)
  15.  
  16. [NoScaleOffset] _BumpMap ("Normal Map", 2D) = "bump" {}
  17. _BumpScale ("Normal Influence", Range(0,10)) = 0.5
  18.  
  19. [HDR]_EmissionColor ("Color", Color) = (0.000000,0.000000,0.000000,1.000000)
  20. [NoScaleOffset]_EmissionMap ("Emission", 2D) = "white" { }
  21. }
  22.  
  23. CGINCLUDE
  24. //@TODO: should this be pulled into a shader_feature, to be able to turn it off?
  25. #define _GLOSSYENV 1
  26. #define UNITY_SETUP_BRDF_INPUT SpecularSetup
  27. ENDCG
  28.  
  29. SubShader{
  30. Tags { "RenderType" = "Opaque" }
  31. LOD 200
  32.  
  33. // Extracts information for lightmapping, GI (emission, albedo, ...)
  34. // This pass is not used during regular rendering.
  35. Pass
  36. {
  37. Name "META"
  38. Tags { "LightMode"="Meta" }
  39.  
  40. Cull Off
  41.  
  42. CGPROGRAM
  43. #pragma vertex vert_meta
  44. #pragma fragment frag_meta
  45.  
  46. #pragma shader_feature _EMISSION
  47. #pragma shader_feature _METALLICGLOSSMAP
  48.  
  49. #include "UnityStandardMeta.cginc"
  50. ENDCG
  51. }
  52.  
  53. CGPROGRAM
  54.  
  55. #include "UnityPBSLighting.cginc"
  56. // Physically based Standard lighting model, and enable shadows on all light types
  57. #pragma surface surf Standard addshadow
  58.  
  59. // Use shader model 3.0 target, to get nicer looking lighting
  60. #pragma target 3.0
  61.  
  62. sampler2D _MainTex;
  63.  
  64. struct Input {
  65. float2 uv_MainTex;
  66. float2 uv_BumpMap;
  67. float2 uv_DissTexture;
  68. float3 worldPos;
  69. };
  70.  
  71. half _Metallic;
  72. half _Glossiness;
  73. sampler2D _MetallicGlossMap;
  74.  
  75. sampler2D _EmissionMap;
  76. float4 _EmissionColor;
  77. float4 _DissolveColor;
  78.  
  79. sampler2D _BumpMap;
  80.  
  81. half _Distance;
  82. half _Interpolation;
  83. half _BumpScale;
  84.  
  85. sampler2D _DissTexture;
  86.  
  87. float4 _BoxCenter,_BoxSize;
  88.  
  89. fixed4 _Color;
  90.  
  91. void surf(Input IN, inout SurfaceOutputStandard o) {
  92.  
  93. float3 surfacePos = IN.worldPos.xyz;
  94.  
  95. //float3 objectCenterWorld = _Object2World[3].xyz;//float3(0,0,0) * mul(unity_ObjectToWorld, float4(0, 0, 0, 1));
  96.  
  97. float dx = min(((_BoxCenter.x + _BoxSize.x) - surfacePos.x), (surfacePos.x - (_BoxCenter.x - _BoxSize.x)));
  98. float dy = min(((_BoxCenter.y + _BoxSize.y)-surfacePos.y), (surfacePos.y - (_BoxCenter.y - _BoxSize.y)));
  99. float dz = min(((_BoxCenter.z + _BoxSize.z) - surfacePos.z), (surfacePos.z - (_BoxCenter.z - _BoxSize.z)));
  100.  
  101. clip((dx));
  102. clip((dy));
  103. clip((dz));
  104.  
  105. fixed4 c = tex2D(_MetallicGlossMap, IN.uv_MainTex);
  106. o.Metallic = c.r * _Metallic ;
  107. o.Smoothness = _Glossiness * c.a;
  108.  
  109. c = tex2D(_MainTex, IN.uv_MainTex);
  110. o.Albedo = c.rgb * _Color.rgb;
  111.  
  112. o.Normal = normalize(UnpackScaleNormal (tex2D (_BumpMap, IN.uv_BumpMap) , _BumpScale));
  113.  
  114. o.Emission = tex2D(_EmissionMap, IN.uv_MainTex) * _EmissionColor;
  115. o.Alpha = c.a;
  116. }
  117. ENDCG
  118. }
  119. Fallback "Diffuse"
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement