Volumes Of Fun http://www.volumesoffun.com/phpBB3/ |
|
First Steps with Ogre and CubicSurface http://www.volumesoffun.com/phpBB3/viewtopic.php?f=14&t=302 |
Page 1 of 2 |
Author: | Illidan [ Sat Dec 17, 2011 7:00 pm ] |
Post subject: | First Steps with Ogre and CubicSurface |
Hello, I started looking into PolyVox yesterday so bare with me if my question is simple. I searched the forum and tried several things but I couldn't get it into Ogre without problems. This is my code: Code: *** SNIP: creating a sceneManager and ManualObject named "test" and attaching it to a node. test->setDynamic(true); PolyVox::SimpleVolume<PolyVox::MaterialDensityPair44> volData(PolyVox::Region(PolyVox::Vector3DInt32(0,0,0), PolyVox::Vector3DInt32(63, 63, 63))); createSphereInVolume(volData, 30); PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> mesh; PolyVox::CubicSurfaceExtractorWithNormals<PolyVox::SimpleVolume, PolyVox::MaterialDensityPair44> surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); surfaceExtractor.execute(); test->begin("BaseWhiteNoLighting", OT_TRIANGLE_LIST); { const std::vector<uint32_t>& vecIndices = mesh.getIndices(); const std::vector<PolyVox::PositionMaterialNormal>& vecVertices = mesh.getVertices(); for (std::vector<PolyVox::PositionMaterialNormal>::const_iterator itVertex = vecVertices.begin(); itVertex != vecVertices.end(); ++itVertex) { const PolyVox::PositionMaterialNormal& vertex = *itVertex; const PolyVox::Vector3DFloat& vertPos = vertex.getPosition(); test->position(vertPos.getX(), vertPos.getY(), vertPos.getZ()); test->normal(vertex.getNormal().getX(), vertex.getNormal().getY(), vertex.getNormal().getZ()); } for (std::vector<uint32_t>::const_iterator itIdx = vecIndices.begin(); itIdx != vecIndices.end(); ++itIdx) { test->index(*itIdx); } } test->end(); The createSphereInVolume is the same function as in the PolyVox examples. This is what I get: http://i.imgur.com/kL60B.jpg And a more close look to a side of the sphere: http://i.imgur.com/EQWbm.jpg I can't get it to have a "solid" look, I just see the wireframe. Obviously I've checked that Ogre works correctly and everything else is displaying normally, not as wireframe. I've even tried applying textures and shaders to it, and I can see the wireframe colored different (for example using a brown texture I could see the lines getting colored brown), but never "solid". I'm probably missing something really simple but I can't get around it, I hope you can point me in the right direction! Thanks in advance for any help and thanks a lot for the library, it's really a pleasure to work with it so far ![]() |
Author: | GM_Riscvul [ Sun Dec 18, 2011 5:29 am ] |
Post subject: | Re: First Steps with Ogre and CubicSurface |
I may be incorrect in this assumption but I believe the code in the documentation is a bit out of date and is meant as more of a basic example than actually working code. I'm not sure what your exact problem is and I find it amazing you can get a cubic extractor to produce a wireframe and yet have ogre display solid objects. I would think it would have to be an error with how you are telling ogre to render the object. I may have some code that can help you understand how to render polyvox meshes. In the showcase forum I have an open source terrain engine featured. You can feel free to look at how my basic shader works and how I create manual objects. It could help you find your problem. You can find the code at code.google.com/p/senior-project-voxel-terrain-generation/ I'm a little busy at the moment but I will try to take another look at your code soon to see if I missed something. |
Author: | Illidan [ Sun Dec 18, 2011 7:15 am ] |
Post subject: | Re: First Steps with Ogre and CubicSurface |
Hi GM_Riscvul, thanks for your answer. EDIT: I have found the error, obviously it was my fault ![]() Now onto something else: I'm now trying to generate a terrain from a heightmap. This is the code I'm using to populate the volume: Code: for (int bX = 0; bX < 16; bX++) { for (int bZ = 0; bZ < 16; bZ++) { int currentHeight = (uint8_t)((ridgedMultiNoise.GetValue(bX, 0, bZ) * 8) + 8); for (int bY = 0; bY < 16; ++bY) { if (bY <= currentHeight) { uint8_t uDensity = PolyVox::MaterialDensityPair44::getMaxDensity(); PolyVox::MaterialDensityPair44 voxel = volData.getVoxelAt(bX, bY, bZ); voxel.setDensity(uDensity); volData.setVoxelAt(bX, bY, bZ, voxel); } } } } The noise function just returns a value from 0 to 1, the rest of the code is the same as in the first post. This is what I'm getting: http://i.imgur.com/2goH6.jpg http://i.imgur.com/pYVnK.jpg Basically it's missing vertexes on 3 faces (i think south, east and bottom, but I may be mistaken), but not in ther other 3. I want it to have vertexes in all sides, like a cube but with the top face a bit different (like Minecraft if you get what I say). This is a shot with wireframe enabled to show the error better (the white lines are for the skybox): http://i.imgur.com/LXgYV.jpg Thanks again for any help, it's really appreciated! |
Author: | ker [ Sun Dec 18, 2011 9:32 am ] |
Post subject: | Re: First Steps with Ogre and CubicSurface |
that's an easy one ![]() ![]() the reasoning behind this is the following: you have voxels until lets say x=10, every voxel x>10 is zero/air. if you extract to 9, the voxels at 10 will have the same material(!= air) as those in 9, and therefore not create a border from ground to air, since there is no air. hope i was clear enough... if not, just extract a somewhat bigger region in all directions and it should do as you asked. |
Author: | Illidan [ Sun Dec 18, 2011 12:04 pm ] |
Post subject: | Re: First Steps with Ogre and CubicSurface |
Thanks a lot ker, it was just that simple ![]() To anyone wondering the same thing, I have added this code before the surface extraction: Code: PolyVox::Region reg = volData.getEnclosingRegion(); reg.setLowerCorner(reg.getLowerCorner() + PolyVox::Vector3DInt32(-1, -1, -1)); reg.setUpperCorner(reg.getUpperCorner() + PolyVox::Vector3DInt32(1, 1, 1)); I hope it's the correct way of doing it, works fine for me. I will play with it some more and come back if I need any help, thanks again for the fast answer. |
Author: | David Williams [ Sun Dec 18, 2011 1:46 pm ] |
Post subject: | Re: First Steps with Ogre and CubicSurface |
Be aware that the CubicSurfaceExtractorWithNormals does have some weird behaviour on the edge cases, which is why three of your faces were present while the other three were not. This should behave consistently with the regular CubicSurfaceExtractor. In time I will remove the 'WithNormals' version, and add a function to add normals onto a mesh which doesn't have them. Then everyone can use the regular version (benefitting from decimation, etc) and can add normals on if they need them. Saves maintaining two surface extractors as well. p.s. @ker - great to see you added an avatar ![]() |
Author: | Illidan [ Sun Dec 18, 2011 2:08 pm ] |
Post subject: | Re: First Steps with Ogre and CubicSurface |
Oh yeah, I don't even need the "trick" with the standard CubicSurfaceExtractor. I will use that from now on, thanks! |
Author: | Illidan [ Wed Dec 21, 2011 3:37 pm ] |
Post subject: | Re: First Steps with Ogre and CubicSurface |
Hello there, it's me again ![]() Let me start off by saying that PolyVox is really an awesome library. I was able to do about everything that came to my mind with little to no effort and almost everything was working on the first try, once I grasped the basics of the library. Really nice work! I worked a bit more on my "project" and I got a lot stuff working, but I also got several more questions. I hope they aren't too many ![]() 1) Is Raycasting with LargeVolume fast? I still have to benchmark it, but I need to do at least 2 of them every logic step (the logic runs 30 times per second right now, so that would be about 60 raycasts per second). Maybe copying a small region around the player to a RawVolume when he moves and performing the raycasts on that would be faster? The raycasts I need to do have a really small distance (2 voxels at most) so I would just have to copy a few voxels. 2) Right now i'm managing my big world of voxels in cubic chunks (16^3), and when I have new data to render I copy the needed region with a VolumeResampler to a RawVolume in the main thread, and then I do the extraction in another thread. Is using the resampler the correct and faster way of doing it? 3) I generate the voxels in the server and I need to send them to the client via network, so I need to optimize the packet size as much as I can. I quickly wrote this snippet of code to do some really basic serialization: http://pastebin.com/4HYeVFM2 Basically I'm looping through the volume and getting the information of a chunk (pos is just the Vector3DInt32 with the position of the chunk), and if I encounter the same material I wait for a different material before writing the data to the packet. But maybe there's an optimized serialization function in PolyVox that I missed or you can suggest a better way of doing it? 4) I'm not really experienced when it comes to shaders, but I was able to get texture atlases working without seams thanks to the post in the ogre3d forum and some shaders posted in this forum, with support for ambient light and a directional light. I will need to add support for several small light sources and shadows in the future, but honestly I have no idea how this can be accomplished. I should probably ask this in the ogre forum, but maybe you had some experience with these things and you can point me in the right direction. That's all for now, thanks in advance to everyone that will take the time to read this post ![]() |
Author: | ker [ Wed Dec 21, 2011 4:27 pm ] |
Post subject: | Re: First Steps with Ogre and CubicSurface |
Illidan wrote: 1) Is Raycasting with LargeVolume fast? I still have to benchmark it, but I need to do at least 2 of them every logic step (the logic runs 30 times per second right now, so that would be about 60 raycasts per second). Maybe copying a small region around the player to a RawVolume when he moves and performing the raycasts on that would be faster? The raycasts I need to do have a really small distance (2 voxels at most) so I would just have to copy a few voxels. I do it several times per frame (at 60fps)... takes less than a ms for those few times. Illidan wrote: 2) Right now i'm managing my big world of voxels in cubic chunks (16^3), and when I have new data to render I copy the needed region with a VolumeResampler to a RawVolume in the main thread, and then I do the extraction in another thread. Is using the resampler the correct and faster way of doing it? my tests did not show any difference between hacking into the volume class, just using get/set voxel and volumeresampler Illidan wrote: 3) I generate the voxels in the server and I need to send them to the client via network, so I need to optimize the packet size as much as I can. I quickly wrote this snippet of code to do some really basic serialization: http://pastebin.com/4HYeVFM2Basically I'm looping through the volume and getting the information of a chunk (pos is just the Vector3DInt32 with the position of the chunk), and if I encounter the same material I wait for a different material before writing the data to the packet.But maybe there's an optimized serialization function in PolyVox that I missed or you can suggest a better way of doing it? this is called run length encryption or RLE, is done inside polyvox, too. the only more compressing way would be a real compression like minecraft... I'd use your method until it becomes an actual problem. |
Author: | David Williams [ Wed Dec 21, 2011 4:40 pm ] |
Post subject: | Re: First Steps with Ogre and CubicSurface |
ker wrote: my tests did not show any difference between hacking into the volume class, just using get/set voxel and volumeresampler It's good to know some people are making use of the new VolumeResampler. Of course, the real benefit from this class comes when your source and destinations regions are different sizes, because in this case it handles the interpolation for you. Illidan wrote: But maybe there's an optimized serialization function in PolyVox that I missed or you can suggest a better way of doing it? As ker says we do have some RLE code in PolyVox, but in time I think I'll replace it with a proper (but lightweight and header-only) compression library. We also have some serialization code exposed but it is a mess. Once we replace the compression library we might expose some better serialization code, but until then you should just use what you have. Illidan wrote: 4) I'm not really experienced when it comes to shaders, but I was able to get texture atlases working without seams thanks to the post in the ogre3d forum and some shaders posted in this forum, with support for ambient light and a directional light. I will need to add support for several small light sources and shadows in the future, but honestly I have no idea how this can be accomplished. I should probably ask this in the ogre forum, but maybe you had some experience with these things and you can point me in the right direction. Your better off asking on a general graphics forum (or the Ogre forums) but I can at least point you to the Cg Tutorial which is available free online: http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter01.html |
Page 1 of 2 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |