Jump to content

How can I force upload of Material and Mesh data at creation time.


photo

Recommended Posts

Hi there,

we are using ObjectMeshStatic and create meshes on the fly from our own format on cpp side.

The materials are also generated on the cpp side and assigned to the ObjectMeshStatic object.

When unigine starts rendering and I change the view direction, the application hangs for some time.

When I did a complete 360 degree manual turn it is fine.

It seems that unigine is not uploading the data to video memory on creation.

How can I force the upload for meshes, materials ,shaders and images loaded by cpp code to stop uploading on demand?

Best regards,

Sebastian

Link to comment
  • 2 months later...

Hi unclebob,

sorry for the late response, just managed to try it out last week.

The ObjectMeshStatic::flushMesh function seems to work only for meshes, as long as I don't overwrite the base material with setMaterial, spikes are not really noticeable.

I didn't see any changes as i updated the render_manager_create_* settings.

I did two screenshots one before turning the viewpoint and one after. You can clearly see the big spike and texture memory will increase after that.

I am running with a 1080 TI on my system now, so Hardware Performance should not be a bottleneck and Unigine version 2.6.1.

Do you have any other ideas to force texture upload?

Seems like you allready have some similiar topic on this.

"https://developer.unigine.com/forum/topic/3241-preload-caching/"

Best regards Sebastian.

render_manager_settings.PNG

spike001.png

spike002.png

Edited by sebastian.vesenmayer
Link to comment

Hi Sebastian!

Are you sure it's related to textures? It looks like a shader compilation hiccup to me. If you're creating new material at runtime, you can warm it up by calling Material::createShaders. Please note that this call will only create shaders for current material states combination and not for all, obviously because there might be millions of combinations. So it's better to call this after you setup all required textures, paremeters and states to material.

Another idea might be to render all nodes before the start to warm up every engine subsystem. You can do it either by calling Viewport::renderNode or just place the node in front of the camera in the world.

Link to comment
void someMaterialCreatingFunction()
{
	//
	// Do some naming stuff
	//

	MaterialPtr unigine_material = meshBase->inherit(material_name.get(), material_library_name.get());	

	//
	// Loading Images and converts 
	//

	ImagePtr image = Image::create();

	//
	// Save and release resources
	//

	unigine_material->save();
	unigine_material->createShaders();
	image->clear();
}

Hi,

I am allready using createShaders() after setting up material, but it did not do the trick. Yes it looks like the textures are not loaded, only two new shaders are created after one turn and texture memory increases by 500 MB as you can see in picture 2 and 3.

Would it help to create a EnvironmentProbe of the complete scene at the beginning to load all material, shader and texture resources?

We need this texture for the environment preset anyway, I guess.

Link to comment

Sebastian,

Try to call Material::getTexture for each texture for each material. In case the texture was defined in the material xml file and not set by hands in the code, this call will fetch the texture from render manager and, combined with render_manager_create_textures flag set to 1, it'll force it to load the texture to GPU if it wasn't there.

Link to comment
×
×
  • Create New...