summaryrefslogtreecommitdiffstats
path: root/src/glsl
diff options
context:
space:
mode:
authorKenneth Graunke <[email protected]>2010-07-21 20:33:42 -0700
committerKenneth Graunke <[email protected]>2010-07-28 15:46:28 -0700
commit04b3643dbf2e0d25e67c86845b2506ad1d26939d (patch)
tree883c2d6ce4153b3e01b41ac28a9145b0f30a84b5 /src/glsl
parentd60b2b03da30093ae85458f1d0be3cc5c33d992c (diff)
ir_constant_expression: Add support for the "refract" builtin.
Diffstat (limited to 'src/glsl')
-rw-r--r--src/glsl/ir_constant_expression.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp
index c8320814a3e..580ef1d4fae 100644
--- a/src/glsl/ir_constant_expression.cpp
+++ b/src/glsl/ir_constant_expression.cpp
@@ -1018,7 +1018,17 @@ ir_call::constant_expression_value()
for (unsigned c = 0; c < op[0]->type->components(); c++)
data.f[c] = op[0]->value.f[c] - 2 * dot_NI * op[1]->value.f[c];
} else if (strcmp(callee, "refract") == 0) {
- return NULL; /* FINISHME: implement this */
+ const float eta = op[2]->value.f[0];
+ const float dot_NI = dot(op[1], op[0]);
+ const float k = 1.0 - eta * eta * (1.0 - dot_NI * dot_NI);
+ if (k < 0.0) {
+ return ir_constant::zero(mem_ctx, this->type);
+ } else {
+ for (unsigned c = 0; c < type->components(); c++) {
+ data.f[c] = eta * op[0]->value.f[c] - (eta * dot_NI + sqrtf(k))
+ * op[1]->value.f[c];
+ }
+ }
} else if (strcmp(callee, "sign") == 0) {
expr = new(mem_ctx) ir_expression(ir_unop_sign, type, op[0], NULL);
} else if (strcmp(callee, "sin") == 0) {