Revision 1e667536
Added by Leszek Koltunski almost 4 years ago
src/main/res/raw/main_vertex_shader.glsl | ||
---|---|---|
75 | 75 |
|
76 | 76 |
float degree(in vec4 region, in vec3 PS) |
77 | 77 |
{ |
78 |
vec3 PO = PS + region.xyz; |
|
79 |
float D = region.w*region.w-dot(PO,PO); // D = |OX|^2 - |PO|^2 |
|
78 |
float ps_sq = dot(PS,PS); |
|
80 | 79 |
|
81 |
if( D<=0.0 ) return 0.0;
|
|
80 |
if( ps_sq==0.0 ) return 1.0;
|
|
82 | 81 |
|
83 |
float ps_sq = dot(PS,PS); |
|
84 |
float one_over_ps_sq = 1.0/(ps_sq-(sign(ps_sq)-1.0)); // return 1.0 if ps_sq = 0.0 |
|
85 |
// Important: if we want to write |
|
86 |
// b = 1/a if a!=0, b=1 otherwise |
|
87 |
// we need to write that as |
|
88 |
// b = 1 / ( a-(sign(a)-1) ) |
|
89 |
// [ and NOT 1 / ( a + 1 - sign(a) ) ] |
|
90 |
// because the latter, if 0<a<2^-24, |
|
91 |
// will suffer from round-off error and in this case |
|
92 |
// a + 1.0 = 1.0 !! so 1 / (a+1-sign(a)) = 1/0 ! |
|
93 |
float DOT = dot(PS,PO)*one_over_ps_sq; |
|
94 |
|
|
95 |
return 1.0 / (1.0 + 1.0/(sqrt(DOT*DOT+D*one_over_ps_sq)-DOT)); |
|
82 |
vec3 PO = PS + region.xyz; |
|
83 |
float d = region.w*region.w-dot(PO,PO); |
|
84 |
|
|
85 |
if( d<=0.0 ) return 0.0; |
|
86 |
|
|
87 |
float b = dot(PS,PO)/ps_sq; |
|
88 |
|
|
89 |
return 1.0 / (1.0 + 1.0/(sqrt(b*b + d/ps_sq)-b)); |
|
96 | 90 |
} |
97 | 91 |
|
98 | 92 |
#endif // NUM_VERTEX>0 |
Also available in: Unified diff
1) Cube: convert it to the latest library. Main difference: objects are rendered better, individual cubits have rounded corners.
2) Examples: some adjustments to MeshJoin & Predeform
3) Library: fix a bug in main_vertex_shader's 'degree' function, which didn't work proprely in case of a vertex which was exactly at the center (i.e. vector PS was zero)