Interior mapping in Unity3D


I have finally started to play with Unity3D. First goal is to get an overview of how shaders work. This will come in handy regardless of what platform I choose as my target. My favorite method when it comes to learning is to port stuff from another languages. Here I get the opportunity to learn two new languages at the same time. And all the trial and error involved often inspires me to do things that wasn’t intended in the first place.

My choice of shader to implement is written by Joost van Dongen (@JoostDevBlog) and he calls it “interior mapping”. It’s a technique to render buildings with a facade with reflections and lighting, and perspectively correct looking interiors (well, at least the walls is correct. Furniture or details on the walls is of course flat) seen through the windows, giving an illusion of loads of geometry on a wall with just two triangles. All done by a single shader. The use of raycasting together with interpolated fragments opens up for a lot of interesting ideas. It’s not a new technique though, I’m just exploring this field for the first time. Check out his excellent paper for details, complete with sources and explanations.

In this demo I use another source of inspiration as well. If you’re into Unity, you have probably seen this cityscape made by @bartekd. I using his example to plot out procedural buildings in a grid, and in the same time learning how to create meshes by scripting. That leaded me to add roads, sidewalks and lights. I also added a simple day/night-system which fades between two sky-boxes (looks weird with  fading sun, but that’s enough for this demo ), this parameter also control the lighting and if the activity in the building. Check it out:


View the procedural city here


One thing that I’m totally missing here is optimization skills. Unity folks will shake their heads and laugh out loud.  I don’t know where to start really. The buildings and ground is just few triangles, but I have added loads of point lights and streetlight models. I should probably use some sort of light-mapping, but I think that is pro-licence-feature only. The ground is also a grid that looks exactly the same in each cell, maybe there is a way to optimize that. I have tried combining children and meshes, but I got stuck with light-problems or hitting the roof of max vertices. The shader has to be unique for each building, so I can’t combine those either. About shader models, this shader uses shader model 3.0, could not fit the instructions needed otherwise. But get rid of random walls from a texture-atlas and it will compile to model 2.0. But framerate is pretty smooth for this experiment and at least I got a playground where I can practice my forthcoming skills.


Download the building shader I put together in Unity. It would be nice to do a surface-shader instead to get real-time shadows, but once again i’m not a owner of a pro license, so that have to wait. If you like, check out the whole scene package. It’s my first Unity experiments, so please be honest and tell me what can be done better.

Now back to the drawingboard, I have an idea that involves physics, so thats my next stop on the Unity bus. Until then, thanks for reading.

Comments (9)

  1. Awesome! I think Beast (the lightmapping) is available in the free version, but you can’t bake AO and global illumination – but regular shadows from lights should be ok. However, it could be hard to use lightmapping with procedural content.

  2. Very cool! It is really nice and an honour to see someone actually do something with my Interior Mapping technique! :)

    I wonder why you say that the shader could not be used with several buildings at the same time? If you align the buildings correctly with the grid of the interiors, then I think you can render tons of buildings using a single mesh. Or am I overlooking something here?

  3. I used the same material from the beginning without problem, but then I wanted to add different types of buildings with varying textures and wall frequencies. The noise texture for the random light variations is created at runtime and is different for each building as well. But maybe you’re right and I’m overlooking this, maybe I can provide the differences through uniform variables instead. Or add each building-type to a corresponding container/mesh and merge those together. I will try that.

  4. By the way, you could improve your window textures greatly by enabling trilinear filtering for them, or maybe even ansisotrophic filtering. This fixes the jumps in the texture of the left most building in the top image, where the texture shrinks into the distance.

  5. Thank you for the tips, I didn’t know that was the reason for the “striped” textures. I have set the “filterMode” to FilterMode.Trilinear now. And updated the picture above.

  6. Thanks for info! I’m running plugin version 3.3.0. I’ve changed the plugin-check now, but I have to find out why the shader not working in 3.3.1.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>