Project

General

Profile

« Previous | Next » 

Revision 1e667536

Added by Leszek Koltunski almost 4 years ago

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)

View differences:

src/main/java/org/distorted/library/effect/VertexEffectDistort.java
131 131
      + "vec4 region= vUniforms[effect+2];                             \n"
132 132
      + "float d = degree(region,ps);                                  \n"
133 133

  
134
      + "if( d>0.0 )                                                   \n"
135
      + "  {                                                           \n"
136
      + "  v += d*force;                                               \n"
134
      + "v += d*force;                                                 \n"
137 135

  
138
      + "  float tp = 1.0+n.z;                                         \n"
139
      + "  float tr = 1.0 / (tp - (1.0 - sign(tp)));                   \n"
136
      + "float tp = 1.0+n.z;                                           \n"
137
      + "float tr = 1.0 / (tp - (sign(tp)-1.0));                       \n"   // proper way to compute 1/x is
138
                                                                             // 1/(x-(sign(x)-1)) and NOT 1/(x+1-sign(x))
140 139

  
141
      + "  float ap = ps.x*n.z - ps.z*n.x;                             \n"   // likewise rotate the ps vector
142
      + "  float bp = ps.y*n.z - ps.z*n.y;                             \n"   //
143
      + "  float cp =(ps.x*n.y - ps.y*n.x)*tr;                         \n"   //
144
      + "  vec3 psRot = vec3( ap+n.y*cp , bp-n.x*cp , dot(ps,n) );     \n"   //
140
      + "float ap = ps.x*n.z - ps.z*n.x;                               \n"   // rotate the ps vector
141
      + "float bp = ps.y*n.z - ps.z*n.y;                               \n"   //
142
      + "float cp =(ps.x*n.y - ps.y*n.x)*tr;                           \n"   //
143
      + "vec3 psRot = vec3( ap+n.y*cp , bp-n.x*cp , dot(ps,n) );       \n"   //
145 144

  
146
      + "  float len = length(psRot);                                  \n"
147
      + "  float corr= sign(len)-1.0;                                  \n"   // make N (0,0,1) if ps=(0,0,0)
148
      + "  vec3 N = vec3( -dot(force,n)*psRot.xy, region.w*len-corr ); \n"   // modified rotated normal
145
      + "float len = length(psRot);                                    \n"
146
      + "float corr= sign(len)-1.0;                                    \n"   // make N (0,0,1) if ps=(0,0,0)
147
      + "vec3 N = vec3( -dot(force,n)*psRot.xy, region.w*len-corr );   \n"   // modified rotated normal
149 148
                                                                             // dot(force,n) is rotated force.z
150
      + "  float an = N.x*n.z + N.z*n.x;                               \n"   // now create the normal vector
151
      + "  float bn = N.y*n.z + N.z*n.y;                               \n"   // back from our modified normal
152
      + "  float cn =(N.x*n.y - N.y*n.x)*tr;                           \n"   // rotated back
153
      + "  n = vec3( an+n.y*cn , bn-n.x*cn , -N.x*n.x-N.y*n.y+N.z*n.z);\n"   // notice 4 signs change!
149
      + "float an = N.x*n.z + N.z*n.x;                                 \n"   // now create the normal vector
150
      + "float bn = N.y*n.z + N.z*n.y;                                 \n"   // back from our modified normal
151
      + "float cn =(N.x*n.y - N.y*n.x)*tr;                             \n"   // rotated back
152
      + "n = vec3( an+n.y*cn , bn-n.x*cn , -N.x*n.x-N.y*n.y+N.z*n.z);  \n"   // notice 4 signs change!
153

  
154
      + "  n = normalize(n);                                           \n";
154 155

  
155
      + "  n = normalize(n);                                           \n"
156
      + "  }                                                           \n";
157 156
    }
158 157

  
159 158
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff