Game Development Community

T3D RTT Progress

by Demolishun · 02/13/2013 (3:35 am) · 13 comments

Short video of progress being made on my loopback audio RTT (render to texture). Some parts of this have been like pulling teeth, but it is getting done in the end.


Some points about the video:

  1. I am using a few types of objects in the scene. Most use different methods to get a texture.
  2. One of the cloud layers is set to the RTT texture target.
  3. The lighting mask for the spotlight is projecting on the ground. I had to modify one of the GFXTexHandle::set function calls to be able to do this.
  4. One of the cube objects is using a DAE object with a material that is using the RTT texture target as a diffuse map.
  5. The other cube object uses just a material reference and is a demo object that comes stock with T3D.
  6. Not shown because it would cause confusion and possibly trigger a seizure is the ground plane object does also work with the RTT texture target.

Basically I am getting close to finishing this up.

Edit:
The change to the GFXTexHandle::set function in gxfTextureHandle.cpp
(the change starts at "// added fhc", and end at "// end added fhc"):
bool GFXTexHandle::set( const String &texName, GFXTextureProfile *profile, const String &desc )
{
   // Clear the existing texture first, so that
   // its memory is free for the new allocation.
   free();
   
   // Create and set the new texture.
   AssertFatal( texName.isNotEmpty(), "Texture name is empty" );
   // added fhc
   String tmpStr = texName;
   if(tmpStr.substr( 0, 1 ).equal("#")){
      NamedTexTarget* textureTarget = NamedTexTarget::find(tmpStr.substr( 1 ));            
      if(textureTarget)
         StrongObjectRef::set(textureTarget->getTexture());         
   }else 
   // end added fhc
      StrongObjectRef::set( TEXMGR->createTexture( texName, profile ) );
   
   #ifdef TORQUE_DEBUG
      if ( getPointer() )
         getPointer()->mDebugDescription = desc;
   #endif
   
   return isValid();
}

Now also make this change in processedMaterial.cpp:
tring ProcessedMaterial::_getTexturePath(const String& filename)
{
   // added fhc
   // prevent path mangling
   if(filename.substr( 0, 1 ).equal("#")){
      return filename;
   }
   // end added fhc

   // if '/', then path is specified, use it.
   if( filename.find('/') != String::NPos )
   {
      return filename;
   }

   // otherwise, construct path
   return mMaterial->getPath() + filename;
}
Now in your materials.cs:
// this maps the texture "Hello" in a shape material to #hellotex name texture target
singleton Material(testcube_Hello)
{
   mapTo = "Hello";
   diffuseMap[0] = "#hellotex";   
};

For other objects it may just be sufficient to provide a texture name. If the editor will not take it by hand you may have to edit it by script. The spot light and cloud layers are examples that you can type in the text in the text field by hand to point to the named texture. But only after you make the above modifications.

I also have had issues with timing of the creation of the name texture target. So I made a custom object that allows me to make the named texture elsewhere (including allocating texture memory). I use this like this:
singleton NamedTexTargetObject(MyTexTargetObject) 
{
   targetName = "hellotex";
   texDims = "1024 1024";
};

I will be releasing a resource with everything spelled out. It will include an example of every object I used. I wanted it to be simpler than it is (and maybe it can be), but I learned a lot on the way.

#1
02/13/2013 (7:09 am)
Very cool!
#2
02/13/2013 (7:41 am)
Yeah, that is cool. :)
#3
02/13/2013 (11:00 am)
See? Now I will have something cool to do with my text-to-speech add-in. Great stuff Frank!
#4
02/13/2013 (11:11 am)
@Richard,
For that we will need to hack in to the actual audio playback as this is general whole computer loopback. So if you want the effects to specifically occur when particular characters speak then you would have to capture only that part of the stream. I have built the code so that the loopbackobjects can talk to arbitrary sources. It will just take a bit of wrangling to figure out how to capture the audio from another source.
#5
02/13/2013 (11:15 am)
That is really impressive,
would you mind to explain on how u set the cloud layer to use rtt texturetarget and is it possible to use it in a models ( in its material.cs file)
the reason why am after this, is are RTT Scopes,
so far i was not succesful to get it done in a proper way..

either way great work!
#6
02/13/2013 (12:03 pm)
The code above and another tweak to a processedMaterial function will allow most RTT to work. I will have to wait until I get home tonight to post the rest of the code changes. I was using another method, but I have found a more efficient, lower level change works just as good.
#7
02/13/2013 (7:45 pm)
@Jolinar,
I updated the blog to reflect the needed changes to get named texture target working with most objects in the game. It allows objects that need raw textures as well as materials to "just work". If you want access to the code sooner then send me an email here: me __at__ demolishun __dot__ com. I will send this anyone that wants it, but my stuff is not complete. If you just want to pick out pieces then have at it. I could create a resource as a WIP that I can update if people want.
#8
02/14/2013 (3:31 am)
Many Thx, i will give it a go
and thank you for the offer of sharing your insights

for starters this should be more then enough
either way your current work is more then worth to be included in a official release, it opens so many possibilities
again thank you for taking the time!
#9
02/14/2013 (12:45 pm)
very nice !
#10
02/15/2013 (10:18 pm)
@J0linar,
Taking time IS about being in a professional community. I consider the time I help other people a part of my business. It pays back because other people offer their expertise/struggle with the subjects at hand. This is what will propel this community forward.

Edit:
I am going to work on a simple resource to help me understand the RTT code and the rendering pipeline in DX and T3D. So it will actually come out before the audio code because I am really lacking a firm grasp on this. I will make some noise when I put that out. Maybe by Monday, we will see.
#11
02/20/2013 (9:53 pm)
I am hitting a snag on the RTT resource for just testing doing RTT. I realized I really have no clue as to how to properly setup the different matrices. I will have to take some book time to understand. I can do the RTT itself. When it comes to drawing stuff I am getting clipping when I don't want it and when I move an object in the z direction it stays the same size. It acts like it is ortho, but it is not. If I try a translate it clips as well.

In addition I tried going the imposter RTT route and I end up with all sorts of artifacts in the object shadow. I was very careful to make it so the render state was preserved, but it royally does not work right.

So to sum up the RTT is the easiest part as I am just having issues with the DX9 rendering pipeline as implemented in T3D. Frankly I have trouble finding parity between the DX9 calls and the actual T3D GFX calls.
#12
02/28/2013 (6:18 pm)
Finally I have some handle on how to use matrices and setup the matrices to use the GUI drawing functions. It was mostly ignorance and NOT CHECKING THE STATE OF THE MATRICES DURING GUI DRAWS. That would have been good to check first hand... So with my mostly dangerous knowledge of setting up the matrices I can do both GUI and perspective drawing modes. I think ortho would be fairly simple as well. I will clean up my code and provide an example RTT object for people to play with.
#13
02/28/2013 (7:16 pm)
Just great, could write a thank you novel - ;)
u know i mean it and can`t wait to get my hands at it!