Author Topic: Global Snow with Non-Y-Up World  (Read 50 times)

Zer0Sum

  • Newbie
  • *
  • Posts: 12
    • View Profile
Global Snow with Non-Y-Up World
« on: June 01, 2021, 01:43:23 AM »
Hi,

I am currently using global snow in my project, and it is working great.

The problem that I have is that my project is a space simulator with realistic worlds that the player can explore. This means that the players, and the world, orientation is not always y-up, it could be arbitrary.

The snow effects on, say, the south pole, mostly works, except it is inverted, like this:

https://imgur.com/FUVOH4h

You can see that the terrain has no snow, and the animal has snow on the bottom, not the top, because the "world" is now, essentially, inverted.

I should have checked this earlier, but is it possible to modify the world up in the snow script, or shader, to handle an arbitrary value?

I took a look myself and couldn't find anything obvious, so I thought I'd ask here.

Thanks!

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 7103
    • View Profile
Re: Global Snow with Non-Y-Up World
« Reply #1 on: June 01, 2021, 10:56:29 AM »
Hi,

Yes, Global Snow is designed for the usual world scene where the terrain is flat.

There're a few areas that should be modified in order to make it work with a 3D spherical world:

1.- The snow occlusion is implemented through a zenithal camera that makes snapshots of the terrain heightmap around the camera. The position of this camera is always above the camera pos, so the position and rotation of the camera should take into account the spherical geometry of the world so it looks to the center of the world and is displaced outside of the center and not just above the camera pos.

2.- In the snow shaders, the occlusion map captured in the previous step is compared to the world position y-pos of each pixel rendered on the screen. This comparison should not only take into account the different in vertical axis but the distance to the surface in x,y,z.

You could disable zenithal occlusion test and make everything get covered by snow although that will also affect objects under roof or inside buildings.

3.- There're other aspects like altitude blending or minimum height which controls where the snow can be rendered. In the shader, those comparisons should consider the x,y,z distance to the surface and not just the vertical distance.

4.- The raytracing loop in the shader assumes the ground is flat. I think this can also cause visual artifacts when rendering the snow vertically (ie. not on the North or the South but around the equator). This can be trickier to solve. To avoid these artifacts the "Flat" instead of Normals or Relief mapping mode should be used in the Snow Appearance section.

This is only an idea as I can't anticipate other potential issues with other options like the footprints.






Zer0Sum

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Global Snow with Non-Y-Up World
« Reply #2 on: June 02, 2021, 03:16:59 AM »
Hi, Thanks for your reply.

That seems somewhat encouraging, it seems to be more or less "possible", at least, to make it work.

Since my planets are a realistic size, they are, effectively, "flat". Any issues caused by the actual curvature of the surface would be imperceptile to the player. So, that simplifies some of the work.

I really just need to adjust the orientation, so, point 1, point 2, and possibly point 3 below.

Do you have any pointers as to where exactly I would need to look to start modifying these?

Thanks!

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 7103
    • View Profile
Re: Global Snow with Non-Y-Up World
« Reply #3 on: June 03, 2021, 01:43:09 PM »
In deferred, look for the SnowOverlay.cginc file. It contains all the snow rendering shader code. Look for the USE_ZENITHAL_DEPTH macro in that code, you will find the snowCover and some references to "_GS_SnowCamPos.y" as the y-pos of the camera. This position is passed from the GlobalSnow.cs script.
Also "minAltitude" in that shader code section where _GS_SnowData6.z contains the altitude blending parameter. You should also change all of that so it uses the distance to surface and not just the y-pos.
This is a start I hope.




Zer0Sum

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Global Snow with Non-Y-Up World
« Reply #4 on: June 04, 2021, 04:57:19 PM »
Excellent, this helped me a lot, I think I am on the right track! Thanks for your help!

Zer0Sum

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Global Snow with Non-Y-Up World
« Reply #5 on: June 04, 2021, 07:12:45 PM »
I've run into a slight snag with this.

It seems that the cricial value is "wsNormal", but I don't know how I can change this from globalsnow.cs.

It seems to be set here:

         float3 wsNormal = tex2D(_GS_GBuffer2Copy, i.uv).xyz * 2.0 - 1.0;

But I can't make sense of how to change that in script (To take a custom vector).

Could I manually add a vector3 to the shader, and modify that from script?

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 7103
    • View Profile
Re: Global Snow with Non-Y-Up World
« Reply #6 on: June 05, 2021, 01:20:14 PM »
That's wsNormal is the normal in world space for every pixel in the screen. It' used to determine if a pixel is on an horizontal surface or on the slope of a hill for example or pointing down in the case of a roof.
Why would you want to pass a single normal for all pixels from a script?

Zer0Sum

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Global Snow with Non-Y-Up World
« Reply #7 on: June 05, 2021, 06:57:09 PM »
Ahhh I see. I thought that was the actual world normal of the camera, IE, the orientation.

Zer0Sum

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Global Snow with Non-Y-Up World
« Reply #8 on: June 08, 2021, 03:05:17 AM »
I am still having issues with the orientation of the snow.

I have managed to make the zenith camera show in the editor, and I can move it to the correct position (IE, above the player, which should change depending on the players orientation).

However I am still having issues modifying the shader code in Snowoverlay.cginc.

the WSNormal is the world space normal of the pixel, so I don't need to modify that, I am assuming.

But the other values seem like the should be correct as they are, but I don't notice any difference when I change the position or rotation of the zenith camera.

I think I am gaining a bit of an understanding into how the code works, but I am still not sure what to change in the actual shader.