当前位置:网站首页>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
}
}
}

边栏推荐
- Preorder traversal of Li Kou 589:n fork tree
- Database base (Study & review for self use)
- Four methods of unity ugui button binding events
- Chapter 12 pipeline monitoring of OpenGL super classic (version 7)
- 力扣704. 二分查找
- Operation of JSON file
- Intellj idea jars projects containing external lib to other project reference methods - jars
- Modbus protocol register
- Unity packaging and publishing webgl error reason exception: failed building webgl player
- Deeply understand the function calling process of C language
猜你喜欢

力扣977. 有序数组的平方

LxC and LXD container summary

Unity2019.3.8f1 development environment configuration of hololens2

Force buckle 27 Removing Elements

Parkour demo
![[vcs+verdi joint simulation] ~ take the counter as an example](/img/fb/214a4e65c53503ecbc38a5e43523cf.png)
[vcs+verdi joint simulation] ~ take the counter as an example

Unity/ue reads OPC UA and OPC Da data (UE4)

mmcv常用API介绍

力扣349. 两个数组的交集

Unity screenshot method
随机推荐
Output directory of log files after unity3d packaging
UnityEngine. JsonUtility. The pit of fromjason()
炒美原油的国际交易平台如何能保障资金安全呢?
Four methods of unity ugui button binding events
JS 数组的排序 sort方法详解
Installation and getting started with pytoch
Unity + hololens2 performance test
The difference between SVG and canvas
Solution to the 292 week match of Li Kou
Unity scroll view element drag and drop to automatically adsorb centering and card effect
Unrealeengine4 - about uobject's giant pit that is automatically GC garbage collected
很紧张,第一天做软件测试,需要做什么?
Unity3d Google Earth
003-JS-DOM-Attr-innerText
Preorder traversal of Li Kou 589:n fork tree
Unity2019.3.8f1 development environment configuration of hololens2
Unity/ue reads OPC UA and OPC Da data (UE4)
How can the international trading platform for frying US crude oil guarantee capital security?
Sourcetree usage
Rotation, translation and scaling of unity VR objects