Aventuras en Voxels

Posted by aeron on Nov. 14, 2012, 12:53 a.m.

Hey guys and gals, I wanted to update on my progress into the realm of voxels, with screenshots again! So, picking up from two blogs ago…

I had to switch graphics libraries because Irrlicht wasn't the best fit. While I knew exactly how I could implement the texturing I want in OpenGL, Irrlicht had no obvious method for implementing texture arrays without hijacking the gl context and running amok. I figured if I was gonna go the GL route I might as well switch to a library that's more GL-friendly from the start. I've experimented with OpenSceneGraph in the past but never paid it right, but it really stuck out to me when I noticed it had texture array support built right in. So, deciding to give it another whirl, I ported what little I had over to OSG. After getting my geometry loaded and displayed, I fidgeted with the texture until I got close to the effect I'm going for:

You can see now my intention is to use large textures but span them over several blocks, retaining the pixellated look of minecraft while subtly breaking up the repetition (at least to an extent). I also played around with the filtering so that it would magnify textures using nearest neighbor (pixellated) and minimize them using a linear filter (blurry), which makes the far away blocks look better:

Satisfied for the time being, I began my descent into the realm of texture arrays. Now, a better way to think of texture arrays is as a 3D texture (well technically that's all they are). You can define their coordinates in the X (U) and Y (V) like a normal 2D texture, but you can also specify a Z (W) which indicates which "layer" you're referring to. The only trick is you can't just go using a 3D texture willy nilly, you have to pass them to a shader and render them there. So I loaded up a couple textures into an array and started figuring out the shader code, which turned out to be as simple as:

#version 120
#extension GL_EXT_gpu_shader4 : enable

uniform sampler2DArray textures;

void main() {
    gl_FragColor = texture2DArray(textures, vec3(gl_TexCoord[0].xy, gl_TexCoord[0].z));
}

My face lit up once I got the original texture back on the screen, and I immediately went back into the code to plant some grass:

Okay, it's a pretty shitty texture I'll admit but I was rushing to see if it worked! ;) After a little more organizing of the materials, I added sides to the grass blocks:

Unfortunately I noticed that the linear filter added some seams on the side block texture that become apparent in between grass and plain dirt blocks:

So I just turned it all off, which helps reduce it a lot though in game you can see a seam peek out now and then:

But yeah, you probably also noticed that the shader doesn't have lighting, so that's on the list now (oh joy!). The good part is I have plenty of freedom regarding the lighting model, and since I'm already in a shader I can experiment with some of the existing techniques by just plugging them in with my sampler. So hopefully I can get something satisfactory soon. Then maybe I'll see about normal maps :D

Well, until next time…

Comments

Glen 11 years, 5 months ago

Very cool. I'm jealous.

death 11 years, 5 months ago

yippee, more minecraft-like engines :3

is it really "voxels" if the world isn't filled with it? this is really nothing more than a cubic 2d plane with added height. I maybe wrong, but i got the idea that a voxel engine, means the game is made up entirely of voxels, so to use Minecraft as an example, digging up the ground, you will see more ground underneath that! and so on.

of course, i realize this is in an early stage :D

i made a similar project before, only i filled the whole world with columns, that had adjustable height, it actually makes digging more realistic in a sense. if digging, it doesn't remove a whole chunk, instead it simply decreases the columns height until it reaches a certain low height, in which you hit stone. (of course i had no cave system at all…)

aeron 11 years, 5 months ago

They're actual voxels, I just didn't do anything fancy with the level generation other than a height check, so it looks like it's just a heightmap. This old screenshot shows off the capability a bit better.

Tangent, since I'm already planning on integrating Lua into the game, I intend to offload the level generator to Lua as well, which should speed up its design as I don't like waiting on the compiler just to dial a single parameter in for the level >_> I feel like the compiler takes extra long since I switched to static libraries, perhaps just because it forces me to link a lot more… maybe I'll switch back to dlls just for my sanity's sake :P

Mega 11 years, 5 months ago

Quote:
I feel like the compiler takes extra long since I switched to static libraries, perhaps just because it forces me to link a lot more… maybe I'll switch back to dlls just for my sanity's sake :P
Pre-compiled headers. I recommend them… sometimes…

This is looking really good, aeron. Couple of questions though; where did you get the GL binaries? I've been having trouble finding some decent ones with GLSL support.

Also, what's your average framerate? :P

aeron 11 years, 5 months ago

Quote:

This is looking really good, aeron. Couple of questions though; where did you get the GL binaries? I've been having trouble finding some decent ones with GLSL support.

Also, what's your average framerate? :P

Thanks! :) I'm using the libopengl32.a and libglu32.a that came with my MingW (TDM-GCC 4.6). FPS is pretty consistent so far, I've yet to push it below 60 frames.