[Solved]GuiOffscreenCanvas and zdepth issue

Expanding and utilizing the engine via C++.
3 posts Page 1 of 1
irei1as
Posts: 72
Joined: Fri Feb 27, 2015 5:13 pm
by irei1as » Sat Nov 19, 2016 7:31 pm
Edit: The problem was solved. Let me add the fix I found at the end.

---
I've tried making a new class that shows a GameTSCtrl but using a particular camera instead of the control object:

guiCameraView.h: http://pastebin.com/eChZDTGG
guiCameraView.cpp: http://pastebin.com/M8yp2bLD

And It works correctly -I ignore all the compile warnings- if that gui is inside playGui.gui.
(It may be one frame late but I don't care about that. I'm rendering the scene twice, after all.)

Now, I want that gui inside a GuiOffscreenCanvas (that canvas is not childed to anything) with something like:

Code: Select all

//offsidescreen("OffName","400 400")
function offsidescreen(%name, %size)
{
   if(%name $= "")
      return;
   //--------------------
   %guiContent = new GuiOffscreenCanvas() {
      targetSize = %size;
      targetFormat = "GFXFormatR8G8B8A8";
      targetName = %name @ "Canvas";
      dynamicTarget = "1";
      numFences = "0";
      displayWindow = "1";
      position = "0 0";
      extent = %size;
      visible = "1";
      active = "1";
   };
   %guiContentCam = new GuiCameraView() {
      Camera = "TheOtherCamera";
      orthoMode = "0";
      nearClip = "0";
      visibleDistance = "0";
      enablePostFX = "0";
      forceFOV = "45";
      position = "0 0";
      extent = %size;
      visible = "1";
      active = "1";
     
      noCursor = "1";
   };
   %guiContent.add(%guiContentCam);
   
   %guiContent.insideCam = %guiContentCam;
   %guiContent.setName(%name);
}


And then use the targetName of the GuiOffscreenCanvas as part of a CustomMaterial so I can show a camera view inside a portal or monitors.

The problem is the zdepth is wrong in that particular texture. Objects are rendered over the terrain when they should be part hidden or the player vanishes after the object if they shot (but the gun keeps with the previous depth).

Image
At the top right you can see a correct use of GuiCameraView as it's child of playgui. The texture of the door shows incorrect z-depth and it comes from the named texture of the guioffscreencanvas.

Any idea where the issue could be that it doesn't work for one and it does for the other one?

Or, how could I render the GuiCameraView directly to a named texture without using guioffscreencanvas? I could just put the GuiCameraView out of screen bounds if needed and use the texture directly.
---

Fix:
It seems GuiOffscreenCanvas targetName texture couldn't save zdepth because it's not defined to do that.

What I needed is to add

Code: Select all

   GFXTexHandle depthTex( mTargetSize.x, mTargetSize.y, GFXFormatD24S8, &GFXDefaultZTargetProfile,
      "guioffscreencanvas::depth thing" );
   mTarget->attachTexture( GFXTextureTarget::RenderSlot(GFXTextureTarget::DepthStencil), depthTex );


before
mTarget->attachTexture( GFXTextureTarget::RenderSlot(GFXTextureTarget::Color0), mTargetTexture );
in guiOffscreenCanvas.cpp

With just that the texture gets zdepth information and works as I wanted.
Image
JeffR
Steering Committee
Steering Committee
Posts: 755
Joined: Tue Feb 03, 2015 9:49 pm
 
by JeffR » Mon Nov 21, 2016 6:39 pm
This is really, really cool.

One of the improvements I'd had slated was a generification of the TSControl view and the cameras with the move to the entity/component stuff and less hardcoded to game connections(similar to your goal with the GuiCameraView).

Idea being you could just point the gui control to a camera, and the camera would always be rendering to a target and poof it just works.

Sounds like you pretty much went for the same sort of deal, so this is pretty awesome to see you got it working already. This'll definitely need to be standard in the engine.

Any chance you could PR the fix and stuff so we can get that in?

(As an aside, the hall-of-mirrors portal effect looks pretty slick)
irei1as
Posts: 72
Joined: Fri Feb 27, 2015 5:13 pm
by irei1as » Mon Nov 21, 2016 7:14 pm
Sure, I was planning to submit a PR on the texture fix.

By the way, another interesting use is to mount a camera in another soldier to split the camera locally like old times multiplayer (1st person rendering must be enabled for their dtablocks).
But the guicamera view kind of fails for PostFX when $backbuffer is involved (underwater shader, for example) so it needs more work.
3 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest