Normal map texture support

Hello all,

in this document (page 4) https://dev.opencascade.org/sites/default/files/documents/release_notes_7.5.0.pdf

it says there is now Normal map texture support.

Could please somebody be so kind and lead me to an example? All I was able to find was in opencascade-7.6.0\src\BinMXCAFDoc\BinMXCAFDoc_VisMaterialDriver.cxx.

I would like to set a normal map texture to a AIS_Shape

Thanks!!

Kirill Gavrilov's picture

Take a look onto XCAFDoc_VisMaterial::FillAspect(). What you need is to define Graphic3d_TextureSet instead of a single texture and assign texture to Graphic3d_TextureUnit_Normal unit (and Graphic3d_TextureUnit_BaseColor for a normal color texture).

Daniel Duesentrieb's picture

Thanks Kirill, I got it going so far:

m_textureset = new Graphic3d_TextureSet(4);

filename = folder + "grassPaver/Grass_Paver_DIFF.png";
m_textureBaseColor = new Graphic3d_Texture2Dmanual (filename.toStdString().c_str());
m_textureset->SetValue(Graphic3d_TextureUnit_BaseColor , m_textureBaseColor);

filename = folder + "grassPaver/Grass_Paver_DIFF.png";
m_textureEmissive = new Graphic3d_Texture2Dmanual (filename.toStdString().c_str());
m_textureset->SetValue(Graphic3d_TextureUnit_Emissive , m_textureEmissive);

filename = folder + "grassPaver/Grass_Paver_OCC.png";
m_textureOcclusion = new Graphic3d_Texture2Dmanual (filename.toStdString().c_str());
m_textureset->SetValue(Graphic3d_TextureUnit_Occlusion , m_textureOcclusion);

filename = folder + "grassPaver/Grass_Paver_NRM.png";
m_textureNormal = new Graphic3d_Texture2Dmanual (filename.toStdString().c_str());
m_textureset->SetValue(Graphic3d_TextureUnit_Normal , m_textureNormal);

Using is as follow

m_textureset = OccGraphics::instance()->textureset();
m_aisDisplay->Attributes()->ShadingAspect()->Aspect()->SetTextureSet(m_textureset);

I tried to assign ONLY Graphic3d_TextureUnit_BaseColor and Graphic3d_TextureUnit_Normal but this is crashing. I have to assign something for Graphic3d_TextureUnit_Emissive and Graphic3d_TextureUnit_Occlusion as well.

I have to admit that I do not fully understand all the different textures yet and not sure what to do.

As attachment the result I get.

The textures are too big to upload here.But this is the link:

Textures

Kirill Gavrilov's picture
m_textureset = new Graphic3d_TextureSet(4);
m_textureBaseColor = new Graphic3d_Texture2Dmanual (filename.toStdString().c_str());
m_textureset->SetValue(Graphic3d_TextureUnit_BaseColor , m_textureBaseColor);

That's not how texture units are supposed to be set in OCCT. Graphic3d_TextureSet::SetValue() just assigns value to an array index - it should be incremented in the loop. Graphic3d_TextureUnit values should be set to to Graphic3d_TextureParams::TextureUnit() property:
m_textureBaseColor->GetParams()->SetTextureUnit (Graphic3d_TextureUnit_BaseColor);

You might want also to specify normal map and occlusion textures as stored in linear, not gamma-corrected color space to avoid their distortion:

Handle(Graphic3d_Texture2D) aTexture = ...;
aTexture->GetParams()->SetTextureUnit (...);
aTexture->SetColorMap (aTexture->GetParams()->TextureUnit() == Graphic3d_TextureUnit_BaseColor || aTexture->GetParams()->TextureUnit() == Graphic3d_TextureUnit_Emissive)

Daniel Duesentrieb's picture

Works great - looks so much better.
Thank you!