当前位置:网站首页>Unity shader flat shadow
Unity shader flat shadow
2022-06-30 05:11:00 【Shannan HSY】
Shader "Custom/PlanarShadow"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
_ShadowInvLen("ShadowInvLen", float) = 6.36 //0.4449261
_ShadowFalloff("ShadowFalloff", float) = 0.49
_ShadowPlane("ShadowPlane",vector) = (0, 1.0, 0, 0.1)
_ShadowFadeParams("ShadowFadeParams",vector) = (1.13, 1.5, 0.7, 0)
}
SubShader
{
Tags{ "RenderType" = "Opaque" "Queue" = "Geometry+10" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
Cull Back
ColorMask RGB
Stencil
{
Ref 0
Comp Equal
WriteMask 255
ReadMask 255
Pass Invert
Fail Keep
ZFail Keep
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
float4 _ShadowPlane;
float _ShadowInvLen;
float4 _ShadowFadeParams;
float _ShadowFalloff;
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 vertex : SV_POSITION;
float3 xlv_TEXCOORD0 : TEXCOORD0;
float3 xlv_TEXCOORD1 : TEXCOORD1;
};
v2f vert(appdata v)
{
v2f o;
float3 lightdir = normalize(_WorldSpaceLightPos0.xyz);
float3 worldpos = mul(unity_ObjectToWorld, v.vertex).xyz;
float distance = (_ShadowPlane.w - dot(_ShadowPlane.xyz, worldpos)) / dot(_ShadowPlane.xyz, lightdir.xyz);
worldpos = worldpos + distance * lightdir.xyz;
o.vertex = mul(unity_MatrixVP, float4(worldpos, 1.0));
float3 center = mul(unity_ObjectToWorld,float4(0,0,0,1)).xyz;
o.xlv_TEXCOORD0 = center;
o.xlv_TEXCOORD1 = worldpos;
return o;
}
float4 frag(v2f i) : SV_Target
{
float3 posToPlane_2 = (i.xlv_TEXCOORD0 - i.xlv_TEXCOORD1);
//float a = (pow((1.0 - clamp(((sqrt(dot(posToPlane_2, posToPlane_2)) * _ShadowInvLen) - _ShadowFadeParams.x), 0.0, 1.0)), _ShadowFadeParams.y) * _ShadowFadeParams.z);
float a = 1.0 - saturate(distance(i.xlv_TEXCOORD0, i.xlv_TEXCOORD1) * _ShadowFalloff);
return float4(0,0,0,a);
}
ENDCG
}
}
}

边栏推荐
- Win10 vs2015 compiling curaengine
- JPA composite primary key usage
- Unity packaging failure solution
- Unity project hosting platform plasticscm (learn to use 1)
- Read and save txt files
- Nestjs configures static resources, template engine, and post examples
- 中文版PyCharm改为英文版PyCharm
- The difference between SVG and canvas
- Unity/ue reads OPC UA and OPC Da data (UE4)
- Unity publishing /build settings
猜你喜欢

Win10 vs2015 compiling curaengine

mmcv常用API介绍

Unity3d lookat parameter description

Some problems encountered in unity steamvr

Virtual and pure virtual destructions
![[learning notes] AssetBundle, xlua, hot update (use steps)](/img/59/9d9f31cfe55a908f2f0705e95ecc05.jpg)
[learning notes] AssetBundle, xlua, hot update (use steps)

QT connecting external libraries
Sourcetree usage

东塔攻防世界—xss绕过安全狗

PWN Introduction (2) stack overflow Foundation
随机推荐
力扣27. 移除元素
Log writing specification
Unity shortcut key
PWN入门(2)栈溢出基础
Very nervous. What should I do on the first day of software testing?
力扣(LeetCode)180. 连续出现的数字(2022.06.29)
Some problems encountered in unity steamvr
Unity determines whether the UI is clicked
z-index属性在什么情况下会失效?
Installation and getting started with pytoch
Network communication problem locating steps
Solution to the 292 week match of Li Kou
Unity obtains serial port data
东塔攻防世界—xss绕过安全狗
力扣704. 二分查找
Generate a slice of mesh Foundation
Harbor API 2.0 query
虚析构和纯虚析构
Chapter 7 vertex processing and drawing commands of OpenGL super classic (7th Edition)
How does unity use mapbox to implement real maps in games?