Unity的Shader学习笔记(13)[20/12/29_周二][51-53]

目录

课时51:FragmentShader-片段颜色混合(阴影)

1.平行光阴影

2.点光源阴影

3.合并两种

4. 5.x版本的宏。


课时51:FragmentShader-片段颜色混合(阴影)

1.平行光阴影

AutoLight.cginc

和教程的不同,我的版本是2020.1,从2018开始也是这样的了。

// -----------------------------
//  Light/Shadow helpers (4.x version)
// -----------------------------
// This version computes light coordinates in the vertex shader and passes them to the fragment shader.

// ---- Spot light shadows
#if defined (SHADOWS_DEPTH) && defined (SPOT)
#define SHADOW_COORDS(idx1) unityShadowCoord4 _ShadowCoord : TEXCOORD##idx1;
#define TRANSFER_SHADOW(a) a._ShadowCoord = mul (unity_WorldToShadow[0], mul(unity_ObjectToWorld,v.vertex));
#define SHADOW_ATTENUATION(a) UnitySampleShadowmap(a._ShadowCoord)
#endif

// ---- Point light shadows
#if defined (SHADOWS_CUBE)
#define SHADOW_COORDS(idx1) unityShadowCoord3 _ShadowCoord : TEXCOORD##idx1;
#define TRANSFER_SHADOW(a) a._ShadowCoord.xyz = mul(unity_ObjectToWorld, v.vertex).xyz - _LightPositionRange.xyz;
#define SHADOW_ATTENUATION(a) UnitySampleShadowmap(a._ShadowCoord)
#define READ_SHADOW_COORDS(a) unityShadowCoord4(a._ShadowCoord.xyz, 1.0)
#endif

// ---- Shadows off
#if !defined (SHADOWS_SCREEN) && !defined (SHADOWS_DEPTH) && !defined (SHADOWS_CUBE)
#define SHADOW_COORDS(idx1)
#define TRANSFER_SHADOW(a)
#define SHADOW_ATTENUATION(a) 1.0
#define READ_SHADOW_COORDS(a) 0
#else
#ifndef READ_SHADOW_COORDS
#define READ_SHADOW_COORDS(a) a._ShadowCoord
#endif
#endif

在上节课的基础上,把这三个宏用进去。

Unity的Shader学习笔记(13)[20/12/29_周二][51-53]

Making multiple shader program variants

https://docs.unity3d.com/kr/2018.3/Manual/SL-MultipleProgramVariants.html

multi_compile_fwdbase compiles all variants needed by ForwardBase (forward rendering base) pass type. The variants deal with different lightmap types and main directional light having shadows on or off.
multi_compile_fwdadd compiles variants for ForwardAdd (forward rendering additive) pass type. This compiles variants to handle directional, spot or point light types, and their variants with cookie textures.
multi_compile_fwdadd_fullshadows - same as above, but also includes ability for the lights to have realtime shadows.
multi_compile_fog expands to several variants to handle different fog types (off/linear/exp/exp2).

多版本编译,和宏配合使用

Unity的Shader学习笔记(13)[20/12/29_周二][51-53]

测试发现前两个宏的实际代码

Unity的Shader学习笔记(13)[20/12/29_周二][51-53]

但是第三个宏将可能代码替换后,提示不存在函数。

UnitySampleShadowmap和unitySampleShadow都提示不存在,而这两个实际上是UnityShadowLibrary.cginc里面的内联函数....

Unity的Shader学习笔记(13)[20/12/29_周二][51-53]

尝试了一会,放弃。不影响。

----------------------------------------------------

2.点光源阴影

拷贝一份pass,修改

Unity的Shader学习笔记(13)[20/12/29_周二][51-53]

效果

Unity的Shader学习笔记(13)[20/12/29_周二][51-53]

3.合并两种

https://docs.unity3d.com/Manual/SL-Blend.html

blend one one 

Unity的Shader学习笔记(13)[20/12/29_周二][51-53]

结果

Unity的Shader学习笔记(13)[20/12/29_周二][51-53]

4. 5.x版本的宏。

UNITY_LIGHT_ATTENUATION

Unity的Shader学习笔记(13)[20/12/29_周二][51-53]

还是有些差异,官方推荐用surfaceShader

======================================================

课时52:FragmentShader-边缘泛光shader1

shadergraph里面有个泛光的节点

边缘查找

向量运算,点积

 

上一篇:CSS(去除无序列表前的小圆点,圆角边框原理,盒子阴影,文字阴影,CSS浮动,清除浮动)


下一篇:css个人整理样式