S
S
s2sk13372017-10-07 18:45:02
C++ / C#
s2sk1337, 2017-10-07 18:45:02

What is the best way to load objects in the engine?

Hello.
I just want to hear a little theory about how to properly load objects within the camera radius. In my free time, I decided to write a simple engine and everything is working out so far ... But now it has come to loading objects from a file. How is it better to do it?
For example, right now, following the example from the Microsoft website, I have the "load geometry" function. Where the shaders are compiled, there is an array with vertices, indexes and texture loading, and then in the render function I just draw the cubes (changing their positions via XMMatrixTranslation) through a loop whose vertices were loaded into the buffer in the "geometry" loading.
Now questions about loading objects from a file...
As I understand it, you need to create one file where there will be vertices of absolutely all objects and their indices, when you start the game, drive all this into an array, and then dynamically load their textures based on the camera coordinates so that they do not clog memory. Am I thinking right? But here I don't know what to do with textures... I didn't quite understand how textures work. Now I have the following lines in the geometry load
dHDlUPVp5M8.jpg
And this texture fits the whole cube
7-Lr1KjuLXE.jpg
How can I make it so that only one side is covered with this texture? Or different textures on different sides. And in general, how to load several textures at once on different objects?
Or would it be more correct to create a separate file for each object? But how then to load them into an array with vertices and indices? If the same file can have the same indexes...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hacenator, 2017-10-12
@hacenator

It is logical to assume that objects can be duplicated, so it makes no sense to write everything in one file. One file per object. Several instances of the same object can be drawn in one call (DrawCall), passing an array of matrices for all the object to the shader.
Further, it is true - before drawing, we do culling - we check whether the object falls into the camera's visibility area and whether it is blocked by another object.
To optimize the work with textures, only some levels of detail (LOD) are loaded, starting from the smallest size. The closer the camera is to the object, the more detail is used. Textures can really be unloaded / loaded on the go. But it makes no sense to constantly drive them back and forth, this will not make the application faster, we must proceed from the amount of free memory and the frequency of using the texture.
Textures are applied to texture coordinates. Those. each vertex corresponds to some texel on the texture, then the overlay is performed using interpolation, so the texture "fills" the entire face of the triangle. Also, all this overlay and blending logic is determined by the shader (pixel) with the help of which various visual effects are achieved - lighting, shadows, reflection. Usually one texture is used to fill one object, in the sense that if one side should be red and the other green, then there will be one texture where there is both a red and a green part, and not two different textures. It's just that it is appropriately superimposed on the object.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question