FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Proper z-ordering of transparent objects without texture

3 posters

Go down

Proper z-ordering of transparent objects without texture Empty Proper z-ordering of transparent objects without texture

Post  Shamaskatu Mon Sep 28, 2009 4:16 pm

I have created a number of semi-transparent objects in my model inside blender. I have created them in 2 different ways, some using UV mapped textures with an alpha component (these work fine, I think), and some with just an object color and alpha value set in blender. The objects that I created without using textures, I did the following:
- set material color & alpha in Blender
- programmatically assign the blend mode during loading to SIO2_MATERIAL_COLOR for the materials used for the objects (since I could not do this in blender)

My render call includes this:
Code:

      // proper distances are updated for the objects based on the frustrum of the camera
      sio2ResourceCull( sio2->_SIO2resource,
                   sio2->_SIO2camera );      
      sio2ResourceRender( sio2->_SIO2resource,
                    sio2->_SIO2window,
                    sio2->_SIO2camera,
                    SIO2_RENDER_SOLID_OBJECT | SIO2_RENDER_TRANSPARENT_OBJECT ); //
      sio2MaterialReset();
The problen I have is that the transparency works correctly only in alphabetical order. (i.e. if object Cube is in front of object Wall, wall is not visible through the cube. If object 'Wall' is in front of 'Cube', then it appears to render correctly - you can see the Cube through the Wall because I'm guessing Wall is rendered last.
I stepped through my code, and it appears that the _SIO2object->dst is being updated properly.
What is funny is that objects that I created using transparent textures with alpha layers all set up in Blender always get the ordering correct. (the transparent objects without textures render correctly both in front and behind an object with created with texture.

Anyone else have this problem or have some suggestions? I think I am going to have to create a dummy texture for these objects in blender and do it that way. >> working on it now...

Shamaskatu

Posts : 10
Join date : 2009-08-18

Back to top Go down

Proper z-ordering of transparent objects without texture Empty Re: Proper z-ordering of transparent objects without texture

Post  cgen2 Tue Sep 29, 2009 4:46 am

I had trouble with transparency too. I left it to get back to so I'm interested to hear what you learn. Sio2 recommended using translucency in Blender instead. I'm a little concerned about the amount of computation required for transparency too.

cgen2

Posts : 38
Join date : 2008-12-14

Back to top Go down

Proper z-ordering of transparent objects without texture Empty Re: Proper z-ordering of transparent objects without texture

Post  Shamaskatu Tue Sep 29, 2009 3:14 pm

I ended up creating a 'default' texture that is basically a 2x2 tga file that is all white and alpha layer that is 1.0. I set this image as texture layer 0 on my objects' material and set the blend mode to COLOR. This appeared to work even with multiple objects (solid/transparent) stacked in front of each other. The alpha set in blender now sets the material's alpha, and I can adjust this on the fly with _SIO2material->alpha = 0.2 for example.

**EDIT** > The following is a tricky problem, and my solution, as it turns out, is not better.. I'm going back to the original code.

After looking into it a bit more, there was still a subtle problem with ordering. scratch The transparency is correct for the most part, except when you bring objects of different sizes close to each other. The _SIO2object->dst property was not quite being updated properly. if a large object was just in front of a small object, then sometimes the small object would completely disappear instead of being visible through the large object. The dst property is set during culling, using the object's bounding sphere radius. The result is what I described, so I modified the sio2ResourceCull to cull (set dst to 0.0) using the bounding sphere, but not to set the distance this way (rather set it using a sphere radius of 0). This can still have trouble with irregular (concave) objects close to each other, I think, like when one object is inside of another. The code I came up with is below.

What I understood about the translucency setting is that it uses a sort of threshold to determine what gets rendered. I wanted to try to stay away from that and render transparency as accurately as I can.

Rendering:
Code:
      // proper distances are updated for the objects based on the frustrum of the camera
      // this routine applies a more accurate dst based on the centers only
      sio2ResourceCullDst( sio2->_SIO2resource,
                  sio2->_SIO2camera );     
      sio2ResourceRender( sio2->_SIO2resource,
                    sio2->_SIO2window,
                    sio2->_SIO2camera,
                    SIO2_RENDER_SOLID_OBJECT | SIO2_RENDER_TRANSPARENT_OBJECT ); //
      sio2MaterialReset();
Made a new sio2ResourceCull that looks like this:
Code:
// routine to correctly calculate dst.
// This improves z-ordering by using a radius of 0 for calculating dst
// rad is still used for culling (sets dst = 0.0)
// still does not work well for irregularly shaped objects
void sio2ResourceCullDst( SIO2resource *_SIO2resource,
                      SIO2camera  *_SIO2camera )
{
   unsigned int i = 0;   
   
   while( i < _SIO2resource->n_object )
   {
      SIO2object *_SIO2object = ( SIO2object * )_SIO2resource->_SIO2object[ i ];
      
      _SIO2object->dst = sio2CameraSphereDistInFrustum( _SIO2camera,
                                           _SIO2object->_SIO2transform->loc,
                                           _SIO2object->rad );
      if ( _SIO2object->dst != 0.0 )
         _SIO2object->dst = sio2CameraSphereDistInFrustumNoCull( _SIO2camera,
                                                  _SIO2object->_SIO2transform->loc,
                                                  0 );
      ++i;
   }
   
   
   i = 0;
   while( i < _SIO2resource->n_emitter )
   {
      SIO2emitter *_SIO2emitter = ( SIO2emitter * )_SIO2resource->_SIO2emitter[ i ];
      
      _SIO2emitter->dst = sio2CameraSphereDistInFrustum( _SIO2camera,
                                            _SIO2emitter->_SIO2transform->loc,
                                            _SIO2emitter->rad );
      if ( _SIO2emitter->dst != 0.0 )
         _SIO2emitter->dst = sio2CameraSphereDistInFrustumNoCull( _SIO2camera,
                                                   _SIO2emitter->_SIO2transform->loc,
                                                   0 );
      ++i;
   }
}
.. and the additional sio2CameraSphereDistInFrustumNoCull function:
Code:
// same as sio2CameraSphereDistInFrustum, except no culling (set to 0)
// only calculates for the last clip plane
float sio2CameraSphereDistInFrustumNoCull( SIO2camera *_SIO2camera,
                                vec3      *_v,
                                float       _r )
{
   unsigned int i = SIO2_CLIP_PLANE - 1;
   
   float d = 0.0f;
   
   _r *= 1.25f;
   
   d = _SIO2camera->frustum[ i ][ 0 ] * _v->x +
      _SIO2camera->frustum[ i ][ 1 ] * _v->y +
      _SIO2camera->frustum[ i ][ 2 ] * _v->z +
      _SIO2camera->frustum[ i ][ 3 ];   
   
   return d + _r;
}


Last edited by Shamaskatu on Tue Sep 29, 2009 6:07 pm; edited 1 time in total

Shamaskatu

Posts : 10
Join date : 2009-08-18

Back to top Go down

Proper z-ordering of transparent objects without texture Empty Re: Proper z-ordering of transparent objects without texture

Post  Shamaskatu Tue Sep 29, 2009 3:38 pm

Okay, I'm going to have to think about the irregular shaped objects thing a bit more... The center of the object is the only thing determining z-order (dst), which is causing problems.
study
sio2CameraRectangleDistInFrustum for some shapes possibly...

Shamaskatu

Posts : 10
Join date : 2009-08-18

Back to top Go down

Proper z-ordering of transparent objects without texture Empty Re: Proper z-ordering of transparent objects without texture

Post  Shamaskatu Tue Sep 29, 2009 6:12 pm

Well with the original sio2 code, using the bounding sphere to calculate dst, it works fine except the case I mentioned before. Specifically this is when you have an object 'hiding' behind another larger object and the edge of its bounding sphere is not as far back as the larger object's bounding sphere. Confused? Me too. Moving on.

Shamaskatu

Posts : 10
Join date : 2009-08-18

Back to top Go down

Proper z-ordering of transparent objects without texture Empty Re: Proper z-ordering of transparent objects without texture

Post  cgen2 Wed Sep 30, 2009 2:54 pm

Nice try.

In the case you mention is the bounding sphere of the hidden object inside the bounding sphere of the larger object?

cgen2

Posts : 38
Join date : 2008-12-14

Back to top Go down

Proper z-ordering of transparent objects without texture Empty Re: Proper z-ordering of transparent objects without texture

Post  Shamaskatu Wed Sep 30, 2009 3:33 pm

Sometimes. When it is, the rendering order is definitely screwed up. I think that the depth calculation in sio2 orders the objects by how far back the furthest point on the bounding sphere is for each object. (distance from frustum clip plane to center point + radius of bounding sphere = dst) Then renders back to front.

I ended up doing my own sorting. It works pretty well for objects somewhat close to each other.

Shamaskatu

Posts : 10
Join date : 2009-08-18

Back to top Go down

Proper z-ordering of transparent objects without texture Empty Re: Proper z-ordering of transparent objects without texture

Post  sio2interactive Fri Oct 02, 2009 6:36 am

Simply check the tutorial04 video... I explain there all the necessary technique for you to have transparency rendered properly. SIO2 have absolutely no problem handling transparent, semi-transparent and alpha leveled objects...
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Proper z-ordering of transparent objects without texture Empty Re: Proper z-ordering of transparent objects without texture

Post  Shamaskatu Fri Oct 02, 2009 7:57 am

That tutorial got me a LONG way, so thanks for putting that together. I think where I went wrong is that I didn't set a non-0 tralu value in blender for materials that I was not using a texture. My object type was then left at SIO2_OBJECT_SOLID for objects that I had set an alpha value.

hmm. That explains the alphabetically ordered objects in my original post, I think, since solid objects are rendered that way.

Shamaskatu

Posts : 10
Join date : 2009-08-18

Back to top Go down

Proper z-ordering of transparent objects without texture Empty Re: Proper z-ordering of transparent objects without texture

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum