• 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 WSWhitehouse · Nov 27, 2021 at 01:42 PM · shaderrenderingvrshadersuniversal

URP Blit Render Feature not rendering in Single Pass Instanced VR

My blit render feature works on the PC outside VR and in multipass rendering. But when rendering the shader in single pass instanced VR the left eye is grey and the right eye is black.

single pass instanced vr

Here is my shader that is being used in the render feature. To keep the shader simple I've removed some code from below and only showing the relevant areas:

       struct Attributes
       {
         float4 vertex : POSITION;
         float2 uv : TEXCOORD0;
 
         UNITY_VERTEX_INPUT_INSTANCE_ID
       };
 
       struct Varyings
       {
         float2 uv : TEXCOORD0;
         float4 vertex : SV_POSITION;
 
         UNITY_VERTEX_INPUT_INSTANCE_ID
         UNITY_VERTEX_OUTPUT_STEREO
       };
 
       Varyings vert(Attributes i)
       {
         UNITY_SETUP_INSTANCE_ID(i);
         
         Varyings o = (Varyings)0;
         UNITY_TRANSFER_INSTANCE_ID(i, o);
         UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
         o.vertex = TransformObjectToHClip(i.vertex.xyz);
         o.uv = UnityStereoTransformScreenSpaceTex(i.uv);
         
         return o;
       }
 
       half4 frag(Varyings i) : SV_Target0
       {
         UNITY_SETUP_INSTANCE_ID(i);
         UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
 
         if (SLICE_ARRAY_INDEX == 0)
         {
           return half4(1,0,0,1);
         }
         else
         {
           return half4(0,0,1,1);
         }
 
       }


Here is the Render Feature code:

 public class RaymarchRenderFeature : ScriptableRendererFeature
 {
   [SerializeField] private RenderPassEvent passEvent = RenderPassEvent.AfterRenderingSkybox;
 
   private RaymarchRenderPass _renderPass;
 
   public override void Create()
   {
     _renderPass = new RaymarchRenderPass(name)
     {
       renderPassEvent = passEvent
     };
   }
 
   public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
   {
     renderer.EnqueuePass(_renderPass);
   }
 }
 
 public class RaymarchRenderPass : ScriptableRenderPass
 {
   private readonly string _profilerTag;
 
   private RenderTargetIdentifier _destination;
 
   public RaymarchRenderPass(string profilerTag)
   {
     _profilerTag = profilerTag;
   }
 
   public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
   {
     RenderTextureDescriptor descriptor = cameraTextureDescriptor;
     // descriptor.enableRandomWrite = true;
     
     cmd.GetTemporaryRT(Shader.PropertyToID("_Destination"), descriptor);
     _destination = new RenderTargetIdentifier("_Destination");
   }
 
   public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
   {
     var camera = renderingData.cameraData.camera;
     var cameraColourTexture = renderingData.cameraData.renderer.cameraColorTarget;
 
 #if UNITY_EDITOR
     if (camera.cameraType is not (CameraType.SceneView or CameraType.Game))
     {
       return;
     }
 #endif
 
     if (!Raymarch.ShouldRender())
     {
       return;
     }
 
     CommandBuffer cmd = CommandBufferPool.Get(_profilerTag);
 
     Raymarch.Material.SetMatrix(Shader.PropertyToID("_CamToWorldMatrix"), camera.cameraToWorldMatrix);
     Raymarch.UploadShaderDataInvoke();
 
     cmd.Blit(cameraColourTexture, _destination, Raymarch.Material);
     cmd.Blit(_destination, cameraColourTexture);
 
     context.ExecuteCommandBuffer(cmd);
     // cmd.Clear();
     CommandBufferPool.Release(cmd);
 
     context.Submit();
   }
 
   public override void OnCameraCleanup(CommandBuffer cmd)
   {
     cmd.ReleaseTemporaryRT(Shader.PropertyToID("_Destination"));
   }
 }

Any help would be much appreciated! If you'd like to check out the rest of the code its available on GitHub: Unity-Raymarching

singlepass-instanced-vr.png (43.0 kB)
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Scene Color Node in Shader Graph not working with Unity's 2D Renderer and URP 5 Answers

Distortion Shader does not render transparent objects (Shader Graph) 2 Answers

Problem with Image Effect shader for Virtual Reality 0 Answers

Unity 2019.3 URP VR [Htc Vive] - post-processing not working properly 0 Answers

Fake Volumetrics via custom bloom 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