Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing GLTF files with correct shading #41514

Closed
sorcierlegrand opened this issue Aug 25, 2020 · 14 comments
Closed

Importing GLTF files with correct shading #41514

sorcierlegrand opened this issue Aug 25, 2020 · 14 comments

Comments

@sorcierlegrand
Copy link

I'm trying to export a simple plane with a set of PBR textures from blender 2.8 to godot (v3.2.2-stable, on ubuntu 18.04), here how's shown in blender

and here how's show in godot

I'm ok with a little difference, after all every program is different, but this is unnaceptable.

I know it's not the exporter, because another viewers of gltf files load it correctly, like this on the web

I even tried the same test HDR background for illumination, and doesn't seem to make a lot of difference, this is the shaders that I'm using in blender

the texture set is this one:
https://cc0textures.com/view?id=Tiles058

has color, normals, metallic, roughness, like it should.

This may be a bug, because the glb file exported is correct, or the error would be visible in other gltf viewers, and it's not.

Steps to reproduce:
Download the texture set, make the same material in blender 2.8 as shown in the picture above, export to gltf and import as a new scene in godot

Minimal reproduction project:
qewrqwer.zip

@Zireael07
Copy link
Contributor

Godot has no way to import Blender shaders (our PBR differs from Blender's PBR enough that 1:1 translation isn't possible). Also Godot uses a different channel for normal maps than Blender.

@sorcierlegrand
Copy link
Author

so godot doesn't follow the gltf standard? because in another gltf applications it works just fine.
Even if it's just that, what's the solution? How do I modify the shaders, or the files, so godot can read them?

@Zireael07
Copy link
Contributor

There is no such thing as GLTF standard when it comes to shaders. Every engine (Unity/UE4/Godot/Blender) has its own shaders with their own quirks (e.g. how strong clearcoat is or what it means to have roughness 1). The things that are standard are the meshes and the textures, everything else depends on the engine.

@Calinou
Copy link
Member

Calinou commented Aug 25, 2020

See #40753.

@fire
Copy link
Member

fire commented Aug 25, 2020

Notice that the sky color is making the result very different.

Edited. I think the normal map is incorrect.

Godot requires the normal map to use the X+, Y- and Z+ coordinates. In other words, if you've imported a material made to be used with another engine, you may have to convert the normal map so its Y axis is flipped. Otherwise, the normal map direction may appear to be inverted on the Y axis.

https://docs.godotengine.org/en/stable/tutorials/3d/spatial_material.html

@sorcierlegrand
Copy link
Author

sorcierlegrand commented Aug 25, 2020

Notice that the sky color is making the result very different.

Edited. I think the normal map is incorrect.

Godot requires the normal map to use the X+, Y- and Z+ coordinates. In other words, if you've imported a material made to be used with another engine, you may have to convert the normal map so its Y axis is flipped. Otherwise, the normal map direction may appear to be inverted on the Y axis.

https://docs.godotengine.org/en/stable/tutorials/3d/spatial_material.html

So how to invert the Y axis? On godot? Do I need another software? Do I change something in blender?

@Calinou
Copy link
Member

Calinou commented Aug 25, 2020

So how to invert the Y axis? On godot? Do I need another software? Do I change something in blender?

Godot doesn't have an import flag to invert the normal map's green channel yet. (This will be added by #39202 once it's merged.)

You need to either modify the normal map in Blender somehow, or use third-party software to flip the normal map's green channel only. This can be done in GIMP with the help of the Colors > Components > Decompose... and Colors > Components > Compose... actions.

@sorcierlegrand
Copy link
Author

There is no such thing as GLTF standard when it comes to shaders. Every engine (Unity/UE4/Godot/Blender) has its own shaders with their own quirks (e.g. how strong clearcoat is or what it means to have roughness 1). The things that are standard are the meshes and the textures, everything else depends on the engine.

That's not completely true, altough the rendering is up to the application, the specification (that exists!) says clearly that GLTF follows a right handed coordinates system (+X,+Y,+Z) so godot does not follow the specification when importing it

https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#coordinate-system-and-units

While I do have to use some workaround now, I would think is best to follow the standards and change the behaviour.

@fire
Copy link
Member

fire commented Aug 25, 2020

One proposal is to take the green channel and if it's related to a gltf2 normal texture, it would be uncompressed, negated, rewritten and exported again.

@Calinou
Copy link
Member

Calinou commented Aug 25, 2020

@fire We can enable the Invert Green Channel import flag automatically for normal maps that come from glTF scenes (see my above PR).

@fire fire changed the title Importing GLTF files witch correct shaders Importing GLTF files with correct shading Aug 25, 2020
@christianclavet
Copy link

christianclavet commented Sep 29, 2020

Hi!

The shading seem fine to me, but not the environment reflection. It seem to reflect on UV space and not in world space | screenspace... I could be wrong...
Also, the hardness channel value seem really low, as this material is a mirror. (Value=0) What is the current value in Godot?

Your web GLTF viewer use another environment texture as Blender (Look like a black and white gradient). But the reflection mapping seem correct considering the image.

By the way, the PBR shading model is all based on the Disney Whitepapers. (Blender, Godot, Unreal, etc.) so it should almost be identical.

@fire
Copy link
Member

fire commented Jan 12, 2021

If I use https://hdrihaven.com/hdri/?h=venice_sunset and make it the panorma sky in Godot 3.2 latest beta it looks like this.

image

The normal map appears to be wrong.

@fire
Copy link
Member

fire commented Jan 12, 2021

The proper texture is generated when I deleted the .import file.

new_imagetexture_proper

The improper normal looks like this.

new_imagetexture

This is the cause of the improper shading.

Closing when you reply or when we clear issues.

@fire fire added the confirmed label Jan 12, 2021
@sorcierlegrand
Copy link
Author

sorcierlegrand commented Jan 18, 2021

Confirming, the shading is indeed corrected in the latest beta version (3.2.4.beta6). Everything looks right now.
Sorry for the late reply.

I close the issue or you guys?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants