.. | .. |
---|
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 | |
---|
.. | .. |
---|
9316 | 9334 | double[] light2camera = new double[16]; |
---|
9317 | 9335 | |
---|
9318 | 9336 | //int newenvy = -1; |
---|
9319 | | - boolean envyoff = true; // false; |
---|
9320 | | - String skyboxname = ""; |
---|
9321 | | - String skyboxext; |
---|
9322 | | - String loadedskyboxname = ""; |
---|
| 9337 | + //boolean envyoff = false; |
---|
| 9338 | + |
---|
| 9339 | + String loadedskyboxname; |
---|
9323 | 9340 | |
---|
9324 | 9341 | cVector light0 = new cVector(0, 0, 0); // 1,3,2); |
---|
9325 | 9342 | //float[] light0 = { 0,0,0 }; |
---|
.. | .. |
---|
10842 | 10859 | |
---|
10843 | 10860 | if (wait) |
---|
10844 | 10861 | { |
---|
10845 | | - Sleep(500); |
---|
| 10862 | + Sleep(200); // blocks everything |
---|
10846 | 10863 | |
---|
10847 | 10864 | wait = false; |
---|
10848 | 10865 | } |
---|
.. | .. |
---|
11065 | 11082 | // |
---|
11066 | 11083 | // newenvy = -1; |
---|
11067 | 11084 | |
---|
11068 | | - if (!skyboxname.equals(this.loadedskyboxname)) |
---|
| 11085 | + if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb")) |
---|
11069 | 11086 | { |
---|
11070 | | - LoadSkybox(skyboxname + "/", skyboxext, false); |
---|
11071 | | - loadedskyboxname = skyboxname; |
---|
| 11087 | + if (cubemaprgb == null) |
---|
| 11088 | + { |
---|
| 11089 | + cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11090 | + } |
---|
| 11091 | + |
---|
| 11092 | + cubemap = cubemaprgb; |
---|
| 11093 | + } |
---|
| 11094 | + else |
---|
| 11095 | + { |
---|
| 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; |
---|
11072 | 11111 | } |
---|
11073 | 11112 | |
---|
11074 | 11113 | ratio = ((double) getWidth()) / getHeight(); |
---|
.. | .. |
---|
11372 | 11411 | |
---|
11373 | 11412 | // if (cam != lightCamera) |
---|
11374 | 11413 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
11375 | | - LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 |
---|
| 11414 | + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 |
---|
11376 | 11415 | } |
---|
11377 | 11416 | |
---|
11378 | 11417 | LA.xformDir(lightposition, cam.toScreen, lightposition); |
---|
.. | .. |
---|
12446 | 12485 | |
---|
12447 | 12486 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12448 | 12487 | |
---|
12449 | | - String program0 = |
---|
| 12488 | + String programmin = |
---|
12450 | 12489 | // Min shader |
---|
12451 | 12490 | "!!ARBfp1.0\n" + |
---|
12452 | 12491 | "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
.. | .. |
---|
12513 | 12552 | "MOV result.color, temp;" + |
---|
12514 | 12553 | "END"; |
---|
12515 | 12554 | |
---|
12516 | | - String program = |
---|
| 12555 | + String programmax = |
---|
12517 | 12556 | "!!ARBfp1.0\n" + |
---|
12518 | 12557 | |
---|
12519 | 12558 | //"OPTION ARB_fragment_program_shadow;" + |
---|
.. | .. |
---|
13369 | 13408 | //once = true; |
---|
13370 | 13409 | } |
---|
13371 | 13410 | |
---|
| 13411 | + String program = programmax; |
---|
| 13412 | + |
---|
| 13413 | + if (Globals.MINSHADER) |
---|
| 13414 | + { |
---|
| 13415 | + program = programmin; |
---|
| 13416 | + } |
---|
| 13417 | + |
---|
13372 | 13418 | System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
13373 | 13419 | System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
13374 | 13420 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
.. | .. |
---|
14618 | 14664 | MODIFIERS |= COMMAND; |
---|
14619 | 14665 | /**/ |
---|
14620 | 14666 | if((mod&SHIFT) == SHIFT) |
---|
14621 | | - manipCamera.RotatePosition(0, -speed); |
---|
14622 | | - else |
---|
14623 | 14667 | manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); |
---|
| 14668 | + else |
---|
| 14669 | + manipCamera.RotatePosition(0, -speed); |
---|
14624 | 14670 | /**/ |
---|
14625 | 14671 | if ((mod & SHIFT) == SHIFT) |
---|
14626 | 14672 | { |
---|
.. | .. |
---|
14639 | 14685 | MODIFIERS |= COMMAND; |
---|
14640 | 14686 | /**/ |
---|
14641 | 14687 | if((mod&SHIFT) == SHIFT) |
---|
14642 | | - manipCamera.RotatePosition(0, speed); |
---|
14643 | | - else |
---|
14644 | 14688 | manipCamera.BackForth(0, speed*delta, 0); // getWidth()); |
---|
| 14689 | + else |
---|
| 14690 | + manipCamera.RotatePosition(0, speed); |
---|
14645 | 14691 | /**/ |
---|
14646 | 14692 | if ((mod & SHIFT) == SHIFT) |
---|
14647 | 14693 | { |
---|
.. | .. |
---|
15362 | 15408 | OCCLUSION_CULLING ^= true; |
---|
15363 | 15409 | System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); |
---|
15364 | 15410 | break; |
---|
15365 | | - case '0': envyoff ^= true; repaint(); break; |
---|
| 15411 | + //case '0': envyoff ^= true; repaint(); break; |
---|
15366 | 15412 | case '1': |
---|
15367 | 15413 | case '2': |
---|
15368 | 15414 | case '3': |
---|
.. | .. |
---|
15372 | 15418 | case '7': |
---|
15373 | 15419 | case '8': |
---|
15374 | 15420 | case '9': |
---|
15375 | | - if (envyoff) |
---|
| 15421 | + if (true) // envyoff) |
---|
15376 | 15422 | { |
---|
15377 | 15423 | BGcolor = (key - '1')/8.f; |
---|
15378 | 15424 | } |
---|
.. | .. |
---|
16084 | 16130 | gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
16085 | 16131 | break; |
---|
16086 | 16132 | case Object3D.hitScale: gr.setColor(Color.cyan); |
---|
16087 | | - gr.drawLine(X, Y, 0, 0); |
---|
| 16133 | + gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
16088 | 16134 | break; |
---|
16089 | 16135 | } |
---|
16090 | 16136 | |
---|
.. | .. |
---|
16633 | 16679 | |
---|
16634 | 16680 | return cubemap; |
---|
16635 | 16681 | } |
---|
| 16682 | + |
---|
16636 | 16683 | int bigsphere = -1; |
---|
16637 | 16684 | |
---|
16638 | 16685 | float BGcolor = 0.5f; |
---|
.. | .. |
---|
16641 | 16688 | |
---|
16642 | 16689 | private void DrawSkyBox(GL gl, float ratio) |
---|
16643 | 16690 | { |
---|
16644 | | - if (envyoff || cubemap == null) |
---|
| 16691 | + if (//envyoff || |
---|
| 16692 | + WIREFRAME || |
---|
| 16693 | + cubemap == null) |
---|
16645 | 16694 | { |
---|
16646 | 16695 | gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); |
---|
16647 | 16696 | gl.glClear(gl.GL_COLOR_BUFFER_BIT); |
---|
.. | .. |
---|
16658 | 16707 | gl.glLoadIdentity(); |
---|
16659 | 16708 | gl.glScalef(1,ratio,1); |
---|
16660 | 16709 | |
---|
16661 | | - colorV[0] = 2; |
---|
16662 | | - colorV[1] = 2; |
---|
16663 | | - colorV[2] = 2; |
---|
16664 | | - colorV[3] = 1; |
---|
16665 | | - gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
16666 | | - gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
16667 | | - |
---|
16668 | | - 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); |
---|
16669 | 16718 | |
---|
16670 | 16719 | //gl.glActiveTexture(GL.GL_TEXTURE1); |
---|
16671 | 16720 | //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); |
---|
.. | .. |
---|
16679 | 16728 | // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting |
---|
16680 | 16729 | // causes the normals to be sent down. Thanks to Ken Dyke. |
---|
16681 | 16730 | //gl.glEnable(GL.GL_LIGHTING); |
---|
16682 | | - gl.glEnable(GL.GL_LIGHTING); |
---|
| 16731 | + gl.glDisable(GL.GL_LIGHTING); |
---|
16683 | 16732 | |
---|
16684 | 16733 | gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP); |
---|
16685 | 16734 | gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP); |
---|
.. | .. |
---|
17503 | 17552 | gl.glFlush(); |
---|
17504 | 17553 | |
---|
17505 | 17554 | /**/ |
---|
17506 | | - 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); |
---|
17507 | 17556 | |
---|
17508 | | - float[] pixels = occlusionsizebuffer.array(); |
---|
| 17557 | + float[] depths = occlusiondepthbuffer.array(); |
---|
17509 | 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 | + |
---|
17510 | 17563 | double r = 0, g = 0, b = 0; |
---|
17511 | 17564 | |
---|
17512 | 17565 | double count = 0; |
---|
.. | .. |
---|
17517 | 17570 | |
---|
17518 | 17571 | double FACTOR = 1; |
---|
17519 | 17572 | |
---|
17520 | | - for (int i = 0; i < pixels.length; i++) |
---|
| 17573 | + for (int i = 0; i < depths.length; i++) |
---|
17521 | 17574 | { |
---|
17522 | 17575 | int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
17523 | 17576 | int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
.. | .. |
---|
17600 | 17653 | |
---|
17601 | 17654 | double scale = ray.z; // 1; // cos |
---|
17602 | 17655 | |
---|
17603 | | - float depth = pixels[newindex]; |
---|
| 17656 | + float depth = depths[newindex]; |
---|
17604 | 17657 | |
---|
17605 | 17658 | /* |
---|
17606 | 17659 | int newindex2 = (x + 1) * OCCLUSION_SIZE + y; |
---|
.. | .. |
---|
17797 | 17850 | static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE); |
---|
17798 | 17851 | static IntBuffer bigAAbuffer; |
---|
17799 | 17852 | static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3); |
---|
17800 | | - static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
| 17853 | + //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
17801 | 17854 | static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17802 | 17855 | static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17803 | 17856 | //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
17804 | | - 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 | + |
---|
17805 | 17861 | static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB); |
---|
17806 | 17862 | static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); |
---|
17807 | 17863 | static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>(); |
---|