Skip to content

[XR][URP] Fix issue with vignette location in XR #5471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 12, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Only set v3 if we are using single pass
That variable is only needed if single-pass instancing/multiview is active, so we can simplify the code to only do the asymetric FOV correction when we are in multi-pass mode.
  • Loading branch information
maloyer-unity committed Sep 1, 2021
commit 890ee1f2ece79791f96989d50fe2a0dd4db3fa3a
Original file line number Diff line number Diff line change
Expand Up @@ -1254,26 +1254,19 @@ void SetupVignette(Material material, XRPass xrPass)
#if ENABLE_VR && ENABLE_XR_MODULE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move the XR specific block into a function, easier to read than bunch of defines.
That function could even be in xrPass.
Something like
vec4 xrPass.applyXREyeOffset(vec2 center); which packs XR eye data into Vec4. Or xrPass.applyEyeOffset( ref vec2 centerAsLeft, out vec2 right);

But just moving this block to SetupVignetteXR() would be tiny bit better IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can extract a good amount of code to the XRPass class, but we still need to do some part of the work in SetupVignette() since when we are rendering in Multi-pass (each eye are rendered completely separately), the center still need to be corrected for each eyes and then placed in v2.xy since AFAIK the shader does not have a variation for "XR enabled, but not single-pass".

I'll see what I can do to reduce the amount of XR specific code in here.

if (xrPass != null && xrPass.enabled)
{
var v3 = Vector4.zero;
float centerDeltaX = 0.5f - center.x;
float centerDeltaY = 0.5f - center.y;

XRView view0 = xrPass.views[0];
v2.x = view0.eyeCenterUV.x - centerDeltaX;
v2.y = view0.eyeCenterUV.y - centerDeltaY;
if (xrPass.views.Count == 1)
v2.x = xrPass.views[0].eyeCenterUV.x - centerDeltaX;
v2.y = xrPass.views[0].eyeCenterUV.y - centerDeltaY;
if (xrPass.singlePassEnabled)
{
v3.z = v2.x;
v3.w = v2.y;
// With single-pass XR, we need a new variable to contain the data for the 2nd view
var v3 = new Vector4(xrPass.views[1].eyeCenterUV.x - centerDeltaX,
xrPass.views[1].eyeCenterUV.y - centerDeltaY,
0.0f, 0.0f);
material.SetVector(ShaderConstants._Vignette_Params3, v3);
}
else
{
XRView view1 = xrPass.views[1];
v3.x = view1.eyeCenterUV.x - centerDeltaX;
v3.y = view1.eyeCenterUV.y - centerDeltaY;
}

material.SetVector(ShaderConstants._Vignette_Params3, v3);
}
#endif

Expand Down