• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by D4rt · Jul 07, 2013 at 02:29 PM · shaderterrainfog

Adding a static fog in the bottom of a terrain

Hi ho, another question.

I'm trying to achieve the effect of a static fog in the bottom of my rocky terrain. It's used mainly for atmosphere and obscuring some ugly details no one needs to know about. ;)

Here is the effect I want, done with Unity's internal fog settings:

![alt text](/storage/temp/12882-fog+example.png)

And here is the problem that can't be fixed with the internal fog.

![alt text](/storage/temp/12883-fog+example2.png)

The fog retracts as it should. Unfortunately it's not the effect I want.

I reckon custom shader is the way to do it but unfortunately I don't have a good grasp on them. Any help (on alternative solutions also) would be much appreciated.

fog example.png (342.8 kB)
fog example2.png (173.2 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by D4rt · Jul 07, 2013 at 03:34 PM

I did a little hack that doesn't work flawlessly and haunts me in my dreams, but hey, as long as others think it works, eh? I added this to my main camera's script.

     private float startY = 0;
     private float fogStart = 0;
     private float fogEnd = 0;
 
     void Awake()
     {
         startY = transform.position.y;
         fogStart = RenderSettings.fogStartDistance;
         fogEnd = RenderSettings.fogEndDistance;
     }
 
     void Update()
     {
         RenderSettings.fogStartDistance = fogStart + transform.position.y - startY;
         RenderSettings.fogEndDistance = fogEnd + transform.position.y - startY;
     }

I'm still thinking about other possibilities and any further ideas would be much welcome.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image D4rt · Jul 07, 2013 at 11:41 PM 0
Share

With properly constraining the x and y movement I've managed to make this look quite nice and robust. I guess I'll have to go with this until I have access to Unity Pro and the Global Fog.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Color changes at distance in procedural terrain 0 Answers

Changing Replacement Shaders at Runtime 2 Answers

Geomorphing terrain with a vertex shader (custom vertex data maybe?+ 0 Answers

Fog/color tint shader for orthographic camera 0 Answers

Unity 5: Bloom causes artifacts on Terrain 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges