turanszkij / WickedEngine

3D engine with modern graphics
https://wickedengine.net
Other
5.86k stars 617 forks source link

Terrain uv mapping performs correct? #839

Closed Wc4ever closed 1 month ago

Wc4ever commented 7 months ago

Have been running some test with terrain, there is a thing I can't understand. Whats the point of mapping like that? debug I did read the code and it dosent seem like a bug, seems like it's done on purpose. But I can't see how it could be used in real game. Also I never saw behaviour like that in other engines. When I trying to use texture with obvious details like rocks they look messy, they appear huge on near distance and they fade away obviously. rocks I assume resolution supposed to go lower but uv mapping have to stay consistent.

turanszkij commented 7 months ago

If I don't do this, then texture tiling in the distance will look extremely bad. I'm curious, do you have a better alternative? This effect is computed in this shader, where the virtual texture tiles are rendered into the atlas: https://github.com/turanszkij/WickedEngine/blob/master/WickedEngine/shaders/terrainVirtualTextureUpdateCS.hlsl#L84 The overscale value will scale the texture tiling based on LOD to increase texture detail close to the camera and reduce tiling in the distance. Let me know if you can improve this.

Nickykun commented 6 months ago

If I don't do this, then texture tiling in the distance will look extremely bad The overscale value will scale the texture tiling based on LOD to increase texture detail close to the camera and reduce tiling in the distance. Let me know if you can improve this.

The huge rocks and grass blades on a mountain looks equally "extremely bad". And the use of patterned is impossible. Is it possible to use a different material on the next LOD iterations? Or generate a texture from a 4x4 texture of a past iteration. This will increase VRAM, however it could be used in real game.

turanszkij commented 6 months ago

This is how it looks like without uv scaling based on LOD, always tiling for max detail: sc_09-05-2024 08-04-38

This is how it looks like constant uv scaling for min detail (1:1 factor texture to chunk): sc_09-05-2024 08-09-02

The current solution is to increase tiling close to camera to max out virtual texture capabilities, but reduce tiling in the distance, which is intentional. Note that the base terrain textures in the Editor are 1024*1024 resolution. If you use higher resolution base textures, tiling will be different, as the it is always computed to map a whole base texture across a whole chunk completely in the distance.

Maybe we should introduce a second "detail" texture map close to the camera, and only blend it in close by, while keeping the base texture tiling constant?

On the other hand, I fixed the flipped texture that is visible on @Wc4ever 's first screenshot.

Wc4ever commented 6 months ago

@turanszkij how you did it, can I recompile shaders on fly some how?)

turanszkij commented 6 months ago

In my first comment I wrote where to modify this effect:

This effect is computed in this shader, where the virtual texture tiles are rendered into the atlas: https://github.com/turanszkij/WickedEngine/blob/master/WickedEngine/shaders/terrainVirtualTextureUpdateCS.hlsl#L84 The overscale value will scale the texture tiling based on LOD to increase texture detail close to the camera and reduce tiling in the distance. Let me know if you can improve this.

Wc4ever commented 6 months ago

@turanszkij No I got it, I mean you got exactly the same screens which leads me you changed the shader without engine reload, or you just serialized the camera position?)

turanszkij commented 6 months ago

Oh I see, when you make changes to the shader source, the Editor will automatically recompile and reload it when the window gets back in focus. You can verify this happening when you open the backlog (Home button), there will be a message posted about shader recompilation. This doesn't work with release builds, for example Steam, you have to do it from a development build.

Wc4ever commented 6 months ago

Just did some research, I think the main problem now there is to much cascades and all of them switching in near distance. Also last lod is to close to mid distance that produce blurry mid distance texture with huge details. tiling_with_distance Actually cascades on near distance not needed here is example of texture scaled x8 it looks fine on near no pronounced tiling. Just use big enough texture, almost every stock let you download 2k textures for surface I think it is good baseline. Снимок1 Also I tested how it works in Space Engineers looks like they use similar approach. They have something like 3-4 cascades in total and first one starts in mid distance also blending is way smoother. Take a look test1 test2 Also scale difference not as huge as we have now(seems like diffrenece x2 or x4 between near and mid distance).

So I think as first steps to tune current approach would be good to reduce number of cascades, rearrange them and may be allow to adjust some setting for example first cascade prescale. Detail material for closeups it is also good idea but seems like more advanced feature to implement.