Facepunch / sbox-issues

173 stars 11 forks source link

[Terrain] Odd acne shadows on terrain when shadow cast is enabled #5760

Closed wheatleymf closed 3 weeks ago

wheatleymf commented 2 months ago

Describe the bug

Shadows appear incorrectly on the terrain.

To Reproduce

  1. Create a new blank scene, you can change default rotation values for the built-in directional light object as you wish
  2. Create a new terrain, import any heightmap (2048 / 4096 resolution will probably make this problem more apparent). For the reference, terrain size in my case was 79872 and terrain height 10000. You can try significantly lowers values, this issue will appear anyway
  3. Go to terrain settings tab, and set "Cast Shadows" to "On"
  4. Fly around, try changing light direction, you'll notice this shadow acne that keeps becoming less or more detailed depending on your camera position and rotation.

Expected behavior

This looks like shadows are being cast from terrain's clipmap instead of what you actually see. I am not sure what actually is happening here.

Media/Files

image Heightmap: (16bit / Windows) http://files.smallfi.sh/u/heightmap16bit.raw

Additional context

No response

samzanemesis commented 1 month ago

should be good, still sucks a bit that it fades out early

wheatleymf commented 1 month ago

should be good, still sucks a bit that it fades out early

Shadows look good now, thank you. Though I've just noticed that there might be something else incorrect with terrain shading, it looks like there's no lighting based on normals applied. I've checked the world space normals and it looks like whole terrain is in tangent space, while normally shaders are required to transform normals to world space. Is this correct?

image

To avoid confusion, terrain with worldspace normals on background is just a static prop with different shader that uses same workflow as most other shaders (TransformNormal( material.Normal, i.vNormalWs, i.vTangentUWs, i.vTangentVWs) for transforming and rendering normals.

handsomematt commented 1 month ago

Not sure what you mean, these are tangent and these are world space normals

image image

Maybe you want more control over the normal strength as calculated per fragment?

wheatleymf commented 1 month ago

Ah, I must have been wrong then, my bad. Yeah, that would be nice - currently terrain feels like it's being shaded flat, even near steep slopes. Normals highlighting bumps and terrain relief more noticeably would be great.