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 /
  • Help Room /
avatar image
1
Question by celsodantas · Feb 23, 2018 at 04:11 AM · vrshadersshaderlabrender textureportals

Building Portal in VR in Single-Pass Stereo shader

Hey there! I'm having trouble writing a shader to render a Portal in VR, and I need help.

Everything I try doesn't work. I can't get both eyes to be aligned (I get crossed eyes when I look to the portal) and the projection of the image looks really wrong. See the gif:


https://i.imgur.com/LxOX6Iy.mp4


To generate this image I'm just getting the same Camera.main, pointing it to a RenderTexture and sending that result to my shader. So I'm seeing my portal through the portal, both should be aligned.

Here's my shader:

             #pragma vertex vert
             #pragma fragment frag
 
             #include "UnityCG.cginc"
 
             sampler2D _RenderedTexture;
             half4 _RenderedTexture_ST;
 
             struct v2f {
                 float4 pos : SV_POSITION;
                 float4 screenPos : TEXCOORD1;
             };
 
             v2f vert(float3 position : POSITION) {
                 v2f o;
 
                 o.pos = UnityObjectToClipPos(position);
                 o.screenPos = ComputeScreenPos(o.pos);
 
                 return o;
             }
 
             float4 frag(v2f i) : SV_TARGET {
 #if UNITY_SINGLE_PASS_STEREO
                 i.screenPos.xy = TransformStereoScreenSpaceTex(i.screenPos.xy, i.screenPos.w);
                 return tex2Dproj(_RenderedTexture, i.screenPos);
 #endif
                 return 0.70;
             }
        

And here's the component I have applied to the portal plane:

 void InitRenderTexture()
 {
     int width = XRSettings.eyeTextureDesc.width;
     int height = XRSettings.eyeTextureDesc.height;
 
     renderTexture = new RenderTexture(width, height, 24);
 
     renderTexture.name = "Portal-Renderer-" + GetInstanceID();
     renderTexture.hideFlags = HideFlags.DontSave;
 
     renderTexture.vrUsage = XRSettings.eyeTextureDesc.vrUsage;
 }
 
 void Update () 
 {
     Camera main = Camera.main;
 
     if (!main) { return; }
     if (isRendering) { return; }
     if (!refObject) { Debug.Log("Missing refObject;"); return; }
     if (!renderTexture) { InitRenderTexture(); }
 
     Debug.Log("Camera aspect ratio: " + Camera.main.aspect);
 
     isRendering = true;
 
     Vector3 originalPosition = main.transform.position;
     
 
     main.targetTexture = renderTexture;
     main.Render();
 
     main.targetTexture = null;
 
     Material material = GetComponent<Renderer>().sharedMaterial;        
     material.SetTexture("_RenderedTexture", renderTexture);
 
     isRendering = false;
 }

I tried using some of ther available methods discribed in https://docs.unity3d.com/Manual/SinglePassStereoRendering.html with no luck. I don't know if the error is in the shader or in how I'm generating the RenderTexture (size or missing param).

Any help will be much appreciated!

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Untoldecay · Apr 01, 2019 at 01:57 PM

Hey @celsodantas , I'm pretty new to unity and VR, and I'm also trying to build a system portal in VR ( on oculus go ). I started with the brackey tutorial on the subject, trying to adapt it.

I'm using the shader he provides in the description, you'll may be find the ressource interesting.

Anyway, I have the same image distorsion problem. In my case, everything aline perfectly in the game view / no distorsion, but ones in the headset the portal image is totally distorded.

Here's a view from the game view http://untoldecay.com/gif/GameView.gif

And here is a view from the headset http://untoldecay.com/gif/goView.gif

Did you found a solution?

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
avatar image
0

Answer by avandenberg · Mar 03, 2020 at 04:52 PM

Hey man, did you manage to figure this out? I would love to know the solution aswel! @celsodantas

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
avatar image
0

Answer by diegodaly · Jan 11, 2021 at 03:35 PM

I'm also looking for this solution! If anyone can guide us please.

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

164 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

Related Questions

Unity 5.3.1p3 - Viewports on Render Textures are warped when Virtual Reality Supported is enabled. 0 Answers

Sandy surface for virtual reality 0 Answers

_Time in Image Effects 0 Answers

Fog not working in my own Vertext Shader 2 Answers

Why is it necessary to transform vertex coordinate in vertex shader? 1 Answer


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