Add new scene textures SceneStencil and ObjectLayer to sample Stencil buffer

This commit is contained in:
Wojtek Figat
2025-10-07 18:10:14 +02:00
parent f8dbf363b6
commit 2f1f380062
5 changed files with 37 additions and 1 deletions

View File

@@ -474,6 +474,23 @@ void MaterialGenerator::ProcessGroupTextures(Box* box, Node* node, Value& value)
value = writeLocal(VariantType::Float3, String::Format(TEXT("GetWorldPos({1}, {0}.rgb)"), depthSample->Value, uv), node);
break;
}
case MaterialSceneTextures::SceneStencil:
case MaterialSceneTextures::ObjectLayer:
{
auto stencilParam = findOrAddSceneTexture(MaterialSceneTextures::SceneStencil);
const auto parent = box->GetParent<ShaderGraphNode<>>();
MaterialGraphBox* uvBox = parent->GetBox(0);
bool useCustomUVs = uvBox->HasConnection();
String uv;
if (useCustomUVs)
uv = MaterialValue::Cast(tryGetValue(uvBox, getUVs), VariantType::Float2).Value;
else
uv = TEXT("input.TexCoord.xy");
const Char* func = type == MaterialSceneTextures::ObjectLayer ? TEXT("STENCIL_BUFFER_OBJECT_LAYER") : TEXT("");
value = writeLocal(VariantType::Int, String::Format(TEXT("{2}(STENCIL_BUFFER_LOAD({0}, {1} * ScreenSize.xy))"), stencilParam.ShaderName, uv, func), node);
_includes.Add(TEXT("./Flax/Stencil.hlsl"));
break;
}
default:
{
// Sample single texture