CesiumGS / cesium-unreal

Bringing the 3D geospatial ecosystem to Unreal Engine
https://cesium.com/platform/cesium-for-unreal/
Apache License 2.0
937 stars 295 forks source link

Apply texture transformation in UMaterial instead of Native #1315

Closed joseph-kaile closed 9 months ago

joseph-kaile commented 10 months ago

Same as https://github.com/CesiumGS/cesium-unity/pull/385 but in Unreal.

kring commented 10 months ago

@joseph-kaile can you please open a PR for the cesium-native changes as well? It looks like there will be two, one into main and one into v0.27.x.

kring commented 9 months ago

Joseph's code in this PR is solid, but it only applies the texture transform to the "baseColorTexture". I extended it to work with all the other textures, too. And added support for texture rotation, so that I could use @emackey's awesome TextureTransformMultiTest glTF to validate it. It seems to be working well:

image

The occlusion test passes, too, it's just a bit hard to see:

image

(Note that I had to turn off "Static Lighting" in the Project Settings in order to make Unreal render the occlusion texture at all.)

Now that I've worked on this, someone else should review and merge it. It depends on CesiumGS/cesium-native#799 so merge that first.

j9liu commented 9 months ago

This looks great to me @kring. I'm pushing a few commits to fix an unrelated test failure, and also some cleanup in the material graph. (No nodes added or removed, just reorganized for visual clarity).

I have one concern about the image you posted: I'm seeing a discrepancy between the "Sample" normal textures and the transformed ones.

image

It almost looks like the normals are completely reversed from the sample ones, even though they're supposed to be the same. But I wasn't able to verify it myself because I didn't know how to get the glTF into the scene. In the end it does seem like the texture coordinate transformations were correct, and maybe the output is somehow being interpreted wrong, but I'm not 100% sure.

emackey commented 9 months ago

Sharp eyes @j9liu. I'm seeing some similar results in Blender, but not in BabylonJS and others. My initial hunch is that there's disagreement as to whether rotating a normal map also rotates the TBN matrix, or if rotating it just influences the UV coordinates only. This probably needs a bit more investigation and possibly a new sample model to test it. But it seems likely unrelated to this PR.

kring commented 9 months ago

Yeah I think that's even visible in the glTF Sample Viewer @emackey:

image

FWIW, the way I've implemented it in Unreal, KHR_texture_transform affects the texture coordinates only.