LGhassen / EnvironmentalVisualEnhancements

Visual enhancements including clouds, lights, etc.
79 stars 9 forks source link

Clouds get clipped when using ThroughTheEyes/VR #24

Closed JonnyOThan closed 2 years ago

JonnyOThan commented 2 years ago

ThroughTheEyes uses a closer near/far plane for the localspace camera, and VR brings it even closer. This results in the clouds getting clipped when in low orbit: image

At about 160km altitude (760km SMA) the clouds seem to fully transition to a scaled space version.

The near plane changes are crucial to how those mods work, and if the far plane isn't also brought closer then you get lighting artifacts.

Is there any way these clouds could always be rendered in scaled space when you are outside the atmosphere? If you can point me where to look in the code I could try it out myself. Thanks!

OK, I see Clouds2D.Scaled - digging in there.

LGhassen commented 2 years ago

If you render the clouds in scaledspace too early, the local terrain will render in front of them, as it becomes semi-transparent when transitioning to scaledSpace. Rather than doing this I would just transition the whole planet to scaledSpace early.

Why is changing the near/far plane so crucial? Maybe we can find another solution to avoid changing the clipping planes? And what are the new values of the clip planes? I'm guessing you are bringing the near plane closer but other parts of the game break if you don't bring the far plane closer too?

LGhassen commented 2 years ago

Alternatively you could also make the clouds always render in scaledspace but don't render over areas which would be in the local camera's view. Just figure out in the scaled cloud shader if the current fragment is within the local camera's clip planes (after the correct transformations) and exit early.

JonnyOThan commented 2 years ago

With ThroughTheEyes, you can see the inside of your helmet - so the near plane has to be at least as close as that geometry. It uses 0.1 by default (stock game is 0.21). And then in VR you can move your head around inside the helmet, so you're able to get the camera much closer - it sets the near plane to 0.02, but I think I can push that out to 0.04 or so. ThroughTheEyes will keep the same far/near ratio as stock, because otherwise you get flickering shadows and other lighting artifacts.

I suppose it might be possible to render the kerbal helmet with a separate camera, on top of everything...I guess this is exactly how IVA mode works.

What altitude does the planet fully transition to scaled space? Where is that controlled?

JonnyOThan commented 2 years ago

I'm experimenting now with shifting the kerbal to the IVA layer and using the InternalCamera instead, while leaving the flight camera's near/far plane distances intact. Seems to be going well, and probably less hairy than messing with planet rendering.

LGhassen commented 2 years ago

Oh that's very nice, yeah that does seem like a good solution.

I think you don't need it anymore but to answer your question there are variables per planet that control when the fade to orbit starts and when the switch to scaledspace is done. pqsDeactivateAltitude I think and something like scaledSpaceFadeStart, the folks that make planets with Kopernicus know them very well.