diff --git a/include/ishaders.h b/include/ishaders.h index 1ee9694df4..6959735c9f 100644 --- a/include/ishaders.h +++ b/include/ishaders.h @@ -58,6 +58,7 @@ class Material FLAG_NOPORTALFOG = 1 << 8, // noPortalFog FLAG_UNSMOOTHEDTANGENTS = 1 << 9, // unsmoothedTangents FLAG_MIRROR = 1 << 10, // mirror + FLAG_POLYGONOFFSET = 1 << 11, // has polygonOffset }; // Surface Flags diff --git a/radiantcore/shaders/ShaderTemplate.cpp b/radiantcore/shaders/ShaderTemplate.cpp index 1cec0e5918..cc4e812a35 100644 --- a/radiantcore/shaders/ShaderTemplate.cpp +++ b/radiantcore/shaders/ShaderTemplate.cpp @@ -94,7 +94,26 @@ bool ShaderTemplate::parseShaderFlags(parser::DefTokeniser& tokeniser, } else if (token == "polygonoffset") { - _polygonOffset = string::convert(tokeniser.nextToken(), 0); + _materialFlags |= Material::FLAG_POLYGONOFFSET; + + // The value argument is optional, try to parse the next token + if (tokeniser.hasMoreTokens()) + { + try + { + _polygonOffset = std::stof(tokeniser.peek()); + // success, exhaust the token + tokeniser.skipTokens(1); + } + catch (const std::logic_error&) // logic_error is base of invalid_argument out_of_range exceptions + { + _polygonOffset = 1.0f; + } + } + else + { + _polygonOffset = 1.0f; + } } else if (token == "clamp") {