添加实时阴影
来源:互联网 发布:网络对传统文化的影响 编辑:程序博客网 时间:2024/06/07 02:22
For the sake of anyone else who is trying to write a fragment shader that receives shadows, I figured it out.
You must do these things:
- '#include "AutoLight.cginc"'
- '#include "Lighting.cginc"'
- Add "Tags {"LightMode" = "ForwardBase"}
- '#pragma multi_compile_fwdbase'
- Add the Unity macros to your VSOut struct, VS and PS: LIGHTING_COORDS, TRANSFER_VERTEX_TO_FRAGMENT, LIGHT_ATTENUATION.
None of this is documented in the Unity manual.
To access the primary directional light color, unity_LightColor[0] works as long as you don't add "Tags {"LightMode" = "ForwardBase"}". If you do add that line, then it doesn't work: use _LightColor0.rgb instead. Why? Who knows.. probably makes sense to someone with access to the Unity source code. Which means no one.
Good luck!
-Peter
- Shader "Custom/PeterShader2" {
- Properties
- {
- _MainTex ("Base (RGB)", 2D) = "white" {}
- }
- CGINCLUDE
- #include "UnityCG.cginc"
- #include "AutoLight.cginc"
- #include "Lighting.cginc"
- uniform sampler2D _MainTex;
- ENDCG
- SubShader
- {
- Tags { "RenderType"="Opaque" }
- LOD 200
- Pass
- {
- Lighting On
- Tags {"LightMode" = "ForwardBase"}
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #pragma multi_compile_fwdbase
- struct VSOut
- {
- float4 pos : SV_POSITION;
- float2 uv : TEXCOORD1;
- LIGHTING_COORDS(3,4)
- };
- VSOut vert(appdata_tan v)
- {
- VSOut o;
- o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
- o.uv = v.texcoord.xy;
- TRANSFER_VERTEX_TO_FRAGMENT(o);
- return o;
- }
- float4 frag(VSOut i) : COLOR
- {
- float3 lightColor = _LightColor0.rgb;
- float3 lightDir = _WorldSpaceLightPos0;
- float4 colorTex = tex2D(_MainTex, i.uv.xy * float2(25.0f));
- float atten = LIGHT_ATTENUATION(i);
- float3 N = float3(0.0f, 1.0f, 0.0f);
- float NL = saturate(dot(N, lightDir));
- float3 color = colorTex.rgb * lightColor * NL * atten;
- return float4(color, colorTex.a);
- }
- ENDCG
- }
- }
- FallBack "Diffuse"
- }
0 0
- 添加实时阴影
- 添加阴影
- 实时阴影技术
- 实时阴影技术
- AR实时阴影制作
- 实时阴影的技术实现
- 2DSprite的实时阴影
- RenderTexture实现实时阴影绘制
- Unity实时阴影实现图解
- 移动设备渲染实时阴影
- 给图片添加阴影
- 给视图添加阴影
- android textView添加阴影
- 给UIView添加阴影
- 添加 阴影 圆角
- 给视图添加阴影
- 给图片添加阴影
- UIButton添加阴影图片
- Android开发——Fragment知识整理(一)
- 第16周项目1-验证算法(3)冒泡排序 直接插入排序
- 深度探索QT窗口系统---几何篇4
- shell脚本编程(一)
- php app 接口 封装xml
- 添加实时阴影
- 句柄和指针
- DOM4J 解析XML文件
- ASP.NET 跳转页面数据的获取 (使用html控件)
- 斐波那契数列 1, 1, 2, 3, 5, 8, 13, 21, 34...
- java中不带package和带package的编译运行方式
- 信号的基本概念
- test
- sublime text3下的bootstrap插件