It is currently Sat Aug 22, 2020 2:52 pm


All times are UTC




Post new topic Reply to topic  [ 73 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next
Author Message
 Post subject: Re: MLE Tech Demo :)
PostPosted: Sat Mar 19, 2011 12:44 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Shanee wrote:
by batch do you mean buffers or Draw calls?


I mean draw calls.

Shanee wrote:
I am still not completely sure how I'd do it but we'll see... (Like how do you go on setting which vertex is now alpha 100% and which one is not each time?)


The vertex data from PolyVox only contains a position, normal, and material. As I copy this into the hardware vertex buffers I'm adding an extra alpha component which I then use in the fragment shader to do the blending.

Shanee wrote:
Also, does it mean you solved the texture atlas bleeding and mip maps problems etc in polyvox? how then? how do you simulate wrap without having seams?


These problems aren't really related to PolyVox. Any application which uses texture atlases has to deal with the problem you describe, and you don't actually have to use texture atlases. For example, if you only have a small number of texture you could simply put them in different texture units.

A lot of people here are using texture atlases because they are using Ogre and hence DirectX 9 capabilities. But you are using DirectX directly, right? If you are on DirectX 10 or 11 then you have access to texture arrays, which solve the bleeding and mipmapping problems completely.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: MLE Tech Demo :)
PostPosted: Sat Mar 19, 2011 12:46 pm 

Joined: Fri Feb 18, 2011 8:41 pm
Posts: 173
Yes, I know this is unrelated to PolyVox, and I am using DirectX 9 unfortunately. I want to be able to support older systems, though I am wondering how sensible this idea is, considering how most systems have DX 10 support by now (or by the time the game will be out)


Top
Offline Profile  
Reply with quote  
 Post subject: Re: MLE Tech Demo :)
PostPosted: Sat Mar 19, 2011 12:48 pm 
User avatar

Joined: Wed Jan 26, 2011 3:20 pm
Posts: 203
Location: Germany
actually, ogre seems to have some kind of support for texture arrays, but I haven't figured it out yet.
(and yes, not for dx9)
http://www.ogre3d.org/forums/viewtopic.php?f=2&t=60462


Top
Offline Profile  
Reply with quote  
 Post subject: Re: MLE Tech Demo :)
PostPosted: Sat Mar 19, 2011 12:49 pm 

Joined: Fri Feb 18, 2011 8:41 pm
Posts: 173
ker wrote:
actually, ogre seems to have some kind of support for texture arrays, but I haven't figured it out yet.
(and yes, not for dx9)
http://www.ogre3d.org/forums/viewtopic.php?f=2&t=60462


Ogre is using OpenGL, as far as I know, if drivers are supported then OpenGL can use texture arrays.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: MLE Tech Demo :)
PostPosted: Sat Mar 19, 2011 12:50 pm 
User avatar

Joined: Wed Jan 26, 2011 3:20 pm
Posts: 203
Location: Germany
actually it supports dx9 and ogl and they're working on dx11


Top
Offline Profile  
Reply with quote  
 Post subject: Re: MLE Tech Demo :)
PostPosted: Sat Mar 19, 2011 2:17 pm 

Joined: Fri Feb 18, 2011 8:41 pm
Posts: 173
David, I wonder - can you combine the technique into one Draw call?

Instead of using additive blending you would just clip the first render attempt and again with the transparent vertices?

Idea: perhaps we can reduce it all to one batch!

http://msdn.microsoft.com/en-us/library ... 26(v=vs.85).aspx

Let's use this:
Code:
clip( Input.Material >= numMaterials ? -1:1 );


Imagine your atlas supports up to 16 textures, you set the transparent vertices to be 16 material ID and then you clip them in pixel shader instead of rendering black.

Add the vertices again to the end and that's it? ;)


Top
Offline Profile  
Reply with quote  
 Post subject: Re: MLE Tech Demo :)
PostPosted: Sat Mar 19, 2011 3:27 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
It's an interesting idea, but in my method I am drawing the three triangles using additive blending. This means that even after all three are drawn, some of the background will show though. This is the reason for drawing the black triangle first, and the black triangle can't be drawn additively (because black wouldn't add anything). The black triangle replaces what ever was there previously, so the other three triangle can be draw additively on top of it.

But it's great to think laterally, and maybe you can come up with something along these lines...

[Edit:] Also, just because I say something won't work, don't take my word for it ;) I'm only thinking off the top of my head here...


Top
Offline Profile  
Reply with quote  
 Post subject: Re: MLE Tech Demo :)
PostPosted: Sat Mar 19, 2011 3:30 pm 

Joined: Fri Feb 18, 2011 8:41 pm
Posts: 173
It's ok, I never take people's word when they say something I want to do won't work :)

I tried it btw, it hid vertices well. Now I am trying to add the triangles twice each time hiding 2 different vertices (modifying the original one to hide 2 as well), let me get back to you. Reducing draw calls to one would be great in my opinion.

Why would any of the background show anyway? I mean, I am rendering 3 triangles each time 2 different vertices invisible. It should complete the form, no?

Edit:
I am getting weird result, as if I am not even adding new vertices. Weird!


Top
Offline Profile  
Reply with quote  
 Post subject: Re: MLE Tech Demo :)
PostPosted: Sat Mar 19, 2011 4:43 pm 

Joined: Fri Feb 18, 2011 8:41 pm
Posts: 173
Maybe someone else would notice if I am doing something very stupid with this code here?
Code:
bool VoxelMesh::Construct(PolyVox::Volume<PolyVox::MaterialDensityPair44>& volume, PolyVox::Region region)
   {
      PolyVox::SurfaceMesh<PolyVox::PositionMaterialNormal> mesh;
      PolyVox::SurfaceExtractor<PolyVox::MaterialDensityPair44> surfaceExtractor(&volume, region, &mesh);

      surfaceExtractor.execute();
      //mesh.smoothPositions(1, true);
      
      const vector<uint32_t>& vecIndices = mesh.getIndices();
      const vector<PolyVox::PositionMaterialNormal>& vecVertices = mesh.getVertices();

      vector<uint32_t> problemVertices;

      float mat1;
      float mat2;
      float mat3;

      for (vector<uint32_t>::const_iterator iter = vecIndices.begin(); iter != vecIndices.end(); iter++)
      {
         mat1 = vecVertices[*iter].getMaterial();
         mat2 = vecVertices[*(iter+1)].getMaterial();
         mat3 = vecVertices[*(iter+2)].getMaterial();


         if (floatComparsion(mat1, mat2) == false || floatComparsion(mat1, mat3) == false || floatComparsion(mat2, mat3) == false)
         {
            
            problemVertices.push_back(*iter);
            problemVertices.push_back(*(iter+1));
            problemVertices.push_back(*(iter+2));
         }

         iter++;
         iter++;
      }

      m_VertexBuffer.Create(sizeof(PolyVox::PositionMaterialNormal) * (mesh.getNoOfVertices() + (problemVertices.size() * 2)));

      m_IndexBuffer.Create((mesh.getNoOfIndices() + problemVertices.size() * 2) * sizeof(DWORD), 8UL, D3DFMT_INDEX32);

      if (vecIndices.empty())
         return false;

      void* pVoid;
      m_IndexBuffer.Lock(&pVoid);

      const void* pIndices = static_cast<const void*>(&(vecIndices[0]));      

      uint32_t count = 0;

      memcpy((pVoid), pIndices, sizeof(uint32_t) * vecIndices.size());

      uint32_t* indices = (uint32_t*)pVoid;

      for (uint32_t i = 0; i < (problemVertices.size() * 2); i++)
      {
         indices[vecIndices.size() + i] = vecVertices.size() + i;
      }

      

      m_IndexBuffer.Unlock();

      const void* pVertices = static_cast<const void*>(&(vecVertices[0]));   

      m_VertexBuffer.Lock(&pVoid);

      count = 0;

      memcpy((pVoid), pVertices, sizeof(PolyVox::PositionMaterialNormal) * vecVertices.size());

      PolyVox::PositionMaterialNormal* vert = (PolyVox::PositionMaterialNormal*)pVoid;


      for (vector<uint32_t>::iterator iter = problemVertices.begin(); iter != problemVertices.end();)
      {
         vert[vecVertices.size() + count] = vert[*iter];
         vert[vecVertices.size() + count + 1] = vert[(*iter+1)];
         vert[vecVertices.size() + count + 1].setMaterial(300);
         vert[vecVertices.size() + count + 2] = vert[(*iter+2)];
         vert[vecVertices.size() + count + 2].setMaterial(300);

         count +=3;

         vert[vecVertices.size() + count] = vert[*iter];
         vert[vecVertices.size() + count].setMaterial(300);
         vert[vecVertices.size() + count + 1] = vert[(*iter+1)];
         vert[vecVertices.size() + count + 2] = vert[(*iter+2)];
         vert[vecVertices.size() + count + 2].setMaterial(300);
         count +=3;

         vert[*iter].setMaterial(300);
         iter++;
         vert[*iter].setMaterial(300);
         iter++;
         iter++;
         


      }

      m_VertexBuffer.Unlock();

      m_NumVertices = vecVertices.size() + problemVertices.size() * 2;
      m_NumFaces = vecIndices.size() / 3 + (problemVertices.size() * 2) / 3;

      m_Region = region;

      m_WorldPosition.Move(region.getLowerCorner().getX(), region.getLowerCorner().getY(), region.getLowerCorner().getZ());
      m_WorldPosition.Update();

      return true;
   }


I am getting them all completely transparent.

I even tried to copy the vertices to one of the additional ones and not setting their material to 300 (transparent) but they still go transparent, as if only the first one really work.

I also noticed that sometimes it copied a vertex with material 300 but the only place I am setting the material to be possibly 300 is in that function, uff!


Top
Offline Profile  
Reply with quote  
 Post subject: Re: MLE Tech Demo :)
PostPosted: Sat Mar 19, 2011 5:22 pm 

Joined: Fri Feb 18, 2011 8:41 pm
Posts: 173
also tried
Code:
PolyVox::PositionMaterialNormal fixVert;

      for (vector<uint32_t>::iterator iter = problemVertices.begin(); iter != problemVertices.end();)
      {
         fixVert = vecVerticest[*iter];
         //fixVert.setMaterial(300);
         uint32_t vert1 = mesh.addVertex(fixVert);
         
         fixVert = vecVerticest[*(iter+1)];
         //fixVert.setMaterial(300);
         uint32_t vert2 = mesh.addVertex(fixVert);

         fixVert = vecVerticest[*(iter+2)];
         //fixVert.setMaterial(300);
         uint32_t vert3 = mesh.addVertex(fixVert);

         mesh.addTriangle(vert1, vert2, vert3);
         
         fixVert = vecVerticest[*iter];
         //fixVert.setMaterial(300);
         vert1 = mesh.addVertex(fixVert);

         fixVert = vecVerticest[*(iter+1)];
         fixVert.setMaterial(300);
         vert2 = mesh.addVertex(fixVert);

         fixVert = vecVerticest[*(iter+2)];
         fixVert.setMaterial(300);
         vert3 = mesh.addVertex(fixVert);

         mesh.addTriangle(vert1, vert2, vert3);

         iter+=3;

      }


the triangle with material 300 commented out will not show


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 73 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net