如何编辑着色器以使其在没有任何灯光的情况下显示其打开的精灵?

How to edit a shader to make it show sprites it's on without any lights?

我在 Internet 上找到了一些可以为旋转对象制作径向模糊效果的着色器。它可以工作并且看起来很酷,但是当我将它应用于精灵时,它的工作方式类似于 Sprite/Diffuse 着色器:它需要一个光源才能被看到,否则它是黑色的。

我如何编辑此着色器以使其像不需要灯光的普通 Sprite/Default 着色器一样工作?

代码如下:

  Shader "Custom/SpinBlur"{
  Properties{
      _Color("Main Color", Color) = (1,1,1,1)
      _Samples("Samples", Range(0,360)) = 100
      _Angle("Angle", Range(0,360)) = 10
      _MainTex("Color (RGB) Alpha (A)", 2D) = "white"
  }
  SubShader{
  Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }

  LOD 200
  Cull Off

  CGPROGRAM
  #pragma target 3.0
  #pragma surface surf Lambert alpha

  sampler2D _MainTex;
  int _Angle;
  int _Samples;
  float4 _Color;

  struct Input {
      float2 uv_MainTex;
      float4 screenPos;
  };

  float2 rotateUV(float2 uv, float degrees) {
      const float Deg2Rad = (UNITY_PI * 2.0) / 360.0;
      float rotationRadians = degrees * Deg2Rad;
      float s = sin(rotationRadians);
      float c = cos(rotationRadians);
      float2x2 rotationMatrix = float2x2(c, -s, s, c);
      uv -= 0.5;
      uv = mul(rotationMatrix, uv);
      uv += 0.5;
      return uv;
  }

  void surf(Input IN, inout SurfaceOutput o) {
      const float Deg2Rad = (UNITY_PI * 2.0) / 360.0;
      const float Rad2Deg = 180.0 / UNITY_PI;
      float2 vUv = IN.uv_MainTex;
      float2 coord = vUv;
      float4 FragColor = float4(0.0, 0.0, 0.0, 0.0);
      int samp = _Samples;
      if (samp <= 0) samp = 1;
      for (float i = 0; i < samp; i++) {
          float a = (float)_Angle / (float)samp;
          coord = rotateUV(coord, a);
          float4 texel = tex2D(_MainTex, coord);
          texel *= 1.0 / samp;
          FragColor += texel;
      }
      float4 c = FragColor*_Color;
      o.Albedo = c.rgb;
      o.Alpha = c.a;
  }
  ENDCG
  }
      FallBack "Diffuse"
  }

写下你的custom lighting model

half4 Lighting<Name> (SurfaceOutput s, UnityGI gi)
{
    return half4(s.Albedo, s.Alpha);
}

void Lighting<Name>_GI (SurfaceOutput s, UnityGIInput data, inout UnityGI gi)
{
}

并将 Lambert 更改为 <Name>