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?
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] 삭제
몇 마디 만하겠습니다