MCPcopy Create free account
hub / github.com/NVIDIA-RTX/RTXNTC / FillMaterialTranscodeMapping

Function FillMaterialTranscodeMapping

samples/renderer/NtcMaterialLoader.cpp:178–343  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

176}
177
178static void FillMaterialTranscodeMapping(NtcMaterial& material, ntc::ITextureSetMetadata* textureSetMetadata,
179 MaterialChannelMap const& channelMap, bool onlyAlphaMask)
180{
181 // Derive the valid channel mask from the shuffle map, because textureSetMetadata->GetValidChannelMask()
182 // returns "1" bits for constant channels, and we want to know where actual textures exist.
183 uint32_t channelMask = 0;
184 for (int ch = 0; ch < NTC_MAX_CHANNELS; ++ch)
185 {
186 if (channelMap.swizzle[ch].type == ntc::ShuffleSourceType::Channel)
187 channelMask |= (1 << ch);
188 }
189
190 // If we only need to create the alpha mask texture, see if the material actually needs an alpha mask
191 // and if the NTC texture set has an alpha mask channel.
192 if (onlyAlphaMask)
193 {
194 // Test the channel mask for the presence of opacity channel.
195 // Note: not testing the material domain because in some cases, one texture set can be reused
196 // for multiple materials with different domains, and we cache and reuse the transcode mapping.
197 // One model with such reuse is AlphaBlendModeTest from the Khronos glTF sample asset collection.
198 bool opacityChannelPresent = TextureSetHasChannels(channelMask, CHANNEL_OPACITY, 1);
199
200 if (!opacityChannelPresent)
201 return;
202
203 TextureTranscodeTask& opacityTexture = material.transcodeMapping.emplace_back();
204 opacityTexture.bcFormat = ntc::BlockCompressedFormat::BC4;
205 opacityTexture.nvrhiBcFormat = nvrhi::Format::BC4_UNORM;
206 opacityTexture.firstChannel = CHANNEL_OPACITY;
207 opacityTexture.numChannels = 1;
208 opacityTexture.pMaterialTexture = &NtcMaterial::opacityTexture;
209 opacityTexture.pFeedbackTexture = &NtcMaterial::opacityTextureFeedback;
210 opacityTexture.name = "Opacity";
211 }
212 else
213 {
214 if (TextureSetHasChannels(channelMask, CHANNEL_BASE_COLOR, 3))
215 {
216 TextureTranscodeTask& baseColorTexture = material.transcodeMapping.emplace_back();
217 baseColorTexture.bcFormat = ntc::BlockCompressedFormat::BC7;
218 baseColorTexture.nvrhiBcFormat = nvrhi::Format::BC7_UNORM_SRGB;
219 baseColorTexture.firstChannel = CHANNEL_BASE_COLOR;
220 baseColorTexture.numChannels = TextureSetHasChannels(channelMask, CHANNEL_OPACITY, 1) ? 4 : 3;
221 static_assert(CHANNEL_OPACITY == CHANNEL_BASE_COLOR + 3);
222 baseColorTexture.sRGB = true;
223 baseColorTexture.pMaterialTexture = &NtcMaterial::baseOrDiffuseTexture;
224 baseColorTexture.pFeedbackTexture = &NtcMaterial::baseOrDiffuseTextureFeedback;
225 baseColorTexture.name = "BaseColor";
226 }
227
228 if (material.useSpecularGlossModel)
229 {
230 if (TextureSetHasChannels(channelMask, CHANNEL_SPECULAR_COLOR, 3))
231 {
232 TextureTranscodeTask& specularTexture = material.transcodeMapping.emplace_back();
233 specularTexture.bcFormat = ntc::BlockCompressedFormat::BC7;
234 specularTexture.nvrhiBcFormat = nvrhi::Format::BC7_UNORM_SRGB;
235 specularTexture.firstChannel = CHANNEL_SPECULAR_COLOR;

Callers 1

LoadMaterialsForSceneMethod · 0.85

Calls 2

TextureSetHasChannelsFunction · 0.85
GetTextureMethod · 0.80

Tested by

no test coverage detected