Prevent some divide by zeros in shaders. Thanks @vlj!

Fixes #518.
This commit is contained in:
Ben Vanik 2016-01-18 11:51:18 -08:00
parent 6777ce6668
commit 2e5c64fb13
1 changed files with 4 additions and 2 deletions

View File

@ -1256,7 +1256,8 @@ void GlslShaderTranslator::ProcessScalarAluInstruction(
// rcp dest, src0.a // rcp dest, src0.a
case AluScalarOpcode::kRcp: case AluScalarOpcode::kRcp:
EmitSourceDepth("ps = 1.0 / src0.x;\n"); // Prevent divide by zero.
EmitSourceDepth("ps = src0.x != 0.0 ? 1.0 / src0.x : 0.0;\n");
break; break;
// rsqc dest, src0.a // rsqc dest, src0.a
@ -1273,7 +1274,8 @@ void GlslShaderTranslator::ProcessScalarAluInstruction(
// rsq dest, src0.a // rsq dest, src0.a
case AluScalarOpcode::kRsq: case AluScalarOpcode::kRsq:
EmitSourceDepth("ps = inversesqrt(src0.x);\n"); // Prevent divide by zero.
EmitSourceDepth("ps = src0.x != 0.0 ? inversesqrt(src0.x) : 0.0;\n");
break; break;
// maxas dest, src0.ab // maxas dest, src0.ab