solenum / exengine

A C99 3D game engine
https://oods.net
MIT License
550 stars 31 forks source link

Taking sponza as a test scene #15

Closed heitaoflower closed 5 years ago

heitaoflower commented 5 years ago

Hi, I recently try to load sponza scene as my test scene.

The scene file consists of two types of media, one is obj mesh file, the other one are images.

however, right now, the iqm tool chain not parser the mtl or usemtl to recognize material texture as the resource id later on.

so in my eyes, I should add some features that support mtl parser for obj format files. because only under this way, we probably gain texture id use you iqm loader.

heitaoflower commented 5 years ago

If necessray I can upload scene files for you.

heitaoflower commented 5 years ago

Please share some idea with me, just cope it once for all.

solenum commented 5 years ago

The only supported model format at the moment is IQM, which is a pretty bare-bones format containing only the vertex data and some material/texture ID/names. If you want to load the sponza scene, I would recommend loading it into blender, and setting the material of each mesh to the texture name.

For example, if a wall is using tex_wall_diffuse.png, you would give it a material with that name, and use the IQM expoter plugin to export the model with material names, and then make sure you store your textures in the texture folder of the engine/game data.

I agree that it's not an ideal solution, but its a pretty compact way to include meta-data like that directly in the model file. An alternative would be to do it in-engine via configs and such, or perhaps even some external level editor that allows you to load a model and apply textures to it/export it with that data.

heitaoflower commented 5 years ago

Thanks for your reply.

For now, I am focusing on add material feature into iqm.

Actually my initial thoughts were to add an extra loader and parser in your iqm module, however, this way will kindly kill the idea and break the original rules of IQM.

so I would like to do some modification with it.

  1. Add a new struct of materiallib in which hold a host of material which will be referenced by mesh material idx.

  2. Add a new struct of material which defines some normal or common vars, like map_kd something like that, you know that.

  3. Add new member field material_lib into a struct of mesh, this will help this mesh to locate accurate material library later.

how do you think about this modification?

look forward to your reply.

solenum commented 5 years ago

I'm not sure I entirely understand to be honest, perhaps just do whatever you want with your fork and I can take a look at that before we do any pull request stuff.

heitaoflower commented 5 years ago

Here is the modification commite log => https://github.com/heitaoflower/iqm/commit/2a4032a1725bab5de12461ec8858580d9b5f34d6

for now, only support obj format mesh which is reference external material config info.

heitaoflower commented 5 years ago

I could able to make some minor changes after tomorrow, and organize the code.

solenum commented 5 years ago

Those changes appear to be for the example C++ IQM loader, right?

heitaoflower commented 5 years ago

I will push later on. by the way, I wonder if you can recommend me some tools to utilize lives at ##oodnet/freenode, the way of the web is not very convenient indeed.

solenum commented 5 years ago

You'll need an IRC client for your OS, or use https://webchat.freenode.net/ and join the channel ##oodnet

heitaoflower commented 5 years ago

I am complete the original job to load sponza scene into engine. however the direction of the world is incorrect. do you know what is going on with it ?

image

In unity or other engines the batman as below figure: image

in contrary the direction was incorrect as below figure in our engine: image

heitaoflower commented 5 years ago

By the way , I have upload the latest asset of sponza to the master branch . https://github.com/heitaoflower/exengine/commit/7b897ede9873c4c8d3a8ba7ca9ecaba0fd51a351 .

besides above, would you share the original scene file with me?

solenum commented 5 years ago

Unity uses Z as the up-axis, I think. You'll probably just need to rotate your models -90 degrees on the X axis before exporting to fix it, or make the iqm loader swap Y and Z.

heitaoflower commented 5 years ago

Thanks for your reply.

This is a snapshot of learnOpenGL demo. image The model always face screen outside. and also i try to fixed or copy the same camera view and proj matrix into our engine, the result is not identical.

Below configure is our engine . image

Totally rendering by OpenGL!

heitaoflower commented 5 years ago

Actually, I had tested the iqm demo with the batman mesh file, It is correct, in other words, the presentation is identical with LearnOpenDemo or another demo.

What is the unique when rendering mesh in our engine, could make an educated guess ? are there any juicy details I neglected?

heitaoflower commented 5 years ago

image

Maybe this snippet code is glue.

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glRotatef(camroll, 0, 0, 1);
glRotatef(campitch, -1, 0, 0);
glRotatef(camyaw, 0, 1, 0);
glRotatef(-90, 1, 0, 0);
glScalef(1, -1, 1);
glTranslatef(-campos.x, -campos.y, -campos.z);

The camera settings are different I see.

heitaoflower commented 5 years ago

I think you are right, I found a snippet code as below. epositions.add(Vec4(vkey.attrib[0] < 0 ? Vec3(0, 0, 0) : attrib[0][vkey.attrib[0]].zxy(), 1)); if (vkey.attrib[2] >= 0) enormals.add(attrib[2][vkey.attrib[2]].zxy());

the order of vertex data in iqm was zxy!!

but I have no idea why the author write like this way?

Vec3 zxy() const { return Vec3(z, x, y); }
Vec3 zyx() const { return Vec3(z, y, x); }
Vec3 yxz() const { return Vec3(y, x, z); }
Vec3 yzx() const { return Vec3(y, z, x); }
Vec3 xzy() const { return Vec3(x, z, y); }
solenum commented 5 years ago

Likely due to a lot of the big engines like Unity using Z as their up-axis. It's easy to fix though, either rotate -90 degrees on the X axis before exporting your model, or just swap the Y and Z when you load the model.