GrayPaint.shader 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // Shader created with Shader Forge v1.38
  2. // Shader Forge (c) Neat Corporation / Joachim Holmer - http://www.acegikmo.com/shaderforge/
  3. // Note: Manually altering this data may prevent you from opening it in Shader Forge
  4. /*SF_DATA;ver:1.38;sub:START;pass:START;ps:flbk:Sprites/Default,iptp:1,cusa:True,bamd:0,cgin:,lico:1,lgpr:1,limd:0,spmd:1,trmd:0,grmd:0,uamb:True,mssp:True,bkdf:False,hqlp:False,rprd:False,enco:False,rmgx:True,imps:True,rpth:0,vtps:0,hqsc:False,nrmq:1,nrsp:0,vomd:0,spxs:False,tesm:0,olmd:1,culm:2,bsrc:3,bdst:7,dpts:2,wrdp:False,dith:0,atcv:False,rfrpo:True,rfrpn:Refraction,coma:15,ufog:False,aust:True,igpj:True,qofs:0,qpre:3,rntp:2,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.5,fgcg:0.5,fgcb:0.5,fgca:1,fgde:0.01,fgrn:0,fgrf:300,stcl:True,atwp:False,stva:128,stmr:255,stmw:255,stcp:6,stps:0,stfa:0,stfz:0,ofsf:0,ofsu:0,f2p0:False,fnsp:False,fnfb:False,fsmp:False;n:type:ShaderForge.SFN_Final,id:1873,x:33730,y:32927,cmnt:Created By Mike Jakubowski,varname:node_1873,prsc:2|emission-9613-OUT,alpha-4805-A;n:type:ShaderForge.SFN_Tex2d,id:4805,x:32620,y:32963,ptovrint:False,ptlb:MainTex,ptin:_MainTex,cmnt:Input Texture,varname:_MainTex_copy,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:True,tagnsco:False,tagnrm:False,ntxv:0,isnm:False;n:type:ShaderForge.SFN_VertexColor,id:8041,x:32620,y:33140,cmnt:Color from Sprite Renderer,varname:node_8041,prsc:2;n:type:ShaderForge.SFN_RgbToHsv,id:3046,x:32782,y:32963,varname:node_3046,prsc:2|IN-4805-RGB;n:type:ShaderForge.SFN_Slider,id:1860,x:32620,y:33310,ptovrint:False,ptlb:Saturation Bound,ptin:_SaturationBound,cmnt:Saturation bound to skip gray pixels,varname:node_1860,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0.1,max:1;n:type:ShaderForge.SFN_Code,id:9613,x:33200,y:33027,varname:node_9613,prsc:2,code:aQBmACAAKABzAGEAdAB1AHIAYQB0AGkAbwBuACAAPgAgAHMAYQB0AHUAcgBhAHQAaQBvAG4AQgBvAHUAbgBkACAAJgAmACAAIQBpAG4AdgBlAHIAcwBlACkAIAByAGUAdAB1AHIAbgAgAHAAaQB4AGUAbAA7AA0ACgBpAGYAIAAoAHMAYQB0AHUAcgBhAHQAaQBvAG4AIAA8ACAAcwBhAHQAdQByAGEAdABpAG8AbgBCAG8AdQBuAGQAIAAmACYAIABpAG4AdgBlAHIAcwBlACkAIAByAGUAdAB1AHIAbgAgAHAAaQB4AGUAbAA7AA0ACgBmAGwAbwBhAHQAIABnAHIAYQB5ACAAPQAgADAALgAzACAAKgAgAHAAaQB4AGUAbAAuAHIAIAArACAAMAAuADUAOQAgACoAIABwAGkAeABlAGwALgBnACAAKwAgADAALgAxADEAIAAqACAAcABpAHgAZQBsAC4AYgA7AA0ACgByAGUAdAB1AHIAbgAgAGMAbwBsAG8AcgBNAHUAbAB0AGkAcABsAGkAZQByACAAKgAgAGMAbwBsAG8AcgAgACoAIABnAHIAYQB5ADsA,output:2,fname:ToGrayscale,width:461,height:168,input:2,input:2,input:0,input:0,input:0,input:4,input_1_label:pixel,input_2_label:color,input_3_label:saturation,input_4_label:saturationBound,input_5_label:colorMultiplier,input_6_label:inverse|A-4805-RGB,B-8041-RGB,C-3046-SOUT,D-1860-OUT,E-7569-OUT,F-6479-OUT;n:type:ShaderForge.SFN_Slider,id:7569,x:32620,y:33400,ptovrint:False,ptlb:Color Multiplier,ptin:_ColorMultiplier,varname:node_7569,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:1,cur:1,max:2;n:type:ShaderForge.SFN_ToggleProperty,id:6479,x:32777,y:33490,ptovrint:False,ptlb:Inverse,ptin:_Inverse,varname:node_6479,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,on:False;proporder:4805-1860-7569-6479;pass:END;sub:END;*/
  5. Shader "Hero Editor/Gray Paint" {
  6. Properties {
  7. [PerRendererData]_MainTex ("MainTex", 2D) = "white" {}
  8. _SaturationBound ("Saturation Bound", Range(0, 1)) = 0.1
  9. _ColorMultiplier ("Color Multiplier", Range(1, 2)) = 1
  10. [MaterialToggle] _Inverse ("Inverse", Float ) = 0
  11. [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
  12. // these six unused properties are required when a shader is used in the UI system, or you get a warning.
  13. _StencilComp("Stencil Comparison", Float) = 8
  14. _Stencil("Stencil ID", Float) = 0
  15. _StencilOp("Stencil Operation", Float) = 0
  16. _StencilWriteMask("Stencil Write Mask", Float) = 255
  17. _StencilReadMask("Stencil Read Mask", Float) = 255
  18. _ColorMask("Color Mask", Float) = 15
  19. }
  20. SubShader {
  21. Tags {
  22. "IgnoreProjector"="True"
  23. "Queue"="Transparent"
  24. "RenderType"="Transparent"
  25. "CanUseSpriteAtlas"="True"
  26. "PreviewType"="Plane"
  27. }
  28. Pass {
  29. Name "FORWARD"
  30. Blend SrcAlpha OneMinusSrcAlpha
  31. Cull Off
  32. ZWrite Off
  33. ZTest [unity_GUIZTestMode]
  34. Blend SrcAlpha OneMinusSrcAlpha
  35. Stencil {
  36. Ref [_Stencil]
  37. Comp [_StencilComp]
  38. Pass [_StencilOp]
  39. ReadMask [_StencilReadMask]
  40. WriteMask [_StencilWriteMask]
  41. }
  42. CGPROGRAM
  43. #pragma vertex vert
  44. #pragma fragment frag
  45. //#define UNITY_PASS_FORWARDBASE
  46. #include "UnityCG.cginc"
  47. #include "UnityUI.cginc"
  48. #pragma multi_compile_fwdbase
  49. //#pragma only_renderers d3d9 d3d11 glcore gles gles3 metal d3d11_9x xboxone ps4 psp2 n3ds wiiu
  50. #pragma target 3.0
  51. uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
  52. uniform float _SaturationBound;
  53. float3 ToGrayscale( float3 pixel , float3 color , float saturation , float saturationBound , float colorMultiplier , half inverse ){
  54. if (saturation > saturationBound && !inverse) return pixel;
  55. if (saturation < saturationBound && inverse) return pixel;
  56. float gray = 0.3 * pixel.r + 0.59 * pixel.g + 0.11 * pixel.b;
  57. return colorMultiplier * color * gray;
  58. }
  59. uniform float _ColorMultiplier;
  60. uniform fixed _Inverse;
  61. float4 _ClipRect;
  62. struct VertexInput {
  63. float4 vertex : POSITION;
  64. float2 texcoord0 : TEXCOORD0;
  65. float4 vertexColor : COLOR;
  66. };
  67. struct VertexOutput {
  68. float4 pos : SV_POSITION;
  69. float2 uv0 : TEXCOORD0;
  70. float4 vertexColor : COLOR;
  71. float4 worldPosition : TEXCOORD1;
  72. };
  73. VertexOutput vert (VertexInput v) {
  74. VertexOutput o = (VertexOutput)0;
  75. o.uv0 = v.texcoord0;
  76. o.vertexColor = v.vertexColor;
  77. o.worldPosition = v.vertex;
  78. o.pos = UnityObjectToClipPos( o.worldPosition );
  79. return o;
  80. }
  81. float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
  82. float isFrontFace = ( facing >= 0 ? 1 : 0 );
  83. float faceSign = ( facing >= 0 ? 1 : -1 );
  84. ////// Lighting:
  85. ////// Emissive:
  86. float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex)); // Input Texture
  87. float4 node_3046_k = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
  88. float4 node_3046_p = lerp(float4(float4(_MainTex_var.rgb,0.0).zy, node_3046_k.wz), float4(float4(_MainTex_var.rgb,0.0).yz, node_3046_k.xy), step(float4(_MainTex_var.rgb,0.0).z, float4(_MainTex_var.rgb,0.0).y));
  89. float4 node_3046_q = lerp(float4(node_3046_p.xyw, float4(_MainTex_var.rgb,0.0).x), float4(float4(_MainTex_var.rgb,0.0).x, node_3046_p.yzx), step(node_3046_p.x, float4(_MainTex_var.rgb,0.0).x));
  90. float node_3046_d = node_3046_q.x - min(node_3046_q.w, node_3046_q.y);
  91. float node_3046_e = 1.0e-10;
  92. float3 node_3046 = float3(abs(node_3046_q.z + (node_3046_q.w - node_3046_q.y) / (6.0 * node_3046_d + node_3046_e)), node_3046_d / (node_3046_q.x + node_3046_e), node_3046_q.x);;
  93. float3 node_9613 = ToGrayscale( _MainTex_var.rgb , i.vertexColor.rgb , node_3046.g , _SaturationBound , _ColorMultiplier , _Inverse );
  94. float3 emissive = node_9613;
  95. float3 finalColor = emissive;
  96. _MainTex_var.a -= 1 - i.vertexColor.a;
  97. #ifdef UNITY_UI_CLIP_RECT
  98. finalColor.a *= UnityGet2DClipping(i.worldPosition.xy, _ClipRect);
  99. #endif
  100. #ifdef UNITY_UI_ALPHACLIP
  101. clip (finalColor.a - 0.001);
  102. #endif
  103. return fixed4(finalColor,_MainTex_var.a);
  104. }
  105. ENDCG
  106. }
  107. Pass {
  108. Name "ShadowCaster"
  109. Tags {
  110. "LightMode"="ShadowCaster"
  111. }
  112. Offset 1, 1
  113. Cull Off
  114. Stencil {
  115. Ref [_Stencil]
  116. Comp [_StencilComp]
  117. Pass [_StencilOp]
  118. ReadMask [_StencilReadMask]
  119. WriteMask [_StencilWriteMask]
  120. }
  121. CGPROGRAM
  122. #pragma vertex vert
  123. #pragma fragment frag
  124. //#define UNITY_PASS_SHADOWCASTER
  125. #include "UnityCG.cginc"
  126. #include "Lighting.cginc"
  127. #pragma fragmentoption ARB_precision_hint_fastest
  128. #pragma multi_compile_shadowcaster
  129. //#pragma only_renderers d3d9 d3d11 glcore gles gles3 metal d3d11_9x xboxone ps4 psp2 n3ds wiiu
  130. #pragma target 2.0
  131. struct VertexInput {
  132. float4 vertex : POSITION;
  133. };
  134. struct VertexOutput {
  135. V2F_SHADOW_CASTER;
  136. float4 worldPosition : TEXCOORD1;
  137. };
  138. VertexOutput vert (VertexInput v) {
  139. VertexOutput o = (VertexOutput)0;
  140. o.worldPosition = v.vertex;
  141. o.pos = UnityObjectToClipPos( o.worldPosition );
  142. TRANSFER_SHADOW_CASTER(o)
  143. return o;
  144. }
  145. float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
  146. float isFrontFace = ( facing >= 0 ? 1 : 0 );
  147. float faceSign = ( facing >= 0 ? 1 : -1 );
  148. SHADOW_CASTER_FRAGMENT(i)
  149. }
  150. ENDCG
  151. }
  152. }
  153. FallBack "Sprites/Default"
  154. //CustomEditor "ShaderForgeMaterialInspector"
  155. }