Revision 50be8733
Added by Leszek Koltunski over 5 years ago
src/main/res/raw/main_vertex_shader.glsl | ||
---|---|---|
72 | 72 |
vec3 signA = sign(A); // |
73 | 73 |
vec3 signA_SQ = signA*signA; // div = PS/A if A!=0, 0 otherwise. |
74 | 74 |
vec3 div = signA_SQ*PS/(A-(ONE-signA_SQ)); // |
75 |
vec3 ret = sign(u_objD)-div; |
|
75 | 76 |
|
76 |
float d1= div.x-div.y;
|
|
77 |
float d2= div.y-div.z;
|
|
78 |
float d3= div.x-div.z;
|
|
77 |
float d1= ret.x-ret.y;
|
|
78 |
float d2= ret.y-ret.z;
|
|
79 |
float d3= ret.x-ret.z;
|
|
79 | 80 |
|
80 |
if( d1*d2>0.0 ) return 1.0-div.y; //
|
|
81 |
if( d1*d3>0.0 ) return 1.0-div.z; // return 1-middle(div.x,div.y,div.z)
|
|
82 |
return 1.0-div.x; //
|
|
81 |
if( d1*d2>0.0 ) return ret.y; //
|
|
82 |
if( d1*d3>0.0 ) return ret.z; // return 1-middle(div.x,div.y,div.z)
|
|
83 |
return ret.x; // (unless size of object is 0 then 0-middle)
|
|
83 | 84 |
} |
84 | 85 |
|
85 | 86 |
////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
93 | 94 |
// Then, the degree of a point with respect to a given (spherical!) Region is defined by: |
94 | 95 |
// |
95 | 96 |
// If P is outside the sphere, return 0. |
96 |
// Otherwise, let X be the point where the halfline SP meets the sphere - then return |PX|/||SX|,
|
|
97 |
// Otherwise, let X be the point where the halfline SP meets the sphere - then return |PX|/|SX|, |
|
97 | 98 |
// aka the 'degree' of point P. |
98 | 99 |
// |
99 | 100 |
// We solve the triangle OPX. |
... | ... | |
134 | 135 |
|
135 | 136 |
if( D<=0.0 ) return 0.0; |
136 | 137 |
|
137 |
vec3 A = sign(PS)*u_objD.xyz + S;
|
|
138 |
vec3 A = sign(PS)*u_objD + S; |
|
138 | 139 |
vec3 signA = sign(A); |
139 | 140 |
vec3 signA_SQ = signA*signA; |
140 | 141 |
vec3 div = signA_SQ*PS/(A-(vec3(1.0,1.0,1.0)-signA_SQ)); |
142 |
vec3 ret = sign(u_objD)-div; // if object is flat, make ret.z 0 |
|
141 | 143 |
|
142 |
float d1= div.x-div.y;
|
|
143 |
float d2= div.y-div.z;
|
|
144 |
float d3= div.x-div.z;
|
|
145 |
float E;
|
|
144 |
float d1= ret.x-ret.y;
|
|
145 |
float d2= ret.y-ret.z;
|
|
146 |
float d3= ret.x-ret.z;
|
|
147 |
float degree_object;
|
|
146 | 148 |
|
147 |
if( d1*d2>0.0 ) E= 1.0-div.y;
|
|
148 |
else if( d1*d3>0.0 ) E= 1.0-div.z;
|
|
149 |
else E= 1.0-div.x;
|
|
149 |
if( d1*d2>0.0 ) degree_object= ret.y; //
|
|
150 |
else if( d1*d3>0.0 ) degree_object= ret.z; // middle of the ret.{x,y,z} triple
|
|
151 |
else degree_object= ret.x; //
|
|
150 | 152 |
|
151 | 153 |
float ps_sq = dot(PS,PS); |
152 | 154 |
float one_over_ps_sq = 1.0/(ps_sq-(sign(ps_sq)-1.0)); // return 1.0 if ps_sq = 0.0 |
153 | 155 |
float DOT = dot(PS,PO)*one_over_ps_sq; |
156 |
float degree_region = 1.0/(1.0 + 1.0/(sqrt(DOT*DOT+D*one_over_ps_sq)-DOT)); |
|
154 | 157 |
|
155 |
return min(1.0/(1.0 + 1.0/(sqrt(DOT*DOT+D*one_over_ps_sq)-DOT)),E);
|
|
158 |
return min(degree_region,degree_object);
|
|
156 | 159 |
} |
157 | 160 |
|
158 | 161 |
#endif // NUM_VERTEX>0 |
Also available in: Unified diff
Correct Distort.