1
\$\begingroup\$

I'm having trouble implementing directional lighting. (I'm not that familiar with 3D.)

The problem is that the lighting does not "follow/flow with" the other blocks next to them.

Diffuse lighting problem

How should I fix this.

At the moment all vertices have there own normals.

Should I combine or re-position normals if the blocks are next to each other?

(I tried combining the normals but then it just looks like a plain, as if its just one color.)

Should I maybe do that kind of behaviour with shadows and is directional lighting specifically for ambient lighting and not so much for diffused lighting?

This is a little bit of the code that contains the normals (the last 3 values).

        {0, {x * BLOCK_RENDER_SIZE                    , y * BLOCK_RENDER_SIZE                    , z * BLOCK_RENDER_SIZE                    , getBlockColor(), -1.0f, -1.0f, -1.0f}},
        {1, {x * BLOCK_RENDER_SIZE                    , y * BLOCK_RENDER_SIZE + BLOCK_RENDER_SIZE, z * BLOCK_RENDER_SIZE                    , getBlockColor(), -1.0f,  1.0f,  1.0f}},

        {2, {x * BLOCK_RENDER_SIZE + BLOCK_RENDER_SIZE, y * BLOCK_RENDER_SIZE + BLOCK_RENDER_SIZE, z * BLOCK_RENDER_SIZE                    , getBlockColor(),  1.0f,  1.0f, -1.0f}},
        {3, {x * BLOCK_RENDER_SIZE + BLOCK_RENDER_SIZE, y * BLOCK_RENDER_SIZE                    , z * BLOCK_RENDER_SIZE                    , getBlockColor(),  1.0f, -1.0f, -1.0f}},

        {4, {x * BLOCK_RENDER_SIZE                    , y * BLOCK_RENDER_SIZE                    , z * BLOCK_RENDER_SIZE + BLOCK_RENDER_SIZE, getBlockColor(), -1.0f, -1.0f,  1.0f}},
        {5, {x * BLOCK_RENDER_SIZE                    , y * BLOCK_RENDER_SIZE + BLOCK_RENDER_SIZE, z * BLOCK_RENDER_SIZE + BLOCK_RENDER_SIZE, getBlockColor(), -1.0f,  1.0f,  1.0f}},

        {6, {x * BLOCK_RENDER_SIZE + BLOCK_RENDER_SIZE, y * BLOCK_RENDER_SIZE + BLOCK_RENDER_SIZE, z * BLOCK_RENDER_SIZE + BLOCK_RENDER_SIZE, getBlockColor(),  1.0f,  1.0f,  1.0f}},
        {7, {x * BLOCK_RENDER_SIZE + BLOCK_RENDER_SIZE, y * BLOCK_RENDER_SIZE                    , z * BLOCK_RENDER_SIZE + BLOCK_RENDER_SIZE, getBlockColor(),  1.0f, -1.0f,  1.0f}}

(I didn't add more code because I don't think its necessary)

\$\endgroup\$
7
  • \$\begingroup\$ This looks more like a minecraft-style world of polygon boxes than a true voxel engine. \$\endgroup\$ – Philipp Jul 6 '14 at 21:44
  • \$\begingroup\$ yes, but they share the same name \$\endgroup\$ – Duckdoom5 Jul 6 '14 at 21:55
  • \$\begingroup\$ You are asking a question about graphics programming, where polygon-based rendering and voxel-based rendering are two completely different things. When you are looking for relevant information, you should always try to use the correct terminology. \$\endgroup\$ – Philipp Jul 6 '14 at 22:05
  • \$\begingroup\$ According to that wiki page you just send me, Minecraft is a voxel engine. According to the Google Image search a voxel engine is also both a minecraft like game and a true voxel engine. But if its not the correct term, please tell me what the term should be and I'll edit the title for you. \$\endgroup\$ – Duckdoom5 Jul 6 '14 at 22:07
  • \$\begingroup\$ There is exactly one sentence in that article which mentions minecraft, and that one sentence says that it uses a polygon-engine and not a voxel-engine. \$\endgroup\$ – Philipp Jul 6 '14 at 22:12
0
\$\begingroup\$

If you would do hard normals for these boxes it would eliminate your problem. For that you have to have a normal not per vertex, but per face.
You could do this by having four vertices with the same normal for each face of the cube, that is 24 vertices. That way, a whole face will receive an even amount of light.

You also mention that you tried to combine normals somehow and got a result where it seems as if it were a plain. It should be the correct behaviour, you can add more immersion to your scene by shadowing it and doing ambient occlusion.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for the reply, I'll try implementing the faces solution tomorrow. That should fix the problem indeed. Although I would like to be able to dived more of the light over the sides of the blocks so if there is another solution that would be nice. Also because I want to add point lights later on. \$\endgroup\$ – Duckdoom5 Jul 6 '14 at 22:00
0
\$\begingroup\$

Before you get too deep into this project I'd like to comment. It looks like you're drawing the whole cube for each block in the world. If I am wrong, then ignore this, but if I'm right you should definitely consider a more efficient approach. You do want one normal per face, which probably means drawing cubes with 24 vertices (4 vertices per face, instead of sharing vertices), but you should also make sure not to draw faces that are next to a solid block. That way you aren't drawing a bunch of polygons underground that never get seen.

\$\endgroup\$
2
  • \$\begingroup\$ I'm not drawing each cube in the world, my drawing is efficient enough so no worries there ;) \$\endgroup\$ – Duckdoom5 Jul 7 '14 at 15:41
  • \$\begingroup\$ I also might have found a way to fix the lighting bug but I'll comeback later and tell if it worked out. \$\endgroup\$ – Duckdoom5 Jul 7 '14 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.