commit 667884b04e302288216a35dcfa6c0f6929846eb6
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Tue May 19 21:01:10 2020 +0100

    Speedup for preapply

diff --git a/src/main/java/org/distorted/library/main/DistortedLibrary.java b/src/main/java/org/distorted/library/main/DistortedLibrary.java
index 62d7de3..fd06115 100644
--- a/src/main/java/org/distorted/library/main/DistortedLibrary.java
+++ b/src/main/java/org/distorted/library/main/DistortedLibrary.java
@@ -305,6 +305,8 @@ public class DistortedLibrary
     String enabledEffectV= VertexEffect.getAllGLSL();
     String enabledEffectF= "{}";
 
+    fullVertHeader += "#define PREAPPLY\n";
+
     String[] feedback = { "v_Position", "v_endPosition" };
 
     try
diff --git a/src/main/java/org/distorted/library/mesh/MeshBase.java b/src/main/java/org/distorted/library/mesh/MeshBase.java
index b13de31..4d91805 100644
--- a/src/main/java/org/distorted/library/mesh/MeshBase.java
+++ b/src/main/java/org/distorted/library/mesh/MeshBase.java
@@ -290,20 +290,12 @@ public abstract class MeshBase
        {
        for(int vertex=0; vertex<mNumVertices; vertex++)
          {
-         posX = feedback.get(6*vertex  );
-         posY = feedback.get(6*vertex+1);
-         posZ = feedback.get(6*vertex+2);
-         norX = feedback.get(6*vertex+3) - posX;
-         norY = feedback.get(6*vertex+4) - posY;
-         norZ = feedback.get(6*vertex+5) - posZ;
-
-         mVertAttribs[vertex*VERT_ATTRIBS + POS_ATTRIB     ] = posX;
-         mVertAttribs[vertex*VERT_ATTRIBS + POS_ATTRIB + 1 ] = posY;
-         mVertAttribs[vertex*VERT_ATTRIBS + POS_ATTRIB + 2 ] = posZ;
-
-         mVertAttribs[vertex*VERT_ATTRIBS + NOR_ATTRIB     ] = norX;
-         mVertAttribs[vertex*VERT_ATTRIBS + NOR_ATTRIB + 1 ] = norY;
-         mVertAttribs[vertex*VERT_ATTRIBS + NOR_ATTRIB + 2 ] = norZ;
+         mVertAttribs[vertex*VERT_ATTRIBS + POS_ATTRIB     ] = feedback.get(6*vertex  );
+         mVertAttribs[vertex*VERT_ATTRIBS + POS_ATTRIB + 1 ] = feedback.get(6*vertex+1);
+         mVertAttribs[vertex*VERT_ATTRIBS + POS_ATTRIB + 2 ] = feedback.get(6*vertex+2);
+         mVertAttribs[vertex*VERT_ATTRIBS + NOR_ATTRIB     ] = feedback.get(6*vertex+3);
+         mVertAttribs[vertex*VERT_ATTRIBS + NOR_ATTRIB + 1 ] = feedback.get(6*vertex+4);
+         mVertAttribs[vertex*VERT_ATTRIBS + NOR_ATTRIB + 2 ] = feedback.get(6*vertex+5);
          }
 
        mVBO.update(mVertAttribs);
diff --git a/src/main/res/raw/main_vertex_shader.glsl b/src/main/res/raw/main_vertex_shader.glsl
index f461b5b..2e4af7b 100644
--- a/src/main/res/raw/main_vertex_shader.glsl
+++ b/src/main/res/raw/main_vertex_shader.glsl
@@ -107,7 +107,13 @@ void main()
 #endif
    
   v_Position      = v;
-  v_endPosition   = v + n;
+
+#ifdef PREAPPLY
+  v_endPosition   = n;
+#else
+  v_endPosition   = v + 0.5*n;
+#endif
+
   v_TexCoordinate = a_TexCoordinate;
   v_Normal        = normalize(vec3(u_MVMatrix*vec4(n,0.0)));
   gl_Position     = u_MVPMatrix*vec4(v,1.0);
