Horde3D

Next-Generation Graphics Engine
It is currently 25.11.2024, 08:15

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: 02.02.2011, 20:17 
Offline

Joined: 02.02.2011, 19:14
Posts: 5
Hi!

Based on the tutorial from the wiki, I am trying to create some procedural geometry and am having some problems with the way UV-mapping it. Here is a simple example with a cube, illustrating my problem:

Code:
   H3DRes matRes = h3dAddResource(H3DResTypes::Material, "materials/testpattern.material.xml", 0);
   h3dutLoadResourcesFromDisk( _params->ContentDirectory.c_str() );
   
   float posData[] = {
      -0.5,   -0.5,   -0.5,
      +0.5,   -0.5,   -0.5,
      -0.5,   -0.5,   +0.5,
      +0.5,   -0.5,   +0.5,
      -0.5,   +0.5,   -0.5,
      +0.5,   +0.5,   -0.5,
      -0.5,   +0.5,   +0.5,
      +0.5,   +0.5,   +0.5,
   };
   unsigned int posDataCount = 8+2;
   unsigned int indexData[] = { 4,0,6, 6,0,2,  2,3,6, 6,3,7,  7,3,5, 5,3,1,  1,0,5, 5,0,4,  4,8,5,  5,8,9 };
   unsigned int indexDataCount = 24;
   short normalData[] = {
      0, 0, 1,
      0, 0, 1,
      0, 0, 1,
      0, 0, 1,
      0, 0, 1,
      0, 0, 1,
      0, 0, 1,
      0, 0, 1,
   };
   float uvData[] = {
      0,0,//0=3
      1,0,//1=2
      1,0,//2=1
      0,0,//3=0
      0,1,//4=7
      1,1,//5=6
      1,1,//6=5
      0,1, //7=4
   };
   H3DRes geoRes = h3dutCreateGeometryRes( "geoRes", posDataCount, indexDataCount, posData, indexData, normalData, 0, 0, uvData, 0 );
   H3DNode model = h3dAddModelNode( H3DRootNode, "DynGeoModelNode", geoRes );
   H3DNode cube = h3dAddMeshNode( model, "DynGeoMesh", matRes, 0, indexDataCount, 0, 3 );

Image

It generates a cube-"shell" without a top or bottom. But now I really want to add a top! Sadly since the UV-coordinates seem to be mapped to the vertices, it is not possible to just add two more entries to indexData to the top and bottom like I did with the sides, because those vertices are mapped to the same UV-Coordinates.

Currently I do a workaround by adding two more vertices like this:

Code:
   H3DRes matRes = h3dAddResource(H3DResTypes::Material, "materials/testpattern.material.xml", 0);
   h3dutLoadResourcesFromDisk( _params->ContentDirectory.c_str() );
   
   float posData[] = {
      -0.5,   -0.5,   -0.5,
      +0.5,   -0.5,   -0.5,
      -0.5,   -0.5,   +0.5,
      +0.5,   -0.5,   +0.5,
      -0.5,   +0.5,   -0.5,
      +0.5,   +0.5,   -0.5,
      -0.5,   +0.5,   +0.5,
      +0.5,   +0.5,   +0.5,
      -0.5,   +0.5,   +0.5,//copy of 6
      +0.5,   +0.5,   +0.5 //copy of 7
   };
   unsigned int posDataCount = 8+2;
   unsigned int indexData[] = { 4,0,6, 6,0,2,  2,3,6, 6,3,7,  7,3,5, 5,3,1,  1,0,5, 5,0,4,  4,8,5,  5,8,9 };
   unsigned int indexDataCount = 24+6;
   short normalData[] = {
      0, 0, 1,
      0, 0, 1,
      0, 0, 1,
      0, 0, 1,
      0, 0, 1,
      0, 0, 1,
      0, 0, 1,
      0, 0, 1,
      0, 0, 1,//one more
      0, 0, 1 //one more
   };
   float uvData[] = {
      0,0,//0=3
      1,0,//1=2
      1,0,//2=1
      0,0,//3=0
      0,1,//4=7
      1,1,//5=6
      1,1,//6=5
      0,1, //7=4
      0,0,//8=top=0
      1,0 //9=top=1
   };
   H3DRes geoRes = h3dutCreateGeometryRes( "geoRes", posDataCount, indexDataCount, posData, indexData, normalData, 0, 0, uvData, 0 );
   H3DNode model = h3dAddModelNode( H3DRootNode, "DynGeoModelNode", geoRes );
   H3DNode cube = h3dAddMeshNode( model, "DynGeoMesh", matRes, 0, indexDataCount, 0, 3 );

Image

Works fine, but that can't be the right way to do it. A cube shouldn't need 12 vertices (?). So here are my questions (which probably already include my problem):
  • If you have two polygons sharing two vertices, is it possible to UV-map both independently of each other?
  • What is the purpose of texture2 in the h3dutCreateGeometryRes? The documentation doesn't tell and the internet is empty.
  • Can you draw Quads or Trianglestrips instead of raw polygons? Would that even be faster?
  • Are transparent pngs not supported, or do they have to be enabled somehow?

Any help would be greatly appreciated.


Top
 Profile  
Reply with quote  
PostPosted: 02.02.2011, 21:56 
Offline

Joined: 15.06.2008, 11:21
Posts: 166
Location: Germany
Quote:
A cube shouldn't need 12 vertices


It should, because all other solutions for uv data are way too costly.

Quote:
If you have two polygons sharing two vertices, is it possible to UV-map both independently of each other?


Think of the extra addressing work required to create several UV sets per vertex (the same applies to normals for flat-shading!) - you would ultimatively need different indices for UV and normal vertex data, and the gpu would have to do more work as well - would kind of defeat what you want, right? ^^

Quote:
Are transparent pngs not supported, or do they have to be enabled somehow?


You have to enable alpha blending in your shader file.

Quote:
Can you draw Quads or Trianglestrips instead of raw polygons? Would that even be faster?


I don't think is possible right now, although it might be faster in some cases (really not in all!) like terrains. Don't know whether it would be worth implementing it though, I saw performance numbers in the internet telling that it might not be.


Top
 Profile  
Reply with quote  
PostPosted: 02.02.2011, 22:36 
Offline

Joined: 02.02.2011, 19:14
Posts: 5
Thanks phoneix64, that helped a lot! :D All my worries just vanished. Texture2 is then probably also useable via shader.

But that double definition of vertices is a little confusing since I haven't done anything 3D yet (you might even have noticed that somehow).
Imagine a theoretical grid/wall of individual square textures, stretching into infinity. Would it be common practice to just define every necessary vertex four times so as to have correct UV-Mapping for every individual square?


Top
 Profile  
Reply with quote  
PostPosted: 02.02.2011, 23:46 
Offline

Joined: 15.06.2008, 11:21
Posts: 166
Location: Germany
If you have a grid of single quads holding a different material each (if I understand you correctly, although this is a situation you want to avoid at all cost, way too many batches as the GPU has to do extra work at every material switch, you best use *one* texture/shader for as much geometry as possible, up to a certain extent, not always, but you should avoid small objects like single quads if you know what I mean) you could also just create one quad (4 vertices) and use a different transformation matrix for each of the tiles of the wall. If you used one material for many quads, you would have to specify a vertex differently for each quad it is a part of.

That example is way too theoretical though. :)


Top
 Profile  
Reply with quote  
PostPosted: 03.02.2011, 06:17 
Offline

Joined: 02.02.2011, 19:14
Posts: 5
Texture Atlas it is then.

Couldn't be happier with your help. :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 7 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® Forum Software © phpBB Group