Shader variables and VR Single Pass rendering

Any issues, problems or troubleshooting topics related to the Prepar3D client application.
User avatar
YoYo
Posts: 312
Joined: Thu Nov 28, 2013 2:53 pm

Re: Shader variables and VR Single Pass rendering

Post by YoYo »

Beau Hollis wrote: Tue Apr 06, 2021 9:07 pm The floating/disappearing ....
Thank You, great news. I added this new line:
worldMatrix[3].xyz += cb_View.mViewInstanceOffset.xyz;
but it doesnt solve my issue (Single pass also). So maybe I talk about different thing I suppose :D.
I was talking about strange effect on some ground textures and I see that this doesnt solve it for me. Its only present in VR mode for sure and it looks just like "floating" effect (so maybe I got it wrong).

To understand it better, I will show you what it is about.

The picture like on 2D monitor:
Image

But in VR (single pass, WMR) it looks like this:
Image
I added shadows but of course there are no shadows here, just to better show the example.

So this effect fits like floating parts of background. The best way to duplicate it - pls land (on the level of the ground) by copter (or use Y key) near the border with water with shoreline. Water must be on High settings or below. You will see something like "layers" effect. Like two textures of the background and his details on not the same level and place but with a difference of about half a meter. Like to kind of textures (textures plus his background) are not on the same level. In 3D it looks very strange, like you are on the ground but you are in the air still. So maybe I was writing about something else :).

On some airports outside the airport plate / runway / aprons with grass textures outside I can notice the same strange 3D effect when Im near the border. Like this grass texture is not on the same level that airport texture (tarmc ect).

Maybe it is like I wrote, the background consists of two elements and one of them is on a different level (maybe detail1.bmp or the other?), but in 3D it makes it seem that we are not on the ground but still in the air?

Can some users confirm this too?
webmaster of www.yoyosims.pl
spec: W10, i9 9900K, RTX 3090, 32 RAM | P3Dv5 | VR only: HP Reverb v2
User avatar
Beau Hollis
Lockheed Martin
Posts: 2238
Joined: Wed Oct 06, 2010 3:25 pm

Re: Shader variables and VR Single Pass rendering

Post by Beau Hollis »

Thanks for details. That's a separate but similar issue in terrain.fx. That will also be fixed in the next release. It can be fixed with a shader change, but the change is a bit complex so you might want to back up your file before modifying it.

To fix the land detail texture allignment, modify terrain.fx Line 632

Code: Select all

float2 LandDetail = (Input.vPosWS.xz + cb_View.mDetailTextureOrigin) * ...
Change cb_View.mDetailTextureOrigin to cb_mView.mDetailTextureOrigin - cb_View.mViewInstanceOffset.xz

Code: Select all

float2 LandDetail = (Input.vPosWS.xz + cb_mView.mDetailTextureOrigin - cb_View.mViewInstanceOffset.xz) * ...

To fix water detail normal map alignment (non ultra waves), change lines 696, 705, 714, 723, 732, and 769

Code: Select all

TBump = ComputeWaterTextureCoordinates(vWorldPos, ...
Change vWorldPos to vWorldPos - cb_View.mViewInstanceOffset

Code: Select all

TBump = ComputeWaterTextureCoordinates(vWorldPos - cb_View.mViewInstanceOffset, ...

In all cases take care not to modify the rest of the line (indicated by the ...)

Thanks
Beau Hollis
Prepar3D Software Architect
User avatar
YoYo
Posts: 312
Joined: Thu Nov 28, 2013 2:53 pm

Re: Shader variables and VR Single Pass rendering

Post by YoYo »

Wow! Beau, you make my day :D.

Image

Its a very, very good news. I'll test it and back with info.
webmaster of www.yoyosims.pl
spec: W10, i9 9900K, RTX 3090, 32 RAM | P3Dv5 | VR only: HP Reverb v2
User avatar
YoYo
Posts: 312
Joined: Thu Nov 28, 2013 2:53 pm

Re: Shader variables and VR Single Pass rendering

Post by YoYo »

Beau, I'm in a hurry back .... :D

Yes!!! It solved this issue. Wow, big improve :). Thanks a lot. Now the water below ULTRA looks like it should and the landclass textures also. Great find and fix! TY!

One thing, maybe its possible to solve it for Single pass also ;)? Shadows from object on the ground, please see this.

I noticed differences between shadow on textures outside the runway/apron - so landclass textures. Maybe is any tweak for this too?
It looks like its out of tune. Maybe its a side effect of single pass, dont know but I see it from the beginning in v5 and Single Pass.
But what its strange - on aprons / runways (so hard surface) its ok! No any problem like on the grass ect.

Pls look on this animation and check position of shadow of the skid (shifting the shadow on the right image from skid - place when the model touches the ground). You can notice that on ground textures the shadow is on on different place than on runway.

Image

In VR it looks like the image is out of sync because in the right image the shadow is on different position on the ground (it gives such a squint effect in VR). It doesn't have this effect on a hard surface, which is what a little strange I suppose (why on hard surface is ok?). Maybe its a shader code again? :) . Shadows in VC are ok too so its present only on textures of the "soft" ground.
webmaster of www.yoyosims.pl
spec: W10, i9 9900K, RTX 3090, 32 RAM | P3Dv5 | VR only: HP Reverb v2
User avatar
Beau Hollis
Lockheed Martin
Posts: 2238
Joined: Wed Oct 06, 2010 3:25 pm

Re: Shader variables and VR Single Pass rendering

Post by Beau Hollis »

{EDITED TO CORRECT A TYPO]
That's one we already fixed in our dev build.

line 601 in terrain.fx:

Code: Select all

float3 shadowPositionWS = Input.vPosWS;
The fix:

Code: Select all

float3 shadowPositionWS = Input.vPosWS - cb_View.mViewInstanceOffset;
Beau Hollis
Prepar3D Software Architect
User avatar
YoYo
Posts: 312
Joined: Thu Nov 28, 2013 2:53 pm

Re: Shader variables and VR Single Pass rendering

Post by YoYo »

Splendid! I'll try it and back with the report :).
webmaster of www.yoyosims.pl
spec: W10, i9 9900K, RTX 3090, 32 RAM | P3Dv5 | VR only: HP Reverb v2
BiologicalNanobot
Posts: 2
Joined: Wed Feb 10, 2021 4:15 pm

Re: Shader variables and VR Single Pass rendering

Post by BiologicalNanobot »

Thank you for the quick workaround!
truthknown
Posts: 55
Joined: Sun Jul 23, 2017 6:25 pm

Re: Shader variables and VR Single Pass rendering

Post by truthknown »

Beau Hollis wrote: Thu Apr 08, 2021 1:26 pm That's one we already fixed in our dev build.

line 601 in terrain.fx:

Code: Select all

float3 shadowPositionWS = Input.vPosWS;
The fix:

Code: Select all

float3 shadowPositionWS = Input.vPosWS - cb_View.mViewInstanceOffset;
Beau, thanks so much for these. We are very happy to make these modifications ourselves while we wait for the next release!!!

Is it safe to say that anywhere in the terrain.fx file that we see Input.vPosWS (and its variations), we should add the associated - cb_View.mViewInstanceOffset?
User avatar
YoYo
Posts: 312
Joined: Thu Nov 28, 2013 2:53 pm

Re: Shader variables and VR Single Pass rendering

Post by YoYo »

Beau Hollis wrote: Thu Apr 08, 2021 1:26 pm That's one we already fixed in our dev build.

line 601 in terrain.fx:

Code: Select all

float3 shadowPositionWS = Input.vPosWS;
The fix:

Code: Select all

float3 shadowPositionWS = Input.vPosWS - cb_View.mViewInstanceOffset;
To be clear, because after the change I lost textures of the ground ;>.

I must change the whole line:
float3 shadowPositionWS = Input.vPosWS; to
const float3 ViewInstancedWS = Input.vPosWS - cb_View.mViewInstanceOffset; ?
Because there are differences at the beginning, before " = " .
webmaster of www.yoyosims.pl
spec: W10, i9 9900K, RTX 3090, 32 RAM | P3Dv5 | VR only: HP Reverb v2
User avatar
Beau Hollis
Lockheed Martin
Posts: 2238
Joined: Wed Oct 06, 2010 3:25 pm

Re: Shader variables and VR Single Pass rendering

Post by Beau Hollis »

To be clear, because after the change I lost textures of the ground ;>.
Sorry. There was a typo in my last post. It has been edited. We've changed some variable names and done some other code cleanup so I'm backporting these shader tweaks to work with the v5.1 version.
[EDIT] I've also edited all the quote blocks above with the correction to prevent confusion
Is it safe to say that anywhere in the terrain.fx file that we see Input.vPosWS (and its variations), we should add the associated - cb_View.mViewInstanceOffset?
That would be a resounding no :). Most things do in fact want to use vPosWS, but there are some special cases like shadows and wave textures, which don't.
Beau Hollis
Prepar3D Software Architect
User avatar
YoYo
Posts: 312
Joined: Thu Nov 28, 2013 2:53 pm

Re: Shader variables and VR Single Pass rendering

Post by YoYo »

Beau, in this new entry is something wrong still:

Image

I think the beginning for current 5.1 HT2 users must look like this (so without "const"):

float3 shadowPositionWS = Input.vPosWS - cb_View.mViewInstanceOffset;

With this I havent this shadow issue in VR :) , shadows from skids look ok on the ground now:

Image

Looks fine!
webmaster of www.yoyosims.pl
spec: W10, i9 9900K, RTX 3090, 32 RAM | P3Dv5 | VR only: HP Reverb v2
User avatar
YoYo
Posts: 312
Joined: Thu Nov 28, 2013 2:53 pm

Re: Shader variables and VR Single Pass rendering

Post by YoYo »

And water (high settings), if you are close, white squares after changes:

Image

Id like to raport it (but I'd like to admit I use Envshade tweaks also ). Soon Id like to reinstall P3Dv5 to the new NvMe M2 drive and I'll check it again with default shaders. TY.
webmaster of www.yoyosims.pl
spec: W10, i9 9900K, RTX 3090, 32 RAM | P3Dv5 | VR only: HP Reverb v2
User avatar
Beau Hollis
Lockheed Martin
Posts: 2238
Joined: Wed Oct 06, 2010 3:25 pm

Re: Shader variables and VR Single Pass rendering

Post by Beau Hollis »

Yes. Sorry. It was still incorrect. YoYo was right about the const. I corrected the variable name from the bad copy/past on the first edit but missed the const keyword. That broke water tiles because water shading moves the shadow location to ripple with the waves and it's not legal to modify a constant variable after it's initially defined. Hopefully I got it correct this time :)
Beau Hollis
Prepar3D Software Architect
Post Reply