Why does this line of GLSL for calculating distance produce inconsistent results, when this one works as expected?

user2680460

I am writing a shader which requires knowledge of the distance between a point and the origin. This is the line I had originally:

float distanceToOrigin = sqrt((pow(a_Position.x,2.0)+pow(a_Position.y,2.0)+pow(a_Position.z,2.0));

But doing that caused the vertices to dissappear in certain regions of the scene.

Replacing that line with this one for calculating Manhattan instead of Euclidean distance produces the results I would expect for Manhattan distance.

float distanceToOrigin = a_position.x + a_position.y + a_position.z;

Why might the first line produce unexpected results?

camenomizoratojoakizunewake

For the pow function the results are undefined for values of x<0 or if x=0 and y=0, not to mention it's a lot slower than plain squaring.

왜 거기에서 length (a_Position)를 사용하지 않습니까?

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Why does `find` in Linux skip expected results when `-o` is used?

분류에서Dev

C++ probability calculating program works when bookmarked in Visual Studio but does not work when run without a bookmark

분류에서Dev

Screen-space distance along line strip in GLSL

분류에서Dev

Why does NVL2 returns NULL when it's not expected?

분류에서Dev

Why does synchronized(this) works?

분류에서Dev

Why does bash need && to echo a variable on one line?

분류에서Dev

Why does redirecting output to a file produce a table?

분류에서Dev

Inconsistent datatypes: expected DATE got NUMBER - when inserting into DB

분류에서Dev

Why does OS X `install` errors on redirected input when the same version of `install` on linux works fine?

분류에서Dev

Why does wget give an error when executed with sudo, but works fine without?

분류에서Dev

Why NodeJS KeepAlive does not seem to work as expected?

분류에서Dev

Why does this command not remove files as expected?

분류에서Dev

Why is Entity Framework having performance issues when calculating a sum

분류에서Dev

Why is this ansible lineinfile command to check for a line in /etc/sudoers failing when a very similar one is succeeding?

분류에서Dev

Why does du and quota results not match?

분류에서Dev

Why does the "which" command give duplicate results?

분류에서Dev

Why does one of my monitors turns off (sleep) when I switch to fullscreen on Flash (Youtube,...)?

분류에서Dev

Why does one of my two Dell monitors unexpectedly enter power save mode when using DisplayPort daisychaining?

분류에서Dev

Why does all Word.Range object change when changing one of them?

분류에서Dev

Calculating the distance between 2 given points

분류에서Dev

DISTANCE expected input to be an agent in Netlogo

분류에서Dev

Libertine container sound does not work on one machine, works on another

분류에서Dev

Does anyone know why my AngularJS directives do not display as expected?

분류에서Dev

Why is does this Toast(Android Studio) works only at the second click

분류에서Dev

Why does the images not come one after another?

분류에서Dev

Strange specular results from GLSL phong shader

분류에서Dev

Float value is not correct when parsing it from a String, double works, why?

분류에서Dev

How does an SDK/framework works when included into xCode projects?

분류에서Dev

Why does iwlist scan return cached results almost every time?

Related 관련 기사

  1. 1

    Why does `find` in Linux skip expected results when `-o` is used?

  2. 2

    C++ probability calculating program works when bookmarked in Visual Studio but does not work when run without a bookmark

  3. 3

    Screen-space distance along line strip in GLSL

  4. 4

    Why does NVL2 returns NULL when it's not expected?

  5. 5

    Why does synchronized(this) works?

  6. 6

    Why does bash need && to echo a variable on one line?

  7. 7

    Why does redirecting output to a file produce a table?

  8. 8

    Inconsistent datatypes: expected DATE got NUMBER - when inserting into DB

  9. 9

    Why does OS X `install` errors on redirected input when the same version of `install` on linux works fine?

  10. 10

    Why does wget give an error when executed with sudo, but works fine without?

  11. 11

    Why NodeJS KeepAlive does not seem to work as expected?

  12. 12

    Why does this command not remove files as expected?

  13. 13

    Why is Entity Framework having performance issues when calculating a sum

  14. 14

    Why is this ansible lineinfile command to check for a line in /etc/sudoers failing when a very similar one is succeeding?

  15. 15

    Why does du and quota results not match?

  16. 16

    Why does the "which" command give duplicate results?

  17. 17

    Why does one of my monitors turns off (sleep) when I switch to fullscreen on Flash (Youtube,...)?

  18. 18

    Why does one of my two Dell monitors unexpectedly enter power save mode when using DisplayPort daisychaining?

  19. 19

    Why does all Word.Range object change when changing one of them?

  20. 20

    Calculating the distance between 2 given points

  21. 21

    DISTANCE expected input to be an agent in Netlogo

  22. 22

    Libertine container sound does not work on one machine, works on another

  23. 23

    Does anyone know why my AngularJS directives do not display as expected?

  24. 24

    Why is does this Toast(Android Studio) works only at the second click

  25. 25

    Why does the images not come one after another?

  26. 26

    Strange specular results from GLSL phong shader

  27. 27

    Float value is not correct when parsing it from a String, double works, why?

  28. 28

    How does an SDK/framework works when included into xCode projects?

  29. 29

    Why does iwlist scan return cached results almost every time?

뜨겁다태그

보관