So I want to achieve a visial asthetic in my game that looks like this enter image description here

Meaning I dont want the outer parts of my dungeon walls to be affected by light. Now I know this is posible if the object itslef is created with 2 materials that way I can make the back material solid black. But I was wondering if there is a easy way to achieve this with a shader.

  • \$\begingroup\$ youtube.com/watch?v=xkcCWqifT9M - this might be useful you can just render everything, not just the things in FOV. \$\endgroup\$ – Candid Moon _Max_ Sep 28 '17 at 9:26
  • \$\begingroup\$ @CandidMoon I'm not exactly sure what do you mean by render everything. Could you please elaborate ? \$\endgroup\$ – Uri Popov Sep 28 '17 at 11:15
  • 1
    \$\begingroup\$ It's possible, but it will depend to some extent on how you're building your walls. Somehow the wall needs to carry awareness of which faces represent the "outside" into the graphics pipeline, which sees them as just a soup of vertices and knows nothing about your level layout. You could paint these faces with particular vertex colours or specially designated UVs in your modelling tool, but if you're assembling your level from Unity primitives, your options are more limited, and would usually require breaking batching. What's your level creation pipeline like so far? \$\endgroup\$ – DMGregory Sep 28 '17 at 11:25
  • \$\begingroup\$ @DMGregory I can use object that are from a modeling software. Right now the walls are such a object while the floor is a unity Quad. Now the things is if I have to get the artist involed he can just provide me the wall model with two materials one for front and one for back and the back one will be a unlit black texture and that will work. \$\endgroup\$ – Uri Popov Sep 28 '17 at 11:37
  • \$\begingroup\$ That will be as easy if not easier than any of the alternatives I mentioned. And if the unlit material gets batched together then it should not introduce any significant performance cost. Any concerns with proceeding in that direction? \$\endgroup\$ – DMGregory Sep 28 '17 at 11:42

I know of two main techniques to achieve this, which most games use with some variation between them:

1) Procedural or voxelized "filler" mesh.

  1. Model your walls as simple 1-sided "planes". By design, 1-sided surfaces can only be seen through one side, as faces with opposite normal are ignored in render. Optionally, but highly recommended, is making these in modular sections.
  2. Fill the space behind the walls with procedural meshing of some sort, either as "roof" (plane) along the top of the walls, or as solid.
  3. Depending on the look&feel you want to achieve, you can give this filler a solid opaque color (IE pitch black), or have it with a material similar to the walls, to "blend in".

This is the technique used in games like Evil Genius: enter image description here

2) Make your lighting work with the "wall" meshes and the procedural nature of the game by design.

  1. Make your "wall" meshes like in the first technique; meaning one-sided, and preferably modular.
  2. Don't use global illumination at all. Instead, make lighting be localized to the player, and/or enemies, and/or proceduraly-generated together with the walls, in pieces. Make it never be generated above the top of the walls. And make each light never exceed the "thickness" of it's own section (two corridors running side-by-side shouldn't "bleed" lighting to each-other).
  3. Profit. The game gives a "dark theme" to the spaces outside the walls by design.

As far as I can tell, this is the technique used in (some areas of) Path of Exile: enter image description here

|improve this answer|||||

Rather than worrying about the color of the back sides of your walls, just put a pure black "roof" above the empty areas.

|improve this answer|||||
  • \$\begingroup\$ Problem is empty areas are procedural generated and I dont want to generate the roof as well. \$\endgroup\$ – Uri Popov Sep 29 '17 at 9:10

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.