Running 'preview mode' in a build.

0 votes
asked Oct 1 by jonlundy@gmail.com (26 points)
I'm building a zspace application in unity.  I'm primarily using  Unity 2017.4.9f1 but I've tried the same items in the 2018 (up to 2018.3.0b3), and have problems there as well.

I've been having problems with shadows in the build.  Everything looks fine in the preview mode, but when I do a build I will sometimes get shadows offset in one eye, which is very disorienting and makes the display look bad.

I saw previous answers here about running in deferred mode which when I implemented them did mostly solve my shadow problem. The offset is gone, but I do occasionally have a shadow that 'disappears' for a bit and then reappears. The shadows are FAR better than in forward rendering.

However using deferred mode means that I can't use MSAA or other hardware anti-aliasing.  All of my lines are crawling all over the place. I tried using  a post process effect on the camera for aliasing (the typical solution), seems to break the zspace view, everything is offcenter.

One solution that I thought would be that if I could run the same path as the preview mode in my build, then my application would look fine, my scenes aren't too complicated, they performance is fine in the editor so I can afford the performance hit.  I attempted to modify the zcore scripts to bring up the preview window in the build mode but it doesn't appear when I do the build. (it pops up fine when I do it in editor mode).

Is there a good solution that allows decent shadows and anti-aliasing?

Thanks

-Jon

1 Answer

+1 vote
answered Oct 1 by AlexShorey (259 points)
selected Oct 2 by jonlundy@gmail.com
 
Best answer

Hi Jon,
Here's something that might work for you.

I grabbed the latest release of Unity's Post-processing Stack v2.
https://github.com/Unity-Technologies/PostProcessing

(using Unity2018.1.0f2)
After setting that up, I believe I ran into the issue you described as everything being off-center. What's actually happening is PostProcessLayer.cs is resetting the Projection Matrices which kills our stereo effect. Maybe some post-process effects need that, but after commenting out the lines calling m_Camera.ResetStereoProjectionMatrices(); anti-aliasing (FXAA & SMAA) appear to work.

Let me know if that helps at all.
Alex S.

commented Oct 1 by jonlundy@gmail.com (26 points)
Thanks, that helped somewhat.  The aliasing is better, but still not as good as forward rendering MSAA.  I also found that sometimes the colors were different in one eye and then would suddenly correct.

Is there an easy way to run 'preview mode' from a build? The preview mode in Forward rendering is perfect, just not the built version.
commented Oct 2 by AlexShorey (259 points)
To enable preview mode in builds the way I think you're imagining would likely require changes on the native dll side. I wouldn't expect us to release the source of this or make the necessary changes ourselves. With that said, it doesn't necessarily preclude the possibility of leveraging whatever quirk is enabling good shadows in preview. The big difference from the main render path is that preview draws to render textures. I don't have time right now to prototype this out myself, but I would attempt to modify zcore in such a way that it uses render textures as a middleman before drawing to screen, similar to preview.

best of luck,
Alex S.
commented Oct 2 by jonlundy@gmail.com (26 points)
Thanks Alex, for now I will use the post processing aliasing trick you gave me, and if I have more time I will redo my attempt to do things manually.  i attempted to get the preview window to show up in a build and it didn't work, I assume it probably took advantage of the Unity Editor APis on the native side.  If I get more time I might attempt to rewrite the logic to manually use the native API, but that will have to be a future task.

One of the frustrations is that since the preview mode is a different path than the build path, doing the testing in unity requires a build since there will be difference between build mode and preview mode, sometimes very significant ones.

Thank you for the tip on the post processing stack, that enables me to do the anti-aliasing and to also experiment with the other effects as well.
...