Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Marco_Stone · Oct 01, 2019 at 02:09 PM · renderingvrgraphicsportal

Overwrite View matrix and projection matrix in VR

I am trying to make portals (Like from the game portal). With the LWRP. I first did it for non VR, where I had RendererFeature That would draw the scene again, but with a different View/projection matrix. I set those matrices with: CommandBuffer.SetViewProjectionMatrices(...);. This works perfectly, but when I enabled VR and tested that. Then the projection/view matrices are just the normal ones from the camera.

Does anyone know a technique I can use to overwrite them like I did with the non-vr version?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Oct 01, 2019 at 10:29 PM 0
Share

Well it should be clear that to get the portals rendered properly you need to render your portals twice for each eye seperately since each eye has a seperate camera and therefore seperate virtual cameras for a single portal. I haven't really played around with VR and I don't have any hardware for it. So I can not help you any further at the moment.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Marco_Stone · Oct 07, 2019 at 08:10 AM

For future reference, I was using Unity 2019.2.6f1.

I saw in the Unity CG documentation that some .cginc files were automatically included, one of them was UnityShaderVariables.cginc. In that I found that unity_MatrixV was redefined as unity_StereoMatrixV[]:

 #if defined(USING_STEREO_MATRICES)
     #define glstate_matrix_projection unity_StereoMatrixP[unity_StereoEyeIndex]
     #define unity_MatrixV unity_StereoMatrixV[unity_StereoEyeIndex]
     #define unity_MatrixInvV unity_StereoMatrixInvV[unity_StereoEyeIndex]
     #define unity_MatrixVP unity_StereoMatrixVP[unity_StereoEyeIndex]
 
     #define unity_CameraProjection unity_StereoCameraProjection[unity_StereoEyeIndex]
     #define unity_CameraInvProjection unity_StereoCameraInvProjection[unity_StereoEyeIndex]
     #define unity_WorldToCamera unity_StereoWorldToCamera[unity_StereoEyeIndex]
     #define unity_CameraToWorld unity_StereoCameraToWorld[unity_StereoEyeIndex]
     #define _WorldSpaceCameraPos unity_StereoWorldSpaceCameraPos[unity_StereoEyeIndex]
 #endif

Then lower in the file it showed where those variables were actually stored:

 #if defined(USING_STEREO_MATRICES)
 GLOBAL_CBUFFER_START(UnityStereoGlobals)
     float4x4 unity_StereoMatrixP[2];
     float4x4 unity_StereoMatrixV[2];
     float4x4 unity_StereoMatrixInvV[2];
     float4x4 unity_StereoMatrixVP[2];
 
     float4x4 unity_StereoCameraProjection[2];
     float4x4 unity_StereoCameraInvProjection[2];
     float4x4 unity_StereoWorldToCamera[2];
     float4x4 unity_StereoCameraToWorld[2];
 
     float3 unity_StereoWorldSpaceCameraPos[2];
     float4 unity_StereoScaleOffset[2];
 GLOBAL_CBUFFER_END
 #endif

Then I tried to use CommandBuffer.SetGlobalMatrixArray(...) to set the array but that would not work for some reason.

The only way I found out how to override the V/P matrices for VR was to use CommandBuffer.SetGlobalConstantBuffer() for UnityStereoGlobals. This however meant that I needed to manage all the matrices. I will put down what I know at this point:

For some reason Unity stores duplicates of the matrices. For example, unity_StereoMatrixP is the same as unity_StereoCameraProjection.

I believe that the Stereo projection/view matrices should be obtainable with Camera.GetStereoViewMatrix(eye) and Camera.GetStereoProjectionMatrix(eye).

The unity_StereoWorldSpaceCameraPos is as you would expect the Camera.transform.position.

And the unity_StereoScaleOffset is split up in 2 parts. 'xy' is the scale and 'zw' is the offset. This is different for each eye. I believe this is used to transform the UV's to be the correct uvs for the render target.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

171 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

PBR Standard Shader not Working Project Wide in Unity 5.3 0 Answers

How can you represent overlapping energy fields? 0 Answers

Why is the CPU usage so high? 1 Answer

Render texture fullscreen on top of camera output 0 Answers

Complex Depth Shader 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges