Siccity / GLTFUtility

Simple GLTF importer for Unity
MIT License
1.02k stars 218 forks source link

URP Shader not working with Unity 2020.3.21f1 #161

Open samekne opened 3 years ago

samekne commented 3 years ago

When importing a .gltf file with the importer, the object is correctly imported into Unity.

The different textures are all set correctly (currently these are the base map (Albedo (RGB)), Normal Map and Metallic Map. The textures are set correctly in the material, but the shader renders everything as pure white. If I create a new material with the standard URP Lit shader and assign all the textures it renders correctly.

I also tried swapping shader from the GLTF URP Shader to the URP Lit shader at runtime. I had to manually assign the Base Map (I'm guessing because URP calls it _BaseMap and GLTF calls it _MainTex) and it also renders fine after this change.

Here is the imported file:

bild

Here is the imported material:

bild

Here is how the model looks in Unity:

bild

Here is how the model looks after the shader swap:

bild

Here is the new shader:

bild

Is there any easy way to fix this? Otherwise I'll write a script that swaps the shader at start but it seems like a very hacky solution.

samekne commented 3 years ago

Update: This seems to be only for meshes that have a set color field. If the meshes don't have this they render normally. See examples here:

bild

Some meshes are rendering properly.

bild

Body does have a color so it doesn't get rendered properly.

bild

Hat doesn't have a color set so it gets rendered properly.

Siccity commented 3 years ago

I don't know why the materials don''t work, but you can override the shaders used in the model import settings

samekne commented 2 years ago

Hey Siccity, thanks for the response! I tried overriding the shader in the model import settings but it crashed Unity (this particular model has 30+ separate skinnedmeshrenderers so maybe thats why). I wrote a simple script to swap all the shared material shaders to the normal lit URP shader (with workflowmode and smoothness both set to 0 and the _MainTex remapped to _BaseMap) and it works fine as a workaround.

samekne commented 2 years ago

Was able to get the importer to use a different shader without crashing Unity, however this solution doesn't work as it doesn't map the base map correctly (when using URP shaders) so sticking with my script for now.