Shader/GlslWriter: Add depth fix (from [0;1] to [-1;1]

This commit is contained in:
Jérôme Leclercq 2021-11-14 13:00:15 +01:00
parent cf8f76baa6
commit c85263c9e7
3 changed files with 10 additions and 4 deletions

View File

@ -43,6 +43,7 @@ namespace Nz
unsigned int glMinorVersion = 0;
bool glES = false;
bool flipYPosition = false;
bool scaleZPosition = false;
};
static const char* GetFlipYUniformName();

View File

@ -96,6 +96,7 @@ namespace Nz
return context.IsExtensionSupported(std::string(ext));
};
env.flipYPosition = true;
env.normalizeDepth = true;
GlslWriter writer;
writer.SetEnv(env);

View File

@ -1146,13 +1146,17 @@ namespace Nz
for (const auto& [name, targetName] : m_currentState->outputFields)
{
bool isOutputPosition = (m_currentState->stage == ShaderStageType::Vertex && m_environment.flipYPosition && targetName == "gl_Position");
bool isOutputPosition = (m_currentState->stage == ShaderStageType::Vertex && targetName == "gl_Position");
Append(targetName, " = ", outputStructVarName, ".", name);
AppendLine(targetName, " = ", outputStructVarName, ".", name, ";");
if (isOutputPosition)
Append(" * vec4(1.0, ", s_flipYUniformName, ", 1.0, 1.0)");
{
if (m_environment.flipYPosition)
AppendLine(targetName, ".y *= ", s_flipYUniformName, ";");
AppendLine(";");
if (m_environment.scaleZPosition)
AppendLine(targetName, ".z = ", targetName, ".z * 2.0 - 1.0;");
}
}
Append("return;"); //< TODO: Don't return if it's the last statement of the function