Add support for using per-texture group sampler in Materials
This commit is contained in:
@@ -290,6 +290,7 @@ void MaterialGenerator::ProcessGroupTextures(Box* box, Node* node, Value& value)
|
||||
PointClamp = 1,
|
||||
LinearWrap = 2,
|
||||
PointWrap = 3,
|
||||
TextureGroup = 4,
|
||||
};
|
||||
const Char* SamplerNames[]
|
||||
{
|
||||
@@ -345,8 +346,18 @@ void MaterialGenerator::ProcessGroupTextures(Box* box, Node* node, Value& value)
|
||||
const bool useLevel = levelBox->HasConnection() || (int32)node->Values[1] != -1;
|
||||
const bool useOffset = offsetBox->HasConnection();
|
||||
const auto offset = useOffset ? eatBox(offsetBox->GetParent<Node>(), offsetBox->FirstConnection()) : Value::Zero;
|
||||
const Char* samplerName;
|
||||
const int32 samplerIndex = node->Values[0].AsInt;
|
||||
if (samplerIndex < 0 || samplerIndex >= ARRAY_COUNT(SamplerNames))
|
||||
if (samplerIndex == TextureGroup)
|
||||
{
|
||||
auto& textureGroupSampler = findOrAddTextureGroupSampler(node->Values[2].AsInt);
|
||||
samplerName = *textureGroupSampler.ShaderName;
|
||||
}
|
||||
else if (samplerIndex >= 0 && samplerIndex < ARRAY_COUNT(SamplerNames))
|
||||
{
|
||||
samplerName = SamplerNames[samplerIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
OnError(node, box, TEXT("Invalid texture sampler."));
|
||||
return;
|
||||
@@ -372,7 +383,7 @@ void MaterialGenerator::ProcessGroupTextures(Box* box, Node* node, Value& value)
|
||||
// Sample texture
|
||||
const String sampledValue = String::Format(format,
|
||||
texture.Value, // {0}
|
||||
SamplerNames[samplerIndex], // {1}
|
||||
samplerName, // {1}
|
||||
uvs.Value, // {2}
|
||||
level.Value, // {3}
|
||||
offset.Value // {4}
|
||||
|
||||
@@ -422,7 +422,7 @@ bool MaterialGenerator::Generate(WriteStream& source, MaterialInfo& materialInfo
|
||||
|
||||
// Resources
|
||||
{
|
||||
int32 srv = 0;
|
||||
int32 srv = 0, sampler = GPU_STATIC_SAMPLERS_COUNT;
|
||||
switch (baseLayer->Domain)
|
||||
{
|
||||
case MaterialDomain::Surface:
|
||||
@@ -466,7 +466,9 @@ bool MaterialGenerator::Generate(WriteStream& source, MaterialInfo& materialInfo
|
||||
}
|
||||
if (_parameters.HasItems())
|
||||
{
|
||||
const auto error = ShaderGraphUtilities::GenerateShaderResources(_writer, _parameters, srv);
|
||||
auto error = ShaderGraphUtilities::GenerateShaderResources(_writer, _parameters, srv);
|
||||
if (!error)
|
||||
error = ShaderGraphUtilities::GenerateSamplers(_writer, _parameters, sampler);
|
||||
if (error)
|
||||
{
|
||||
OnError(nullptr, nullptr, error);
|
||||
|
||||
Reference in New Issue
Block a user