New York, finally, does not consist of cardboard boxes.
In Marvel’s Spider-Man in many windows you can see the full interior. This is done with a single trick – everything is recreated using a special shader.
Co-founder of the studio Ronimo Games (Awesomenauts) Jost van Dongen on the site Gamasutra published the text, which dismantled the principle of creating realistic interiors in Marvel’s Spider-Man. The author himself dealt with this issue in the framework of his graduate research in 2007. We chose from the main material
The work of this effect is clearly demonstrated in the video Kotaku
At 0:40 this video shows that the rooms actually ignore the geometry of the building: the door is where the window should be. If you look into the same room, but from another window, you will notice that there is already a completely different interior. All this suggests that the rooms are fake, but, nevertheless, they are absolutely correct from the point of view of perspective and have real depth.
This is not to say that this is a big disadvantage, since users pay less attention to such details. Such interiors are simply a backdrop that contributes to giving depth to a city without much impact on performance
So, this whole effect is based on the interior mapping technique. The principle of its work is that the building itself does not contain any additional geometry. Interiors exist only in the shader. He rayskates with walls, ceiling and floor to indicate what the player should see in the interior
A ray used for raycasting is simply a ray from camera to pixel. The rendered pixel is on the outside of the building, so only part of the beam behind the pixel is used. This is due to the fact that this part is located inside the building.
Reykasting may seem complicated and costly, but in fact it is very useful in this case. The trick is one limitation: when planning the interior, the ceilings and walls are at a constant distance. Knowing this, you can easily calculate the location of the player, the ceiling and the walls of the room.
The ceilings and walls themselves are infinite geometric planes. The calculation of the intersection between the infinite plane and the beam takes only a few steps and reduces the load on the system
There are six planes in total: the ceiling, the floor and the four walls. However, only three are enough, since the direction of the user’s gaze is known. For example, if you look at the ceiling, you do not need to check the floor. Similarly, of the four walls, only two need to be considered, which are in the direction in which the player is looking.
To find out exactly what the user sees, you need to calculate the intersection of the beam with each of these three planes. The intersection that is closest to the camera makes it clear which plane is displayed in this pixel.
Then the intersection point is used as the coordinate of the texture to match the color of the pixel. For example, if the beam reaches the ceiling at position (x, y, z), then (x, y) is used as the coordinate of the texture, ignoring z.
At the same time, the intersection calculations for each of the three planes, due to the intelligent packing of variables, can be performed simultaneously
Also with the help of interior mapping you can, for example, change the lighting in different rooms to simulate the alternation of day and night. For this, a noise texture is applied, from which the index of the room is calculated as the coordinates of the texture
Since there is only a propagation of rays in the plane, all rooms are simple rectangles with textures. All the furniture in the room is on the texture, which means that it remains flat. In Marvel’s Spider-Man, this is noticeable when approaching: tables in the rooms are in fact flat textures on the walls.
As you can see in the image below, you can supplement this technique with one or more additional texture layers. But it gives an additional load on performance
Interior mapping was also used in Simcity (2013). The developers improved the original idea and combined several textures into one to create the depth of the rooms. The video below (starting at 1:00) explains how the technology works
The author of the original text attached a link to his interior mappingdemonstration . Also in Unreal Engine 4 you can find this technique as a function of InteriorCubeMap