diff options
author | Kenneth Graunke <[email protected]> | 2010-07-21 22:37:50 -0700 |
---|---|---|
committer | Kenneth Graunke <[email protected]> | 2010-07-28 15:46:29 -0700 |
commit | 546f3a27540c408c9d83368c5f6144e13167dcb3 (patch) | |
tree | 322d11aaed7f3a0db8b870fdb92e16146776effb /src/glsl | |
parent | a4ca1cfb66160c4ea2325f503ff025a4adc35084 (diff) |
ir_constant_expression: Add support for the "smoothstep" builtin.
Diffstat (limited to 'src/glsl')
-rw-r--r-- | src/glsl/ir_constant_expression.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
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) { |