Jump to content

[SOLVED] WorldOccluderTerrain visualizer


photo

Recommended Posts

Proposal

 

New WorldOccluderTerrain should visualize occlusion heightfield geometry like occluder box/mesh, so occluder can be propperly positioned and scaled to match scenery. Without such visualization this is nearly impossible.

 

 

Temporary Workaround

 

Some custom script code for approximated visualization. Maybe also useful for other users.

 

post-82-0-90863700-1290155305_thumb.jpg

 

///////////////////////////////////////////////////////////////////////////////
int update() {

   .....
   if( engine.editor.isLoaded() == 1 )
   {
       visualizeOccluderTerrain( "occluder" );
   }
   .....
}

///////////////////////////////////////////////////////////////////////////////
void visualizeOccluderTerrain( string occluderName )
{
   // get occluder
   int indexOccluder = engine.editor.findNode( occluderName );

   if( indexOccluder == -1 )
   {
       return;
   }

   Node node = engine.editor.getNode( indexOccluder );

   WorldOccluderTerrain occluder = class_cast( node.getTypeName(),node );

   if( occluder == 0 )
   {
       return;
   }

   // get occluder dimensions
   vec3 position = occluder.getPosition();

   vec3 boundMin = occluder.getBoundMin();
   vec3 boundMax = occluder.getBoundMax();

   // visualize occluder heightfield values as boxes
   Image image = occluder.getHeightsImage();

   if( image == 0 )
   {
       return;
   }

   vec3 size = vec3( boundMax - boundMin );

   vec3 sizeBox;

   sizeBox.x = size.x / image.getWidth();
   sizeBox.y = size.y / image.getHeight();
   sizeBox.z = size.z;

   for( int x=0; x<image.getWidth(); x++ )
   {
       for( int y=0; y<image.getHeight(); y++ )
       {
           vec4 pixel = image.get2D( x, y );

           if( pixel.x > 0.0f )
           {
               sizeBox.z = size.z * pixel.x;

               mat4 transform = translate( position.x + ( 0.5f + x ) * sizeBox.x,
                                           position.y + ( 0.5f + y ) * sizeBox.y,
                                           position.z + 0.5f * sizeBox.z );

               engine.visualizer.renderSolidBox( transform, sizeBox, vec4(0.0f,0.0f,1.0f,0.1f) );
           }
       }
   }
}

Link to comment
  • 2 years later...

Depending on the occluder mask image size visualizers have significant impact on frame rate. But as this kind of visualization is only used for debugging purposes and occluder mask verification this should be no problem.

Link to comment
  • 2 weeks later...

Ulf, performance penalty is too high, that's the reason Frustum doesn't want to implement this feature. It's Ok in case of small oclluders, but in projects of Valley scale, it's basically a death sentence. If approximate it even further, it won't make much sense, since it'll be too rough for fine-tuning occluders.

 

It's great you've shared this code snippet, so everybody can use in their projects, if necessary.

Link to comment

Manguste, no problem, I think the UNIGINE-script is a more flexible solution anyway. It can also be easily optimized in case of very large occluders depending on user requiremenst e.g. just visualizing occluder cells around cursor position within a certain radius to limit the count of rendered boxes and required render time (though I think large occluders should better be avoided performance-wise).

Link to comment
×
×
  • Create New...