- Home /
Make transparency ignore meshes inside?
Hello everyone, I'm currently working a 2.5D building game where players can place different kinds of structures inside a building to build it floor by floor. Whenever something is built the game places another "building" behind it called the floor, this is necessary so that when a building is removed the story above isn't floating in the air but has some kind of support underneath; the floor is always moved and stretched around by the game so that it always matches the space used by the buildings.
Right now all the buildings are just cubes stretched out in different rectangular shapes with a single texture applied to them, it has worked well enough up until now. However, when I wanted to introduce a structure that has glass windows you can see through I noticed I can't actually see through them at all. I thought I got the material's transparency or the texture settings wrong but it turns out I'm simply seeing the floor through the windows.
The situation is basically as follows
That long grey thing is the floor, it is positioned almost exactly as a building, it's just slightly thinner so the textures don't overlap, in other words it's actually "inside" the cube mesh representing the building.
The problem here of course is that the front face has those see-through windows that let you see the floor, when they should let you see the sky behind instead.
I'm not sure how to get out of this predicament; the most obvious solution would be to not make the floor go through buildings at all, but that would make it much more complicated, the floor would need to be split and merged constantly when buildings are added or removed. It would be much simpler if I could tweak my mesh or the material so that the transparency acts as expected, or some other solution I'm not seeing right now... does anyone know how to achieve the desired effect?
Thanks in advance
lemmie see if i understand this correctly, those windows on the left are transparent, right now the long gray rectangle is going inside of the building on the left so all you can see through the windows is the gray rectangle and what you want is some kind of shader(or something) that will ignore the gray box so looking through the windows would show sky?
I cant really think of a shader that can ignore other geometry like that or some kind of way to delete intersecting geometry like a boolean in a modeling program. But maybe a different solution would be to make your floor a bunch of chunks in a line(being the smallest possible size of sections you can place), then just remove colliding chunks when you place your section(sorry if im totally off base of what youre looking for, it's just a thought)
I forgot to mention, the game camera actually faces straight on so the left sides are irrelevant, what should happen is what you said but with the front face (the large lit one).
I was thinking of scrapping this "single stretching floor" approach and just have smaller floors to fill the gaps between buildings myself but I was concerns about the performance impact of having so many little GameObjects scattered around
Not sure if there is something for your situation, but there are a couple of shaders available on the wiki. Try the transparent shaders. $$anonymous$$aybe you are lucky.
Tried all the Unity 3.x shaders that might apply but unfortunately none of them seem to help
Answer by dorpeleg · Apr 05, 2013 at 06:50 PM
I only see 3 options for this:
1.Make it so the floors split (like you said, it might hurt performance).
2.Find some why to use render texture to display the sky behind(might be even worse for performance).
3.Just draw "sky" in your texture, it won't be real-time moving sky but will give best performance.
Looks like your making something like SimTower, should be cool in 3D :)
Yeah, that's the plan actually!
I think I'll give number 1 a shot, maybe rig a script to fill the floors with 1x1 tiles to simulate a worst case scenario... hopefully since the floors don't really do anything other than stay there they won't have a noticeable impact on performance. Either that or make them stretch just to fill gaps ins$$anonymous$$d of filling the whole floor, should be the best approach.
It seems all your meshes are boxes, so that is good for performance.
If you could make a really smart code that will stretch when needed and split when needed, then it should help performance.
Apparently filling with tiny boxes is not a good idea, I made a test with 100 floors and it outright killed performance. Looks like I'll have to go for the stretching gap fill approach after all
Like I said, try to make a smart code that will stretch when needed and split when needed, then it should help performance.
Yeah, working on the split/merge thing now, hopefully it will be good enough to handle a big building AND all the simulation going on at the same time!