Horde3D

Next-Generation Graphics Engine
It is currently 17.11.2018, 16:37

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: 14.09.2018, 17:17 
Offline

Joined: 08.03.2018, 12:00
Posts: 2
Let me just get this out of the way: I am not a graphics programmer, I may confuse a couple terms and concepts so please bear with me.

I have a scene made of cubes that I've generated with h3dutCreateGeometryRes and a light node.
Code:
    float posData[] = {
        -0.5f, -0.5f, -0.5f,
        0.5f, -0.5f, 0.5f,
        0.5f, -0.5f, -0.5f,
        -0.5f, -0.5f, 0.5f,
        -0.5f, 0.5f, -0.5f,
        0.5f, 0.5f, 0.5f,
        0.5f, 0.5f, -0.5f,
        -0.5f, 0.5f, 0.5f
    };

    unsigned int indexData[] = {
        // bottom
        0, 1, 2, 3, 1, 0,
        // top
        4, 5, 6, 7, 5, 4,
        // left
        0, 3, 4, 3, 7, 4,
        // right
        1, 2, 6, 1, 6, 5,
        // back
        3, 1, 5, 3, 5, 7
        // front
        // nothing yet.
    };

    short normalData[] = { // ignore the bad normals.
        0, 0, 1,
        0, 0, 1,
        0, 0, 1,
        0, 0, 1,
        0, 0, 1,
        0, 0, 1,
        0, 0, 1,
        0, 0, 1,
    };

    float uvData[] = {
        0, 0,
        1, 0,
        0, 1,
        1, 1,
        0, 0,
        1, 0,
        0, 1,
        1, 1,
    };

    blockGeom = h3dutCreateGeometryRes("geoRes", 8, 30, posData, indexData, normalData, 0, 0, uvData, 0);

These cubes are of size 1,1,1 and I have a 16x16x16 chunk of them.

The light node is constructed this way:
Code:
    H3DNode light = h3dAddLightNode(this->scene, "Light1", 0, "LIGHTING", "SHADOWMAP");
    h3dSetNodeTransform(light, 0, 0, 18, 0, 0, 0, 1, 1, 1);
    h3dSetNodeParamF(light, H3DLight::RadiusF, 0, 5.f);
    h3dSetNodeParamF(light, H3DLight::ColorF3, 0, 1);
    h3dSetNodeParamF(light, H3DLight::ColorF3, 1, 0);
    h3dSetNodeParamF(light, H3DLight::ColorF3, 2, 0);
    h3dSetNodeParamF(light, H3DLight::FovF, 90, 5); // Not sure what FOV means in terms of light, is it a spotlight?


Also I'm very sure I'm doing something wrong when adding an actual voxel:
Code:
    blocks[x][y][z] = h3dAddModelNode(this->scene, "DynGeoModelNode", blockGeom);
    h3dAddMeshNode(blocks[x][y][z], "DynGeoMesh", g->assets.matBlock, 0, 30, 0, 3);
    h3dSetNodeTransform(blocks[x][y][z], x, y, z, 0, 0, 0, 1, 1, 1);


First off, is it mandatory that each node has it's own name? It's a bit of a pain for voxel worlds (Although I might combine voxels in each chunk into it's own model for speed.
Also I'm not sure if the last argument to h3dAddMeshNode is correct, it seems to render corrently regardless of what I put there.


Sorry for such a barrage of questions, I've been trying to figure stuff out with this library for a long time (there's little documentation), and asking help from humans is usually a last resort.


Top
 Profile  
Reply with quote  
PostPosted: 14.09.2018, 18:22 
Offline

Joined: 17.11.2009, 17:00
Posts: 168
Location: Russia, Moscow
Hello. I'll try to answer what I know:

Midnightas wrote:
short normalData[] = { // ignore the bad normals.
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
};


If you have incorrect normals you will have incorrect lighting in your scene. Normals are probably the most important part in procedurally generated geometry if you want the geometry to render correctly. Please note that each vertex should have its own normal. In a cube, you'll have to create 24 vertices (minimum, some parts of the cube will have the same normals/uvs) or 36 vertices (so that you can fully customize each vertex normal and the way lighting acts).

Midnightas wrote:
h3dSetNodeParamF(light, H3DLight::FovF, 90, 5); // Not sure what FOV means in terms of light, is it a spotlight?


Currently Horde supports spotlights and point lights. If you set field of view below 180 degrees, it is spotlight, otherwise point light. Directional light is in the works.

Midnightas wrote:
blocks[x][y][z] = h3dAddModelNode(this->scene, "DynGeoModelNode", blockGeom);
h3dAddMeshNode(blocks[x][y][z], "DynGeoMesh", g->assets.matBlock, 0, 30, 0, 3);
h3dSetNodeTransform(blocks[x][y][z], x, y, z, 0, 0, 0, 1, 1, 1);


You can create one model and add several meshes to it.
Yes, each scene node should have a name, because engine internally uses it for searching.

Midnightas wrote:
h3dAddMeshNode(blocks[x][y][z], "DynGeoMesh", g->assets.matBlock, 0, 30, 0, 3);


Umm, that is strange. The last parameter is the number of vertices (well, actually it is the last vertex of the mesh in geometry, but you start from zero, so it acts as vertex counter). You set it as 4. So, even now in your code you have 8 vertices in a cube, so this is incorrect.
The 30 parameter is also probably incorrect because it acts as the number of indices. Currently you have 8 indices (so it should look like g->assets.matBlock, 0, 7).

As I've noted in the beginning, if you wish to correctly perform lighting on these cubes you'll have to make them either 24 or 36 vertices for each cube. Indices and normals should also be set correctly.


Top
 Profile  
Reply with quote  
PostPosted: 15.09.2018, 15:18 
Offline

Joined: 08.03.2018, 12:00
Posts: 2
Thank you! I've decided to instead load geometry from a file instead, as this would allow different voxel types to have custom models, but it works now.

Image


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group