Unity里实现Sprite Renderer的阴影

  • 时间:
  • 浏览:1

此外还要另另一个多多Shader,来接受阴影:

Tags { "RenderType"="Opaque" }

};

更多unity2018的功能介绍请到paws3d爪爪学院查找。

}

};

struct v2f

}

float4 vertex : SV_POSITION;

TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)

};

return col;

SHADOW_CASTER_FRAGMENT(i)

o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);

float4 frag(v2f i) : SV_Target

struct v2f {

struct appdata

Properties {

o.Albedo = c.rgb;

{

float4 vertex : POSITION;

{

float2 uv_MainTex;

o.color = v.color;

}

}

Pass

增加光源并且,运行Scene即可见阴影(不运行语录脚本的内容这麼运行会意味着着分析不开启阴影)。

float4 texcoord : TEXCOORD1;

sampler2D _MainTex;

{

{

_MainTex ("Base (RGB)", 2D) = "white" {}

}

CGPROGRAM

ENDCG

{

sampler2D _MainTex;

fixed4 color : COLOR;

Tags {"LightMode"="ForwardBase"}

ENDCG

};

float2 uv : TEXCOORD;

GetComponent().castShadows =true;

}

v2f vert (appdata v)

_AlphaCutOff ("AlphaCutOff", Range(0,1)) = 0.05

SubShader

}

CGPROGRAM

{

{

voidOnEnable(){

Pass

clip(col.a - _AlphaCutOff);

Shader "Custom/Diffuse2DTexture" {

fixed _AlphaCutOff;

float2 uv : TEXCOORD;

o.texcoord = v.texcoord;

SubShader {

fixed4 col = tex2D(_MainTex, i.uv) * i.color;

GetComponent().receiveShadows =true;

o.Alpha = c.a;

o.color = v.color;

}

只是我这是不足英文的,还还要Shader帮忙,下面的Shader请倒进产生Shadow的物体上:

将以下脚本附到产生Shadow的物体上:

}

fixed4 frag (v2f i) : SV_Target

FallBack "Diffuse"

Tags {"LightMode"="ShadowCaster"}

{

{

fixed4 col = tex2D(_MainTex, i.texcoord) * i.color;

v2f o;

struct Input {

half4 c = tex2D (_MainTex, IN.uv_MainTex);

LOD 100

sampler2D _MainTex;

fixed _AlphaCutOff;

}

Properties

{

fixed4 color : COLOR;

}

CGPROGRAM

half3 normal : NORMAL;

}

{

v2f o;

return o;

_MainTex ("Texture", 2D) = "white" {}

fixed4 color : COLOR;

void surf (Input IN, inout SurfaceOutput o) {

V2F_SHADOW_CASTER;

}

ENDCG

clip(col.a - _AlphaCutOff);

v2f vert(appdata_full v)

o.uv = v.uv;

Shader "Custom/SpriteDiffuse"

}

return o;