In today's post we will examine a patent application submitted by Sega back in 1998 relating to the generation of graphics suitable for interactive role playing games (RPGs), with the inventors listed as Yu Suzuki, Takeshi Hirai, Kazuo Kondo and Kazunori Masuda.
While Shenmue itself is not mentioned by name within the document, of course, the concepts described within can be readily recognized as pertaining to the soon-to-be-published game series. This includes two algorithms in particular for the automated generation of in-game content that were designed to save having to store vast amount of data on the limited space afforded by physical discs: Yu Suzuki dubbed these Magic Weather and Magic Rooms. We will focus on these two systems in this post.
The patent document contains 24 pages in total, over half of them being diagrams and flowcharts.
The US patent document contains 24 pages |
As a whole, the patent brings together a number of concepts that describe what we know today simply as the "game engine". The motivation was to ensure that the Graphical Processing Unit (GPU) receives display data fast enough to ensure that the display is updated frequently enough to maintain smooth output. The game prepares and sends a single image, or "frame", to the GPU in a never-ending loop. This means that the game's logic processing must be handled efficiently in the time period between one frame being sent to the GPU to be displayed, and the next.
An English-language version is available in the form of the US patent application document, from which the diagrams in this post have been sourced. The language used in the English version is rather stilted and confusing, so relevant snippets of text have been translated from the Japanese original in preference. Additional color images have been included for illustrative purposes.
Before diving into the patent itself, let's have a brief recap on what these two systems are about.
Thanks to LemonHaze who provided technical explanations and information about the implementation in the first two Shenmue games.
Magic Weather
"The game contains a system that realistically recreates the weather and other natural phenomena. That system is called Magic Weather. In the game, the weather changes as time passes: fine, cloudy, rainy. These changes are based on the long-term weather data for Yokosuka, the town in which the game is set."Let's consider a case in the actual game where it is, say, fine one day and rainy the next. The weather conditions encountered by the player will differ depending on how they go through the game. For a player that moves ahead rapidly, they may visit a certain house on a fine morning. On the other hand, a player who plays more slowly may end up visiting the house the following night in the rain."
Magic Rooms
"When we were making Kowloon Walled City, I wanted to put everything in the rooms we made. There were thousands of rooms, and I wanted all of them to be free to roam. The designer told me it was impossible, so I thought there was no use in entrusting that task to him (laughs), and that’s when I thought, we could just make the program create them itself."
Next, we will move on to the patent itself, starting with details of the revolutionary new weather system.
Patent Application Details on "Weather Processing" (Magic Weather)
"An image generator for generating images that incorporate a virtual weather environment inside a virtual three-dimensional space, with a means to identify at regular intervals the current camera position in the three-dimensional space and the current time; and a means for controlling the sky, weather, and weather intensity that make up at least part of the background on the display screen, corresponding to the camera position and current time identified."
In other words, it is a system that delivers changing weather effects according to the current time and location: a description that perfectly fits Shenmue's Magic Weather.
Details
An explanation is given of the weather processing, with an accompanying flowchart (Figure 1).
Whenever the prescribed amount of time (for example, one hour) has passed since the previous weather processing, the weather condition is determined from a table of weather data, based on the current camera position and time.
Figure 1: weather processing flowchart |
The weather table is described as having entries for each designated play area or location in the game. It contains detailed settings including the date, hour of the day, appearance of the background sky, weather condition (for example: cloudy / foggy / rain / sleet / snow / clear) and intensity of the weather condition.
An example weather table is given in Figure 2:
Figure 2: example weather data table (date, hour, sky/background, weather, intensity). |
The text goes on to explain:
"Sunny and cloudy conditions are represented by adjusting the brightness of the entire screen, and this brightness is further changed according to the time of day. Wind (including direction and force) may be added to this weather information".
With the fine level of control that is possible, it might be expected that this would require a great deal of data to be stored, but this was not the case. The weather data could be stored in a compact format, with each entry in the weather table able to be expressed as a single 16-bit number (a range from 0x0000 to 0xFFFF in hexadecimal) as shown in Figure 3:
Figure 3: example weather data format |
Despite its compact form, each entry would be able to specify one of 16 different sky images, one of 16 weather effects, and one of 256 intensity levels.
As the player moves between areas, weather conditions may change. The patent suggests handling this either by setting the weather condition to remain the same within each individual play area; or alternatively carrying out interpolation to ensure a smooth transitioning of weather condition between areas.
This smooth transitioning is implemented with combinations of "B-spline" curves (examples of which are illustrated in the diagram below), with each representing one of the weather types that exist. This means that, for example, snow can turn smoothly to rain - or any other weather transition imaginable.
Combinations of B-spline curves can be used to ensure smooth transitions |
Implementation in Shenmue I
In Shenmue I, weather condition changes are defined within a date range of 1 November 1986 to 16 April 1987 (by comparison, the game's story commences on 29 November 1986 with the latest ending date being that of the "bad ending" on 15 April).
Famously, the game includes historical data for the actual 1986/87 weather in Yokosuka, although this can be enabled only after clearing the game; the first play-through uses a separate defined set of weather conditions.
Yu Suzuki highlights the weather system at the Shenmue Premiere in Yokohama |
Below is a small snippet of actual data for Snow, courtesy of LemonHaze, who notes that Shenmue I is one of the few games in existence where weather conditions are fully specified through a lookup table rather than just setting the effects when needed, or setting them randomly.
As can be seen, the data table follows a similar format to that laid out in the patent. (The "ValueRaw" is a number between 0 and 255, although this is converted to a fractional representation when used by Shenmue's code).
Day,Month,Year,Hour,Minute,ValueRaw
29,11,1986,8,0,255
29,11,1986,13,30,95
29,11,1986,14,0,0
7,12,1986,20,0,0
7,12,1986,20,30,159
7,12,1986,21,30,255
7,12,1986,23,0,159
7,12,1986,23,30,0
10,12,1986,22,30,0
10,12,1986,23,0,95
11,12,1986,6,30,95
Implementation in Shenmue II
With Shenmue II, the fully-defined weather table approach is simplified by defining only the upper limits of the weather over a given time span; Pseudo Random Number Generation ("PRNG") is then applied, with changes smoothed as previously using B-spline curves, to determine the weather at any point in time.
This randomized approach is adequate, due to the limited number of different weather types; the game also does not support an option to replay using historical weather, which removes the need to support a full lookup table. The weather can also be set as required for specific events and cut scenes.
Rainy weather conditions (Shenmue II) |
Benefits
The discussion of the Magic Weather system concludes by emphasizing the improvement over the other, simpler weather systems to date:
"Therefore, in comparison to conventional representations of weather conditions which merely change the sky (background) after a prescribed time elapses, it is possible to display detailed weather conditions realistically. This provides a sufficient sense of realism and increases interest in each respective scene of the RPG."
Details from the Patent Application: "Room Creation" (Magic Rooms)
"This routine enforces rules for arranging furniture and other items based on human thought patterns and uses a random number table to arrange furniture and household items, thereby creating a room with a lived-in feel in the virtual game space."
A "Magic Rooms" furnished room interior, with windows in the far wall (Shenmue II) |
As shown in the flowchart in Figure 4, firstly parts such as the walls and furniture are created (step S1).
Figure 4: room layout flowchart (corrected to add a step that was missing from the diagram in the English-language version of the patent) |
Even the circumstances of the room's resident are taken into account (step S2). These include information such as "sex, age, whether he/she has a family, their family structure, health, financial status, and so on". A list of applicable furniture for the room is compiled, in accordance with these conditions (step S3).
"Next, the room is divided into areas, each of which has its own characteristics (step S4). An example is shown in Figure 5. In this example, areas 1, 3, 4, 6, 7 and 9 are the main areas where furniture is to be placed. For area 8, which is next to a window, the placement of furniture depends on the type of window - if it leads to a veranda then an object can not be placed here, but potentially a piece of furniture less than the height of the window may be placed. Area 5 is the central area for daily life and so a table may be placed there. Furniture would normally not be placed in area 2 to avoid blocking the door."
Figure 5: example of a room divided into areas (5a, left) and arrows indicating the directions in which furniture may face (5b, right) |
The direction in which each piece of furniture faces is also decided. As shown in Figure 5b, possible directions are determined according to the area.
Next, the principle points of daily life in the room is determined (step S5, "Principle Elements of Living" in the diagram):
"The TV and audio equipment (especially the speakers), etc. are directed to this center point. In our example, the living focus is determined in the following order of priority: first, the center of the table, second, the center of the sofa (when there is no table), and third, the center of the room (when there is neither a table nor a sofa). As an exception, if the resident is fighting sickness, then the position of the pillow of the bed is set as the focal point for daily life."
Examples of furniture placed using the Magic Rooms algorithm in Shenmue II. See Jcgamer's indepth guest post series for a survey of the various items to be found in the Kowloon buildings. |
Furniture is then arranged (step S6). Information pertaining to the arrangement of furniture includes:
- Furniture type: bed, cabinet, desk, table, TV, sofa, etc.
- Size: length, width, height of furniture
- Space required for use: length, width, height
- Storage space: (length, width, height size) x margin
- Possible placement areas within the room (e.g. area 1, area 3)
- Suitability for use: e.g. target age
- The layout area will be decided with a table of random numbers. By changing the random number seed, many different rooms may be created.
- Pieces of furniture are placed in order of size starting with the largest, and those that do not fit are discarded.
- Furniture that does not fit in a single area is placed by expanding into surrounding areas if they have empty space available. The surrounding areas will be reduced by the same amount.
- If extra space remains in an area after placing a piece of furniture, the surrounding areas will be expanded accordingly.
Furniture is "placed naturally - not blocking windows or doors" (room interior from the Tea Break Bldg in Shenmue II) |
Thanks very much for revealing this great information.
ReplyDeleteCheers Terry! I was surprised at the level of detail that went into ensuring the magic rooms looked natural and "lived-in". (Although none of them seemed to have a light switch!).
Deleteincredible article, thanks for writing. i was a bit disappointed to see that the magic weather in s1 isn't randomized - without knowing about their space requirements, i would think it's straightforward to randomly insert values into the lookup table.
ReplyDeletenevertheless an awesome achievement on behalf of the sega team!
Thanks for your comment, and glad you enjoyed the article. As you say, it probably would have been easy enough for the development team to make the weather fully random, so perhaps they took the opportunity to handcraft the experience.
Delete