Passthrough portals

Any issues, problems or troubleshooting topics related to the additional features present in the Prepar3D Professional Plus client application.
Post Reply
Smoku
Posts: 12
Joined: Tue Nov 09, 2021 11:48 am

Passthrough portals

Post by Smoku »

Hello,

I have been looking for some information on how to upload custom portal model quite a while now and did find nothing. When creating the portal there is a drop-down menu named "Shape". Below there are usual options (rectangle, sphere etc) and "custom model". In v.5.1 update overview there is an information "Added ability to load in custom models to be used as portals.".
How do I upload my custom model for the mask?

Thanks in advance,
Regards,
Smoku
Smoku
Posts: 12
Joined: Tue Nov 09, 2021 11:48 am

Re: Passthrough portals

Post by Smoku »

Gentleman, at the moment it looks like you have only stated that you added the ability to load custom models for portals, and in fact just added an empty option in drop-down menu. Is it something strange that customer wants to use something you claim to be a part of your product?
Please, if there is no such option - let me know and I will discard this path. If there is and you just don't know how to achieve what I'm trying to acomplish - let me know, I will try to email your collegues. Leaving someone without any answers on support forum is frustrating.
User avatar
Beau Hollis
Lockheed Martin
Posts: 2452
Joined: Wed Oct 06, 2010 3:25 pm

Re: Passthrough portals

Post by Beau Hollis »

You can draw basic occlusion meshes using the AR portals using motion controllers on SteamVR or Varjo. Portals work by writing alpha into the final image. By default alpha is not written, but the write mask can be modified to include alpha. This can be done via flags when drawing primitives via PDK (what portals do), or via a script in the case of materials (what our XR mask models of F16/F35 do). Now that we ship the masked models with the app, you can add ARMask.lua (found in Scripts folder) to your material to turn the material into a mask. You might want to make a modified version of the script if you want masking to be conditional or alpha to fade in over time.

We usually do this in the cockpit model itself, but it can also be done using a separate model. The Portal setting now let you replace the primitive shape with a model GUID.

To use the model based portal, you need to create a model and add it the P3D model library. This process is outlined in the modeling SDK and adding the ARMask.lua script to the materials you want to behave as portals. When you export your model, a GUID will be defined for the model. You need to copy paste the model GUID into the portal settings to make a model based portal. Once you do this the XML that saves out would look something like this:

Code: Select all

        <PortalSet>
            <Name>MyPortalModel</Name>
            <PortalSetOriginReference>Aircraft</PortalSetOriginReference>
            <Enabled>False</Enabled>
            <EnableDepthRead>False</EnableDepthRead>
            <Portal>
                <Name></Name>
                <Color>0.000000,0.000000,0.000000,0.000000</Color>
                <Dimensions>0.000000,0.000000,0.000000,0.000000</Dimensions>
                <XYZ>0.000000,0.000000,0.000000</XYZ>
                <PBH>0.000000,0.000000,0.000000</PBH>
                <Shape>Custom Model</Shape>
                <Enabled>True</Enabled>
                <ModelGuid>{DE4C166A-664D-4C24-B6A0-E16846B0FAF1}</ModelGuid>
                <ModelScale>1.000000</ModelScale>
            </Portal>
        </PortalSet>

We don't have a material option in our max exporter specifically for the color write mask, but it can be done with the use of a lua script. Here is what our default ARMask.lua does:
!lua

--Values used to set write mask.
local writeRGB = 0x00000007
local writeAll = 0x0000000F

varset("T:WriteMask", "Long", writeAll)

--Set diffuse color to black.
varset("T:DiffuseColorRed", "Number", 0.0)
varset("T:DiffuseColorGreen", "Number", 0.0)
varset("T:DiffuseColorBlue", "Number", 0.0)
varset("T:DiffuseColorAlpha", "Number", 0.0)
The key line in there is varset("T:WriteMask", "Long", writeAll). By default, materials that use alpha, don't write the alpha into the backbuffer.

Also, our portals are drawn using the PDK custom object draw capability, so a c++ addon could be used to draw your own. See custom object draw sample and gaze data sample for some uses of this. The trick with portals is setting the render flags correctly. These are the ones we use for our porals:
RenderFlags flags;
flags.DrawFromBase = false;
flags.DrawWithVC = true;
flags.DepthReadDisable = true;
flags.AlphaWriteEnable = true;
You might want depth read on in some cases if you intend to have foreground objects occlude your portals.

The GUID based portal drawing relies on an new WorldObjectService PDK feature in 5.1 where objects can be flagged to draw in the VC:

Code: Select all

        if (primitive.m_fObjectID == -1 && primitive.m_ModelGuid != nullGUID)
        {
            WorldObjectFlags flags;
            flags.bRenderInVirtualCockpit = true;

            HRESULT hr = P3D::PdkServices::GetWorldObjectService()->CreateObject(primitive.m_ModelGuid, primitive.m_WorldTransform, primitive.m_fModelScale, flags, (UINT&)(primitive.m_fObjectID));
        }
        else
        {
            P3D::PdkServices::GetWorldObjectService()->MoveObject(primitive.m_fObjectID, primitive.m_WorldTransform, FALSE);
        }
So if you wanted to do something more complex like moving your mask model around based on tracking data, this could be accomplished with your own C++ add-on that mimics what our portal implementation does.
Beau Hollis
Prepar3D Software Architect
Post Reply