From 6ed65dcb597fb2153cef75bf1845978f1115658c Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Fri, 14 Dec 2018 22:53:55 -0500 Subject: [PATCH] Repair shadow, normal push + attractor mesh. --- CameraPane.java | 211 +++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 151 insertions(+), 60 deletions(-) diff --git a/CameraPane.java b/CameraPane.java index dda961a..a5a5ed5 100644 --- a/CameraPane.java +++ b/CameraPane.java @@ -2000,10 +2000,12 @@ */ TextureData ReduceTexture(TextureData texturedata, int resolution) // String name) { + int pixelformat = texturedata.getPixelFormat(); + int stride = 1; - if (texturedata.getPixelFormat() == GetGL().GL_RGB || texturedata.getPixelFormat() == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE) + if (pixelformat == GetGL().GL_RGB || pixelformat == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE) stride = 3; - if (texturedata.getPixelFormat() == GetGL().GL_RGBA || texturedata.getPixelFormat() == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA) + if (pixelformat == GetGL().GL_RGBA || pixelformat == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA) stride = 4; int width = texturedata.getWidth(); @@ -7442,6 +7444,8 @@ //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100); //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar); double scale = lightCamera.SCALE / lightCamera.Distance(); +// PATCH FILLE AUX JEANS + //scale *= lightCamera.shaper_fovy / 25; gl.glScaled(2 * scale, 2 * scale, -scale); gl.glTranslated(0, 0, lightCamera.DECAL); @@ -7590,7 +7594,8 @@ float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation - float[] options3 = new float[]{1, 1, 1, 1}; // fog color. image intensity + float[] options3 = new float[]{1, 1, 1, 0}; // fog color + float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen static int imagecount = 0; // movie generation @@ -7690,7 +7695,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); @@ -7706,7 +7711,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); @@ -7923,7 +7928,7 @@ if (!BOXMODE) { - System.out.println("image: " + fullname + " (" + (GrafreeD.wav.cursor / 735 / 4) + ")"); + System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")"); } if (!BOXMODE) @@ -8784,7 +8789,7 @@ if (!IsFrozen()) { // dec 2012 - if (!(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)) + if (!ambientOcclusion && !(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)) { framecount++; shadowbuffer.display(); @@ -8912,7 +8917,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++) { @@ -8927,7 +8932,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); @@ -9089,6 +9094,8 @@ //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100); //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar); double scale = lightCamera.SCALE / lightCamera.Distance(); +// PATCH FILLE AUX JEANS + //scale *= lightCamera.shaper_fovy / 25; gl.glScaled(2 * scale, 2 * scale, -scale); gl.glTranslated(0, 0, lightCamera.DECAL); @@ -9228,6 +9235,8 @@ { //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar); double scale = lightCamera.SCALE / lightCamera.Distance(); +// PATCH FILLE AUX JEANS + //scale *= lightCamera.shaper_fovy / 25; gl.glScaled(2 * scale, 2 * scale, -scale); gl.glTranslated(0, 0, lightCamera.DECAL); //System.out.println("DECAL = " + LIGHTDECAL + "; SCALE = " + LIGHTSCALE); @@ -9379,6 +9388,7 @@ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 63, options2, 0); gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 62, options3, 0); + gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 61, options4, 0); options2[0] *= renderCamera.Distance(); @@ -9750,40 +9760,40 @@ selectedpoint.radius = radius; selectedpoint.recalculate(); selectedpoint.material = new cMaterial(); - selectedpoint.material.color = 0.25f; + selectedpoint.material.color = 0.15f; // Yellow selectedpoint.material.modulation = 0.75f; - debugpoint.radius = radius; - debugpoint.recalculate(); - debugpoint.material = new cMaterial(); - debugpoint.material.color = 0.25f; - debugpoint.material.modulation = 0.75f; + debugpointG.radius = radius; + debugpointG.recalculate(); + debugpointG.material = new cMaterial(); + debugpointG.material.color = 0.25f; // Green + debugpointG.material.modulation = 0.75f; - debugpoint2.radius = radius; - debugpoint2.recalculate(); - debugpoint2.material = new cMaterial(); - debugpoint2.material.color = 0.75f; - debugpoint2.material.modulation = 0.75f; + debugpointP.radius = radius; + debugpointP.recalculate(); + debugpointP.material = new cMaterial(); + debugpointP.material.color = 0.75f; // Purple + debugpointP.material.modulation = 0.75f; - debugpoint3.radius = radius; - debugpoint3.recalculate(); - debugpoint3.material = new cMaterial(); - debugpoint3.material.color = 0.5f; - debugpoint3.material.modulation = 0.75f; + debugpointC.radius = radius; + debugpointC.recalculate(); + debugpointC.material = new cMaterial(); + debugpointC.material.color = 0.5f; // Cyan + debugpointC.material.modulation = 0.75f; - debugpoint4.radius = radius; - debugpoint4.recalculate(); - debugpoint4.material = new cMaterial(); - debugpoint4.material.color = 0f; - debugpoint4.material.modulation = 0.75f; + debugpointR.radius = radius; + debugpointR.recalculate(); + debugpointR.material = new cMaterial(); + debugpointR.material.color = 0f; // Red + debugpointR.material.modulation = 0.75f; InitPoints(radius); } selectedpoint.draw(this, /*(Composite)*/ null, false, false); - debugpoint.draw(this, /*(Composite)*/ null, false,false); - debugpoint2.draw(this, /*(Composite)*/ null, false,false); - debugpoint3.draw(this, /*(Composite)*/ null, false,false); - debugpoint4.draw(this, /*(Composite)*/ null, false,false); + debugpointG.draw(this, /*(Composite)*/ null, false,false); + debugpointP.draw(this, /*(Composite)*/ null, false,false); + debugpointC.draw(this, /*(Composite)*/ null, false,false); + debugpointR.draw(this, /*(Composite)*/ null, false,false); // DrawPoints(this); } @@ -9821,12 +9831,14 @@ if (checker != null && drawMode == DEFAULT) { - // BindTexture(IMMORTAL_TEXTURE); + //BindTexture(IMMORTAL_TEXTURE); + BindTextures(checker.GetTextures(), checker.texres); // NEAREST GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR); DrawChecker(gl); //checker.Draw(this, null, false); // ReleaseTexture(IMMORTAL_TEXTURE); + ReleaseTextures(checker.GetTextures()); } if (object.parent != null) @@ -10357,11 +10369,13 @@ "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough "PARAM params7 = program.env[7];" + // noise power, opacity power "PARAM options0 = program.env[63];" + // fog density, intensity, elevation - "PARAM options1 = program.env[62];" + // fog rgb color, image intensity + "PARAM options1 = program.env[62];" + // fog rgb color + "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen "PARAM pointlight = program.env[127];" + // ... "PARAM zero = { 0.0, 0.0, 0.0, 0.0 };" + "PARAM halfhalf = { 0.25, 0.25, 0.25, 1.0 };" + "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" + + "PARAM threequarter = { 0.75, 0.75, 0.75, 1.0 };" + "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" + "PARAM ten = { 10, 10, 10, 1.0 };" + "PARAM one3rd = { 0.5, 0.33333333333, 0.333333333, 1.0 };" + @@ -10382,6 +10396,7 @@ "PARAM lodbias = { 10,10,10,10 };" + // 20, -2, -20, 1.0 };" + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + "PARAM one2048th = { 0.00048828125, 0.00048828125, 0.00048828125, 1.0 };" + + "PARAM ninetenth = { 0.9, 0.9, 0.9, 1.0 };" + "PARAM almostone = { 0.999, 0.999, 0.999, 1.0 };" + "PARAM c256 = { 256, 256, 256, 1.0 };" + "PARAM c256i = { 0.00390625, 0.00390625, 0.00390625, 1.0 };" + @@ -10422,6 +10437,10 @@ "TEMP R1;" + "TEMP R2;" + "TEMP R3;" + + "TEMP min;" + + "TEMP max;" + + "TEMP average;" + + "TEMP saturation;" + "TEMP keep1;" + "TEMP keep2;" + "TEMP keep3;" + @@ -10952,10 +10971,40 @@ // skin? // Saturation for skin - /**/ // c'est ici - (Skinshader? "DP3 temp.x, final,one;" + + /**/ + (Skinshader? + "DP3 average.x, final,one;" + + "MUL average, one3rd.xxxx,average.xxxx;" + + + "MIN min.x, final.x,final.y;" + + "MIN min.x, min.x,final.z;" + + + "MAX max.x, final.x,final.y;" + + "MAX max.x, max.x,final.z;" + + "MOV max, max.xxxx;" + + + "SUB saturation, max, final;" + + + "ADD temp.x, max.x, one10th.x;" + + "RCP temp.x, temp.x;" + + "MUL temp.x, temp.x, half.x;" + + "MUL saturation, saturation, temp.xxxx;" + + + "DP3 ndotl.x, normald, light;" + + "MAX ndotl.x, ndotl.x, -ndotl.x;" + + + "SUB temp.x, one.x, ndotl.x;" + + "ADD temp.x, temp.x, options2.z;" + // lightsheen + "ADD temp.y, one.y, options2.y;" + // sursurface + "MUL temp.x, temp.x, temp.y;" + + + "MUL saturation, saturation, temp.xxxx;" + + "SUB_SAT temp, max, saturation;" + +/** + "DP3 temp.x, final,one;" + "MUL R2, one3rd.xxxx,temp.xxxx;" + - "SUB temp, final,R2;" + + "SUB temp, final, R2;" + + // using light angle "DP3 ndotl.x, normald,light;" + //"SLT ndotl.y, ndotl.x, zero.x;" + @@ -10968,7 +11017,6 @@ // using light intensity "MOV ndotl.z, R2.x;" + "MUL ndotl.z, ndotl.z, ndotl.z;" + // tuning... - // june 2014 "MAD R1.x, ndotl.z,slope.y,one.x;" + // "SUB ndotl.x, one.x, ndotl.x;" + @@ -10980,6 +11028,7 @@ //"MUL R2.y, shadow.x,R2.y;" + // avril 2014 "MAD temp.x, R2.y, ndotl.y, temp.x;" + // red shift (skin) +/**/ // "ADD final, R2,temp;" + "MOV final, temp;" @@ -11069,7 +11118,7 @@ /**/ // HDR "MOV temp.z, final.a;" + - "MUL final, final,options1.w;" + + "MUL final, final,options2.x;" + "MOV final.a, temp.z;" + /**/ @@ -11262,6 +11311,7 @@ String Shadow(String depth, String shadow) { return "MAX temp.x, ndotl.x, one64th.x;" + + "MIN temp.x, temp.x, ninetenth.x;" + /**/ // Sine "MUL temp.y, temp.x, temp.x;" + @@ -12814,7 +12864,9 @@ { mouseMode |= ZOOM; } - if ((modifiers & META) == META) + + boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK); + if (capsLocked || (modifiers & META) == META) { mouseMode |= VR; // BACKFORTH; } @@ -12828,6 +12880,7 @@ } if ((modifiers & SHIFT) == SHIFT || forcetranslate) { + mouseMode &= ~VR; mouseMode |= TRANSLATE; } // if ((modifiers & SHIFT_META) == SHIFT_META) @@ -13217,7 +13270,8 @@ FlipTransform(); break; case ENTER: - object.editWindow.ScreenFit(); // Edit(); + // object.editWindow.ScreenFit(); // Edit(); + ToggleLive(); break; case DELETE: ClearSelection(); @@ -14394,7 +14448,7 @@ gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS); gl.glPushMatrix(); gl.glLoadIdentity(); - PushMatrix(checker.toParent); + //PushMatrix(checker.toParent); gl.glMatrixMode(GL.GL_TEXTURE); gl.glPushMatrix(); @@ -14417,8 +14471,8 @@ gl.glNormal3f(0.0f, 0.0f, 1.0f); - float step = 0.1666f; //0.25f; - float stepv = step * 1652 / 998; + float step = 2; // 0.1666f; //0.25f; + float stepv = 2; // step * 1652 / 998; int i0 = 0; /* @@ -14488,15 +14542,27 @@ //float u = (i+1)/2; //float v = (j+1)/2; - gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2); + if (checker.flipV) + gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1) / 2); + else + gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2); gl.glVertex3f(i, j, -0.5f); + if (checker.flipV) + gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2); + else gl.glTexCoord2f((i + 1 + step) / 2, (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2); gl.glVertex3f(i + step, j, -0.5f); + if (checker.flipV) + gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2); + else gl.glTexCoord2f((i + 1 + step) / 2, (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2); gl.glVertex3f(i + step, j + stepv, -0.5f); + if (checker.flipV) + gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2); + else gl.glTexCoord2f((i + 1) / 2, (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2); gl.glVertex3f(i, j + stepv, -0.5f); } @@ -14508,7 +14574,7 @@ gl.glMatrixMode(GL.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GL.GL_MODELVIEW); - PopMatrix(null); // checker.toParent); // null); + //PopMatrix(null); // checker.toParent); // null); gl.glPopMatrix(); PopTextureMatrix(checker.toParent); gl.glMatrixMode(GL.GL_TEXTURE); @@ -14677,6 +14743,11 @@ // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]); // 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); @@ -15066,13 +15137,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++) { @@ -15157,7 +15234,7 @@ double scale = ray.z; // 1; // cos - int p = pixels[newindex]; + float depth = pixels[newindex]; /* int newindex2 = (x + 1) * OCCLUSION_SIZE + y; @@ -15181,10 +15258,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; } @@ -15300,12 +15390,12 @@ 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(); - static Sphere debugpoint3 = new Sphere(); - static Sphere debugpoint4 = new Sphere(); + static Sphere debugpointG = new Sphere(); + static Sphere debugpointP = new Sphere(); + static Sphere debugpointC = new Sphere(); + static Sphere debugpointR = new Sphere(); static Sphere debugpoints[] = new Sphere[8]; @@ -15358,7 +15448,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