Project

General

Profile

« Previous | Next » 

Revision 7c227ed2

Added by Leszek Koltunski almost 8 years ago

Bugfix in vertex shader (vertices were shot into outer space if P==S, i.e. if center point was exactly equal to the vertex being computed)

View differences:

src/main/res/raw/main_vertex_shader.glsl
97 97
  vec2 PO  = PS + region.xy;
98 98
  float D = region.z*region.z-dot(PO,PO);      // D = |OX|^2 - |PO|^2
99 99
  float ps_sq = dot(PS,PS);
100
  float DOT  = dot(PS,PO)/ps_sq;
100
  float one_over_ps_sq = 1.0/(ps_sq+1.0-sign(ps_sq));  // return 1.0 if ps_sq = 0.0
101
  float DOT  = dot(PS,PO)*one_over_ps_sq;
101 102

  
102
  return max(sign(D),0.0) / (1.0 + 1.0/(sqrt(DOT*DOT+D/ps_sq)-DOT));  // if D<=0 (i.e p is outside the Region) return 0.
103
  return max(sign(D),0.0) / (1.0 + 1.0/(sqrt(DOT*DOT+D*one_over_ps_sq)-DOT));  // if D<=0 (i.e p is outside the Region) return 0.
103 104
  }
104 105

  
105 106
//////////////////////////////////////////////////////////////////////////////////////////////
......
113 114
  float B = sign(A.x*A.y);
114 115
  float E = B*B*(1.0 + min(-PS.x/A.x,-PS.y/A.y));
115 116
  float ps_sq = dot(PS,PS);
116
  float DOT  = dot(PS,PO)/ps_sq;
117
  float one_over_ps_sq = 1.0/(ps_sq+1.0-sign(ps_sq));  // return 1.0 if ps_sq = 0.0
118
  float DOT  = dot(PS,PO)*one_over_ps_sq;
117 119

  
118
  return max(sign(D),0.0) * min(1.0/(1.0 + 1.0/(sqrt(DOT*DOT+D/ps_sq)-DOT)),E);  // if D<=0 (i.e p is outside the Region) return 0.
120
  return max(sign(D),0.0) * min(1.0/(1.0 + 1.0/(sqrt(DOT*DOT+D*one_over_ps_sq)-DOT)),E);  // if D<=0 (i.e p is outside the Region) return 0.
119 121
  }
120 122

  
121 123
//////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff