Unity3D开发之Unity5版本自写Shader没有雾的效果问题

原本项目是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:
  1. Add #pragma multi_compile_fog
  2. Add UNITY_FOG_COORDS(n) to your vertex-to-fragment struct
  3. Add UNITY_TRANSFER_FOG(o,o.vertex); to your vertex shader. "o" is output struct name, and "o.vertex" is position in clip space.
  4. 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  onlyaffects 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)