| 320 | } |
| 321 | |
| 322 | void BasicMaterial::optimizeTexture(const TextureSlot slot, const TextureAnalyzer::Result& texInfo, TextureOptimizationStats& stats) |
| 323 | { |
| 324 | FALCOR_ASSERT(getTexture(slot) != nullptr); |
| 325 | TextureChannelFlags channelMask = getTextureSlotInfo(slot).mask; |
| 326 | |
| 327 | switch (slot) |
| 328 | { |
| 329 | case TextureSlot::BaseColor: |
| 330 | { |
| 331 | bool previouslyOpaque = isOpaque(); |
| 332 | |
| 333 | auto pBaseColor = getBaseColorTexture(); |
| 334 | bool hasAlpha = isAlphaSupported() && pBaseColor && doesFormatHaveAlpha(pBaseColor->getFormat()); |
| 335 | bool isColorConstant = texInfo.isConstant(TextureChannelFlags::RGB); |
| 336 | bool isAlphaConstant = texInfo.isConstant(TextureChannelFlags::Alpha); |
| 337 | |
| 338 | // Update the alpha range. |
| 339 | if (hasAlpha) mAlphaRange = float2(texInfo.minValue.a, texInfo.maxValue.a); |
| 340 | |
| 341 | // Update base color parameter and texture. |
| 342 | float4 baseColor = getBaseColor(); |
| 343 | if (isColorConstant) |
| 344 | { |
| 345 | baseColor = float4(texInfo.value.xyz(), baseColor.a); |
| 346 | mIsTexturedBaseColorConstant = true; |
| 347 | } |
| 348 | if (hasAlpha && isAlphaConstant) |
| 349 | { |
| 350 | baseColor = float4(baseColor.xyz(), texInfo.value.a); |
| 351 | mIsTexturedAlphaConstant = true; |
| 352 | } |
| 353 | setBaseColor(baseColor); |
| 354 | |
| 355 | if (isColorConstant && (!hasAlpha || isAlphaConstant)) |
| 356 | { |
| 357 | clearTexture(Material::TextureSlot::BaseColor); |
| 358 | stats.texturesRemoved[(size_t)slot]++; |
| 359 | } |
| 360 | else if (isColorConstant) |
| 361 | { |
| 362 | // We don't have a way to specify constant base color with non-constant alpha since they share a texture slot. |
| 363 | // Count number of cases and issue a perf warning later instead. |
| 364 | stats.constantBaseColor++; |
| 365 | } |
| 366 | |
| 367 | updateAlphaMode(); |
| 368 | |
| 369 | if (!previouslyOpaque && isOpaque()) stats.disabledAlpha++; |
| 370 | |
| 371 | break; |
| 372 | } |
| 373 | case TextureSlot::Specular: |
| 374 | { |
| 375 | if (texInfo.isConstant(channelMask)) |
| 376 | { |
| 377 | clearTexture(Material::TextureSlot::Specular); |
| 378 | setSpecularParams(texInfo.value); |
| 379 | stats.texturesRemoved[(size_t)slot]++; |
no test coverage detected