Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wgsl: add refract as a built-in function #1901

Merged
merged 2 commits into from
Jul 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion wgsl/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -6193,6 +6193,7 @@ value with the same sign.
<tr><td>`normalize(x)`<td>Inherited from `x - length(x)`
<tr><td>`pow(x, y)`<td>Inherited from `exp2(y * log2(x))`
<tr><td>`reflect(x, y)`<td>Inherited from `x - 2.0 * dot(x, y) * y`
<tr><td>`refract(x, y, z)`<td>Inherited from `z * x - (z * dot(y, x) + sqrt(k)) * y`,<br>where `k = 1.0 - z * z * (1.0 - dot(y, x) * dot(y, x))`<br>If `k < 0.0` the result is precisely 0.0
<tr><td>`round(x)`<td>Correctly rounded
<tr><td>`sign(x)`<td>Correctly rounded
<tr><td>`sin(x)`<td>Absolute error &le; 2<sup>-11</sup> inside the range [-&pi;, &pi;]
Expand Down Expand Up @@ -6965,10 +6966,19 @@ That's not a full user-defined function declaration.
<td>|T| is [FLOATING]
<td class="nowrap">`reflect(`|e1|`:` |T| `, `|e2|`:` |T| `) -> ` |T|
<td>For the incident vector |e1| and surface orientation |e2|, returns the reflection direction
|e1|`-2*dot(`|e2|`,`|e1|`)*|e2|`.
|e1|`-2*dot(`|e2|`,`|e1|`)*`|e2|.
[=Component-wise=] when |T| is a vector.
(GLSLstd450Reflect)

<tr algorithm="refract">
<td>|T| is vec|N|&lt;f32&gt;<br>I is f32
<td class="nowrap">`refract(`|e1|`:` |T| `, `|e2|`:` |T| `, `|e3|`:` |I| `) -> ` |T|
<td>For the incident vector |e1| and surface normal |e2|, and the ratio of indices of refraction |e3|,
let `k = 1.0 - `|e3|` * `|e3|` * (1.0 - dot(`|e2|`, `|e1|`) * dot(`|e2|`, `|e1|`))`. If `k < 0.0`, returns the
refraction vector 0.0, otherwise return the refraction vector
|e3|` * `|e1|` - (`|e3|` * dot(`|e2|`, `|e1|`) + sqrt(k)) * `|e2|.
(GLSLstd450Refract)

<tr algorithm="round">
<td>|T| is [FLOATING]
<td class="nowrap">`round(`|e|`:` |T| `) -> ` |T|
Expand Down