MCPcopy Create free account
hub / github.com/DiligentGraphics/DiligentFX / InitTextureAttribs

Method InitTextureAttribs

Hydrogent/src/HnMaterial.cpp:242–304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240}
241
242void HnMaterial::InitTextureAttribs(HnTextureRegistry& TexRegistry, const USD_Renderer& UsdRenderer, const TexNameToCoordSetMapType& TexNameToCoordSetMap)
243{
244 GLTF::MaterialBuilder MatBuilder{m_MaterialData};
245
246 auto SetTextureParams = [&](const pxr::TfToken& Name, Uint32 Idx) {
247 GLTF::Material::TextureShaderAttribs& TexAttribs = MatBuilder.GetTextureAttrib(Idx);
248
249 auto coord_it = TexNameToCoordSetMap.find(Name);
250 TexAttribs.UVSelector = coord_it != TexNameToCoordSetMap.end() ?
251 static_cast<float>(coord_it->second) :
252 0;
253
254 TexAttribs.UBias = 0;
255 TexAttribs.VBias = 0;
256 TexAttribs.UVScaleAndRotation = float2x2::Identity();
257
258 auto tex_it = m_Textures.find(Name);
259 if (tex_it != m_Textures.end())
260 {
261 if (const HnMaterialParameter* Param = m_Network.GetParameter(HnMaterialParameter::ParamType::Transform2d, Name))
262 {
263 float2x2 UVScaleAndRotation = float2x2::Scale(Param->Transform2d.Scale[0], Param->Transform2d.Scale[1]);
264 float Rotation = Param->Transform2d.Rotation;
265 if (Rotation != 0)
266 {
267 UVScaleAndRotation *= float2x2::Rotation(DegToRad(Rotation));
268 }
269
270 TexAttribs.UBias = Param->Transform2d.Translation[0];
271 TexAttribs.VBias = Param->Transform2d.Translation[1];
272
273 TexAttribs.UVScaleAndRotation = UVScaleAndRotation;
274 }
275 }
276 else
277 {
278 tex_it = m_Textures.emplace(Name, GetDefaultTexture(TexRegistry, Name)).first;
279 }
280
281 if (ITextureAtlasSuballocation* pAtlasSuballocation = tex_it->second->pAtlasSuballocation)
282 {
283 TexAttribs.TextureSlice = static_cast<float>(pAtlasSuballocation->GetSlice());
284 TexAttribs.AtlasUVScaleAndBias = pAtlasSuballocation->GetUVScaleBias();
285 }
286 else
287 {
288 TexAttribs.TextureSlice = static_cast<float>(tex_it->second->TextureId);
289 TexAttribs.AtlasUVScaleAndBias = float4{1, 1, 0, 0};
290 }
291 };
292
293 const auto& TexAttribIndices = UsdRenderer.GetSettings().TextureAttribIndices;
294 // clang-format off
295 SetTextureParams(HnTokens->diffuseColor, TexAttribIndices[PBR_Renderer::TEXTURE_ATTRIB_ID_BASE_COLOR]);
296 SetTextureParams(HnTokens->normal, TexAttribIndices[PBR_Renderer::TEXTURE_ATTRIB_ID_NORMAL]);
297 SetTextureParams(HnTokens->metallic, TexAttribIndices[PBR_Renderer::TEXTURE_ATTRIB_ID_METALLIC]);
298 SetTextureParams(HnTokens->roughness, TexAttribIndices[PBR_Renderer::TEXTURE_ATTRIB_ID_ROUGHNESS]);
299 SetTextureParams(HnTokens->occlusion, TexAttribIndices[PBR_Renderer::TEXTURE_ATTRIB_ID_OCCLUSION]);

Callers

nothing calls this directly

Calls 1

GetParameterMethod · 0.45

Tested by

no test coverage detected