Missing Pbr textures in GI render scene

Enable path tracking:
aPrarms.IsGlobalIlluminationEnabled = true;
aPrarms.Method = Graphic3d_RenderingMode::Graphic3d_RM_RAYTRACING;

When rendering 30 models with pbr materials and BaseColorTexture present, the textures set later will be lost

Dmitrii Pasukhin's picture

hello, Could you please give a little more details?

Best regards, Dmitrii.

Le Zhang's picture

Thank you for your reply. I have reproduced the problem in the Cad Assistant. There is a lack of contrast material between non-GI rendering and GI rendering. This glb file contains a large number of texture maps

My code looks like this:

Set parameters

Graphic3d_RenderingParams& aPrarms = aView->ChangeRenderingParams();

aPrarms.FrustumCullingState = Graphic3d_RenderingParams::FrustumCulling::FrustumCulling_On;

aPrarms.Method = Graphic3d_RenderingMode::Graphic3d_RM_RAYTRACING;

aPrarms.RaytracingDepth = 3;

aPrarms.SamplesPerPixel = 2;

aPrarms.CoherentPathTracingMode = true;

aPrarms.IsReflectionEnabled = false;

aPrarms.IsTransparentShadowEnabled = true;

aPrarms.TwoSidedBsdfModels = true;

aPrarms.ToneMappingMethod = Graphic3d_ToneMappingMethod_Filmic;

aPrarms.ToEnableDepthPrepass = true;

aPrarms.TransparencyMethod = Graphic3d_RenderTransparentMethod::Graphic3d_RTM_DEPTH_PEELING_OIT;

aPrarms.RebuildRayTracingShaders = true;

aPrarms.IsAntialiasingEnabled = false;

aPrarms.NbMsaaSamples = 1;

aPrarms.ShadingModel = Graphic3d_TypeOfShadingModel::Graphic3d_TOSM_PBR;

aPrarms.UseEnvironmentMapBackground = true;

aPrarms.IsGlobalIlluminationEnabled = true;

Setting IBL Add models and set pbr properties in custom AIS

Handle(RWGltf_MaterialMetallicRoughness) aPbr;
				TopLoc_Location aDummyLoc;
				Handle(RWGltf_GltfLatePrimitiveArray) aLateData = Handle(RWGltf_GltfLatePrimitiveArray)::DownCast(BRep_Tool::Triangulation(aFace, aDummyLoc));
				if (aLateData)
				{
					aPbr = aLateData->MaterialPbr();
				}
				Handle(Graphic3d_ArrayOfTriangles) aArray = StdPrs_ShadedShape::FillTriangles(aFace,true, gp_Pnt2d(0.0, 0.0),gp_Pnt2d(1.0, 1.0),gp_Pnt2d(1.0, 1.0));
				Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
			
				if (aPbr.IsNull())
				{
					return;
				}



				bool aHasTex = true;
				Standard_Integer aNbTexUnits = 0;
				if (!aPbr->BaseColorTexture.IsNull()) { ++aNbTexUnits; }
				if (!aPbr->EmissiveTexture.IsNull()) { ++aNbTexUnits; }
				if (!aPbr->NormalTexture.IsNull()) { ++aNbTexUnits; }
				if (!aPbr->OcclusionTexture.IsNull()) { ++aNbTexUnits; }
				if (!aPbr->MetallicRoughnessTexture.IsNull()) { ++aNbTexUnits; }
				if (aNbTexUnits == 0)
				{
					aHasTex = false;
				}




				Handle(Graphic3d_Aspects) aAspect = new Graphic3d_Aspects();

					if (aHasTex)
					{
						Handle(Graphic3d_TextureSet) aSet = new Graphic3d_TextureSet(aNbTexUnits);
						auto SetImage = [&](int theIndex, Graphic3d_TextureUnit theType, const  Handle(Image_Texture)& theTexture)
						{
							aSet->SetValue(theIndex, new XCAFPrs_Texture(*theTexture, theType));

						};
						Standard_Integer aTexIter = 0;
						if (aPbr->BaseColorTexture)
						{
							SetImage(aTexIter++, Graphic3d_TextureUnit::Graphic3d_TextureUnit_BaseColor, aPbr->BaseColorTexture);
						}
						if (aPbr->EmissiveTexture)
						{
							SetImage(aTexIter++, Graphic3d_TextureUnit::Graphic3d_TextureUnit_Emissive, aPbr->EmissiveTexture);
						}
						if (aPbr->OcclusionTexture)
						{
							SetImage(aTexIter++, Graphic3d_TextureUnit::Graphic3d_TextureUnit_Occlusion, aPbr->OcclusionTexture);
						}
						if (aPbr->NormalTexture)
						{
							SetImage(aTexIter++, Graphic3d_TextureUnit::Graphic3d_TextureUnit_Normal, aPbr->NormalTexture);
						}
						if (aPbr->MetallicRoughnessTexture)
						{
							SetImage(aTexIter++, Graphic3d_TextureUnit::Graphic3d_TextureUnit_MetallicRoughness, aPbr->MetallicRoughnessTexture);
						}


						aAspect->SetTextureSet(aSet);
						aAspect->SetTextureMapOn();
					}
					else
					{
						aAspect->SetTextureMapOff();
					}
					Graphic3d_MaterialAspect aMaterialAspect(Graphic3d_NameOfMaterial_UserDefined);
					auto aAlpha = aPbr->BaseColor.Alpha();
					auto aMetallic = aPbr->Metallic;
					auto aRoughness = aPbr->Roughness;
					if (aAlpha > 1.0f)
					{
						aAlpha = 1.0f;
					}
					else if (aAlpha<0.0f)
					{
						aAlpha = 0.0f;
					}
					if (aMetallic > 1.0f)
					{
						aMetallic = 1.0f;
					}
					else if (aMetallic<0.0f)
					{
						aMetallic = 0.0f;
					}
					if (aRoughness > 1.0f)
					{
						aRoughness = 1.0f;
					}
					else if (aRoughness<0.0f)
					{
						aRoughness = 0.0f;
						
					}

					aMaterialAspect.SetDiffuseColor(aPbr->BaseColor.GetRGB());
					aMaterialAspect.SetAlpha(aAlpha);
					aMaterialAspect.SetSpecularColor(Quantity_Color(Graphic3d_Vec3(aMetallic)));
					aMaterialAspect.SetShininess(1.0f - aRoughness);
					if (aMaterialAspect.Shininess() < 0.01f)
					{
						aMaterialAspect.SetShininess(0.01f);
					}
					aMaterialAspect.SetEmissiveColor(Quantity_Color(aPbr->EmissiveFactor.cwiseMin(Graphic3d_Vec3(1.0f))));


					Graphic3d_PBRMaterial aPbrMaterial;
					aPbrMaterial.SetColor(aPbr->BaseColor.GetRGB());
					aPbrMaterial.SetAlpha(aAlpha);
					aPbrMaterial.SetMetallic(aMetallic);
					aPbrMaterial.SetEmission(aPbr->EmissiveFactor);
					aPbrMaterial.SetRoughness(aRoughness);
					aPbrMaterial.SetIOR(1.5);
					aMaterialAspect.SetRefractionIndex(1.5);
					aMaterialAspect.SetPBRMaterial(aPbrMaterial);
					aMaterialAspect.SetBSDF(Graphic3d_BSDF::CreateMetallicRoughness(aPbrMaterial));
					aAspect->SetFrontMaterial(aMaterialAspect);
					
					aAspect->SetShadingModel(Graphic3d_TypeOfShadingModel::Graphic3d_TypeOfShadingModel_Pbr);


				aGroup->AddPrimitiveArray(aArray);
				aGroup->SetGroupPrimitivesAspect(aAspect);
gkv311 n's picture

Please check and share the Message Log in CAD Assistant to see if there are some warnings or errors (considerb enabling 'Verbose Log' in CAD Assistant settings to see more details). You may also have the log into text file.

Please also use 'code' tags on the Forum for inserting code snippets.

Le Zhang's picture

Thank you for your reply. The code and Message Log have been added

gkv311 n's picture

Could you share the model or at least some problematic part of it? Maybe model contains some material extensions to glTF 2 core, supported by Blender, but not by OCCT glTF reader...

Le Zhang's picture

Unable to upload files larger than 5M, I split the model into 4 pieces

I did "myAISContext->EraseAll(true)" before import; ", respectively import the split model, no white material appears; But remove "myAISContext->EraseAll(true); ", continuous import, after the import of the model will lose materials

The split model in the Cad Assistant is also GI rendering normal, you can merge into a glb to test

gkv311 n's picture

Current implementation of Metalic-Roughness materials in OCCT Path-Tracing engine has a limitation. When metal-roughness texture is provided, it expects metallness to be set to 1.0 within material itself, (e.g. texture should define metallness factor with no extra multiplier), otherwise converted BRDF material becomes invalid. This description could be found only in GLSL source code, though.

In this model, metallness is set to `0.0`, which triggers this issue in OCCT. Although model is valid in terms of glTF 2.0 (metallness factors of material and texture should be multiplied together), but you may set metallness to 1.0 to workaround the limitation.

Le Zhang's picture

Thank you very much for your answer