-
Notifications
You must be signed in to change notification settings - Fork 392
Commit 5215a63
docs: Fix specification clarity and behavior of smoothstep
Swap the confusing edge0/edge1 nomenclature of the smoothstep
declaration to the more intuitive low/high.
It was pointed out on Slack by Arnon Marcus that the spec's
description of smoothstep was ambiguous about the behavior when
low==high: does it return 0 or 1 if x is the same value? The
documentation is unclear.
The implementation returned 1, which I think is the "correct" behavior
in the sense that it matches the results of step() function with that
edge. So update the documentation to match.
Also Arnon pointed out that things are especially weird if low > high,
it's non-monotonic. This seems to be fixed by simply reversing the
relative order of the `if x < low` and `if x >= high` tests:
basically, it also makes it match step(x, high) and be monotonic.
This is a cleaner formal definition of what smoothstep should do,
namely:
if (x >= high) {
return 1.0f;
} else if (x < low) {
return 0.0f;
} else {
float t = (x - low) / (high - low);
return (3.0f-2.0f*t)*(t*t);
}
Signed-off-by: Larry Gritz <lg@larrygritz.com>1 parent 9f4aa5e commit 5215a63
File tree
4 files changed
+90
-87
lines changed- src
- doc
- include/OSL
- shaders
4 files changed
+90
-87
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3488 | 3488 | | |
3489 | 3489 | | |
3490 | 3490 | | |
3491 | - | ||
3492 | - | ||
3491 | + | ||
3492 | + | ||
3493 | 3493 | | |
3494 | - | ||
3494 | + | ||
3495 | 3495 | | |
3496 | - | ||
3497 | - | ||
3496 | + | ||
3497 | + | ||
3498 | 3498 | | |
3499 | 3499 | | |
3500 | 3500 | | |
3501 | 3501 | | |
3502 | - | ||
3503 | - | ||
3502 | + | ||
3503 | + | ||
3504 | 3504 | | |
3505 | - | ||
3505 | + | ||
3506 | 3506 | | |
3507 | - | ||
3507 | + | ||
3508 | 3508 | | |
3509 | - | ||
3509 | + | ||
3510 | + | ||
3511 | + | ||
3510 | 3512 | | |
3511 | 3513 | | |
3512 | 3514 | | |
3513 | 3515 | | |
3514 | 3516 | | |
3515 | 3517 | | |
3516 | - | ||
3517 | - | ||
3518 | + | ||
3519 | + | ||
3518 | 3520 | | |
3519 | - | ||
3520 | - | ||
3521 | - | ||
3522 | - | ||
3523 | - | ||
3524 | - | ||
3525 | - | ||
3526 | - | ||
3521 | + | ||
3522 | + | ||
3523 | + | ||
3524 | + | ||
3525 | + | ||
3526 | + | ||
3527 | + | ||
3527 | 3528 | | |
3528 | 3529 | | |
3529 | 3530 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
458 | 458 | | |
459 | 459 | | |
460 | 460 | | |
461 | - | ||
461 | + | ||
462 | 462 | | |
463 | - | ||
464 | - | ||
465 | - | ||
463 | + | ||
464 | + | ||
465 | + | ||
466 | 466 | | |
467 | 467 | | |
468 | 468 | | |
469 | 469 | | |
470 | - | ||
470 | + | ||
471 | 471 | | |
472 | - | ||
473 | - | ||
474 | - | ||
475 | - | ||
472 | + | ||
473 | + | ||
474 | + | ||
475 | + | ||
476 | + | ||
477 | + | ||
476 | 478 | | |
477 | 479 | | |
478 | 480 | | |
479 | 481 | | |
480 | 482 | | |
481 | 483 | | |
482 | - | ||
484 | + | ||
483 | 485 | | |
484 | - | ||
485 | - | ||
486 | - | ||
487 | - | ||
488 | - | ||
489 | - | ||
490 | - | ||
486 | + | ||
487 | + | ||
488 | + | ||
489 | + | ||
490 | + | ||
491 | 491 | | |
492 | 492 | | |
493 | 493 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1311 | 1311 | | |
1312 | 1312 | | |
1313 | 1313 | | |
1314 | - | ||
1315 | - | ||
1316 | - | ||
1317 | - | ||
1318 | - | ||
1314 | + | ||
1315 | + | ||
1316 | + | ||
1317 | + | ||
1318 | + | ||
1319 | + | ||
1320 | + | ||
1319 | 1321 | | |
1320 | 1322 | | |
1321 | 1323 | | |
1322 | 1324 | | |
1323 | - | ||
1325 | + | ||
1324 | 1326 | | |
1325 | - | ||
1327 | + | ||
1326 | 1328 | | |
1327 | - | ||
1328 | - | ||
1329 | - | ||
1330 | - | ||
1331 | - | ||
1332 | - | ||
1333 | - | ||
1334 | - | ||
1329 | + | ||
1330 | + | ||
1331 | + | ||
1332 | + | ||
1333 | + | ||
1334 | + | ||
1335 | + | ||
1336 | + | ||
1335 | 1337 | | |
1336 | 1338 | | |
1337 | 1339 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
322 | - | ||
322 | + | ||
323 | 323 | | |
324 | - | ||
324 | + | ||
325 | 325 | | |
326 | - | ||
327 | - | ||
328 | - | ||
326 | + | ||
327 | + | ||
328 | + | ||
329 | 329 | | |
330 | - | ||
330 | + | ||
331 | 331 | | |
332 | - | ||
333 | - | ||
334 | - | ||
332 | + | ||
333 | + | ||
334 | + | ||
335 | 335 | | |
336 | 336 | | |
337 | - | ||
337 | + | ||
338 | 338 | | |
339 | - | ||
340 | - | ||
341 | - | ||
339 | + | ||
340 | + | ||
341 | + | ||
342 | 342 | | |
343 | - | ||
343 | + | ||
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
347 | - | ||
347 | + | ||
348 | 348 | | |
349 | - | ||
350 | - | ||
351 | - | ||
349 | + | ||
350 | + | ||
351 | + | ||
352 | 352 | | |
353 | - | ||
353 | + | ||
354 | 354 | | |
355 | - | ||
356 | - | ||
357 | - | ||
355 | + | ||
356 | + | ||
357 | + | ||
358 | 358 | | |
359 | 359 | | |
360 | - | ||
360 | + | ||
361 | 361 | | |
362 | - | ||
362 | + | ||
363 | 363 | | |
364 | - | ||
364 | + | ||
365 | 365 | | |
366 | - | ||
366 | + | ||
367 | 367 | | |
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
372 | 372 | | |
373 | - | ||
373 | + | ||
374 | 374 | | |
375 | 375 | | |
376 | 376 | | |
377 | 377 | | |
378 | - | ||
378 | + | ||
379 | 379 | | |
380 | - | ||
381 | - | ||
382 | - | ||
380 | + | ||
381 | + | ||
382 | + | ||
383 | 383 | | |
384 | - | ||
384 | + | ||
385 | 385 | | |
386 | - | ||
387 | - | ||
388 | - | ||
386 | + | ||
387 | + | ||
388 | + | ||
389 | 389 | | |
390 | 390 | | |
391 | 391 | | |
| |||
0 commit comments