Texture mapping gLTF <--> Ogre

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
User avatar
spookyboo
Silver Sponsor
Silver Sponsor
Posts: 1141
Joined: Tue Jul 06, 2004 5:57 am
x 151
Contact:

Texture mapping gLTF <--> Ogre

Post by spookyboo »

In gLTF the metalness in a texture is represented by the B channel, while the roughness is represented by the G channel (using a combined texture). How does this map to a metallic and roughness map in Ogre?
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: Texture mapping gLTF <--> Ogre

Post by xrgo »

I also use it like this... but R is roughness G is metalness, sadly I just had to edit the template shaders for it to work, but it would be awesome if that can be integrated in ogre as optional
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Texture mapping gLTF <--> Ogre

Post by dark_sylinc »

You'll have to split them into two textures by loading the texture in an Image, and create 2 Images, then create the two textures based on those 2 images.

In the future I'm planning on optimizing PBS so you can pack individual textures into one texture (at the possible expense of quality in some cases), but this is complex stuff, so it will be a long time before it gets implemented.

For example different arrangements include:
  • Example 1 (I hear Frostbite uses this)
    • 1 RGBA texture
      • R contains diffuse luminance, which is applied on a solid colour defined by the material (i.e. different shades of blue). Alternatively it can contain metalness.
      • GA contains normal mapping
      • B contains roughness
      • This RGBA texture can also be compressed, e.g. using BC3 compression (or the higher quality BC6/BC7 if GPU supports it). Note that compression isn't free; as for example in BC3, the G and A channels are usually used for normal maps (R & B are zeroed out) because they have the best compression quality in BC3. Using R & B channels is possible, but it degrades the quality of the normal map because the compression quality of the G channel fluctuates (BC3 is a lossy format); but this may be solvable with BC7's higher quality compression.
      • This encoding allows to put up to 4 textures into 1; saving GPU RAM, disk space, bandwidth and the number of texture fetches (which leads to higher shader performance).
  • Example 2
    • GA for normal mapping
    • R for roughness
    • This is the same as Example 1, but less taxing on compression.
  • Example 3 (Dishonored 2 uses this)
    • Diffuse BC7
    • Normals BC5
    • Roughness BC4
    • Metalness BC4 (alternatively, Metal + Roughness in the same texture using BC5)
For reference:
  • BC3 is an old RGBA compression format. RGB is 565 (green gets 1 more bit), Alpha is compressed like in BC4
  • BC4 is a monochrome compression format. One channel.
  • BC5 is BC4 with 2 channels.
  • BC7 is a high quality RGBA format supported only by DX11 or newer cards.
  • None of these formats are supported on iOS; iOS has ASTC and PVRTC. ASTC is very powerful and flexible.
However for editing purposes (rather than performance packing) it's usually best to work with separate textures (e.g. uncompressed RGBA for diffuse, uncompressed RG for normal maps, etc).
So Ogre would have to provide an interface to arbitrarily map tex types to textures and channels, or at least provide a set of different efficient schemes to choose from. "Arbitrarily" is difficult, which is why it won't be implemented in the short term.
User avatar
devxkh
Halfling
Posts: 84
Joined: Tue Aug 02, 2016 6:07 pm
Location: Germany
x 12

Re: Texture mapping gLTF <--> Ogre

Post by devxkh »

xrgo wrote: Fri Sep 29, 2017 4:55 pm I also use it like this... but R is roughness G is metalness, sadly I just had to edit the template shaders for it to work, but it would be awesome if that can be integrated in ogre as optional
@Xrgo Would you like it to share? :)
Looks like a blocker for me. I want to directly load gltf files, without manually extracting the textures ...
I can load a gltf 2.0 direclty into a SubMesh with textures now.
But it's still missing the metallness and roughness texture, because gltf is baking them into one texture.
https://github.com/KhronosGroup/glTF/issues/857
Image
My little OGRE engine -> FrankE WIP
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: Texture mapping gLTF <--> Ogre

Post by xrgo »

devxkh wrote: Mon Oct 30, 2017 12:11 am@Xrgo Would you like it to share? :)
would be something like this:
somewhere in pixelshader_ps.glsl

Code: Select all

  vec2 reflectivityValue = vec2(1,1);
  @property( specular_map )
    reflectivityValue = sqrt( texture( textureMaps[@value( specular_map_idx )], vec3(inPs.uv@value(uv_specular).xy, specularIdx) ).xy );
  @end
  @property( !specular_map && roughness_map )
    reflectivityValue = sqrt( texture( textureMaps[@value( roughness_map_idx )], vec3(inPs.uv@value(uv_roughness).xy, roughnessIdx) ).xy );
  @end
(the sqrt its because I am storing these textures in the same array as the diffuse so this corrects gamma)
and in Texture_piece_ps.glsl

Code: Select all

@property( metallic_workflow )
@piece( SampleSpecularMap )
	@property( specular_map )
		float metalness = reflectivityValue.y * material.F0.x; //use the G channel of the sampled value for metalness
...........
@property( roughness_map )
	@piece( SampleRoughnessMap )ROUGHNESS = material.kS.w * reflectivityValue.x; //use the R channel of the sampled value for roughness
ROUGHNESS = max( ROUGHNESS, 0.001f );@end
@end
Post Reply