2
\$\begingroup\$

I would like my background made of the same tiles as my foreground but with a filter which makes it appear further away from the camera.

Making the objects smaller is easy, I just have to decrease the scale of the tilemap.

But I also want it to have a "fog effect". So for example if the sky is blue then the tiles will be as blueish as far they are from the camera.

How could I implement this?

Example for fog effect:

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Are you talking about a 2D sidescroller just like in the image? Or a 3D one? \$\endgroup\$ – TomTsagk Jul 24 '18 at 11:25
  • \$\begingroup\$ 2D, just like in the image. \$\endgroup\$ – Tudvari Jul 24 '18 at 13:23
  • \$\begingroup\$ What's wrong with making the background actually further away and applying a fog effect? \$\endgroup\$ – clabe45 Jul 25 '18 at 18:15
3
\$\begingroup\$

If you are only interested in 2D fog, you can simply change the color of the background sprites so it looks like it is behind a fog. In Unity, you can simply change the color of the Image component, or the color of the material (depending how you are drawing them).

For example, try adding a dark grey color to it.

This has the disadvantage that you can't apply light-colors, as white means use the Texture's original color. Instead, you can make a trick shader-wise, if you feel comfortable with that, simply making pixels of an object whiter than they should, the further away they are from the camera.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ This is a very elegant solution for dark colors. Thanks! \$\endgroup\$ – Tudvari Jul 24 '18 at 17:07
  • \$\begingroup\$ Doesn't Unity support other blend modes? Screen or multiply the background layer by a constant to get a good fog look. \$\endgroup\$ – rebusB Jul 24 '18 at 21:13
  • \$\begingroup\$ @rebusB multiply is the default I think, that's why if you put all white, all colors will have the value 1f so the texture keeps its original colors. I'm not sure if it's possible to do addition, which would support white as well, that's why I suggested a custom shader, so the user can have total control \$\endgroup\$ – TomTsagk Jul 24 '18 at 21:30
  • \$\begingroup\$ Right! Blend modes are pretty core to shader code... Turns out the article I was reading on Unity Blend Modes was plugging a plug-in so crafting shaders would be the way to go. \$\endgroup\$ – rebusB Jul 24 '18 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.