Oculus-VR / Unity-Graphics

Unity Graphics - Including Scriptable Render Pipeline
Other
66 stars 50 forks source link

Not working when changing shader at runtime with App SpaceWarp #4

Open smitdylan2001 opened 2 years ago

smitdylan2001 commented 2 years ago

I have a cross platform game I want to add spacewarp support to on quest. I use custom shaders which don't support motion vectors, so in Awake I change the shader to the Lit (also tested Simple Lit) shader and added the main tex to the material again. If I do this there is a LOT of issues. Objects seem to have a link to their original position and have weird artifacts between them as if the object exists on start position, end position and everything in between at the same time.

smitdylan2001 commented 2 years ago

I tried both doing it in Awake and have the same issue if I do it with callback while building https://docs.unity3d.com/ScriptReference/Callbacks.PostProcessSceneAttribute.html

tsaileo1 commented 2 years ago

Hey, I'd recommend adding the motion vector pass to your custom shader instead of swaping the shaders at runtime. That might be easier and cause less issues. Try looking at how the motion vector pass is added in the Lit shader and you can do the same or something similar in your custom shader.

smitdylan2001 commented 2 years ago

Hey, I'd recommend adding the motion vector pass to your custom shader instead of swaping the shaders at runtime. That might be easier and cause less issues. Try looking at how the motion vector pass is added in the Lit shader and you can do the same or something similar in your custom shader.

Sadly no one in our team is skilled enough to do this, at least not next to all other work. The shaders are made in amplify, and they become quite complex behind the scenes. If it's not as hard as it seems I wouldn't mind trying, but doubt it will go great. Sadly the amplify team couldn't help me further either, as they don't have great support for custom render pipelines.

P.S. the callbacks I mentioned in my reply should change the shaders at runtime, so that should have worked, and this would be a good thing to look into in general as some games do change shaders or materials at runtime, which now could cause issues.

tsaileo1 commented 2 years ago

How are you enabling space warp? Are you calling OVRManager.SetSpaceWarp()? Another question I have is if you're trying to switch the shader on awake, why not have it as the Lit shader starting off? Is there something preventing you from having the object with the Lit shader on it initially?

Unfortunately, I'm not to familiar with amplify. I could help investigate a bit to see how the shaders are built under that system.

smitdylan2001 commented 2 years ago
  1. i think so? I was using a sample project to start with: https://github.com/nukadelic/unity-application-spacewarp/ and added in my materials/sjaders from my main project. There is a button which sets spacewarp true or false.
  2. The regular game uses custom shaders with a combined texture map for specular, roughness, etc. This costs extra vram and performance and for the quest we wanted to get it working with jist the maintexture for performance reasons.
tsaileo1 commented 2 years ago

Ah, I was talking to nukadelic in the other issue they posted here. There was a bug in how that sample project was enabling space warp. Try updating the sample project to see if it has been fixed. If not you can see what we discussed here to fix it: https://github.com/Oculus-VR/Unity-Graphics/issues/3

I see you have a cross platform game to uses one shader type for like PC and you want a lighter variant for Quest. I would recommend seeing if space warp is being turned on properly first and seeing if your script still works in switching the shader.