如何编辑着色器,使之出现精灵它是在没有任何灯光?

问题描述 投票:1回答:1

我发现在互联网上,使纺纱对象径向模糊效果的一些着色器。它的工作原理,看起来很酷,但是当我把它应用到一个精灵,但是它就像雪碧/漫着色器:它需要一个光源可以看到,否则它是黑色的。

我怎么可以编辑这个着色器,使其像正常雪碧/默认着色器,并不需要一个轻松的工作?

下面的代码:

  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"
  }
unity3d shader hlsl
1个回答
2
投票

写下您的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>

© www.soinside.com 2019 - 2024. All rights reserved.