Skip to content

Commit

Permalink
Merge branch 'disableAlpha' into 'main'
Browse files Browse the repository at this point in the history
[REMIX-3366] [PR:76] Add texture category: disable alpha for tagged (legacy) textures

See merge request lightspeedrtx/dxvk-remix-nv!897
  • Loading branch information
MarkEHenderson committed Jul 17, 2024
2 parents 7dfe612 + 5876feb commit 604c037
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 7 deletions.
3 changes: 3 additions & 0 deletions RtxOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ Tables below enumerate all the options and their defaults set by RTX Remix. Note
|rtx.legacyMaterial.emissiveIntensity|float|0|The default emissive intensity to use for non\-replaced "legacy" materials\.|
|rtx.legacyMaterial.enableEmissive|bool|False|A flag to determine if emission should be used on non\-replaced "legacy" materials\.|
|rtx.legacyMaterial.enableThinFilm|bool|False|A flag to determine if a thin\-film layer should be used on non\-replaced "legacy" materials\.|
|rtx.legacyMaterial.ignoreAlphaChannel|bool|False|A flag to determine if the albedo alpha channel should be ignored on non\-replaced "legacy" materials\.|
|rtx.legacyMaterial.metallicConstant|float|0.1|The default metallic constant to use for non\-replaced "legacy" materials\. Should be in the range 0 to 1\.|
|rtx.legacyMaterial.opacityConstant|float|1|The default opacity constant to use for non\-replaced "legacy" materials\. Should be in the range 0 to 1\.|
|rtx.legacyMaterial.roughnessConstant|float|0.7|The default perceptual roughness constant to use for non\-replaced "legacy" materials\. Should be in the range 0 to 1\.|
Expand Down Expand Up @@ -428,6 +429,7 @@ Tables below enumerate all the options and their defaults set by RTX Remix. Note
|rtx.opaqueMaterial.albedoBias|float|0|A bias factor to add to all albedo values in the opaque material\. Should only be used for debugging or development\.|
|rtx.opaqueMaterial.albedoScale|float|1|A scale factor to apply to all albedo values in the opaque material\. Should only be used for debugging or development\.|
|rtx.opaqueMaterial.enableThinFilmOverride|bool|False|A flag to force the thin\-film layer on the opaque material to be enabled\. Should only be used for debugging or development\.|
|rtx.opaqueMaterial.ignoreAlphaChannelOverride|bool|False|A flag to ignore the alpha channel of the colormap on the opaque material\. Should only be used for debugging or development\.|
|rtx.opaqueMaterial.layeredWaterNormalEnable|bool|True|A flag indicating if layered water normal should be enabled or disabled\.<br>Note that objects must be properly classified as animated water to be rendered with this mode\.|
|rtx.opaqueMaterial.layeredWaterNormalLodBias|float|5|The LoD bias to use when sampling from the normal map on layered water for the second layer of detail\.<br>This value typically should be greater than 0 to allow for a more blurry mip to be selected as this allows for a low frequency variation of normals to be applied to the higher frequency variation from the typical normal map\.<br>Only takes effect when layered water normals are enabled \(and an object is properly classified as animated water\)\.|
|rtx.opaqueMaterial.layeredWaterNormalMotion|float2|-0.25, -0.3|A vector describing the motion in the U and V axes across a texture to apply for layered water\.<br>Only takes effect when layered water normals are enabled \(and an object is properly classified as animated water\)\.|
Expand Down Expand Up @@ -729,6 +731,7 @@ Tables below enumerate all the options and their defaults set by RTX Remix. Note
|rtx.geometryAssetHashRuleString|string|positions,indices,geometrydescriptor|Defines which hashes we need to include when sampling from replacements and doing USD capture\.|
|rtx.geometryGenerationHashRuleString|string|positions,indices,texcoords,geometrydescriptor,vertexlayout,vertexshader|Defines which asset hashes we need to generate via the geometry processing engine\.|
|rtx.hideInstanceTextures|hash set||Textures on draw calls that should be hidden from rendering, but not totally ignored\.<br>This is similar to rtx\.ignoreTextures but instead of completely ignoring such draw calls they are only hidden from rendering, allowing for the hidden objects to still appear in captures\.<br>As such, this is mostly only a development tool to hide objects during development until they are properly replaced, otherwise the objects should be ignored with rtx\.ignoreTextures instead for better performance\.|
|rtx.ignoreAlphaOnTextures|hash set||Textures for which to ignore the alpha channel of the legacy colormap\. Textures will be rendered fully opaque as a result\.|
|rtx.ignoreBakedLightingTextures|hash set||Textures for which to ignore two types of baked lighting, Texture Factors and Vertex Color\.<br><br>Texture Factor disablement:<br>Using this feature on selected textures will eliminate the texture factors\.<br>For instance, if a game bakes lighting information into the Texture Factor for particular textures, applying this option will remove them\.<br>This becomes useful when unexpected results occur due to the Texture Factor\.<br>Consider an example where the original texture contains red tints baked into the Texture Factor\. If a user replaces the texture, it will blend with the red tints, resulting in an undesirable reddish outcome\.<br>In such cases, users can employ this option to eliminate the unwanted tints from their replacement textures\.<br>Similarly, users can tag textures if shadows are baked into the Texture Factor, causing the replacing texture to appear darker than anticipated\.<br><br>Vertex Color disablement:<br>Using this feature on selected textures will eliminate the vertex colors\.<br><br>Note, enabling this setting will automatically disable multiple\-stage texture factor blendings for the selected textures\.<br>Only use this option when necessary, as the Texture Factor and Vertex Color can be used for simulating various texture effects, tagging a texture with this option will unexpectedly eliminate these effects\.|
|rtx.ignoreLights|hash set||Lights that should be ignored\.<br>Any matching light will be skipped and not added to be ray traced\.|
|rtx.ignoreTextures|hash set||Textures on draw calls that should be ignored\.<br>Any draw call using an ignore texture will be skipped and not ray traced, useful for removing undesirable rasterized effects or geometry not suitable for ray tracing\.|
Expand Down
1 change: 1 addition & 0 deletions public/include/remix/remix_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ extern "C" {
REMIXAPI_INSTANCE_CATEGORY_BIT_THIRD_PERSON_PLAYER_MODEL = 1 << 18,
REMIXAPI_INSTANCE_CATEGORY_BIT_THIRD_PERSON_PLAYER_BODY = 1 << 19,
REMIXAPI_INSTANCE_CATEGORY_BIT_IGNORE_BAKED_LIGHTING = 1 << 20,
REMIXAPI_INSTANCE_CATEGORY_BIT_IGNORE_ALPHA_CHANNEL = 1 << 21,
} remixapi_InstanceCategoryBit;

typedef uint32_t remixapi_InstanceCategoryFlags;
Expand Down
4 changes: 3 additions & 1 deletion src/dxvk/imgui/dxvk_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ namespace dxvk {
{"playermodeltextures", "Player Model Texture (optional)", &RtxOptions::Get()->playerModelTexturesObject()},
{"playermodelbodytextures", "Player Model Body Texture (optional)", &RtxOptions::Get()->playerModelBodyTexturesObject()},
{"opacitymicromapignoretextures", "Opacity Micromap Ignore Texture (optional)", &RtxOptions::Get()->opacityMicromapIgnoreTexturesObject()},
{"ignorebakedlightingtextures","Ignore Baked Lighting Textures (optional)", &RtxOptions::Get()->ignoreBakedLightingTexturesObject()}
{"ignorebakedlightingtextures","Ignore Baked Lighting Textures (optional)", &RtxOptions::Get()->ignoreBakedLightingTexturesObject()},
{"ignorealphaontextures","Ignore Alpha Channel of Textures (optional)", &RtxOptions::Get()->ignoreAlphaOnTexturesObject()}
};

ImGui::ComboWithKey<RenderPassGBufferRaytraceMode> renderPassGBufferRaytraceModeCombo {
Expand Down Expand Up @@ -565,6 +566,7 @@ namespace dxvk {

LegacyMaterialDefaults& legacyMaterial = RtxOptions::Get()->legacyMaterial;
ImGui::Checkbox("Use Albedo/Opacity Texture (if present)", &legacyMaterial.useAlbedoTextureIfPresentObject());
ImGui::Checkbox("Ignore Texture Alpha Channel", &legacyMaterial.ignoreAlphaChannelObject());
ImGui::ColorEdit3("Albedo", &legacyMaterial.albedoConstantObject());
ImGui::DragFloat("Opacity", &legacyMaterial.opacityConstantObject(), 0.01f, 0.f, 1.f);
ImGui::ColorEdit3("Emissive Color", &legacyMaterial.emissiveColorConstantObject());
Expand Down
12 changes: 10 additions & 2 deletions src/dxvk/rtx_render/rtx_materials.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ struct LegacyMaterialDefaults {
RTX_OPTION("rtx.legacyMaterial", float, metallicConstant, 0.1f, "The default metallic constant to use for non-replaced \"legacy\" materials. Should be in the range 0 to 1.");
RTX_OPTION("rtx.legacyMaterial", Vector3, emissiveColorConstant, Vector3(0.0f, 0.0f, 0.0f), "The default emissive color constant to use for non-replaced \"legacy\" materials. Should be a color in sRGB colorspace with gamma encoding.");
RTX_OPTION("rtx.legacyMaterial", bool, enableEmissive, false, "A flag to determine if emission should be used on non-replaced \"legacy\" materials.");
RTX_OPTION("rtx.legacyMaterial", bool, ignoreAlphaChannel, false, "A flag to determine if the albedo alpha channel should be ignored on non-replaced \"legacy\" materials.");
RTX_OPTION("rtx.legacyMaterial", bool, enableThinFilm, false, "A flag to determine if a thin-film layer should be used on non-replaced \"legacy\" materials.");
RTX_OPTION("rtx.legacyMaterial", bool, alphaIsThinFilmThickness, false, "A flag to determine if the alpha channel from the albedo source should be treated as thin film thickness on non-replaced \"legacy\" materials.");
// Note: Should be something non-zero as 0 is an invalid thickness to have (even if this is just unused).
Expand Down Expand Up @@ -383,7 +384,7 @@ struct RtOpaqueSurfaceMaterial {
const Vector4& albedoOpacityConstant,
float roughnessConstant, float metallicConstant,
const Vector3& emissiveColorConstant, bool enableEmission,
bool enableThinFilm, bool alphaIsThinFilmThickness, float thinFilmThicknessConstant,
bool ignoreAlphaChannel, bool enableThinFilm, bool alphaIsThinFilmThickness, float thinFilmThicknessConstant,
uint32_t samplerIndex, float displaceIn,
uint32_t subsurfaceMaterialIndex) :
m_albedoOpacityTextureIndex{ albedoOpacityTextureIndex }, m_normalTextureIndex{ normalTextureIndex },
Expand All @@ -393,7 +394,7 @@ struct RtOpaqueSurfaceMaterial {
m_albedoOpacityConstant{ albedoOpacityConstant },
m_roughnessConstant{ roughnessConstant }, m_metallicConstant{ metallicConstant },
m_emissiveColorConstant{ emissiveColorConstant }, m_enableEmission{ enableEmission },
m_enableThinFilm { enableThinFilm }, m_alphaIsThinFilmThickness { alphaIsThinFilmThickness },
m_ignoreAlphaChannel { ignoreAlphaChannel }, m_enableThinFilm { enableThinFilm }, m_alphaIsThinFilmThickness { alphaIsThinFilmThickness },
m_thinFilmThicknessConstant { thinFilmThicknessConstant }, m_samplerIndex{ samplerIndex }, m_displaceIn{ displaceIn },
m_subsurfaceMaterialIndex(subsurfaceMaterialIndex) {
updateCachedData();
Expand Down Expand Up @@ -489,6 +490,11 @@ struct RtOpaqueSurfaceMaterial {
flags |= OPAQUE_SURFACE_MATERIAL_FLAG_ALPHA_IS_THIN_FILM_THICKNESS;
}
}

if (m_ignoreAlphaChannel) {
flags |= OPAQUE_SURFACE_MATERIAL_FLAG_IGNORE_ALPHA_CHANNEL;
}

writeGPUHelper(data, offset, flags);

assert(offset - oldOffset == kSurfaceMaterialGPUSize);
Expand Down Expand Up @@ -596,6 +602,7 @@ struct RtOpaqueSurfaceMaterial {
h = XXH64(&m_metallicConstant, sizeof(m_metallicConstant), h);
h = XXH64(&m_emissiveColorConstant, sizeof(m_emissiveColorConstant), h);
h = XXH64(&m_enableEmission, sizeof(m_enableEmission), h);
h = XXH64(&m_ignoreAlphaChannel, sizeof(m_ignoreAlphaChannel), h);
h = XXH64(&m_enableThinFilm, sizeof(m_enableThinFilm), h);
h = XXH64(&m_alphaIsThinFilmThickness, sizeof(m_alphaIsThinFilmThickness), h);
h = XXH64(&m_thinFilmThicknessConstant, sizeof(m_thinFilmThicknessConstant), h);
Expand Down Expand Up @@ -636,6 +643,7 @@ struct RtOpaqueSurfaceMaterial {

bool m_enableEmission;

bool m_ignoreAlphaChannel;
bool m_enableThinFilm;
bool m_alphaIsThinFilmThickness;
float m_thinFilmThicknessConstant;
Expand Down
3 changes: 2 additions & 1 deletion src/dxvk/rtx_render/rtx_opacity_micromap_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,8 @@ namespace dxvk {
return false;
}

if (instance.testCategoryFlags(InstanceCategories::IgnoreOpacityMicromap)) {
if (instance.testCategoryFlags(InstanceCategories::IgnoreOpacityMicromap) ||
instance.testCategoryFlags(InstanceCategories::IgnoreAlphaChannel)) {
return false;
}

Expand Down
2 changes: 2 additions & 0 deletions src/dxvk/rtx_render/rtx_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ namespace dxvk {
"Using this feature on selected textures will eliminate the vertex colors.\n\n"
"Note, enabling this setting will automatically disable multiple-stage texture factor blendings for the selected textures.\n"
"Only use this option when necessary, as the Texture Factor and Vertex Color can be used for simulating various texture effects, tagging a texture with this option will unexpectedly eliminate these effects.");
RW_RTX_OPTION("rtx", fast_unordered_set, ignoreAlphaOnTextures, {},
"Textures for which to ignore the alpha channel of the legacy colormap. Textures will be rendered fully opaque as a result.");
RW_RTX_OPTION("rtx.antiCulling", fast_unordered_set, antiCullingTextures, {},
"Textures that are forced to extend life length when anti-culling is enabled.\n"
"Some games use different culling methods we can't fully match, use this option to manually add textures to force extend their life when anti-culling fails.");
Expand Down
1 change: 1 addition & 0 deletions src/dxvk/rtx_render/rtx_remix_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ namespace {
if (flags & REMIXAPI_INSTANCE_CATEGORY_BIT_IGNORE_ANTI_CULLING ){ result.set(InstanceCategories::IgnoreAntiCulling ); }
if (flags & REMIXAPI_INSTANCE_CATEGORY_BIT_IGNORE_MOTION_BLUR ){ result.set(InstanceCategories::IgnoreMotionBlur ); }
if (flags & REMIXAPI_INSTANCE_CATEGORY_BIT_IGNORE_OPACITY_MICROMAP ){ result.set(InstanceCategories::IgnoreOpacityMicromap ); }
if (flags & REMIXAPI_INSTANCE_CATEGORY_BIT_IGNORE_ALPHA_CHANNEL ){ result.set(InstanceCategories::IgnoreAlphaChannel ); }
if (flags & REMIXAPI_INSTANCE_CATEGORY_BIT_HIDDEN ){ result.set(InstanceCategories::Hidden ); }
if (flags & REMIXAPI_INSTANCE_CATEGORY_BIT_PARTICLE ){ result.set(InstanceCategories::Particle ); }
if (flags & REMIXAPI_INSTANCE_CATEGORY_BIT_BEAM ){ result.set(InstanceCategories::Beam ); }
Expand Down
9 changes: 8 additions & 1 deletion src/dxvk/rtx_render/rtx_scene_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,9 @@ namespace dxvk {
float thinFilmThicknessConstant = 0.0f;
float displaceIn = 1.0f;

// Ignore colormap alpha of legacy texture if tagged as 'ignoreAlphaOnTextures'
bool ignoreAlphaChannel = lookupHash(RtxOptions::ignoreAlphaOnTextures(), drawCallState.getMaterialData().getHash());

Vector3 subsurfaceTransmittanceColor(0.0f, 0.0f, 0.0f);
float subsurfaceMeasurementDistance = 0.0f;
Vector3 subsurfaceSingleScatteringAlbedo(0.0f, 0.0f, 0.0f);
Expand Down Expand Up @@ -969,6 +972,10 @@ namespace dxvk {
// Todo: Incorporate this and the color texture into emissive conditionally
// emissiveColorTextureIndex != kSurfaceMaterialInvalidTextureIndex ? 100.0f

if (!ignoreAlphaChannel) {
ignoreAlphaChannel = defaults.ignoreAlphaChannel();
}

thinFilmEnable = defaults.enableThinFilm();
alphaIsThinFilmThickness = defaults.alphaIsThinFilmThickness();
thinFilmThicknessConstant = defaults.thinFilmThicknessConstant();
Expand Down Expand Up @@ -1041,7 +1048,7 @@ namespace dxvk {
albedoOpacityConstant,
roughnessConstant, metallicConstant,
emissiveColorConstant, enableEmissive,
thinFilmEnable, alphaIsThinFilmThickness,
ignoreAlphaChannel, thinFilmEnable, alphaIsThinFilmThickness,
thinFilmThicknessConstant, samplerIndex, displaceIn,
subsurfaceMaterialIndex
};
Expand Down
1 change: 1 addition & 0 deletions src/dxvk/rtx_render/rtx_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ namespace dxvk {
setCategory(InstanceCategories::IgnoreAntiCulling, lookupHash(RtxOptions::antiCullingTextures(), textureHash));
setCategory(InstanceCategories::IgnoreMotionBlur, lookupHash(RtxOptions::motionBlurMaskOutTextures(), textureHash));
setCategory(InstanceCategories::IgnoreOpacityMicromap, lookupHash(RtxOptions::opacityMicromapIgnoreTextures(), textureHash));
setCategory(InstanceCategories::IgnoreAlphaChannel, lookupHash(RtxOptions::ignoreAlphaOnTextures(), textureHash));
setCategory(InstanceCategories::IgnoreBakedLighting, lookupHash(RtxOptions::ignoreBakedLightingTextures(), textureHash));

setCategory(InstanceCategories::Hidden, lookupHash(RtxOptions::hideInstanceTextures(), textureHash));
Expand Down
1 change: 1 addition & 0 deletions src/dxvk/rtx_render/rtx_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ enum class InstanceCategories : uint32_t {
IgnoreAntiCulling,
IgnoreMotionBlur,
IgnoreOpacityMicromap,
IgnoreAlphaChannel,
Hidden,
Particle,
Beam,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ OpaqueSurfaceMaterialInteraction opaqueSurfaceMaterialInteractionCreate(
thinFilmThickness = float16_t(0.0f);
}
}

#if defined(RAY_TRACING_PRIMARY_RAY) && defined(RAY_PIPELINE)
if (cb.debugView == DEBUG_VIEW_RAW_ALBEDO)
{
Expand Down Expand Up @@ -562,6 +562,11 @@ OpaqueSurfaceMaterialInteraction opaqueSurfaceMaterialInteractionCreate(
albedo, opacity, surface, opacity, emissiveBlendOverrideInfluence);
}

if (opaqueSurfaceMaterial.flags & OPAQUE_SURFACE_MATERIAL_FLAG_IGNORE_ALPHA_CHANNEL)
{
opacity = 1.h;
}

// Note: Gamma correct albedo input (be it from a constant or a texture). Currently assuming all textures are not using sRGB formats which
// automatically do this conversion.
// This conversion is done *after* calcOpaqueSurfaceMaterialOpacity to correctly apply double multiplicative blending.
Expand Down
1 change: 1 addition & 0 deletions src/dxvk/shaders/rtx/pass/material_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ struct OpaqueMaterialOptions {

// Overrides

RTX_OPTION("rtx.opaqueMaterial", bool, ignoreAlphaChannelOverride, false, "A flag to ignore the alpha channel of the colormap on the opaque material. Should only be used for debugging or development.");
RTX_OPTION("rtx.opaqueMaterial", bool, enableThinFilmOverride, false, "A flag to force the thin-film layer on the opaque material to be enabled. Should only be used for debugging or development.");
RTX_OPTION("rtx.opaqueMaterial", float, thinFilmThicknessOverride, 0.0f,
"The thin-film layer's thickness in nanometers for the opaque material when the thin-film override is enabled.\n"
Expand Down
1 change: 1 addition & 0 deletions src/dxvk/shaders/rtx/utility/shared_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#define OPAQUE_SURFACE_MATERIAL_FLAG_HAS_METALLIC_TEXTURE (1 << 4)
#define OPAQUE_SURFACE_MATERIAL_FLAG_HAS_EMISSIVE_TEXTURE (1 << 5)
#define OPAQUE_SURFACE_MATERIAL_FLAG_HAS_SUBSURFACE_MATERIAL (1 << 6)
#define OPAQUE_SURFACE_MATERIAL_FLAG_IGNORE_ALPHA_CHANNEL (1 << 7)

#define OPAQUE_SURFACE_MATERIAL_INTERACTION_FLAG_HAS_HEIGHT_TEXTURE (1 << 0)
#define OPAQUE_SURFACE_MATERIAL_INTERACTION_FLAG_USE_THIN_FILM_LAYER (1 << 1)
Expand Down
4 changes: 3 additions & 1 deletion src/lssusd/usd_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace dxvk {
// Used when readin/writing with Remix USD mods.
static const char* getInstanceCategorySubKey(InstanceCategories cat) {
static_assert((uint32_t) InstanceCategories::Count == 21, "Please add/remove the category to the below table.");
static_assert((uint32_t) InstanceCategories::Count == 22, "Please add/remove the category to the below table.");
switch (cat) {
case InstanceCategories::WorldUI:
return "remix_category:world_ui";
Expand All @@ -21,6 +21,8 @@ namespace dxvk {
return "remix_category:ignore_motion_blur";
case InstanceCategories::IgnoreOpacityMicromap:
return "remix_category:ignore_opacity_micromap";
case InstanceCategories::IgnoreAlphaChannel:
return "remix_category:ignore_alpha_channel";
case InstanceCategories::Hidden:
return "remix_category:hidden";
case InstanceCategories::Particle:
Expand Down

0 comments on commit 604c037

Please sign in to comment.