KhronosGroup / glTF-Sample-Models

glTF Sample Models
3.13k stars 1.31k forks source link

Normal texture TestMap_blur.png does not conform to the glTF 2.0 spec #364

Closed erich666 closed 11 months ago

erich666 commented 2 years ago

I thought this was an issue with the glTF 2.0 spec itself, but the problem is simply that the normal texture TestMap_blur.png is poorly formed. There are a few of these PNGs used in this repo. They should be replaced with a proper texture, to avoid confusion (I certainly was confused to see it).

See https://github.com/KhronosGroup/glTF/issues/2223 for the full explanation and a possible replacement texture (one that is properly scaled in the blue, Z, channel).

Short version is that it maps blue [0.0 .. 1.0], not blue (0.5 .. 1.0], to z [0 .. 1]. For example, pixel 394,303 has a triplet of (242,89,82) - the blue value is too small, because they're using the wrong mapping. The spec is specific on this point:

Normal textures SHOULD NOT contain blue values less than or equal to 0.5.

The triplet is valid if mapping the whole range of blue values to z [0 .. 1], but that's not what the spec requires.

Here's a full analysis of this triplet. It's easy to convert with both mappings and see if the value (242,89,82) uses one of them.

Assuming blue (0.5 .. 1.0]: Vector 242 89 82 converts to 0.898, -0.302, -0.357 length was wrong at 1.012

Assume blue [0.0 .. 1.0] (which is the wrong mapping, not what glTF requires): Vector 242 89 82 converts to 0.898, -0.302, 0.322, length 1.001

Clearly this triplet is using the wrong mapping. When converted, it gives a vector of length 1.001 using this mapping, showing that this mapping is the intent of the texture.

erich666 commented 2 years ago

I made a replacement TestMap_Normal.png file, attached below.

Copied from https://github.com/KhronosGroup/glTF/issues/2223: Using NormalMap-Online, I negated the TestMap_blur.png image, negated the red channel (always needed), and set the z-range from -1 to +1 in the tool, then output.

Assuming Z ranges from -1 to 1: Vector 242 89 169 converts to 0.898, -0.302, 0.325, length 1.004

This compares well with the original range - see above.

This texture's Z values are properly in the -1 to +1 range, unlike the current versions in glTF-Sample-Models. I tested on the model TextureTransformMultiTest.gltf in directory glTF-Sample-Models/2.0/TextureTransformMultiTest/glTF with two viewers, Omniverse Create's and Windows' 3D Viewer. The results seemed reasonable. Replacing the same file in glTF-Sample-Models/sourceModels/TextureTransformMultiTest, the file TextureTransformMultiTest.blend looks reasonable in Blender.

TestMap_Normal

DRx3D commented 11 months ago

@emackey @lexaknyazev : Is this still an issue? Should it be transferred or closed?

If there is no response to this comment by 27 Nov, then this issue will be closed.

lexaknyazev commented 11 months ago

This issue should be closed. See https://github.com/KhronosGroup/glTF-Sample-Assets/issues/41#issuecomment-1817221967.

DRx3D commented 11 months ago

Closing per recommendation from @lexaknyazev