Shader/GlslWriter: Add depth fix (from [0;1] to [-1;1]
This commit is contained in:
parent
cf8f76baa6
commit
c85263c9e7
|
|
@ -43,6 +43,7 @@ namespace Nz
|
||||||
unsigned int glMinorVersion = 0;
|
unsigned int glMinorVersion = 0;
|
||||||
bool glES = false;
|
bool glES = false;
|
||||||
bool flipYPosition = false;
|
bool flipYPosition = false;
|
||||||
|
bool scaleZPosition = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char* GetFlipYUniformName();
|
static const char* GetFlipYUniformName();
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,7 @@ namespace Nz
|
||||||
return context.IsExtensionSupported(std::string(ext));
|
return context.IsExtensionSupported(std::string(ext));
|
||||||
};
|
};
|
||||||
env.flipYPosition = true;
|
env.flipYPosition = true;
|
||||||
|
env.normalizeDepth = true;
|
||||||
|
|
||||||
GlslWriter writer;
|
GlslWriter writer;
|
||||||
writer.SetEnv(env);
|
writer.SetEnv(env);
|
||||||
|
|
|
||||||
|
|
@ -1146,13 +1146,17 @@ namespace Nz
|
||||||
|
|
||||||
for (const auto& [name, targetName] : m_currentState->outputFields)
|
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)
|
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
|
Append("return;"); //< TODO: Don't return if it's the last statement of the function
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue