原本项目是Unity 4.6版本的,升级到Unity 5之后发现原本的雾不再看见了,然后查了一下相关资料,发现官方是改变了雾的渲染。
这里有相关的官方方式:
http://forum.unity3d.com/threads/official-changing-how-fog-is-done-in-unity-shaders.261217/
里面有比较重要的一段:
For surface shaders, nothing needs to be done; fog variants & code will be generated. You can add "nofog" to #pragma surface line, if you really don't want fog. For vertex/fragment shaders, if you want fog you have to do this:
Add #pragma multi_compile_fog
Add UNITY_FOG_COORDS(n) to your vertex-to-fragment struct
Add UNITY_TRANSFER_FOG(o,o.vertex); to your vertex shader. "o" is output struct name, and "o.vertex" is position in clip space.
Add UNITY_APPLY_FOG(i.fogCoord, col); to end of your pixel shader. "i" is input struct name, and "col" is the color computed in your pixel shader. This applies standard fog color; if you want custom fog color (as some particle/additive shaders do, for example), you can do UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fixed4(0,0,0,0)); to fog towards black for example.
For fixed function shaders, nothing needs to be done. "Fog { ... }" command in shaderlab still works, but now it _only_affects fixed function shaders (for non-fixed function, see point 2 above). By default, fog modes used by scenes are included into game data build. If you know you'll want to change them at runtime, you can choose "Custom fog modes" (default is "automatic") under project's Graphics Settings, and tick checkboxes you need.
本文分享自微信公众号 - Unity3D游戏开发精华教程干货(u3dnotes)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。