当前位置:   article > 正文

Unity Shader溶解 软硬边--基于Blend One One

blend one one

之前做过两版溶解效果都是基于Blend SrcAlpha OneMinusSrcAlpha,众所周知这种模式是通过透明度来实现半透效果的,但是如果特效跟你说我现在要基于叠加(Blend One One)模式呢?代码会跟半透明模式有些许区别 因为Blend One One是无法使用透明度那么它现在来了!

  1. Shader "Custom/Add" {
  2. Properties{
  3. _Diffuse("Diffuse", 2D) = "white" {}
  4. _DiffuseColor("DiffuseColor", Color) = (1,1,1,1)
  5. _DiffusePower("DiffusePower", Float) = 1
  6. _DissolveTex("DissolveTex", 2D) = "white" {}
  7. _SoftSize("SoftSize",Range(0,2)) = 0
  8. _DissolveStep("DissolveStep",Range(0,1)) = 0
  9. [Toggle(CustomColor)]_IsCustom("自定义颜色",float) = 0
  10. _DissolveColor("DissolveColor",Color) = (1,1,1,1)
  11. _DissolveColorPW("DissolveColorPW",float) = 1
  12. }
  13. SubShader{
  14. Tags {
  15. "IgnoreProjector" = "True"
  16. "Queue" = "Transparent"
  17. "RenderType" = "Transparent"
  18. }
  19. Pass {
  20. Blend One One
  21. Cull Off
  22. ZWrite Off
  23. CGPROGRAM
  24. #pragma vertex vert
  25. #pragma fragment frag
  26. #include "UnityCG.cginc"
  27. #pragma target 2.0
  28. uniform sampler2D _Diffuse; uniform float4 _Diffuse_ST;
  29. uniform float4 _DiffuseColor;
  30. uniform sampler2D _DissolveTex; uniform float4 _DissolveTex_ST;
  31. uniform float _DiffusePower;
  32. float _DissolveStep;
  33. float _SoftSize;
  34. float4 _DissolveColor;
  35. float _DissolveColorPW;
  36. float _IsCustom;
  37. struct VertexInput {
  38. float4 vertex : POSITION;
  39. float2 uv0 : TEXCOORD0;
  40. float4 uv1 : TEXCOORD1;
  41. float4 uv2 : TEXCOORD2;
  42. float4 vertexColor : COLOR;
  43. };
  44. struct VertexOutput {
  45. float4 pos : SV_POSITION;
  46. float2 uv0 : TEXCOORD0;
  47. float4 uv1 : TEXCOORD1;
  48. float4 uv2 : TEXCOORD2;
  49. float4 vertexColor : COLOR;
  50. };
  51. VertexOutput vert(VertexInput v) {
  52. VertexOutput o = (VertexOutput)0;
  53. o.uv0 = v.uv0;
  54. o.uv1 = v.uv1;
  55. o.uv2 = v.uv2;
  56. o.vertexColor = v.vertexColor;
  57. o.pos = UnityObjectToClipPos(v.vertex);
  58. return o;
  59. }
  60. float4 frag(VertexOutput i) : COLOR {
  61. float4 _Diffuse_var = tex2D(_Diffuse,TRANSFORM_TEX(i.uv0 ,_Diffuse));
  62. float4 dissolveVar = tex2D(_DissolveTex,TRANSFORM_TEX(i.uv0, _DissolveTex));
  63. float3 diffColor = fixed3(_Diffuse_var.rgb*_DiffusePower*_DiffuseColor.rgb*_DiffuseColor.a*_Diffuse_var.a);
  64. float3 emissive = i.vertexColor.rgb*diffColor;
  65. float softTmp = _SoftSize;
  66. float DissolveStepTmp = _DissolveStep;
  67. float percent = saturate((max(0.001,dissolveVar.r) - DissolveStepTmp) / (softTmp*DissolveStepTmp));
  68. float3 finalColor = lerp(emissive, _DissolveColor*_DissolveColorPW*i.vertexColor.rgb*_Diffuse_var.a,step(percent,0.8)*_IsCustom);
  69. return fixed4(finalColor*percent,1);
  70. }
  71. ENDCG
  72. }
  73. }
  74. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/96672
推荐阅读
相关标签
  

闽ICP备14008679号