New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding depth option to the texture of guiOffscreenCanvas #1829

Merged
merged 2 commits into from Jan 2, 2017

Conversation

Projects
None yet
4 participants
@irei1as
Contributor

irei1as commented Nov 22, 2016

Related to: http://forums.torque3d.org/viewtopic.php?f=10&p=6964#p6964

These small changes fix the rendering in the named texture of a guiOffscreenCanvas with 3d views.
Without this change, the objects in the 3d view are copied as they're created and that causes depth issues (objects behind being rendered in front).

Creating the gui with the field "useDepth" as true enables the fix.
It's off by default so guiOffscreenCanvas that don't use 3d views or don't need the texture part won't get the extra workload of the fix.

-Example of its use-
Add these functions to a .cs script in a "Full" project and exec it:
`

   //createRearView(0);
   //createRearView(1);
   function createRearView(%depthtest)
   {
      if(!isObject(RearViewUpdater))
      {
         %tickObj = new ScriptTickObject(RearViewUpdater);
         %tickObj.setProcessTicks(true);
         MissionCleanup.add(%tickObj);
        
        %guiOffscreen = new GuiOffscreenCanvas() {
           targetSize = "300 300";
           targetFormat = "GFXFormatR8G8B8A8";
           targetName = "RearViewTexture";
           dynamicTarget = "1";
           useDepth = %depthtest; //this one to enable the depth fix
           numFences = "0";
           displayWindow = "1";
           position = "0 0";
           extent = "300 300";
           visible = "1";
           active = "1";
           
           new GameTSCtrl() {
              cameraZRot = "180";
              position = "0 0";
              extent = "300 300";
           };
        };
        %guiOffscreen.cursorOff();
        
        %tickObj.guiOffCan = %guiOffscreen;
        
        %playGuiRearWindow = new GuiBitmapCtrl() {
           position = "100 100";
           extent = "150 150";
        };
        PlayGui.add(%playGuiRearWindow);
        
        %tickObj.miniWindow = %playGuiRearWindow;
     }
  }

  function RearViewUpdater::onInterpolateTick(%this, %delta)
  {
     (%this.miniWindow).setNamedTexture("RearViewTexture");
  }

  function RearViewUpdater::onRemove(%this)
  {
     (%this.miniWindow).delete();
     (%this.guiOffCan).delete();
  }

`

After that, start the desert level. If you add a few TSStatic and half-bury them in the terrain the fix will be shown better.

Now, use in the console:
createRearView(0);

This will create a guiOffscreenCanvas with the fix disabled as its useDepth field is zero.

You'll see a small window showing the rear view of the soldier. This window has depth errors like objects not being correctly covered by the terrain.

Delete the window and the guiOffscreenCanvas with:
RearViewUpdater.delete();

Finally use:
createRearView(1);

to create a guiOffscreenCanvas with the fix enabled (useDepth field is true).

Now the window should show the objects being correctly rendered.

irei1as added some commits Nov 22, 2016

Update guiOffscreenCanvas.h
Variables to add depth in the .cpp file.
Add a fix to the depth for the target texture
Fix to the named texture to have the 3d depth correctly rendered if a 3d view is inside the guiOffscreenCanvas.
It's disabled by default so it shouldn't change anything to projects that use guiOffscreenCanvas without the texture (like Oculus rendering).
@dottools

This comment has been minimized.

Show comment
Hide comment
@dottools

dottools Nov 22, 2016

Nicely done. Thanks for the PR.

dottools commented Nov 22, 2016

Nicely done. Thanks for the PR.

@Areloch Areloch added the Improvement label Nov 24, 2016

@Lopuska

This comment has been minimized.

Show comment
Hide comment
@Lopuska

Lopuska Jan 2, 2017

Member

Just perfect. Thanks (:

Member

Lopuska commented Jan 2, 2017

Just perfect. Thanks (:

@Lopuska Lopuska self-assigned this Jan 2, 2017

@Lopuska Lopuska merged commit d164781 into GarageGames:development Jan 2, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment