I'm a former Flash dev working in Unity (or in 3D for that matter) for the first time.

For the game I'm working on, I've designed an interior room like so:

enter image description here

To represent void/space outside the bounds of the current room, there's just black. In order to hide the back faces of the exterior facing walls, I've created a snug fitting mesh cutout which sits just below the lip of the wall. If I moved the camera below the surface, you would clearly see that.

I'm quite new to Unity, and have very little experience with shaders.

Anyway, I figured this would be a good place to try for creating my first shader, but I'll need some help.

I'd like to blur/soften the edges where the wall lip meets the void, like so:

enter image description here

The only way I could achieve this effect would be by hacky means, like by using a gradient texture (#00000000 -> #FF000000) UVed around the edges of the wall lips, but I suspect there is a more elegant solution by rendering the black surface with a shader.

Currently, even with a basic understanding of fragment shaders and the rendering process, I would have no idea where to start if I tried to write my own. When I read shader script I can only stare in wonder at the sheer etherealness of it. I just don't know how to craft a solution in such basic terms, but I'd love to learn.

I understand the answer is probably as simple as 'use a gaussian blur', but i would appreciate some more input to steer me on the right path, and maybe some examples to help me understand.

  • \$\begingroup\$ Your gradient method (or equivalently vertex colours) will generally perform better, particularly on mobile platforms. That said, there are some simple shaders we can use without more expensive screenspace blurring — is it always the vertices below the floor level that need the effect? And are they always at the same elevation? If so, we can use worldspace position to tweak the colours. \$\endgroup\$
    – DMGregory
    Feb 1, 2017 at 19:37
  • \$\begingroup\$ The walls are always 3 metres tall, the void edge is at 2.75m height, around the edges. Please expound. \$\endgroup\$
    – hedgehog90
    Feb 1, 2017 at 20:00
  • \$\begingroup\$ One way to do this with a shader would be to use the worldspace colouring trick described in this answer. Effectively, you tint any pixels below your floor plane with increasingly opaque shades of black. \$\endgroup\$
    – DMGregory
    Feb 2, 2017 at 17:59


You must log in to answer this question.

Browse other questions tagged .