From 546f3a27540c408c9d83368c5f6144e13167dcb3 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 22:37:50 -0700 Subject: [PATCH] ir_constant_expression: Add support for the "smoothstep" builtin. --- src/glsl/ir_constant_expression.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index a2748a726cc..b6cb2d86726 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -1064,7 +1064,21 @@ ir_call::constant_expression_value() for (unsigned c = 0; c < op[0]->type->components(); c++) data.f[c] = sinhf(op[0]->value.f[c]); } else if (strcmp(callee, "smoothstep") == 0) { - return NULL; /* FINISHME: implement this */ + assert(num_parameters == 3); + assert(op[1]->type == op[0]->type); + unsigned edge_inc = op[0]->type->is_scalar() ? 0 : 1; + for (unsigned c = 0, e = 0; c < type->components(); e += edge_inc, c++) { + const float edge0 = op[0]->value.f[e]; + const float edge1 = op[1]->value.f[e]; + if (edge0 == edge1) { + data.f[c] = 0.0; /* Avoid a crash - results are undefined anyway */ + } else { + const float numerator = op[2]->value.f[c] - edge0; + const float denominator = edge1 - edge0; + const float t = CLAMP(numerator/denominator, 0, 1); + data.f[c] = t * t * (3 - 2 * t); + } + } } else if (strcmp(callee, "sqrt") == 0) { expr = new(mem_ctx) ir_expression(ir_unop_sqrt, type, op[0], NULL); } else if (strcmp(callee, "step") == 0) { -- 2.30.2