stackgl / shader-school

:mortar_board: A workshopper for GLSL shaders and graphics programming
Other
4.28k stars 252 forks source link

03-intro-3 : Degenerate cases make this very difficult... #84

Closed mdda closed 10 years ago

mdda commented 10 years ago

The README hint file (with the ascii-art diagram) is kind of misleading : the beautiful (and concise) answer that you're looking for doesn't follow directly from the rubric. Moreover, because your VERIFY field covers the whole of the xy plane, it includes degenerate cases where A is collinear with B (and pointing in the opposite direction). This prevents the following from working (which is more directly derivable from your diagram, etc) :

  highp float pct = length(a) / (length(a)+length(b));
  vec2 c = a + pct * (b-a);
  return normalize(c);

The attached patch fixes the degenerate case area where A is pointing almost in opposite direction to B. Reasonable solutions will now work. My guess is that was the original intention, since your existing code includes a 0.01 error ball around the expected solution anyway.

Hope this makes sense Martin :-)

mikolalysenko commented 10 years ago

Thanks for the fix! I've been meaning to get around to this, and totally agree.