Jump to content

[Solved]GuiOffscreenCanvas and zdepth issue


Recommended Posts

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:

//offsidescreen("OffName","400 400")
function offsidescreen(%name, %size)
  if(%name $= "")
  %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.insideCam = %guiContentCam;


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).


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.



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

What I needed is to add


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



mTarget->attachTexture( GFXTextureTarget::RenderSlot(GFXTextureTarget::Color0), mTargetTexture );

in guiOffscreenCanvas.cpp

With just that the texture gets zdepth information and works as I wanted.


Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...