[HLMS] manually creating datablock and using textures loaded from array of bytes Topic is solved

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


Post Reply
User avatar
Ybalrid
Halfling
Posts: 89
Joined: Thu Jul 10, 2014 6:52 pm
Location: France
x 31
Contact:

[HLMS] manually creating datablock and using textures loaded from array of bytes

Post by Ybalrid »

Hi!

I'm currently in the process of writing a small glTF importer based on tinygltf, mostly for fun, and the flexibility that the format (seems to) offer. :-)

I'm at the point where I'm loading meshes correctly, so I'm now tackling loading materials.

tiny_gltf loads the images for you using stb_image, and provide you with a simple array of bytes and the relevant metadata (number of channels, width, height, stuff like this).

workflow is set to

I figured out that I could load this data into an Ogre::Image object this way with Image::loadDynamicImage, then creating a texture (TextureManager::createManual) and feed it that object:

Code: Select all


	Ogre::TexturePtr OgreTexture = textureManager->createManual(name,
		Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		Ogre::TextureType::TEX_TYPE_2D, image.width, image.height,
		1, 1, pixelFormat, Ogre::TU_DEFAULT
#ifdef DEBUG_TEXTURE_OUTPUT
		| Ogre::TU_RENDERTARGET
#endif
	);

	OgreTexture->loadImage(OgreImage);

#ifdef DEBUG_TEXTURE_OUTPUT
	//This was for debug, for that line to work you nee dthe texture to be declared with "texture usage render target"
	OgreTexture->getBuffer()->getRenderTarget()->writeContentsToTimestampedFile(name, ".png");
#endif

the DEBUG_TEXTURE_OUTPUT macro just add the TU_RENDERTARGET flag in order to write the content of the texture to disc, to debug if anything goes wrong. When set, I see the good textures beein written to files, so I assume the texture is properly loaded at this point.

The problem I'm having is when creating an HlmsPbs datablock. I can create one and set every parameters I want by code (color, metalness, roughness... All that jazz)


Image
Image

The problem I'm having is when I attempt to set a diffuse texture to my datablock, I'm getting a full black output, that is quite odd:

Code: Select all

		
		datablock->setTexture(Ogre::PbsTextureTypes::PBSM_DIFFUSE, 0, texture);
Image

I tried to solve the problem by myself, but I'm running out of ideas ^^"

It looks like I'm doing something that makes the generated pixel shader just output black pixels, but I don't really know where to look at this point.

Somebody know what I'm doing wrong here? ^^"
Ogre_glTF Ogre v2-1 GLTF2 loader : topic link github repo
BtOgre21 Fork of btOgre, for Ogre v2-1 : topic link github repo
OIS Current maintainer : Official repository
Annwvyn VR focused game engine using Ogre : https://github.com/Ybalrid/Annwvyn https://annwvyn.org/
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: [HLMS] manually creating datablock and using textures loaded from array of bytes

Post by dark_sylinc »

Create your texture as TEX_TYPE_2D_ARRAY. PBS does not support non-array textures (except for the environment map which must be a cubemap)
User avatar
Ybalrid
Halfling
Posts: 89
Joined: Thu Jul 10, 2014 6:52 pm
Location: France
x 31
Contact:

Re: [HLMS] manually creating datablock and using textures loaded from array of bytes

Post by Ybalrid »

dark_sylinc wrote: Mon Jan 01, 2018 9:47 pm Create your texture as TEX_TYPE_2D_ARRAY. PBS does not support non-array textures (except for the environment map which must be a cubemap)
Oh s***, now that you tell me this, I think I remember that detail...
Image

So it's working fine right now, thanks alot!

While I have you on hand, what's the best stategy to use a metallic-roughness map. as far as I understand they pack both information into a single texture in the R and G channels. I don't think Ogre support that out of the box.

Should I split that into 2 grey scale maps or is there a better option?

PS: Happy new year Matías! Thank you a lot for answering all my silly questions while I'm messing around with the 2.x branches ;-)
Ogre_glTF Ogre v2-1 GLTF2 loader : topic link github repo
BtOgre21 Fork of btOgre, for Ogre v2-1 : topic link github repo
OIS Current maintainer : Official repository
Annwvyn VR focused game engine using Ogre : https://github.com/Ybalrid/Annwvyn https://annwvyn.org/
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: [HLMS] manually creating datablock and using textures loaded from array of bytes

Post by dark_sylinc »

Ybalrid wrote: Mon Jan 01, 2018 9:58 pm While I have you on hand, what's the best stategy to use a metallic-roughness map. as far as I understand they pack both information into a single texture in the R and G channels. I don't think Ogre support that out of the box.

Should I split that into 2 grey scale maps or is there a better option?
Yup. At the moment splitting them into two greyscale maps is the only option.
Ybalrid wrote: Mon Jan 01, 2018 9:58 pmPS: Happy new year Matías! Thank you a lot for answering all my silly questions while I'm messing around with the 2.x branches ;-)
Thanks! Happy new year to you too!
User avatar
Ybalrid
Halfling
Posts: 89
Joined: Thu Jul 10, 2014 6:52 pm
Location: France
x 31
Contact:

Re: [HLMS] manually creating datablock and using textures loaded from array of bytes

Post by Ybalrid »

Just thought about that: shouldn't the setTexture() method of HlmsPbsDatablock assert (in debug builds) that the texture is in a compatible type, by testing newTexture->getTextureType() against TEX_TYPE_2D_ARRAY (if texture is not reflection) like the other overload does?
Ogre_glTF Ogre v2-1 GLTF2 loader : topic link github repo
BtOgre21 Fork of btOgre, for Ogre v2-1 : topic link github repo
OIS Current maintainer : Official repository
Annwvyn VR focused game engine using Ogre : https://github.com/Ybalrid/Annwvyn https://annwvyn.org/
Post Reply