Moonflow-Studio / Moonflow-Lensflare-System

■■Finished■■ Unity full pipeline multi light source lens flare rendering scheme based on atlas
MIT License
134 stars 19 forks source link

Z-distance for VR headsets #8

Open PaulTapper1 opened 3 years ago

PaulTapper1 commented 3 years ago

Hi

Thanks for making this.... lens flares not working in Universal RP is a real problem.

I am trying to get this working in my Oculus Quest 2 VR project. At the moment URPLensFlare.cs has DISTANCE = 1f; which means that it draws as if its very close to my head (so my eyes have to focus right in to see it). If I set DISTANCE = 3000f; then the two viewpoints of my eyes see it correctly as something focussed in the distance, but now it draws behind objects in the scene.

Do you know if other users are using this in a VR project?... how do I make it appear at the correct distance for the two viewpoints, but not get Z-tested away by objects in the scene?

Thanks for any help

Paul

Reguluz commented 3 years ago

Hi, I'm so sorry for that. For I don't have any VR development kit, I can't be sure that if this solution will run correctly on VR project. And I have never thought about making adaption. However, I think you could close the ZTest function of the material you use for rendering flares. I've just updated an example material with a new shader. This shader is copied from ParticleUnlit shader inside URP package. For I need to show the custom property, I have close the original editor of this shader(but the properties are the same). I added ZTest option and set it on "Never" option as default. Maybe you can trying this shader to solve your problem(I'm really not sure if it will effect or not). I'll waiting for your feedback.

Reguluz commented 3 years ago

And you can contrast this new shader with the original version to find the code I have added. If this methods can solve your problem, you can do the same change for any shader you will used for rendering flares.

PaulTapper1 commented 3 years ago

Hi Reguluz

I Pulled your latest code and tried it. Unfortunately it doesn't seem to have disabled the z-test :( . If I draw the flares at DISTANCE = 3000; they still z-sort behind objects in the scene.

I've actually decided against Universal RP for our project for now anyway, due to performance issues, so please don't spend any more time trying to fix it for me, but I guess it could be a useful thing to fix for other possible users. You could probably reproduce the problem easily yourself by just setting DISTANCE = 3000; and checking it aren't getting z-tested.

Thanks for trying.

Paul

Reguluz commented 3 years ago

Hi Reguluz

I Pulled your latest code and tried it. Unfortunately it doesn't seem to have disabled the z-test :( . If I draw the flares at DISTANCE = 3000; they still z-sort behind objects in the scene.

I've actually decided against Universal RP for our project for now anyway, due to performance issues, so please don't spend any more time trying to fix it for me, but I guess it could be a useful thing to fix for other possible users. You could probably reproduce the problem easily yourself by just setting DISTANCE = 3000; and checking it aren't getting z-tested.

Thanks for trying.

Paul

Oh, I'm so sorry that this solution based on rendering billboard typed mesh on the scene, and the DISTANCE property set the real distance between the mesh and your camera. I designed it for non VR situation so the distance of lshould be a bit more far from "near clip plane". Though I don't have any VR equipments, I'm sure that there will be some solution by changing shader settings to solve your question. Maybe you could think about using stencil to force render flare meshes in front of any other game objects. And this lens flare render system don't requires any special usages of different render pipeline, so it could be rendered correctly in any render pipeline.You can still have a try