Slopes

View previous topic View next topic Go down

Slopes

Post by Slaihne on Sat May 14, 2011 9:49 am

I think i've got the slope bug now Smile

I've got the sloped pieces fitted into the landscape generation for upward faces atm. Downward facing slopes should be a simple matter of reversing this and i don't see a problem with that aspect.

I'm currently working with 4 straight slopes, N, S, W, and E. 4 internal corners and 4 external corners. Then i have them all for the downward facing ones too. So 24 blocks in total, oh and the proper cube version makes 25.

The number of blocks now required for each block proper is 25 then, but i've allowed 32 in case i want to add other slight variations. This isn't a problem as i was always using 16 bits for the block number. I'm using the top 32k block numbers as sloped blocks, so this gives me 1024 blocks that can be sloped.

But, and there's always a but, I'm now face with the problem of what to draw and when.

With solid blocks only, it's a binary thing really. I'm a solid block, is there a solid block to east? There is. Okay then i won't draw my east face. There isn't, then i will draw my east face. Pretty simple really.

Now with slopes there are a lot more combinations. I'm reckoning there are 25 x 25 possible combinations. for each of 6 directions. Which makes 3750 possible combinations. Now, i feel a lot of those will be duplicates so i'm confident that i can pre-generate all the possible combinations.

So now i'm working on a tool to pre-generate all the drawing instructions for each possible situation.

In terms of building and digging, i'm thinking of having a toggle so the player can turn slope mode on or off. The landscape will be generated with slopes but when the player toggles slope mode off then they will build as normal with cube blocks. When they toggle slopes on then as they dig or place blocks, the landscape immediately surrounding the block dug or placed will adjust with slopes. So, with slopes on, if you dig a single block out of a flat plain then the hole would have sloped edges all the way round.
avatar
Slaihne

Posts : 264
Join date : 2011-03-17
Age : 50

View user profile

Back to top Go down

Re: Slopes

Post by Slaihne on Tue May 17, 2011 2:52 pm

I should have a new version out by the end of the weekend complete with slopes.

I've got the ComboMaker up and running now, and have its output integrated into the block engine.

It seems to work quite well, so far the speed difference is small (around 5% slower) but i now only have a single routine that adds a face to the chunk mesh.
I say face but now its actually a bunch of triangles.

The ComboMaker is set up with all the different block 'styles'; a cube, a slope facing north, a corner piece in a particular orientation etc.
It then pre-generates what needs drawn, for the east face, if a north slope abutts a cube on its east side etc.

The block engine loads these instructions in and then all i need to do is use the current block's 'style', plus the 'style' of the block it's touching and the direction.
This gives me a bunch of vertices and indices which i just add to a vertex buffer, no actual calculations at all in the engine as such.

It's opened an interesting train of thought now...

I used to consider the blocks as cubes but now i'm thinking about them more in terms of actual models with 7 ways to group the triangles.
7 because of the 6 faces of a cube and an extra one for triangles which don't face in one of these directions.

It would be possible, with some modification of the engine, to have something like a cube where each face is a small 4 sided pyramid.
Normally i would have to do this sort of thing with an actual model, the downside being that ALL the triangles would be draw, even if two of these objects were touching each other. It would look fine but on a wireframe you would be able to see the extra triangles being drawn internally.

With what i'm working on at the moment, you could seperate each of the 'faces' into the 6 basic directions then the internal faces wouldn't be drawn when two of the objects are touching.

It's an interesting thought but i don't think i'll be progressing it.

Oh, one more good thing about the current method i have is that anyone can alter how the each block 'style' is drawn, just by changing the blockcombo file.
A silly example would be if someone wants to draw 4 triangles per face of each cube, they can, just by altering the file correctly.

One last thing that i've been thinking on is 'modding'. If anyone has any ideas on what they'd like to see please let me know.
avatar
Slaihne

Posts : 264
Join date : 2011-03-17
Age : 50

View user profile

Back to top Go down

Re: Slopes

Post by Slaihne on Wed May 18, 2011 2:39 pm

Thought i'd share a pic of current progress on this...

http://blokworld.forumotion.co.uk/gallery/General-Images/Slopes-Progress-pic_8.htm

The warning blocks are placeholders for corner pieces.
The lighting is wrong on the slopes, ie hard coded atm.

The engine is only drawing the triangles it needs to to show the slopes, they aren't overlaid model blocks as they were in a previous image.

Liquid will need tweaked a bit but shouldn't be major since i use a separate channel for liquids. (try messing with the Vent block, it lets the sea pass through it).
avatar
Slaihne

Posts : 264
Join date : 2011-03-17
Age : 50

View user profile

Back to top Go down

Re: Slopes

Post by Slaihne on Wed May 18, 2011 2:52 pm

In case anyone is interested, here's an example of the some lines from the Combo file...

1,0,0,6,4,0,1,2,0,3,1,0,1,1,1,1,0,0,1,0,1,1,1

Takin them in order, they mean, If Slope Type 1 (a solid cube) abutts slope type 0 (an empty cube) in direction 0 (up) then there are 6 vertex indices for 4 vertices. The next 6 digits are the indices, the last 4 triplets are 4 x,y,z coords. Together, the indices and vertices describe the two triangles needed to draw this face.


Here's one involving a slope...

1,2,5,3,3,0,1,2,1,1,0,1,1,1,1,0,0

Takin them in order, they mean, If Slope Type 1 (a solid cube) abutts
slope type 2 (a flat slope with the fat end to the north) in direction 5 (east) then there are 3 vertex
indices for 3 vertices. The next 3 digits are the indices, the last 3
triplets are 4 x,y,z coords. Together, the indices and vertices describe
the triangles needed to draw this face. In this case a single triangle because the slope covers the other triangle of the east face of the solid cube.
avatar
Slaihne

Posts : 264
Join date : 2011-03-17
Age : 50

View user profile

Back to top Go down

Re: Slopes

Post by Slaihne on Thu May 19, 2011 2:57 pm

A small update, with all the upward facing slope blocks in place.

http://blokworld.forumotion.co.uk/gallery/General-Images/Upward-Slopes-pic_9.htm

The down facing slopes (for overhangs and cave ceilings) are next. Then the lighting needs rejigged to cope with slopes.
avatar
Slaihne

Posts : 264
Join date : 2011-03-17
Age : 50

View user profile

Back to top Go down

Re: Slopes

Post by Slaihne on Fri May 20, 2011 3:02 pm

avatar
Slaihne

Posts : 264
Join date : 2011-03-17
Age : 50

View user profile

Back to top Go down

Re: Slopes

Post by Nicadeamas on Mon Jun 20, 2011 7:59 pm

.
Wow...
How does the engine know not to render what is below the top surface?

Is each cube of area within the world designated to an origin ID which is what is looking around at the ID's around it in order to calculate the class and or type of the mesh belonging to that origin?

If that's the case then the whole engine is basically a sequence of if else statements which are activated on world creation, or on event changed in and origin... right?

Nicadeamas

Posts : 5
Join date : 2011-06-20

View user profile

Back to top Go down

Re: Slopes

Post by Slaihne on Tue Jun 21, 2011 2:38 pm

The block doesn't actually know its on the 'top' surface as such.

As i'm handling each block i first evaluate the block above and below and the 8 blocks all around it. The last 8 blocks say what type of slope i should use. The above and below say whether there should be a slope at all.

Once i know what type of slope (or a plain cube block) i then look in all 6 directions and see what type of block is there. This can basically be empty, a cube block, or a slope block.

I use the block being looked at in combination with the current block and this tells me what triangles to draw. I already have the triangles precalculated in a big lookup table so they are fast to setup.

The simple example is a solid current block butting against an empty block. I will pull 2 triangles out of the lookup table in this case and stick them into a buffer ready to draw.

Oh, and there's a couple of errors in the table i use to decide which slope and also the vertex lookup table in the current version Wink
avatar
Slaihne

Posts : 264
Join date : 2011-03-17
Age : 50

View user profile

Back to top Go down

Re: Slopes

Post by Nicadeamas on Tue Jun 21, 2011 7:22 pm

.
So then if you delete a block, or change it to a class of block that is labeled as translucent, then it shoots a command over to the touching blocks to tell them to refresh their info and adjust.

Making me wander what happens if the player breaks into a large open space in the ground. By default the cubes making the walls for that cavern would make themselves render because they notice the air class cube next to them. Which means you would be using un-necessary resources in rendering the caverns below the player which he actually should not be rendering.
So how do you get the cavern walls below the player to tell themselves not to render themselves?

I don't have the programming skills to help provide a solution for slope errors. but I think I understand it well enough I might be able to offer solution idea's through If Else statements and or cases.

Nicadeamas

Posts : 5
Join date : 2011-06-20

View user profile

Back to top Go down

Re: Slopes

Post by Slaihne on Mon Jun 27, 2011 12:54 pm

When a block is removed or built, it actually regenerates the whole mesh for that chunk and the 8 chunks around it. A chunk is 128 blocks tall and 16x16 blocks on the horizontal. The neighbouring chunks are regenned because of lighting.

When a player breaks into a cavern, the cavern was already being rendered because of the empty blocks in there that's correct.

If you use one of the demo's and press 'W' you should be able to see the caverns being drawn below the ground (there's one close to the start location). If you fly into the cave and the press W again you should be able to then place lights to illuminate it. So, you see the caves are always being drawn.

There are techniques to use to prevent this. One i've read about is occlusion culling but i'm still in two minds about this. It would help if the player is in a cave, yes since it wouldn't have to render the ground detail and vice-versa. But it wouldn't help if the player is on top of a mountain looking down at complex landscape surrounding him.

I think something like rendering the nearby blocks first so that z-culling on the video card can limit the amount of overdraw is just as good.

Occlusion culling may be better if you are drawing meshes with tens of thousands of polygons but the meshes i end up drawing mainly have relatively few polygons.

The slopes shouldn't be a major issue to fix. The lookup table to generate the meshes is created by a program i wrote. The table to decide which type of slope block is done by hand. The former has some errors when a downward sloping block ends up beside an upward sloping block the latter has at least one wrong set of data that leads to no sloping block being chosen.
avatar
Slaihne

Posts : 264
Join date : 2011-03-17
Age : 50

View user profile

Back to top Go down

Re: Slopes

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum