From d34fd9341c61d13677e029cb187d4dacff5e44ea Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Fri, 26 Oct 2018 20:31:01 -0400 Subject: [PATCH] Much better AO. --- CameraPane.java | 59 ++++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 44 insertions(+), 15 deletions(-) diff --git a/CameraPane.java b/CameraPane.java index 8fe82ec..f2d438e 100644 --- a/CameraPane.java +++ b/CameraPane.java @@ -7693,7 +7693,7 @@ if (renderCamera != lightCamera) for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.matConcat(parentcam.toParent, matrix, matrix); + LA.matConcat(matrix, parentcam.toParent, matrix); // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); @@ -7709,7 +7709,7 @@ if (renderCamera != lightCamera) for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.matConcat(matrix, parentcam.fromParent, matrix); + LA.matConcat(parentcam.fromParent, matrix, matrix); // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); @@ -8915,7 +8915,7 @@ // if (parentcam != renderCamera) // not a light if (cam != lightCamera) for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.matConcat(parentcam.toParent, matrix, matrix); + LA.matConcat(matrix, parentcam.toParent, matrix); for (int j = 0; j < 4; j++) { @@ -8930,7 +8930,7 @@ // if (parentcam != renderCamera) // not a light if (cam != lightCamera) for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.matConcat(matrix, parentcam.fromParent, matrix); + LA.matConcat(parentcam.fromParent, matrix, matrix); //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); @@ -9754,7 +9754,7 @@ selectedpoint.radius = radius; selectedpoint.recalculate(); selectedpoint.material = new cMaterial(); - selectedpoint.material.color = 0.25f; + selectedpoint.material.color = 0.15f; selectedpoint.material.modulation = 0.75f; debugpoint.radius = radius; @@ -12854,7 +12854,9 @@ { mouseMode |= ZOOM; } - if ((modifiers & META) == META) + + boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK); + if (capsLocked || (modifiers & META) == META) { mouseMode |= VR; // BACKFORTH; } @@ -12868,6 +12870,7 @@ } if ((modifiers & SHIFT) == SHIFT || forcetranslate) { + mouseMode &= ~VR; mouseMode |= TRANSLATE; } // if ((modifiers & SHIFT_META) == SHIFT_META) @@ -13257,7 +13260,8 @@ FlipTransform(); break; case ENTER: - object.editWindow.ScreenFit(); // Edit(); + // object.editWindow.ScreenFit(); // Edit(); + ToggleLive(); break; case DELETE: ClearSelection(); @@ -14718,6 +14722,11 @@ // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]); // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]); + // Will fit the mesh !!! + selectedpoint.toParent[0][0] = 0.0001; + selectedpoint.toParent[1][1] = 0.0001; + selectedpoint.toParent[2][2] = 0.0001; + glu.gluUnProject(x,y,depth,view,0,tempmat2,0,viewport,0,selectedpoint.toParent[3],0); // if (object.selection != null && object.selection.Size() > 0) @@ -15106,13 +15115,19 @@ gl.glFlush(); /**/ - gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusionsizebuffer); + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer); - int[] pixels = occlusionsizebuffer.array(); + float[] pixels = occlusionsizebuffer.array(); double r = 0, g = 0, b = 0; double count = 0; + + gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, tempmat2, 0); + + float mindepth = 1; + + double FACTOR = 1; for (int i = 0; i < pixels.length; i++) { @@ -15197,7 +15212,7 @@ double scale = ray.z; // 1; // cos - int p = pixels[newindex]; + float depth = pixels[newindex]; /* int newindex2 = (x + 1) * OCCLUSION_SIZE + y; @@ -15221,10 +15236,23 @@ scale = (1 - modu) * modv; */ - r += ((p >> 16) & 0xFF) * scale / 255; - g += ((p >> 8) & 0xFF) * scale / 255; - b += (p & 0xFF) * scale / 255; + //r += ((p >> 16) & 0xFF) * scale / 255; + //g += ((p >> 8) & 0xFF) * scale / 255; + //b += (p & 0xFF) * scale / 255; + + if (mindepth > depth) + { + mindepth = depth; + } + double z_eye = tempmat2[3*4 + 2] / (depth * -2.0 + 1.0 - tempmat2[2*4 + 2]); + + double factor = 1 - Math.exp(-z_eye * z_eye / FACTOR); + + r += factor * scale; + g += factor * scale; + b += factor * scale; + count += scale; } @@ -15340,7 +15368,7 @@ int AAbuffersize = 0; //double[] selectedpoint = new double[3]; - static Sphere selectedpoint = new Sphere(); + static Superellipsoid selectedpoint = new Superellipsoid(); static Sphere previousselectedpoint = null; static Sphere debugpoint = new Sphere(); static Sphere debugpoint2 = new Sphere(); @@ -15398,7 +15426,8 @@ static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE); static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE); - static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); + //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); + static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB); static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>(); -- Gitblit v1.6.2