[Miscellaneous talk] Some content made during the holidays (Unity editor extension, road pathfinding system, indoor lighting LOD system)

foreword

  It’s rare that I have some free time recently, so I decided to add a random talk, writing about some things worth recording during last summer vacation and this year’s winter vacation. However, I am really troubled recently, and I am really thinking about what to do in the future when I am about to find a job. The previous idea has always been to work for a few years to save some money and then make games by myself. After all, I have never wavered in my determination to make games (in fact, maybe games are just a form of expression), but maybe I have been busy every day for a long time. I am a little tired of the life I don't know why, and I want to start doing things I am interested in early.

  But up to now, there are two choices: On the one hand, I want to release a game before graduation, so I have been rushing to develop it, because I have less energy and time after work, and I am also worried that once I get on the road to work, I will lose my life. It is difficult to turn back (for example, to be satisfied with the ordinary life of work or to recognize the reality, etc.); If you don’t plan to look for a job, your savings will probably last a few months at most, but if you want to find a job that you feel is quite satisfactory, you can accumulate funds faster, and you have to deliberately prepare some projects and research that you can get. , Then brush up the algorithm questions, etc., basically say goodbye to the idea of ​​playing games before graduation. Although choosing a two-year postgraduate program at that time made time more stressful, which was also the main reason for my recent annoyance, I don’t regret it in the long run. After all, I never felt that I had to be a postgraduate learned something.

  But sometimes I also think that since I want to choose to make games by myself, I really should let go of a lot of things. Maybe I have not been able to do this... So in fact, the things in this article come from this way, that is, I still choose in the end In order to make games, I also officially returned to my game last summer. As for job hunting, I can only spend less time preparing, and the rest depends on fate~

  Back to the topic, in fact, this content is also a continuation of the previous miscellaneous talk . It is still the scene of the campus (or modern city), and it is also a continuation of the problem of the empty scene mentioned before.

road finding system

  Roads are essential in campus or urban scenes. There can be fewer pedestrians to enhance the atmosphere, but they cannot be absent. The following scene is used to simply simulate a section of road in the campus:

white means road
    The requirements in the game project are also very simple. If there is a pedestrian in the scene, I tell it the target position, and he can walk along the road and find the end point, that is, pathfinding. The Navigation provided in Unity can achieve this. You only need to mark the white object as Navigation Static, click Bake, and the corresponding walkable area will be generated. The effect is as follows:

Unity Navigation Pathfinding

  It's simple and works well, but it's not correct. Because the road is obviously very wide, but because it is the shortest path to find the way, so the pedestrians all find the shortest route and walk along the edge. Obviously this is not what we want. At first, my idea was to find out if there are any plug-ins that solve similar problems and change the source code, but then I considered that my needs are not that complicated, and using Unity Navigation would consume a lot of performance, so I chose to write one myself. Simple waypoint pathfinding system, after specifying the target location, pedestrians can move to the destination in a walking way closer to people. First the previous rendering:

Simple waypoint pathfinding, the details can be polished and perfected according to the needs, but the basic structure is already in place

In terms of implementation, the idea of ​​path points and road width between points is adopted. The simple editing of roads in the scene is realized through the extended editor, and operations such as batch movement, deletion, and copying are supported. Redo. (Here, due to the relationship between the data structure, it cannot be serialized automatically, and manual serialization is required so that the path data can be stored persistently)

Add a new road and modify the target location

find way again

Undo the changes just made, and then modify some parameters, you can also achieve the effect similar to Unity Navigation pathfinding in the picture above: (here is only a similar effect achieved by modifying the parameters, not to say that the shortest path pathfinding within the road range is realized. If you really want to implement it, you should need additional code)

Modify parameters to achieve different pathfinding effects

  The above parts were completed in the summer vacation last year. At that time, the function of using weights to make pedestrians choose the farther road with a certain probability (because the reality is like this, people don’t always walk along the shortest road, but because in some cases unsatisfactory and the following solution is currently used, this method is abandoned). Of course, in the end, considering the performance issue, I felt that it was unnecessary to use automatic pathfinding for a large number of passers-by with a sense of atmosphere, so I added the function of editing the path above the path point, that is, the preset road, and adjusted the parameters on the road. The automatic generation of pedestrians coming and going is also realized after modifying the requirements this winter vacation (to be honest, it didn’t take long to realize, but thinking about what kind of effect is needed in the game and what kind of effect is enough to set off the atmosphere. It’s been a long time, and I also deliberately found some other games with similar systems to see the effects of others):

Red is the road edited above the waypoint, the green point is the start point, and the blue point is the end point

Warm up (similar to the functionality in the Unity particle system) and automatically generate pedestrians on the road according to the parameters when the player approaches

Indoor lighting LOD system

  This thing is actually a continuation of the lighting problem in the previous article. Of course, it is not limited to lighting, but it mainly deals with lighting problems. If I really want to say, it is currently a semi-finished product, and it will continue to be improved when there is time. The application scenarios are as follows: teaching buildings or office buildings have very spacious windows, and players can see the details of the interior through the windows within a certain distance outside the windows (including the softer lighting effect produced by multiple ceiling lights in the room), while the farther The distance mainly reflects the role of light (because at night, the difference between how many windows are on in a building is very obvious), and it doesn't matter how far away it is. First of all, the pipeline should be changed to a delayed rendering pipeline. Otherwise, the number of objects receiving light is limited, and the efficiency of coloring per piece is still low. Then, suppose a scene built according to actual needs is as follows:

  In fact, such a pile of light sources is quite inappropriate, and the actual building is much larger than this. It is only half of the scene in the building with light sources. If I don’t optimize my notebook, the frame rate can drop to a fast single digit when running, so optimize It is necessary (this may also be the reason why the indoor and outdoor of many games are not connected, the indoor cannot be seen from the outside, and the indoor seen from the outside is false).

  The current optimization logic is also very simple: due to the characteristics of the scene, when the camera is in a room, it is impossible to see things in other rooms, and when the player is not on the front side with windows, the player cannot see indoor. And when the player is a little far away, only one large light source will be loaded, and the basic effect is still good. In the actual project scene test, in the scene of indoor details of half a building plus lighting, compared with the case where only LOD Group is used, the frame rate has been improved by more than 100 frames. In theory, the frame rate can be improved more in the case of more complex scenes (because The more details are cropped out).

Surrounding rooms do not load when the player is indoors

Load details when outside the window, the range can be adjusted freely

  In fact, you can also see a problem in the above picture 1, that is, the light from the bottom obviously leaks into the room above. This is because there may be many similar lights in the scene, and lights do not cast shadows in order to reduce performance overhead. This can lead to the fact that if a room has the lights turned off, but surrounding rooms have lights on, the room with the lights off will appear to have some light as well. Similarly, because the dome lights placed in the room are usually regular and have commonality, it may not be worth the loss to place so many point light sources, so I was considering a custom lighting model at the time, but in fact, it is currently acceptable. You can wait for the follow-up If there is a real need, it will be modified, which is why it is said to be a semi-finished product.

Guess you like

Origin blog.csdn.net/qq_43459138/article/details/129359298