Unity, skydome and far clipping

I'm developing for movil VR, so performances are a must here.

Any good practice for VR is written to avoid skybox unity and use skydomes instead. I created a dome in blender with its texture and all that.

I import the dome as fbx, apply Mobile / Unlit shader and texture image, it looks great.

My problem is when the game starts, the dome goes out of the clipping plane. Parameters:

  • Setting up a large clipping plane, this results in a lot of material that I would like to clip without getting clipped.
  • Install some kind of two pass render, I didn't even try, the overhead sounds are terrible.
  • Set the clipping plane high and then set the culling one layer below for everything else that works but introduces a resolution issue since the "action" is actually near the player.

I haven't tested, but I'm pretty sure that for a dome in VR, we can go with one render as the background, the same for both eyes (since it's in infinite and shouldn't be parallax.


I did this by adding a second chamber Clear Flags: Depth only

, culling mask only DomeLayer

and actually move the camera to the DomeLayer

main camera (with googleVR demo scene) is set to Clear Flags: Don't clear

, discarding the mask onEverything but DomeLayer

And it seems to work, but

  • There is de-sync between both cameras. enter image description here Notice the angle of the small first cone (main camera) and the direction of the larger outer cone (dome camera), by the way, I cannot set the camera as a child of the left or right cameras, because they don't exist before I start the game.

  • The overhead of switching the second camera to view is impressive. enter image description here I turned off the dome camera, let it run a little and turn it back on, notice the SetPass and any other metrics. The impact of the second chamber is ugly.

I am running on a laptop that does not have a dedicated graphics card, but still, there is an overhead and the thing is designed to work on a mobile device.

Am I doing something wrong?

+3


source to share


3 answers


Just use two cameras, the first will display all of your environments, and the second will only display for your dome. Just change what each camera will display with the following steps:

1) First camera: set the tag as MainCamera , then options clear flags: do not clear and Culling Mask: Mixed ... (select every layer except DomeLayer

)

2) Create a new layer called DomeLayer

3) Create the second camera as the child of the first camera, then set the parameters: Clear flags: depth only and Culling Mask: DomeLayer . Also the parameter of the second camera Depth

must be -1

4) Then place the Dome object on DomeLayer

and every other object on any layers exceptDomeLayer



Here is a screenshot of an example scene:

First camera: enter image description here

Second chamber (child of the first chamber):

enter image description here

This way you can adjust the clip plane on your dual camera separately without losing performance.

+2


source


Add a new camera for your skyDome and follow these steps



  • Make sure the camera for the skyDome does not have a mainCamera tag.
  • create a new layer skyDome.
  • Change this camera's layer to skyDome.
  • Change the skyDome mesh layer to skyDome.
  • Set the Clear flag of this camera in the Skybox.
  • Set this camera's drop mask to the skyDome layer only.
  • Set the Clear flag only for the main camera for depth only.
  • Set the drop mask of the layer to everything else than skyDome.
+2


source


You can accomplish this with some shader tricks and a single camera.

Create a new unlit shader.

Set the RenderQueue of the rendering material after the geometry. This will reduce redundancy. https://docs.unity3d.com/Manual/SL-SubShaderTags.html

Try

"Queue"="Geometry+1"

      

Disable Depth Recording (Zwrite Off) - This saves performance and prevents your skydome from clipping any transparency.

Enable Depth Check (ZTest LEqual) - This will prevent other geometry from closing your skysphere.

In the vertex shader, you can create the illusion of a skysphere at "infinity" by scrolling the plane of the near / far clip.

Proj Mat [2][2] = -(far+near) / (far - near)
Proj Mat [3][2] = -2*far*near / (far - near)

      

http://www.terathon.com/gdc07_lengyel.pdf

float4x4 newMat= UNITY_MATRIX_P;
newMat[2][2]= -(1001.0/999.0);
newMat[3][2]= -2*1000.0/999.0;
v.vertex.xyz *= 100;
v.vertex = mul(UNITY_MATRIX_V,v.vertex);
o.vertex = mul(newMat,v.vertex);

      

+2


source







All Articles