Help with DistortionCorrectSpherical post-process

SDK supports Prepar3D’s philosophy of an open development architecture and encourages third parties to bring new innovations with improved add-ons and training content.
Locked
wledzian
Posts: 5
Joined: Tue Apr 10, 2012 4:14 pm

Help with DistortionCorrectSpherical post-process

Post by wledzian »

I'm trying to set up a true spherical projection, but the built-in DistortionCorrectSpherical is either incorrect or not what I think it is. I'd like to have three views adjacent to each other, to show a seamless match at the edges, but the edges don't line up quite right.

I've tried looking at the shader, but I'm having a bit of a hard time wrapping my head around the contents - Chiefly, it includes the following:

cbuffer PSDistortionCB
{
float sideBH;
float sideCH;
float sideBV;
float sideCV;

};

I understand that the ...H variables are horizontal and the ...V are vertical, but I'm not sure what they represent beyond that. Can someone please fill me in?

More generally, is there a reference available describing the various data that are accessible from within a shader?

Thanks,
- Wayne
wledzian
Posts: 5
Joined: Tue Apr 10, 2012 4:14 pm

Re: Help with DistortionCorrectSpherical post-process

Post by wledzian »

I never did figure out if the original code includes references to the input FOV, so I just hard-coded the values I need. The result is a nice 210 degree equirectangular projection.

I'd still like to know how to read the total image FOV within the shader, so I don't have to edit the shader each time I need a different FOV. A document describing what parameters are available to read within the shader would be nice as well.

Thanks!

PS... JeeHell, I'm watching your posts to see if you ever come up with a solution to the cloud lighting issues across window borders.

<img src='https://i.imgur.com/1sfJrng.jpg' />
JeeHell
Posts: 94
Joined: Sun Jan 15, 2012 11:04 pm

Re: Help with DistortionCorrectSpherical post-process

Post by JeeHell »

IIRC I was able to make a fixed lighting accross all views, but this was not so beautiful and felt a bit unnatural.
However, the luck is when using blending with video projectors, this means the difference in cloud lighting also blends and is not really noticeable anymore. This might not be the case with really good blending (using shutters) and very bright projectors, but in my case so far it's not so bad.
I still wonder how for instance immersive does its job here, as they seem to not have that issue... I think some people have more data out of LM than others...

Regards
wledzian
Posts: 5
Joined: Tue Apr 10, 2012 4:14 pm

Re: Help with DistortionCorrectSpherical post-process

Post by wledzian »

I was planning to use Sol7 to perform the warping and blending, so any artifacts in the source image will be present in the final image. As my simulator will not be used in a professional environment, I can tolerate the artifact.
wledzian
Posts: 5
Joined: Tue Apr 10, 2012 4:14 pm

Re: Help with DistortionCorrectSpherical post-process

Post by wledzian »

<?xml version="1.0" encoding="UTF-8"?>

<SimBase.Document Type="AceXML" version="1,0">

<PostProcessEffects.PostProcessDefinition>
<EffectName>Perspective to Spherical h70v40</EffectName>
<ShaderFileName>PerspectiveToSpherical.psh</ShaderFileName>
<ShaderEntryPoint>PerspectiveToSpherical</ShaderEntryPoint>
<ColorRequest>TRUE</ColorRequest>
<DepthRequest>FALSE</DepthRequest>
</PostProcessEffects.PostProcessDefinition>

</SimBase.Document>





//-----------------------------------------------------------------------------
// PerspectiveToSpherical.psh
// Copyright (c) Wayne Ledzian. All Rights Reserved
// For best results, this shader should be applied to
// a window which matches the angular dimensions listed
// in fovIN.x and fovIN.y. The output is a window with
// angular dimensions listed in fovOUT.x and fovOUT.y.
// Adjust as necessary.
// Multiple windows may be used for very wide FOV;
// Each window should be <= 120 degrees for best results.
//-----------------------------------------------------------------------------

// Must define GSQUAD_EMIT_TEXCOORD

#include "Quad.sh"

Texture2D<float4> srcTex : register( t0 );

float4 PerspectiveToSpherical(PsQuad vert) : SV_Target
{
// Assume defined FOV
float2 fovIN = (0.0f, 0.0f);
fovIN.x = 70.0f;
fovIN.y = 49.0f;
float2 fovOUT = (0.0f, 0.0f);
fovOUT.x = 70.0f;
fovOUT.y = 40.0f;

// Get texture dimensions
int2 texDims = int2(0.0f, 0.0f);
srcTex.GetDimensions(texDims.x, texDims.y);

// Initialize and transform current screenspace coordinates
// from [0.0 --> 1.0] to [-0.5 --> +0.5]
float2 normUV = (0.0f, 0.0f);
normUV = vert.texcoord.xy - 0.5f;

// Determine height from origin to projection plane
float h = 0.5f / tan(radians(fovIN.x / 2.0f));

// Calculate new UNSCALED image sampling coordinates
float2 alphaUV = (0.0f, 0.0f);
alphaUV = fovIN * normUV;

float2 newUV = (0.0f, 0.0f);
newUV.x = h * tan(radians(alphaUV.x));
newUV.y = sqrt((h * h) + (newUV.x * newUV.x)) * tan(radians(alphaUV.y));

// newUV.y is in same scale as newUV.x.
// it needs to be rescaled.
float ScaleFactor = 0.5f/(h * tan(radians(fovIN.y / 2.0f)));
newUV.x = newUV.x * (fovOUT.x / fovIN.x);
newUV.y = newUV.y * ScaleFactor * (fovOUT.y / fovIN.y);

// Translate back to [0.0 --> 1.0] coord system.
newUV = newUV + 0.5f;

// Output color
float4 color = float4(0.0f, 0.0f, 0.0f, 0.0f);
color = srcTex.Load(int3(texDims.x * newUV.x, texDims.y * newUV.y, 0));
return color;
}
Locked