ezEngine / ezEngine

An open source C++ game engine.
https://ezEngine.net
MIT License
1.27k stars 170 forks source link

[BUG] Material Editor behaves inconsistent with updating preview #1320

Open RiederAlex opened 1 month ago

RiederAlex commented 1 month ago

Currently working with the MaterialEditor (both with Visual Shader Editor and file based) behaves inconsistent in terms of Saving/Transforming.

The behavior observed is the following when unsaved changes exist on a material:

Expected behavior: Saving does also update the preview or Saving does not update the thumbnail (= does not trigger a transform). In ezEngine.Release.23.12.0 saving did not trigger a transform, so this behavior was consistent.

I've took some time and investigated this issue (as initially though the Material Editor is completely broken).

Back in 0199cb8f4a a change was introduced:

[...] ezAssetTableWriter also takes care of reloading modified resources. Instead of reloading all resources a new dedicated message is sent to only reload a single resource: ezReloadResourceMsgToEngine. Fixes #804 [...]

This means that the ezAssetTableWriter (what is called after Save) now no longer reloads all assets, only the one that was actually changed. However, this now causes issues - as the ezMaterialResource is reloaded (via ezReloadResourceMsgToEngine), but the shader & the shader permutations are not, resulting in this inconsistent state.

Manually triggering a transform pre-save works, as this triggers a thumbnail creation on the engine process, which triggers a "ReloadAllResources" inside ezEngineProcessDocumentContext::HandleMessage.

I did investigate solutions, but I failed to find a fix which seems good (= does not reload all resources, as by the original intend of that change). The main issue from my current understanding is that reloading a ezMaterialResourcedoes not trigger any sort of reload for the ezShaderResource/ezShaderPermutationResource.

Generally speaking I've failed to find a way to reload all shader permutations for a specific shader via code - the only work-around I've spotted would be to do ezShaderManager::PreloadSinglePermutation or implementing PreloadPermutations.

jankrassnigg commented 2 weeks ago

Thanks for the detailed bug report. The material editor always had problems with updating the preview when you use the visual shader feature and add modify the inputs (add or remove textures or other inputs). Probably also in some other cases. In such situations the only way to fix it, is to close the material document and reopen it again. I never had time to look into this further.

Anyway, this may be unrelated to the problem that you are seeing, but it may have happened to you when you assumed "it is completely broken".