Voxel lighting problem solved

Published February 16, 2015
Advertisement
[color=rgb(51,51,51)][font=Georgia]


[font=arial]I have fixed a problem that has bugged me for quite some time. For most of the development of SeedWorld, up until last week, every chunk was not able to access voxels from immediate neighbors. This shortcoming was avoided with the code for voxel collisions, which worked by finding the right[/font]

[/font][/color][color=rgb(51,51,51)][font=Georgia]


[font=arial]chunk from the group of chunks to test whether a block is solid or empty, given world coordinates as input. But sometimes you needed to find out based on local coordinates, relative to a chunk's location. This was evident in the mesh building process, as it did ray casting from each visible voxel to determine if a voxel needs to be shaded darker, and by how much.[/font]

[/font][/color]
[color=rgb(51,51,51)][font=Georgia]


[font=arial]The edge voxels were a problem for raycasting since it could not raycast further out from the edges of the chunk. Any rays that reached the edge were considered "not blocked" and the voxel received full light. This created a seam of lighter colored voxels around the edges.[/font]

[/font][/color]
[color=rgb(51,51,51)][font=Georgia]


[font=arial]20150214-banding1.png?w=605[/font]

[/font][/color]
[color=rgb(51,51,51)][font=Georgia]


[font=arial]Now since each chunk now has access to its eight neighbors surrounding the sides, you can simply make the ray "step into" these chunks and continue traveling the distance it's supposed to instead of ending prematurely. My first attempt to fix this didn't go well. I was modifying the starting coordinates of each ray and using that to find the neighbor chunk. It ended up looking worse:[/font]

[/font][/color]
[color=rgb(51,51,51)][font=Georgia]


[font=arial]20150214-banding2.png?w=605[/font]

[/font][/color]
[color=rgb(51,51,51)][font=Georgia]


[font=arial]These seams appeared because the ray was checking against the solid voxel it started from. So it always subtracted contribution from the light, making the edges dark. This was fixed by updating the ray coordinates after each step, seeing if they go out of bounds (from 0 to 32) and then picking the correct neighbor chunk to continue and reset the local coordinates. Now the seams are gone and the shading is correct.[/font]

[/font][/color]
[color=rgb(51,51,51)][font=Georgia]


[font=arial]20150214-no-banding.png?w=605[/font]

[/font][/color]
[color=rgb(51,51,51)][font=Georgia]


[font=arial]Now the chunks don't look as obvious. This was pretty satisfying to fix, and probably so much that I will move on to work on other parts of the game. There are still visible seams at height intervals (because rays don't have neighbors to check on the Y axis) but this is still a lot better than seeing an entire grid of lines going across the landscape. So it's not something I am focused on improving at the moment.[/font]

[/font][/color]
[color=rgb(51,51,51)][font=Georgia]


[font=arial]As for what I will be working on next, I have been looking at some UI libraries to see which I will add into the game. I've already picked one to try for the moment, and if it is easy enough to use without having to break or re-code a large part of my game, I'll stick with it and start adding some game features.[/font]

[/font][/color]
8 likes 5 comments

Comments

Aardvajk
Looking really good.
February 17, 2015 04:12 PM
riuthamus

This is reminding me more and more of that one game that came out about a year ago. I cant remember the name off the top of my head but it had alot of steam behind it. Guy released it and then nothing. Keep up the work as this is looking great!

February 17, 2015 07:07 PM
CC Ricers

This is reminding me more and more of that one game that came out about a year ago. I cant remember the name off the top of my head but it had alot of steam behind it. Guy released it and then nothing. Keep up the work as this is looking great!

Cube World?

February 17, 2015 09:43 PM
bdubreuil

This is reminding me more and more of that one game that came out about a year ago. I cant remember the name off the top of my head but it had alot of steam behind it. Guy released it and then nothing. Keep up the work as this is looking great!

Actually it was like 2-3 years ago and yes it was Cube World.

February 20, 2015 02:44 AM
riuthamus

Yep, cubeworld is 100% the one i was talking about.

February 23, 2015 02:47 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement