Anatta336 / driven-decals

A mesh-based PBR decal system for Unity's universal render pipeline.
MIT License
576 stars 75 forks source link

Decal Asset Inspector issue #5

Open smoothblur opened 3 years ago

smoothblur commented 3 years ago

Hello,

I'm not getting any errors but in the decal asset inspector the inspector UI element that shows the texture and the region defined for the decal is solid black and no highlighted texture region is visible.

Clicking and dragging on the UI does update the min/max values but there is no visual update.

Unity version 2020.1.9f1 - URP Version 9.0.0-preview.72 - Any thoughts?

Thanks!

smoothblur commented 3 years ago

Tried rolling URP back to 8.2.0 and same issue. Switched back to 9.0.0-preview and the Decal Asset inspector actually worked for bit and then started drawing black again.

smoothblur commented 3 years ago

After some further digging it seems like the issue is related to Source Control. I'm using Plastic SCM and have various file types setup as lockable and the Unity Library Folder is ignored. (Packages are located in the package cache folder in the Library) Thus the Decal Asset Inspector can't access the materials in the "Packages/com.samdriver.driven-decals/Editor/Resources/" folder that it uses uses to draw the decal region in the inspector.

For now I'm just moving the package files into my projects Asset Folder and updating that path in the Decal Asset Inspector script. Given that Unity now owns Plastic SCM Im guessing other users would end up with the same problem eventually.

smoothblur commented 3 years ago

Something is wonky in DecalAssetInspector with the call to:

EditorGUI.DrawPreviewTexture(previewRegion, previewTexture, overlayBoundsMaterial);

Definitely seems buggy/broken in Unity 2020.1.x. I tried updating to the latest version of Unity 2020.1.11f1 and its still not working properly.

If I take the OverlayBoundsMaterial and add it to a mesh in the scene when I select decal assets in the project I can see that the material is updating to show the decal atlas and the selection region properly. But the inspector only draws a black rectangle. If I remove the custom material from the DrawPreviewTexture function call the base texture then shows up in the inspector, but the selected region is obviously not drawn to the preview with out the material parameter.

I setup a fresh project in Unity 2020.1.11 and added Drawn Decals to it. The asset inspector texture view was working, then stopped working and then started working again. My larger Unity project is at least consistently just drawing a black rect.

I tested making my own custom inspector window with a call to EditorGUI.DrawPreviewTexture() using both the OverlayBoundsMaterial and simpler custom unlit shader. Both attempts resulted in a black rectangle. So it seems like there is a bug with custom materials and the use of EditorGUI.DrawPreviewTexture() in Unity 2020.1.x. I'm trying one last effort to figure out if its related to some other asset in my project or purely a bug in Unity, or SRP, or URP, etc.

Anatta336 commented 3 years ago

Hello, Thanks for the detailed report. Just to confirm are you seeing the fault in Unity 2020.1.11 with the standard 8.2.0 URP? I've not managed to reproduce it yet, but still waiting on some downloads to finish so I can properly recreate your situation.

There's a couple of possible causes that I'll look into. I think DecalAssetInspector handles the material incorrectly, causing the material asset itself to be modified. That was always a bit messy, but now Unity might be picking up on that and breaking things. More generally the URP may not be designed for a Unlit master node to be used for rendering a random bit of in-editor UI, so I may need to swap out that for a traditional shader.

Thanks again for the report. I'll hopefully be back soon with a reproduction.

smoothblur commented 3 years ago

Yes, its happening in 2020.1.9, 2020.1.11 and I'm just about to try 2020.1.12. I've tried URP 8.2.0 and URP 9.0.0 preview, same issue. I'm also still trying to make sure that nothing in my project is causing problems. But I've had it happen in a clean project also. Sorry for the multiple posts, just trying to isolate the issue reliably. Another person using my same project over source control sees the same issues so its definitely Unity or Project Asset related.

smoothblur commented 3 years ago

Tested in clean 2020.1.12f1 project, no source control, no other 3rd party assets, URP 8.2.0. Decal asset inspector draws black. Initially it did work but it stopped working and went to drawing only black while I was testing. Tried it both as a package and as local asset. Seems like its probably a bug in Unity with EditorGUI.DrawPreviewTexture() when using a custom material.

smoothblur commented 3 years ago

I can post of video of the issue if that helps at all. Let me know.

Anatta336 commented 3 years ago

Sorry for the rather slow "soon."

I've not been able to reproduce the error yet. Unity 2020.1.12f1, URP 8.2.0 in a fresh project with the decals being the only added package. As it's seemingly a rendering problem it may be that it's hardware dependent, although your colleague also having the issue brings that into some doubt. I'm using an AMD R9 290 for what it's worth.

Regardless, I've tried to fix it! On the 0.8.0 branch DecalAssetInspector now works on a copy of the material asset it uses rather than messing with the stored one. It's a bit of a long shot. But you can try installing this branch through the package manager, remove the current Driven Decals package and add https://github.com/Anatta336/driven-decals.git#0.8.0

Edit to add: That branch also moves the sample decals out of the main package, so you'll need to selectively install the "Fasteners" sample if they're being used to test.

smoothblur commented 3 years ago

I will test that out and see how it looks. Hardware wise I'm running it on my RTX 2080. Thanks.

smoothblur commented 3 years ago

Still having the same issue in with the 0.8.0 branch. Trying a few things on my and will report back.

Anatta336 commented 3 years ago

Thanks for the update. I'm increasingly thinking that (as you said earlier) it's a problem with EditorGUI.DrawPreviewTexture() either in general, when using custom shaders, when using custom shaders made with the shader graph editor, and probably with a certain system configuration.

I still haven't managed to reproduce it on my machine, but I have had someone else report seemingly the same issue.

smoothblur commented 3 years ago

Seems to be working fine so far in Unity 2020.2. Doing a bit more testing to confirm that there are no other issues.

Based on that it indeed seems to be a bug in Unity 2020.1 when using custom materials/shaders with EditorGUI.DrawPreviewTexture().