.. | .. |
---|
110 | 110 | //private Mat4f spotlightTransform = new Mat4f(); |
---|
111 | 111 | //private Mat4f spotlightInverseTransform = new Mat4f(); |
---|
112 | 112 | static GLContext glcontext = null; |
---|
113 | | - /*static*/ com.sun.opengl.util.texture.Texture cubemap; |
---|
| 113 | + /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb |
---|
| 114 | + /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom; |
---|
| 115 | + /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb; |
---|
114 | 116 | boolean reverseUP = false; |
---|
115 | 117 | static boolean frozen = false; |
---|
116 | 118 | boolean enablebackspace = false; // patch for back buffer refresh |
---|
.. | .. |
---|
173 | 175 | static boolean doublesided = false; // true; // reversed normals are awful for conformance |
---|
174 | 176 | boolean anisotropy = true; |
---|
175 | 177 | boolean softshadow = true; // slower but better false; |
---|
176 | | - boolean opacityhalo = false; |
---|
| 178 | + boolean opacityhalo = false; // reverse the halo effect (e.g. glass) |
---|
177 | 179 | |
---|
178 | 180 | boolean macromode = false; |
---|
179 | 181 | |
---|
.. | .. |
---|
188 | 190 | |
---|
189 | 191 | private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); |
---|
190 | 192 | |
---|
191 | | - public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException |
---|
| 193 | + public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException |
---|
192 | 194 | { |
---|
193 | 195 | try |
---|
194 | 196 | { |
---|
195 | | - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
| 197 | + return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
196 | 198 | } catch (IOException e) |
---|
197 | 199 | { |
---|
198 | 200 | System.out.println("NAME = " + name); |
---|
199 | 201 | e.printStackTrace(); // throw new RuntimeException(e); |
---|
| 202 | + return null; |
---|
200 | 203 | } |
---|
201 | 204 | } |
---|
202 | 205 | |
---|
.. | .. |
---|
8358 | 8361 | // else |
---|
8359 | 8362 | // if (!texname.startsWith("/")) |
---|
8360 | 8363 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8361 | | - if (!FileExists(texname)) |
---|
| 8364 | + if (!FileExists(texname) && !texname.startsWith("@")) |
---|
8362 | 8365 | { |
---|
8363 | 8366 | texname = fallbackTextureName; |
---|
8364 | 8367 | } |
---|
.. | .. |
---|
8441 | 8444 | new Exception().printStackTrace(); |
---|
8442 | 8445 | } else |
---|
8443 | 8446 | { |
---|
| 8447 | + if (texname.startsWith("@")) |
---|
| 8448 | + { |
---|
| 8449 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8450 | + if (texturecache == null) |
---|
| 8451 | + texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution); |
---|
| 8452 | + else |
---|
| 8453 | + new Exception().printStackTrace(); |
---|
| 8454 | + } else |
---|
| 8455 | + { |
---|
8444 | 8456 | if (textureon) |
---|
8445 | 8457 | { |
---|
8446 | 8458 | String cachename = texname; |
---|
.. | .. |
---|
8500 | 8512 | texturecache = new CacheTexture(texturedata,resolution); |
---|
8501 | 8513 | //texture = GetTexture(tex, bump); |
---|
8502 | 8514 | } |
---|
| 8515 | + } |
---|
8503 | 8516 | } |
---|
8504 | 8517 | //} |
---|
8505 | 8518 | } |
---|
.. | .. |
---|
8768 | 8781 | |
---|
8769 | 8782 | gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0); |
---|
8770 | 8783 | MAXSTACK = temp[0]; |
---|
8771 | | - System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
| 8784 | + if (Globals.DEBUG) |
---|
| 8785 | + System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
8772 | 8786 | gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0); |
---|
8773 | 8787 | MAXSTACK = temp[0]; |
---|
8774 | | - System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
| 8788 | + if (Globals.DEBUG) |
---|
| 8789 | + System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
8775 | 8790 | |
---|
8776 | 8791 | // Use debug pipeline |
---|
8777 | 8792 | //drawable.setGL(new DebugGL(gl)); // |
---|
.. | .. |
---|
8779 | 8794 | gl = drawable.getGL(); // |
---|
8780 | 8795 | |
---|
8781 | 8796 | GL gl3 = getGL(); |
---|
8782 | | - System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
| 8797 | + if (Globals.DEBUG) |
---|
| 8798 | + System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
8783 | 8799 | |
---|
8784 | 8800 | |
---|
8785 | 8801 | //float pos[] = { 100, 100, 100, 0 }; |
---|
.. | .. |
---|
9220 | 9236 | |
---|
9221 | 9237 | void LoadEnvy(int which) |
---|
9222 | 9238 | { |
---|
| 9239 | + assert(false); |
---|
| 9240 | + |
---|
9223 | 9241 | String name; |
---|
9224 | 9242 | String ext; |
---|
9225 | 9243 | |
---|
.. | .. |
---|
10841 | 10859 | |
---|
10842 | 10860 | if (wait) |
---|
10843 | 10861 | { |
---|
10844 | | - Sleep(500); |
---|
| 10862 | + Sleep(200); // blocks everything |
---|
10845 | 10863 | |
---|
10846 | 10864 | wait = false; |
---|
10847 | 10865 | } |
---|
.. | .. |
---|
11064 | 11082 | // |
---|
11065 | 11083 | // newenvy = -1; |
---|
11066 | 11084 | |
---|
11067 | | - if (object.skyboxname != null) |
---|
| 11085 | + if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb")) |
---|
11068 | 11086 | { |
---|
11069 | | - if (!object.skyboxname.equals(this.loadedskyboxname)) |
---|
| 11087 | + if (cubemaprgb == null) |
---|
11070 | 11088 | { |
---|
11071 | | - LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
11072 | | - loadedskyboxname = object.skyboxname; |
---|
| 11089 | + cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
11073 | 11090 | } |
---|
| 11091 | + |
---|
| 11092 | + cubemap = cubemaprgb; |
---|
11074 | 11093 | } |
---|
11075 | 11094 | else |
---|
11076 | 11095 | { |
---|
11077 | | - cubemap = null; |
---|
11078 | | - loadedskyboxname = null; |
---|
| 11096 | + if (object.skyboxname != null) |
---|
| 11097 | + { |
---|
| 11098 | + if (!object.skyboxname.equals(this.loadedskyboxname)) |
---|
| 11099 | + { |
---|
| 11100 | + cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11101 | + loadedskyboxname = object.skyboxname; |
---|
| 11102 | + } |
---|
| 11103 | + } |
---|
| 11104 | + else |
---|
| 11105 | + { |
---|
| 11106 | + cubemapcustom = null; |
---|
| 11107 | + loadedskyboxname = null; |
---|
| 11108 | + } |
---|
| 11109 | + |
---|
| 11110 | + cubemap = cubemapcustom; |
---|
11079 | 11111 | } |
---|
11080 | 11112 | |
---|
11081 | 11113 | ratio = ((double) getWidth()) / getHeight(); |
---|
.. | .. |
---|
11379 | 11411 | |
---|
11380 | 11412 | // if (cam != lightCamera) |
---|
11381 | 11413 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
11382 | | - LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 |
---|
| 11414 | + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 |
---|
11383 | 11415 | } |
---|
11384 | 11416 | |
---|
11385 | 11417 | LA.xformDir(lightposition, cam.toScreen, lightposition); |
---|
.. | .. |
---|
12453 | 12485 | |
---|
12454 | 12486 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12455 | 12487 | |
---|
12456 | | - String program0 = |
---|
| 12488 | + String programmin = |
---|
12457 | 12489 | // Min shader |
---|
12458 | 12490 | "!!ARBfp1.0\n" + |
---|
12459 | 12491 | "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
.. | .. |
---|
12520 | 12552 | "MOV result.color, temp;" + |
---|
12521 | 12553 | "END"; |
---|
12522 | 12554 | |
---|
12523 | | - String program = |
---|
| 12555 | + String programmax = |
---|
12524 | 12556 | "!!ARBfp1.0\n" + |
---|
12525 | 12557 | |
---|
12526 | 12558 | //"OPTION ARB_fragment_program_shadow;" + |
---|
.. | .. |
---|
13376 | 13408 | //once = true; |
---|
13377 | 13409 | } |
---|
13378 | 13410 | |
---|
| 13411 | + String program = programmax; |
---|
| 13412 | + |
---|
| 13413 | + if (Globals.MINSHADER) |
---|
| 13414 | + { |
---|
| 13415 | + program = programmin; |
---|
| 13416 | + } |
---|
| 13417 | + |
---|
13379 | 13418 | System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
13380 | 13419 | System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
13381 | 13420 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
.. | .. |
---|
14625 | 14664 | MODIFIERS |= COMMAND; |
---|
14626 | 14665 | /**/ |
---|
14627 | 14666 | if((mod&SHIFT) == SHIFT) |
---|
14628 | | - manipCamera.RotatePosition(0, -speed); |
---|
14629 | | - else |
---|
14630 | 14667 | manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); |
---|
| 14668 | + else |
---|
| 14669 | + manipCamera.RotatePosition(0, -speed); |
---|
14631 | 14670 | /**/ |
---|
14632 | 14671 | if ((mod & SHIFT) == SHIFT) |
---|
14633 | 14672 | { |
---|
.. | .. |
---|
14646 | 14685 | MODIFIERS |= COMMAND; |
---|
14647 | 14686 | /**/ |
---|
14648 | 14687 | if((mod&SHIFT) == SHIFT) |
---|
14649 | | - manipCamera.RotatePosition(0, speed); |
---|
14650 | | - else |
---|
14651 | 14688 | manipCamera.BackForth(0, speed*delta, 0); // getWidth()); |
---|
| 14689 | + else |
---|
| 14690 | + manipCamera.RotatePosition(0, speed); |
---|
14652 | 14691 | /**/ |
---|
14653 | 14692 | if ((mod & SHIFT) == SHIFT) |
---|
14654 | 14693 | { |
---|
.. | .. |
---|
16091 | 16130 | gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
16092 | 16131 | break; |
---|
16093 | 16132 | case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
16094 | | - gr.drawLine(X, Y, 0, 0); |
---|
| 16133 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
16095 | 16134 | break; |
---|
16096 | 16135 | } |
---|
16097 | 16136 | |
---|
.. | .. |
---|
16650 | 16689 | private void DrawSkyBox(GL gl, float ratio) |
---|
16651 | 16690 | { |
---|
16652 | 16691 | if (//envyoff || |
---|
| 16692 | + WIREFRAME || |
---|
16653 | 16693 | cubemap == null) |
---|
16654 | 16694 | { |
---|
16655 | 16695 | gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); |
---|
.. | .. |
---|
16667 | 16707 | gl.glLoadIdentity(); |
---|
16668 | 16708 | gl.glScalef(1,ratio,1); |
---|
16669 | 16709 | |
---|
16670 | | - colorV[0] = 2; |
---|
16671 | | - colorV[1] = 2; |
---|
16672 | | - colorV[2] = 2; |
---|
16673 | | - colorV[3] = 1; |
---|
16674 | | - gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
16675 | | - gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
16676 | | - |
---|
16677 | | - gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); |
---|
| 16710 | +// colorV[0] = 2; |
---|
| 16711 | +// colorV[1] = 2; |
---|
| 16712 | +// colorV[2] = 2; |
---|
| 16713 | +// colorV[3] = 1; |
---|
| 16714 | +// gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
| 16715 | +// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
| 16716 | +// |
---|
| 16717 | +// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); |
---|
16678 | 16718 | |
---|
16679 | 16719 | //gl.glActiveTexture(GL.GL_TEXTURE1); |
---|
16680 | 16720 | //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); |
---|
.. | .. |
---|
16688 | 16728 | // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting |
---|
16689 | 16729 | // causes the normals to be sent down. Thanks to Ken Dyke. |
---|
16690 | 16730 | //gl.glEnable(GL.GL_LIGHTING); |
---|
16691 | | - gl.glEnable(GL.GL_LIGHTING); |
---|
| 16731 | + gl.glDisable(GL.GL_LIGHTING); |
---|
16692 | 16732 | |
---|
16693 | 16733 | gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP); |
---|
16694 | 16734 | gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP); |
---|
.. | .. |
---|
17512 | 17552 | gl.glFlush(); |
---|
17513 | 17553 | |
---|
17514 | 17554 | /**/ |
---|
17515 | | - gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer); |
---|
| 17555 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer); |
---|
17516 | 17556 | |
---|
17517 | | - float[] pixels = occlusionsizebuffer.array(); |
---|
| 17557 | + float[] depths = occlusiondepthbuffer.array(); |
---|
17518 | 17558 | |
---|
| 17559 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer); |
---|
| 17560 | + |
---|
| 17561 | + int[] pixels = selectsizebuffer.array(); |
---|
| 17562 | + |
---|
17519 | 17563 | double r = 0, g = 0, b = 0; |
---|
17520 | 17564 | |
---|
17521 | 17565 | double count = 0; |
---|
.. | .. |
---|
17526 | 17570 | |
---|
17527 | 17571 | double FACTOR = 1; |
---|
17528 | 17572 | |
---|
17529 | | - for (int i = 0; i < pixels.length; i++) |
---|
| 17573 | + for (int i = 0; i < depths.length; i++) |
---|
17530 | 17574 | { |
---|
17531 | 17575 | int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
17532 | 17576 | int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
.. | .. |
---|
17609 | 17653 | |
---|
17610 | 17654 | double scale = ray.z; // 1; // cos |
---|
17611 | 17655 | |
---|
17612 | | - float depth = pixels[newindex]; |
---|
| 17656 | + float depth = depths[newindex]; |
---|
17613 | 17657 | |
---|
17614 | 17658 | /* |
---|
17615 | 17659 | int newindex2 = (x + 1) * OCCLUSION_SIZE + y; |
---|
.. | .. |
---|
17806 | 17850 | static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE); |
---|
17807 | 17851 | static IntBuffer bigAAbuffer; |
---|
17808 | 17852 | static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3); |
---|
17809 | | - static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
| 17853 | + //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
17810 | 17854 | static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17811 | 17855 | static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17812 | 17856 | //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
17813 | | - static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17857 | + static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17858 | + |
---|
| 17859 | + static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17860 | + |
---|
17814 | 17861 | static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB); |
---|
17815 | 17862 | static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); |
---|
17816 | 17863 | static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>(); |
---|