I’m currently working on a project that requires low poly City Buildings in the background for the night skyline. Now I want to add a material for the windows that chooses at random (maybe world position or with a noise?) if certain windows will be light or dark. Just to make the city skyline more atmospheric and realistic. How would you do it?
You’re probably overthinking it and can get away with just having a simple texture with randomly lit windows. If you really want to, you can cut some parts into the surface of a building and then adjust the UV’s of that area to randomize it more.
You could have a building mesh with every window having a separate material slot/index (say, your building has material index 0 and eight windows are materials 1 - 8). Then on construct, you could create a dynamic material instance, assign the building texture to index 0 of this material and then do a ‘for loop’ from 1 to 8 and, on each loop, do random integer in range 0-1 and, based on this number, switch between assigning a lit or unlit material to the material index in from the ‘for loop’.
Don’t do that, that’s really bad for performance
I’m having serious trouble posting here. Getting all sorts of errors when trying to upload pics and files. Anyway, I’m attaching a zip file with the building with changing lights I’ve just made. You can unpack the ‘Building’ folder to your content folder in your project and test it out. If you open your project and in the content window find the ‘Building’ folder and run the level included, press space bar on the keyboard and the lights on the building will change randomly every time. The key to this is to create a building model with separate material index for each window.
Hi. Can you explain why?
I take that back, it doesn’t work straight away if you import it to your project because references are messed up. But you can still see how the nodes are set up in the Building blueprint
way to many draw calls. best way to set it up would be to have a few emissive masks and change them in the construction script if it HAS to be a little random every time its played. cheapest way is to just have one mask for each building, no one will notice if the lights change unless its a main focal point
HI. Even if there’s only one base material used in this example? (The lit and unlit window materials are instances of the the base building material with colour and emission parameters changed. And I don’t even think creating dynamic material instance was necessary). Do you mean that to display each window in say, multiple buildings, is a separate draw call? I’m genuinely just trying to learn. Thanks
Thanks for your answers.
Since it’s really just in the background, I only want to place static meshes without any Blueprints to save as much performance as possible. I was thinking something like a noise material that is based on world position and increasing the noise size so much that is always covers at least the size of one full window, but no matter how I tweak it, there are always spots that cover half of a window or several window bits that makes it look like random spots instead of lit up windows.
I’ll probably end up adding another material for light windows on the static meshes and in the 3d program I will manually select a few windows and give it this bright material so in the game you could probably tell the buildings are clones, but as long as I place them far apart from each other it shouldn’t be too obvious.
Still open for other suggestions if someone knows a better solution.
Applying a different material to a polygon will add draw calls. And it’s really unnecessary because it’s a background object and doesn’t need to be complex.
If you really want to, you can do something like that in your 3D software first by adjusting the UV’s which will allow you to use just one material.
In any case, it’s really simple to texture a building with windows and make it more randomized if you need to without doing anything crazy, it’s just UV mapping.
i am trying to do this aswell and half covered windows is all i get…
Just use a Random noise texture and map each window UV to a single pixel.
The end result should be what you need with each window having a random intensity.