Game Development Community

Why is "BeginSort" sceneObject rendering in front of terrain

by Steven Peterson · in Torque Game Engine · 05/03/2006 (8:58 am) · 3 replies

I'm working on new cloudLayers, which are derived from sceneObject.

if (state->isObjectRendered(this))
   {      
      SceneRenderImage* image = new SceneRenderImage;
      image->obj = this;
      image->isTranslucent = true;
      image->sortType = SceneRenderImage::BeginSort;
      state->insertRenderImage(image);
   }

According to all the docs that block in CloudLayer::PrepRenderImage() should cause the layer to be rendered after/in-front-of the sky but before/behind the terrain or anything else. Instead it is rendering in-front-of everything! In fact there is no discernable difference between using: "BeginSort", "Normal", or "EndSort".

Changing "isTranslucent" never seems to change anything either, except that setting it to True and using "SceneRenderImage::Sky;" is a run-time error on mission-load.

The clouds look great excet that they are in the wrong render-Order. Using a "SceneRenderImage::Sky;" (and isTranslucent=false) pins the clouds to the sky correctly. However, if I have multiple layers in this case, as the player walks/looks around the sky flickers between: no-layers, layer1, layer2, both.

I think using "SceneRenderImage::BeginSort;" for my sort-type is the correct setting, and the problem may be in renderObject(). However I don't really understand everything thats happening here. What might be causing this object to render out-of-order regardless? Can anyone point me in the right direction?


NOTE: The renerObject() function is a descendent of the one found in sky.cc.


Thanks for any help!
Steven

#1
05/03/2006 (11:59 am)
Finally got it fixed! Solution:

CloudLayer.h
S32 mThisLayer;
static S32 mLayerCount;

CloudLayer::CloudLayer()
...
mThisLayer = mLayerCount++;
...

CloudLayer::prepRenderImage()
...
   if (state->isObjectRendered(this))
   {      
      SceneRenderImage* image = new SceneRenderImage;
      image->obj = this;
      image->isTranslucent = false;
      image->sortType = SceneRenderImage::[b]Sky[/b];
      [b]image->textureSortKey = 200 - mThisLayer;[/b]
      state->insertRenderImage(image);
   }
   ...


So the correct sortType turned out to be "Sky". The "flicker" I was getting between multiple layers was fixed by dynamically assigning each layer its own "textureSortKey".

Thanks to RayG for helping out! :-)
#2
05/03/2006 (12:06 pm)
Thanks for posting yr results here, Steven!
#3
05/03/2006 (12:50 pm)
I try to make a habit of it - in the hopes others will too. :-)