From 64e20f390e4b8e58bd0006dde8fa10fba1dac1d5 Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Fri, 16 Aug 2019 13:25:19 -0400 Subject: [PATCH] Fix box and VR keys. --- CameraPane.java | 408 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 315 insertions(+), 93 deletions(-) diff --git a/CameraPane.java b/CameraPane.java index 07290d0..8acf68e 100644 --- a/CameraPane.java +++ b/CameraPane.java @@ -110,7 +110,11 @@ //private Mat4f spotlightTransform = new Mat4f(); //private Mat4f spotlightInverseTransform = new Mat4f(); static GLContext glcontext = null; - /*static*/ com.sun.opengl.util.texture.Texture cubemap; + /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb + /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom; + /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb; + boolean transformMode; + boolean reverseUP = false; static boolean frozen = false; boolean enablebackspace = false; // patch for back buffer refresh @@ -173,7 +177,7 @@ static boolean doublesided = false; // true; // reversed normals are awful for conformance boolean anisotropy = true; boolean softshadow = true; // slower but better false; - boolean opacityhalo = false; + boolean opacityhalo = false; // reverse the halo effect (e.g. glass) boolean macromode = false; @@ -187,6 +191,19 @@ } private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); + + public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException + { + try + { + return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); + } catch (IOException e) + { + System.out.println("NAME = " + name); + e.printStackTrace(); // throw new RuntimeException(e); + return null; + } + } void SetAsGLRenderer(boolean b) { @@ -206,7 +223,8 @@ SetCamera(cam); - SetLight(new Camera(new cVector(10, 10, -20))); + // Warning: not used. + SetLight(new Camera(new cVector(15, 10, -20))); object = o; @@ -1484,6 +1502,8 @@ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z); } + float[] colorV = new float[4]; + void SetColor(Object3D obj, Vertex p0) { CameraPane display = this; @@ -1551,8 +1571,6 @@ { return; } - - float[] colorV = new float[3]; if (false) // marked) { @@ -2499,7 +2517,7 @@ com.sun.opengl.util.texture.TextureIO.newTextureData( getClass().getClassLoader().getResourceAsStream(name), true, - com.sun.opengl.util.texture.TextureIO.PNG); + GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG); } catch (java.io.IOException e) { throw new javax.media.opengl.GLException(e); @@ -8345,7 +8363,7 @@ // else // if (!texname.startsWith("/")) // texname = "/Users/nbriere/Textures/" + texname; - if (!FileExists(texname)) + if (!FileExists(texname) && !texname.startsWith("@")) { texname = fallbackTextureName; } @@ -8428,6 +8446,15 @@ new Exception().printStackTrace(); } else { + if (texname.startsWith("@")) + { + // texturecache = textures.get(texname); // suspicious + if (texturecache == null) + texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution); + else + new Exception().printStackTrace(); + } else + { if (textureon) { String cachename = texname; @@ -8487,6 +8514,7 @@ texturecache = new CacheTexture(texturedata,resolution); //texture = GetTexture(tex, bump); } + } } //} } @@ -8755,10 +8783,12 @@ gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0); MAXSTACK = temp[0]; - System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); + if (Globals.DEBUG) + System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0); MAXSTACK = temp[0]; - System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); + if (Globals.DEBUG) + System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); // Use debug pipeline //drawable.setGL(new DebugGL(gl)); // @@ -8766,7 +8796,8 @@ gl = drawable.getGL(); // GL gl3 = getGL(); - System.out.println("INIT GL IS: " + gl.getClass().getName()); + if (Globals.DEBUG) + System.out.println("INIT GL IS: " + gl.getClass().getName()); //float pos[] = { 100, 100, 100, 0 }; @@ -8931,7 +8962,7 @@ if (cubemap == null) { - LoadEnvy(5); + //LoadEnvy(1); } //cubemap.enable(); @@ -9207,6 +9238,8 @@ void LoadEnvy(int which) { + assert(false); + String name; String ext; @@ -9218,37 +9251,58 @@ cubemap = null; return; case 1: - name = "cubemaps/box_"; - ext = "png"; + name = "cubemaps/rgb/"; + ext = "jpg"; reverseUP = false; break; case 2: - name = "cubemaps/uffizi_"; - ext = "png"; - break; // reverseUP = true; break; + name = "cubemaps/uffizi/"; + ext = "jpg"; + reverseUP = false; + break; case 3: - name = "cubemaps/CloudyHills_"; - ext = "tga"; + name = "cubemaps/CloudyHills/"; + ext = "jpg"; reverseUP = false; break; case 4: - name = "cubemaps/cornell_"; + name = "cubemaps/cornell/"; ext = "png"; reverseUP = false; break; + case 5: + name = "cubemaps/skycube/"; + ext = "jpg"; + reverseUP = false; + break; + case 6: + name = "cubemaps/SaintLazarusChurch3/"; + ext = "jpg"; + reverseUP = false; + break; + case 7: + name = "cubemaps/Sodermalmsallen/"; + ext = "jpg"; + reverseUP = false; + break; + case 8: + name = "cubemaps/Sodermalmsallen2/"; + ext = "jpg"; + reverseUP = false; + break; + case 9: + name = "cubemaps/UnionSquare/"; + ext = "jpg"; + reverseUP = false; + break; default: - name = "cubemaps/rgb_"; - ext = "png"; /*mipmap = true;*/ reverseUP = false; + name = "cubemaps/box/"; + ext = "png"; /*mipmap = true;*/ + reverseUP = false; break; } - - try - { - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); - } catch (IOException e) - { - throw new RuntimeException(e); - } + + LoadSkybox(name, ext, mipmap); } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) @@ -9280,8 +9334,12 @@ static double[] model = new double[16]; double[] camera2light = new double[16]; double[] light2camera = new double[16]; - int newenvy = -1; - boolean envyoff = true; // false; + + //int newenvy = -1; + //boolean envyoff = false; + + String loadedskyboxname; + cVector light0 = new cVector(0, 0, 0); // 1,3,2); //float[] light0 = { 0,0,0 }; cVector dirlight = new cVector(0, 0, 1); // 1,3,2); @@ -9761,10 +9819,12 @@ rati = 1 / rati; gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000); } - assert (newenvy == -1); + + //assert (newenvy == -1); + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); - DrawSkyBox(gl); + DrawSkyBox(gl, (float)rati); gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB); accPerspective(gl, renderCamera.shaper_fovy / ratio, @@ -10801,7 +10861,7 @@ if (wait) { - Sleep(500); + Sleep(200); // blocks everything wait = false; } @@ -11017,13 +11077,43 @@ gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); } - if (newenvy > -1) +// if (newenvy > -1) +// { +// LoadEnvy(newenvy); +// } +// +// newenvy = -1; + + if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb")) { - LoadEnvy(newenvy); + if (cubemaprgb == null) + { + cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false); + } + + cubemap = cubemaprgb; } - - newenvy = -1; - + else + { + if (object.skyboxname != null) + { + if (!object.skyboxname.equals(this.loadedskyboxname)) + { + if (cubemap != null && cubemap != cubemaprgb) + cubemap.dispose(); + cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); + loadedskyboxname = object.skyboxname; + } + } + else + { + cubemapcustom = null; + loadedskyboxname = null; + } + + cubemap = cubemapcustom; + } + ratio = ((double) getWidth()) / getHeight(); //System.out.println("ratio = " + ratio); @@ -11039,7 +11129,7 @@ if (!IsFrozen() && !ambientOcclusion) { - DrawSkyBox(gl); + DrawSkyBox(gl, (float)ratio); } //if (selection_view == -1) @@ -11325,7 +11415,7 @@ // if (cam != lightCamera) //for (int count = parentcam.GetTransformCount(); --count>=0;) - LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 } LA.xformDir(lightposition, cam.toScreen, lightposition); @@ -12399,51 +12489,74 @@ //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); - String program = + String programmin = // Min shader "!!ARBfp1.0\n" + - "PARAM zero123 = { 0.0, 1.0, 2.0, 1.25 };" + + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + + "PARAM light2cam0 = program.env[10];" + + "PARAM light2cam1 = program.env[11];" + + "PARAM light2cam2 = program.env[12];" + "TEMP temp;" + "TEMP light;" + "TEMP ndotl;" + "TEMP normal;" + "TEMP depth;" + + "TEMP eye;" + + "TEMP pos;" + "MAD normal, fragment.color, zero123.z, -zero123.y;" + - + Normalize("normal") + "MOV light, state.light[0].position;" + "DP3 ndotl.x, light, normal;" + // shadow - "MOV temp, fragment.texcoord[1];" + - TextureFetch("depth", "temp", "1") + + "MOV pos, fragment.texcoord[1];" + + "MOV temp, pos;" + + ShadowTextureFetch("depth", "temp", "1") + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + - "SLT temp.x, fragment.texcoord[1].z, depth.z;" + - + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + // No shadow when out of frustum //"SGE temp.y, depth.z, zero123.y;" + //"LRP temp.x, temp.y, zero123.y, temp.x;" + - "MUL ndotl.x, ndotl.x, temp.x;" + - "MAX ndotl.x, ndotl.x, pow2.y;" + + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow + // Backlit + "MOV pos.w, zero123.y;" + + "DP4 eye.x, pos, light2cam0;" + + "DP4 eye.y, pos, light2cam1;" + + "DP4 eye.z, pos, light2cam2;" + + Normalize("eye") + + + "DP3 ndotl.y, -eye, normal;" + + //"MUL ndotl.y, ndotl.y, pow2.x;" + + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit + "SUB ndotl.y, zero123.y, ndotl.y;" + + //"SUB ndotl.y, zero123.y, ndotl.y;" + + //"MUL ndotl.y, ndotl.y, pow2.z;" + + + //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient + //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient + + // Pigment "TEX temp, fragment.texcoord[0], texture[0], 2D;" + "LRP temp, zero123.w, temp, one;" + // texture proportion "MUL temp, temp, ndotl.x;" + "MUL temp, temp, zero123.z;" + - "MOV temp.w, zero123.y;" + // reset alpha + //"MUL temp, temp, ndotl.y;" + + "MOV temp.w, zero123.y;" + // reset alpha "MOV result.color, temp;" + "END"; - String program2 = + String programmax = "!!ARBfp1.0\n" + //"OPTION ARB_fragment_program_shadow;" + @@ -12581,20 +12694,20 @@ "MUL temp, floor, mapgrid.x;" + //"TEX depth0, temp, texture[1], 2D;" + (((mode & FP_SOFTSHADOW) == 0) ? "" : - TextureFetch("depth0", "temp", "1") + + ShadowTextureFetch("depth0", "temp", "1") + "") + "ADD temp.x, temp.x, mapgrid.x;" + //"TEX depth1, temp, texture[1], 2D;" + (((mode & FP_SOFTSHADOW) == 0) ? "" : - TextureFetch("depth1", "temp", "1") + + ShadowTextureFetch("depth1", "temp", "1") + "") + "ADD temp.y, temp.y, mapgrid.x;" + //"TEX depth2, temp, texture[1], 2D;" + - TextureFetch("depth2", "temp", "1") + + ShadowTextureFetch("depth2", "temp", "1") + "SUB temp.x, temp.x, mapgrid.x;" + //"TEX depth3, temp, texture[1], 2D;" + (((mode & FP_SOFTSHADOW) == 0) ? "" : - TextureFetch("depth3", "temp", "1") + + ShadowTextureFetch("depth3", "temp", "1") + "") + //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + //"MOV params, material;" + @@ -12968,7 +13081,7 @@ // display shadow only (fakedepth == 0) "SUB temp.x, half.x, shadow.x;" + "MOV temp.y, -params5.z;" + // params6.x;" + - "SLT temp.z, temp.y, -one2048th.x;" + + "SLT temp.z, temp.y, -c256i.x;" + "SUB temp.y, one.x, temp.z;" + "MUL temp.x, temp.x, temp.y;" + "KIL temp.x;" + @@ -13299,8 +13412,19 @@ //once = true; } - System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); - System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); + String program = programmax; + + if (Globals.MINSHADER) + { + program = programmin; + } + + if (Globals.DEBUG) + { + System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); + System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); + } + loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); //gl.glNewList(displayListID, GL.GL_COMPILE); @@ -13347,7 +13471,8 @@ "\n" + "END\n"; - System.out.println("Program shadow #" + 0 + "; length = " + program.length()); + if (Globals.DEBUG) + System.out.println("Program shadow #" + 0 + "; length = " + program.length()); loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); //gl.glNewList(displayListID, GL.GL_COMPILE); @@ -13392,7 +13517,8 @@ return out; } - String TextureFetch(String dest, String src, String unit) + // Also does frustum culling + String ShadowTextureFetch(String dest, String src, String unit) { return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + "SGE " + src + ".w, " + src + ".x, eps.x;" + @@ -14545,11 +14671,17 @@ void GoDown(int mod) { MODIFIERS |= COMMAND; + boolean isVR = (mouseMode&VR)!=0; /**/ if((mod&SHIFT) == SHIFT) - manipCamera.RotatePosition(0, -speed); + { + if (isVR) + manipCamera.RotateInterest(0, -speed); + else + manipCamera.RotatePosition(0, -speed); + } else - manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); + manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth()); /**/ if ((mod & SHIFT) == SHIFT) { @@ -14559,6 +14691,8 @@ mouseMode |= BACKFORTH; } + targetLookAt.set(manipCamera.lookAt); + //prevX = X = anchorX; prevY = Y = anchorY - (int) (renderCamera.Distance()); } @@ -14567,10 +14701,17 @@ { MODIFIERS |= COMMAND; /**/ + boolean isVR = (mouseMode&VR)!=0; + if((mod&SHIFT) == SHIFT) - manipCamera.RotatePosition(0, speed); + { + if (isVR) + manipCamera.RotateInterest(0, speed); + else + manipCamera.RotatePosition(0, speed); + } else - manipCamera.BackForth(0, speed*delta, 0); // getWidth()); + manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth()); /**/ if ((mod & SHIFT) == SHIFT) { @@ -14580,6 +14721,8 @@ mouseMode |= BACKFORTH; } + targetLookAt.set(manipCamera.lookAt); + //prevX = X = anchorX; prevY = Y = anchorY + (int) (renderCamera.Distance()); } @@ -14589,9 +14732,14 @@ MODIFIERS |= COMMAND; /**/ if((mod&SHIFT) == SHIFT) - manipCamera.Translate(speed*delta, 0, getWidth()); + manipCamera.Translate(speed*delta, 0, getWidth()); else - manipCamera.RotatePosition(speed, 0); + { + if ((mouseMode&VR)!=0) + manipCamera.RotateInterest(-speed, 0); + else + manipCamera.RotatePosition(speed, 0); + } /**/ if ((mod & SHIFT) == SHIFT) { @@ -14601,6 +14749,8 @@ mouseMode |= ROTATE; } // TRANSLATE; + targetLookAt.set(manipCamera.lookAt); + prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance()); prevY = Y = anchorY; } @@ -14610,9 +14760,15 @@ MODIFIERS |= COMMAND; /**/ if((mod&SHIFT) == SHIFT) - manipCamera.Translate(-speed*delta, 0, getWidth()); + manipCamera.Translate(-speed*delta, 0, getWidth()); else - manipCamera.RotatePosition(-speed, 0); + { + if ((mouseMode&VR)!=0) + manipCamera.RotateInterest(speed, 0); + else + manipCamera.RotatePosition(-speed, 0); + } + /**/ if ((mod & SHIFT) == SHIFT) { @@ -14622,6 +14778,8 @@ mouseMode |= ROTATE; } // TRANSLATE; + targetLookAt.set(manipCamera.lookAt); + prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance()); prevY = Y = anchorY; } @@ -15291,20 +15449,24 @@ OCCLUSION_CULLING ^= true; System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); break; - case '0': envyoff ^= true; repaint(); break; + //case '0': envyoff ^= true; repaint(); break; case '1': case '2': case '3': case '4': case '5': - newenvy = Character.getNumericValue(key); - repaint(); - break; case '6': case '7': case '8': case '9': - BGcolor = (key - '6')/3.f; + if (true) // envyoff) + { + BGcolor = (key - '1')/8.f; + } + else + { + //newenvy = Character.getNumericValue(key); + } repaint(); break; case '!': @@ -16002,14 +16164,14 @@ { switch (hitSomething) { - case Object3D.hitCenter: gr.setColor(Color.pink); + case Object3D.hitCenter: gr.setColor(Color.white); gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); break; case Object3D.hitRotate: gr.setColor(Color.yellow); gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); break; case Object3D.hitScale: gr.setColor(Color.cyan); - gr.drawLine(X, Y, 0, 0); + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); break; } @@ -16028,7 +16190,7 @@ if (hasMarquee) { gr.setXORMode(Color.white); - gr.setColor(Color.red); + gr.setColor(Color.white); if (!firstime) { gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH); @@ -16495,6 +16657,8 @@ private /*static*/ boolean firstime; private /*static*/ cVector newView = new cVector(); private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, @@ -16507,29 +16671,67 @@ { com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); + int usedsuf = 0; + for (int i = 0; i < suffixes.length; i++) { - String resourceName = basename + suffixes[i] + "." + suffix; - TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), - mipmapped, - FileUtil.getFileSuffix(resourceName)); - if (data == null) + String[] suffixe = suffixes; + String[] fallback = suffixes2; + String[] fallfallback = suffixes3; + + for (int c=usedsuf; --c>=0;) { - throw new IOException("Unable to load texture " + resourceName); +// String[] temp = suffixe; +// suffixe = fallback; +// fallback = fallfallback; +// fallfallback = temp; } + + String resourceName = basename + suffixe[i] + "." + suffix; + TextureData data; + + try + { + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), + mipmapped, + FileUtil.getFileSuffix(resourceName)); + } + catch (Exception e) + { + try + { + resourceName = basename + fallback[i] + "." + suffix; + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), + mipmapped, + FileUtil.getFileSuffix(resourceName)); + } + catch (Exception e2) + { + resourceName = basename + fallfallback[i] + "." + suffix; + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), + mipmapped, + FileUtil.getFileSuffix(resourceName)); + } + } + //System.out.println("Target = " + targets[i]); cubemap.updateImage(data, targets[i]); } return cubemap; } + int bigsphere = -1; float BGcolor = 0.5f; - private void DrawSkyBox(GL gl) + float ambientLight[] = {1f, 1f, 1f, 1.0f}; + + private void DrawSkyBox(GL gl, float ratio) { - if (envyoff || cubemap == null) + if (//envyoff || + WIREFRAME || + cubemap == null) { gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); gl.glClear(gl.GL_COLOR_BUFFER_BIT); @@ -16544,7 +16746,17 @@ // Compensates for ExaminerViewer's modification of modelview matrix gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); + gl.glScalef(1,ratio,1); +// colorV[0] = 2; +// colorV[1] = 2; +// colorV[2] = 2; +// colorV[3] = 1; +// gl.glDisable(gl.GL_COLOR_MATERIAL); +// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); +// +// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); + //gl.glActiveTexture(GL.GL_TEXTURE1); //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); @@ -16576,6 +16788,7 @@ { gl.glScalef(1.0f, -1.0f, 1.0f); } + gl.glScalef(-1.0f, 1.0f, 1.0f); gl.glMultMatrixd(viewrot_1, 0); gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); //viewer.updateInverseRotation(gl); @@ -16616,7 +16829,8 @@ gl.glDisable(GL.GL_TEXTURE_GEN_R); cubemap.disable(); - ////cubemap.unbind(); + //cubemap.dispose(); + if (CULLFACE) { gl.glEnable(gl.GL_CULL_FACE); @@ -16834,7 +17048,7 @@ //new Exception().printStackTrace(); System.out.println("select buffer init"); // Use debug pipeline - drawable.setGL(new DebugGL(drawable.getGL())); + //drawable.setGL(new DebugGL(drawable.getGL())); GL gl = drawable.getGL(); @@ -17152,6 +17366,7 @@ public void init(GLAutoDrawable drawable) { + if (Globals.DEBUG) System.out.println("shadow buffer init"); GL gl = drawable.getGL(); @@ -17380,10 +17595,14 @@ gl.glFlush(); /**/ - gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer); + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer); - float[] pixels = occlusionsizebuffer.array(); + float[] depths = occlusiondepthbuffer.array(); + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer); + + int[] pixels = selectsizebuffer.array(); + double r = 0, g = 0, b = 0; double count = 0; @@ -17394,7 +17613,7 @@ double FACTOR = 1; - for (int i = 0; i < pixels.length; i++) + for (int i = 0; i < depths.length; i++) { int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2; int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2; @@ -17477,7 +17696,7 @@ double scale = ray.z; // 1; // cos - float depth = pixels[newindex]; + float depth = depths[newindex]; /* int newindex2 = (x + 1) * OCCLUSION_SIZE + y; @@ -17674,11 +17893,14 @@ static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE); static IntBuffer bigAAbuffer; static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3); - static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); + //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 java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); + static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); + + static IntBuffer occlusioncolorbuffer = IntBuffer.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