Jump to content
  • Advertisement
Sign in to follow this  
winsrp

a normals problem with voxels

This topic is 2466 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

so I was making my procedural landscape, with cubes (yeah like minecraft.... again.. i know), and i figured out that the landscape was not big enough, so I should make it look a little more further away, doing so resulted in passing from 60 fps with v-sync on, to around 5 fps... so at first i had a view distance of 256*128*256 cubes and i wanted something in the 1024*1024*1024 range... of course this killed my video card.

I was previously creating 4 vertices for each face with 6 indexes, so if i wanted to draw a cube floating in mid air, i will need to draw the same vertexes 3 times!!!... and if i had 4 block on a 2x2 layout, the center vertex will be drawn 4 times!!, not to mention other layouts that ended up with a single vertex drawn up to 6 times!!, so this was not acceptable, and I entered the obscure optimization path to meet my goal, and I had to meet rendering goal, performance goal, and generation time goal, as this cannot take 2 minutes to load or it wont work either.

A couple days later the goal is met, but then i tried to apply normals at my vertexes.. and there was a ... holy crap moment, when the final rendering came out.... first holy crap was looking at the landscape which was rather nice, had my 60 fps, ran in under 45 secs which is not bad for so many cubes (~34 Million).

[attachment=7708:gen test1.png]

The optimization I did was, never repeat a single vertex (not entirely true but, at least 90% of the vertexes are unique, the other 10% are the ones on the edges of the sections that since they have their own vertexbuffer they must be repeated)

but since this change i can no longer set the normals to either up, left, right and so on, since a vertex now belong to several faces, so I sum up all the normals reading the faces the vertex belongs too and after that i normalize the result, this gives me this odd look.

[attachment=7709:gen test2.png]

Is there any way to do normals by face instead of by vertex? Something that can be calculated in the pixel shader other than the vertex shader maybe?

Share this post


Link to post
Share on other sites
Advertisement
I just treated vertices at the same position but with different normals to be different, which of course increases the amount of data quite significantly.The only other way i can think of off the top of my head is to not store normals in the vertex format at all. Instead set up the indices such that all faces in the same index buffer have the same normal and then pass the normal as a uniform. That increases the amount of draw calls by factor 6 obviously.

Share this post


Link to post
Share on other sites
treating vertices at the same position will be going back to the beginning, where i had duplicated vertices, and so, no good.

the other idea, its not so bad... , since you would be making face batches by normals, and the index list will still be a big, the only problem I see (in my particular case at least), is that vertices have already been passed to the vertex buffer and vertices are the ones carrying the normals.

Any other ideas?

Share this post


Link to post
Share on other sites
when u create your vertex normals, do u check for co-planar normals on the vertice? this can be an over-looked problem for why your normals are resulting in a bit...funky look.

just a minor suggestion.

Share this post


Link to post
Share on other sites
slicer can you explain that a little further?

what I do is, I extract the vertices that belong to a face, and add the corresponding normals to that vertices, then when all the normals are added up, I normalize all the results.

Share this post


Link to post
Share on other sites
what you have to do when you just don't get what going on by looking at the code, make it graphical...

Now i get that I'm doing it wrong... not entirely, just the corners... it should be 45 degrees or 90 degrees on all normals , and its very clear I'm not getting there.

[attachment=7724:gen test normals.png]

Share this post


Link to post
Share on other sites
OHHHH!!! you can do that... now I have to do my own pixel shader... dang.. I was using basic effect.

Share this post


Link to post
Share on other sites
uhh I also found the source code of the basic effect... I'm a total noob in these shader stuff...

Share this post


Link to post
Share on other sites
Yep, you can do it :-) However, be aware that I have heard that there can be problems perhaps on the edges of polygons. Maybe the ddx/ddy is not well defined here... I forget. I've never seen an issue in practice though.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!