.. | .. |
---|
18 | 18 | import javax.imageio.ImageIO; |
---|
19 | 19 | import javax.imageio.ImageWriteParam; |
---|
20 | 20 | import javax.imageio.ImageWriter; |
---|
| 21 | +import javax.imageio.ImageReadParam; |
---|
| 22 | +import javax.imageio.ImageReader; |
---|
21 | 23 | import javax.imageio.plugins.jpeg.JPEGImageWriteParam; |
---|
| 24 | +import javax.imageio.stream.ImageInputStream; |
---|
22 | 25 | import javax.imageio.stream.ImageOutputStream; |
---|
23 | 26 | import javax.imageio.ImageWriteParam; |
---|
24 | 27 | |
---|
.. | .. |
---|
30 | 33 | import java.nio.*; |
---|
31 | 34 | |
---|
32 | 35 | import gleem.linalg.Mat4f; |
---|
| 36 | +import javax.imageio.ImageTypeSpecifier; |
---|
33 | 37 | |
---|
34 | 38 | class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener |
---|
35 | 39 | { |
---|
.. | .. |
---|
44 | 48 | static boolean ABORTED = false; |
---|
45 | 49 | |
---|
46 | 50 | static int STEP = 1; |
---|
| 51 | + |
---|
| 52 | + private static BufferedImage CreateBim(byte[] bytes, int width, int height) |
---|
| 53 | + { |
---|
| 54 | + int[] pixels = new int[bytes.length/3]; |
---|
| 55 | + for (int i=pixels.length; --i>=0;) |
---|
| 56 | + { |
---|
| 57 | + int i3 = i*3; |
---|
| 58 | + pixels[i] = 0xFF; |
---|
| 59 | + pixels[i] <<= 8; |
---|
| 60 | + pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 61 | + pixels[i] <<= 8; |
---|
| 62 | + pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 63 | + pixels[i] <<= 8; |
---|
| 64 | + pixels[i] |= bytes[i3] & 0xFF; |
---|
| 65 | + } |
---|
| 66 | + /* |
---|
| 67 | + int r=0,g=0,b=0,a=0; |
---|
| 68 | + for (int i=0; i<width; i++) |
---|
| 69 | + for (int j=0; j<height; j++) |
---|
| 70 | + { |
---|
| 71 | + int index = j*width+i; |
---|
| 72 | + int p = pixels[index]; |
---|
| 73 | + a = ((p>>24) & 0xFF); |
---|
| 74 | + r = ((p>>16) & 0xFF); |
---|
| 75 | + g = ((p>>8) & 0xFF); |
---|
| 76 | + b = (p & 0xFF); |
---|
| 77 | + pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
| 78 | + } |
---|
| 79 | + /**/ |
---|
| 80 | + BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
| 81 | + rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
| 82 | + return rendImage; |
---|
| 83 | + } |
---|
47 | 84 | |
---|
48 | 85 | /*static*/ private boolean CULLFACE = false; // true; |
---|
49 | 86 | /*static*/ boolean NEAREST = false; // true; |
---|
.. | .. |
---|
60 | 97 | //boolean REDUCETEXTURE = true; |
---|
61 | 98 | boolean CACHETEXTURE = true; |
---|
62 | 99 | boolean CLEANCACHE = false; // true; |
---|
63 | | - boolean MIPMAP = true; // false; // true; |
---|
| 100 | + boolean MIPMAP = false; // true; // never works... |
---|
64 | 101 | boolean COMPRESSTEXTURE = false; |
---|
65 | 102 | boolean KOMPACTTEXTURE = false; // true; |
---|
66 | 103 | boolean RESIZETEXTURE = false; |
---|
.. | .. |
---|
73 | 110 | //private Mat4f spotlightTransform = new Mat4f(); |
---|
74 | 111 | //private Mat4f spotlightInverseTransform = new Mat4f(); |
---|
75 | 112 | static GLContext glcontext = null; |
---|
76 | | - /*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; |
---|
| 116 | + boolean transformMode; |
---|
| 117 | + |
---|
77 | 118 | boolean reverseUP = false; |
---|
78 | 119 | static boolean frozen = false; |
---|
79 | 120 | boolean enablebackspace = false; // patch for back buffer refresh |
---|
.. | .. |
---|
127 | 168 | |
---|
128 | 169 | |
---|
129 | 170 | // OPTIONS |
---|
130 | | - boolean Skinshader = true; |
---|
| 171 | + boolean Skinshader = false; // true; |
---|
131 | 172 | boolean cameraLight = false; |
---|
132 | 173 | boolean UVdebug = false; |
---|
133 | 174 | boolean Udebug = false; |
---|
.. | .. |
---|
136 | 177 | static boolean doublesided = false; // true; // reversed normals are awful for conformance |
---|
137 | 178 | boolean anisotropy = true; |
---|
138 | 179 | boolean softshadow = true; // slower but better false; |
---|
139 | | - boolean opacityhalo = false; |
---|
| 180 | + boolean opacityhalo = false; // reverse the halo effect (e.g. glass) |
---|
140 | 181 | |
---|
141 | 182 | boolean macromode = false; |
---|
142 | 183 | |
---|
.. | .. |
---|
150 | 191 | } |
---|
151 | 192 | |
---|
152 | 193 | private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); |
---|
| 194 | + |
---|
| 195 | + public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException |
---|
| 196 | + { |
---|
| 197 | + try |
---|
| 198 | + { |
---|
| 199 | + return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
| 200 | + } catch (IOException e) |
---|
| 201 | + { |
---|
| 202 | + System.out.println("NAME = " + name); |
---|
| 203 | + e.printStackTrace(); // throw new RuntimeException(e); |
---|
| 204 | + return null; |
---|
| 205 | + } |
---|
| 206 | + } |
---|
153 | 207 | |
---|
154 | 208 | void SetAsGLRenderer(boolean b) |
---|
155 | 209 | { |
---|
.. | .. |
---|
169 | 223 | |
---|
170 | 224 | SetCamera(cam); |
---|
171 | 225 | |
---|
172 | | - SetLight(new Camera(new cVector(10, 10, -20))); |
---|
| 226 | + // Warning: not used. |
---|
| 227 | + SetLight(new Camera(new cVector(15, 10, -20))); |
---|
173 | 228 | |
---|
174 | 229 | object = o; |
---|
175 | 230 | |
---|
.. | .. |
---|
487 | 542 | LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1); |
---|
488 | 543 | LA.vecCross(obj.v0, obj.v1, obj.v2); |
---|
489 | 544 | LA.vecNormalize(obj.v2); |
---|
490 | | - gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z); |
---|
| 545 | + |
---|
| 546 | + SetGLNormal(gl, (float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z); |
---|
491 | 547 | } |
---|
492 | 548 | |
---|
493 | 549 | // P |
---|
.. | .. |
---|
509 | 565 | y += ny * obj.NORMALPUSH; |
---|
510 | 566 | z += nz * obj.NORMALPUSH; |
---|
511 | 567 | |
---|
512 | | - gl.glNormal3f(nx, ny, nz); |
---|
| 568 | + SetGLNormal(gl, nx, ny, nz); |
---|
513 | 569 | } |
---|
514 | 570 | gl.glColor4f(pv.AO, pv.AO, pv.AO, 1); |
---|
515 | 571 | SetColor(obj, pv); |
---|
.. | .. |
---|
541 | 597 | y += ny * obj.NORMALPUSH; |
---|
542 | 598 | z += nz * obj.NORMALPUSH; |
---|
543 | 599 | |
---|
544 | | - gl.glNormal3f(nx, ny, nz); |
---|
| 600 | + SetGLNormal(gl, nx, ny, nz); |
---|
545 | 601 | } |
---|
546 | 602 | //System.out.println("vertexq = " + qv.s + ", " + qv.t); |
---|
547 | 603 | // boolean locked = false; |
---|
.. | .. |
---|
589 | 645 | y += ny * obj.NORMALPUSH; |
---|
590 | 646 | z += nz * obj.NORMALPUSH; |
---|
591 | 647 | |
---|
592 | | - gl.glNormal3f(nx, ny, nz); |
---|
| 648 | + SetGLNormal(gl, nx, ny, nz); |
---|
593 | 649 | } |
---|
594 | 650 | |
---|
595 | 651 | // if ((dot&4) == 0) |
---|
.. | .. |
---|
825 | 881 | //// tris.postdraw(this); |
---|
826 | 882 | } |
---|
827 | 883 | |
---|
828 | | - static Camera localcamera = new Camera(); |
---|
| 884 | + static Camera localAOcamera = new Camera(); |
---|
829 | 885 | static cVector from = new cVector(); |
---|
830 | 886 | static cVector to = new cVector(); |
---|
831 | 887 | |
---|
.. | .. |
---|
834 | 890 | CameraPane cp = this; |
---|
835 | 891 | |
---|
836 | 892 | Camera keep = cp.RenderCamera(); |
---|
837 | | - cp.renderCamera = localcamera; |
---|
| 893 | + cp.renderCamera = localAOcamera; |
---|
838 | 894 | |
---|
839 | 895 | if (br.trimmed) |
---|
840 | 896 | { |
---|
.. | .. |
---|
852 | 908 | br.positions[i3 + 2] + br.normals[i3 + 2]); |
---|
853 | 909 | LA.xformPos(from, transform, from); |
---|
854 | 910 | LA.xformPos(to, transform, to); // RIGID ONLY |
---|
855 | | - localcamera.setAim(from, to); |
---|
| 911 | + localAOcamera.setAim(from, to); |
---|
856 | 912 | |
---|
857 | 913 | CameraPane.occlusionbuffer.display(); |
---|
858 | 914 | |
---|
.. | .. |
---|
886 | 942 | to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z); |
---|
887 | 943 | LA.xformPos(from, transform, from); |
---|
888 | 944 | LA.xformPos(to, transform, to); // RIGID ONLY |
---|
889 | | - localcamera.setAim(from, to); |
---|
| 945 | + localAOcamera.setAim(from, to); |
---|
890 | 946 | |
---|
891 | 947 | CameraPane.occlusionbuffer.display(); |
---|
892 | 948 | |
---|
.. | .. |
---|
1195 | 1251 | { |
---|
1196 | 1252 | if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0) |
---|
1197 | 1253 | { |
---|
1198 | | - gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]); |
---|
| 1254 | + SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]); |
---|
1199 | 1255 | } else |
---|
1200 | 1256 | { |
---|
1201 | | - gl.glNormal3f(0, 0, 1); |
---|
| 1257 | + SetGLNormal(gl, 0, 0, 1); |
---|
1202 | 1258 | } |
---|
1203 | 1259 | |
---|
1204 | 1260 | if (c != null) |
---|
.. | .. |
---|
1222 | 1278 | { |
---|
1223 | 1279 | if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0) |
---|
1224 | 1280 | { |
---|
1225 | | - gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]); |
---|
| 1281 | + SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]); |
---|
1226 | 1282 | } else |
---|
1227 | 1283 | { |
---|
1228 | | - gl.glNormal3f(0, 0, 1); |
---|
| 1284 | + SetGLNormal(gl, 0, 0, 1); |
---|
1229 | 1285 | } |
---|
1230 | 1286 | if (c != null) |
---|
1231 | 1287 | { |
---|
.. | .. |
---|
1250 | 1306 | { |
---|
1251 | 1307 | if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0) |
---|
1252 | 1308 | { |
---|
1253 | | - gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]); |
---|
| 1309 | + SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]); |
---|
1254 | 1310 | } else |
---|
1255 | 1311 | { |
---|
1256 | | - gl.glNormal3f(0, 0, 1); |
---|
| 1312 | + SetGLNormal(gl, 0, 0, 1); |
---|
1257 | 1313 | } |
---|
1258 | 1314 | if (c != null) |
---|
1259 | 1315 | { |
---|
.. | .. |
---|
1435 | 1491 | { |
---|
1436 | 1492 | if (!selectmode) |
---|
1437 | 1493 | { |
---|
1438 | | - gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z); |
---|
| 1494 | + SetGLNormal(gl, (float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z); |
---|
1439 | 1495 | gl.glColor4f(pv.AO, pv.AO, pv.AO, 1); |
---|
1440 | 1496 | |
---|
1441 | 1497 | if (flipV) |
---|
.. | .. |
---|
1447 | 1503 | gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z); |
---|
1448 | 1504 | } |
---|
1449 | 1505 | |
---|
| 1506 | + float[] colorV = new float[4]; |
---|
| 1507 | + |
---|
1450 | 1508 | void SetColor(Object3D obj, Vertex p0) |
---|
1451 | 1509 | { |
---|
1452 | 1510 | CameraPane display = this; |
---|
.. | .. |
---|
1514 | 1572 | { |
---|
1515 | 1573 | return; |
---|
1516 | 1574 | } |
---|
1517 | | - |
---|
1518 | | - float[] colorV = new float[3]; |
---|
1519 | 1575 | |
---|
1520 | 1576 | if (false) // marked) |
---|
1521 | 1577 | { |
---|
.. | .. |
---|
1764 | 1820 | |
---|
1765 | 1821 | display.modelParams7[0] = 0; |
---|
1766 | 1822 | display.modelParams7[1] = 1000; |
---|
1767 | | - display.modelParams7[2] = 0; |
---|
| 1823 | + display.modelParams7[2] = material.parallax; |
---|
1768 | 1824 | display.modelParams7[3] = 0; |
---|
1769 | 1825 | |
---|
1770 | 1826 | //display.modelParams6[0] = 100; // criss de bug de bump |
---|
.. | .. |
---|
1997 | 2053 | switch(viewcode) |
---|
1998 | 2054 | { |
---|
1999 | 2055 | case 0: return "main"; |
---|
2000 | | - case 1: return "one"; |
---|
2001 | | - case 2: return "two"; |
---|
2002 | | - case 3: return "three"; |
---|
| 2056 | + case 1: return "Red"; |
---|
| 2057 | + case 2: return "Green"; |
---|
| 2058 | + case 3: return "Blue"; |
---|
2003 | 2059 | case 4: return "light"; |
---|
2004 | 2060 | } |
---|
2005 | 2061 | |
---|
.. | .. |
---|
2405 | 2461 | return currentGL; |
---|
2406 | 2462 | } |
---|
2407 | 2463 | |
---|
2408 | | - private BufferedImage CreateBim(TextureData texturedata) |
---|
| 2464 | + static private BufferedImage CreateBim(TextureData texturedata) |
---|
2409 | 2465 | { |
---|
2410 | | - // cache to disk |
---|
2411 | | - Buffer buffer = texturedata.getBuffer(); // getMipmapData(); |
---|
2412 | | - //buffers[0]. |
---|
2413 | | - ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer(); |
---|
2414 | | - int[] pixels = new int[bytebuf.capacity()/3]; |
---|
2415 | | - int width = texturedata.getWidth(); //(int)Math.sqrt(pixels.length); // squared |
---|
2416 | | - int height = width; |
---|
2417 | | - for (int i=pixels.length; --i>=0;) |
---|
2418 | | - { |
---|
2419 | | - int i3 = i*3; |
---|
2420 | | - pixels[i] = 0xFF; |
---|
2421 | | - pixels[i] <<= 8; |
---|
2422 | | - pixels[i] |= bytebuf.get(i3+2) & 0xFF; |
---|
2423 | | - pixels[i] <<= 8; |
---|
2424 | | - pixels[i] |= bytebuf.get(i3+1) & 0xFF; |
---|
2425 | | - pixels[i] <<= 8; |
---|
2426 | | - pixels[i] |= bytebuf.get(i3) & 0xFF; |
---|
2427 | | - } |
---|
2428 | | - /* |
---|
2429 | | - int r=0,g=0,b=0,a=0; |
---|
2430 | | - for (int i=0; i<width; i++) |
---|
2431 | | - for (int j=0; j<height; j++) |
---|
2432 | | - { |
---|
2433 | | - int index = j*width+i; |
---|
2434 | | - int p = pixels[index]; |
---|
2435 | | - a = ((p>>24) & 0xFF); |
---|
2436 | | - r = ((p>>16) & 0xFF); |
---|
2437 | | - g = ((p>>8) & 0xFF); |
---|
2438 | | - b = (p & 0xFF); |
---|
2439 | | - pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; |
---|
2440 | | - } |
---|
2441 | | - /**/ |
---|
2442 | | - BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); |
---|
2443 | | - rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); |
---|
2444 | | - return rendImage; |
---|
| 2466 | + Grafreed.Assert(texturedata != null); |
---|
| 2467 | + |
---|
| 2468 | + int width = texturedata.getWidth(); |
---|
| 2469 | + int height = texturedata.getHeight(); |
---|
| 2470 | + |
---|
| 2471 | + Buffer buffer = texturedata.getBuffer(); |
---|
| 2472 | + ByteBuffer bytebuf = (ByteBuffer)buffer; |
---|
| 2473 | + |
---|
| 2474 | + byte[] bytes = bytebuf.array(); |
---|
| 2475 | + |
---|
| 2476 | + return CreateBim(bytes, width, height); |
---|
| 2477 | + } |
---|
| 2478 | + |
---|
| 2479 | + private void SetGLNormal(javax.media.opengl.GL gl, float nx, float ny, float nz) |
---|
| 2480 | + { |
---|
| 2481 | + gl.glNormal3f(nx, ny, nz); |
---|
| 2482 | + |
---|
| 2483 | + if (ny > 0.9 || ny < -0.9) |
---|
| 2484 | + // Ground or ceiling |
---|
| 2485 | + gl.glVertexAttrib3f(4, 1, 0, 0); |
---|
| 2486 | + else |
---|
| 2487 | + // Walls |
---|
| 2488 | + gl.glVertexAttrib3f(4, 0, 1, 0); |
---|
2445 | 2489 | } |
---|
2446 | 2490 | |
---|
2447 | 2491 | /**/ |
---|
.. | .. |
---|
2452 | 2496 | |
---|
2453 | 2497 | int resolution; |
---|
2454 | 2498 | |
---|
2455 | | - CacheTexture(com.sun.opengl.util.texture.Texture tex, int res) |
---|
| 2499 | + CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res) |
---|
2456 | 2500 | { |
---|
2457 | | - texture = tex; |
---|
| 2501 | + texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata); |
---|
| 2502 | + texturedata = texdata; |
---|
2458 | 2503 | resolution = res; |
---|
2459 | 2504 | } |
---|
2460 | 2505 | } |
---|
2461 | 2506 | /**/ |
---|
2462 | 2507 | |
---|
2463 | 2508 | // TEXTURE static Texture texture; |
---|
2464 | | - static public java.util.Hashtable<String, CacheTexture> textures = new java.util.Hashtable<String, CacheTexture>(); |
---|
2465 | | - static public java.util.Hashtable<BufferedImage, CacheTexture> bimtextures = new java.util.Hashtable<BufferedImage, CacheTexture>(); |
---|
2466 | | - static public java.util.HashSet<String> usedtextures = new java.util.HashSet<String>(); |
---|
| 2509 | + static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2510 | + static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>(); |
---|
| 2511 | + static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>(); |
---|
| 2512 | + static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>(); |
---|
2467 | 2513 | |
---|
2468 | 2514 | int pigmentdepth = 0; |
---|
2469 | 2515 | public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
.. | .. |
---|
2471 | 2517 | public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; |
---|
2472 | 2518 | //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; |
---|
2473 | 2519 | public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); |
---|
2474 | | - public static String NOISE_TEXTURE = "WHITE_NOISE"; |
---|
| 2520 | + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); |
---|
2475 | 2521 | // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); |
---|
2476 | 2522 | |
---|
2477 | | - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) |
---|
| 2523 | + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) |
---|
2478 | 2524 | { |
---|
2479 | 2525 | TextureData texturedata = null; |
---|
2480 | 2526 | |
---|
.. | .. |
---|
2484 | 2530 | com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
2485 | 2531 | getClass().getClassLoader().getResourceAsStream(name), |
---|
2486 | 2532 | true, |
---|
2487 | | - com.sun.opengl.util.texture.TextureIO.PNG); |
---|
| 2533 | + GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG); |
---|
2488 | 2534 | } catch (java.io.IOException e) |
---|
2489 | 2535 | { |
---|
2490 | 2536 | throw new javax.media.opengl.GLException(e); |
---|
.. | .. |
---|
2493 | 2539 | if (bump) |
---|
2494 | 2540 | texturedata = ConvertBump(texturedata, false); |
---|
2495 | 2541 | |
---|
2496 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2497 | | - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
| 2542 | +// com.sun.opengl.util.texture.Texture texture = |
---|
| 2543 | +// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
2498 | 2544 | |
---|
2499 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
2500 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2545 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
| 2546 | + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
2501 | 2547 | |
---|
2502 | | - return texture; |
---|
| 2548 | + return texturedata; |
---|
2503 | 2549 | } |
---|
2504 | 2550 | |
---|
2505 | | - com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump) |
---|
| 2551 | + com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump) |
---|
2506 | 2552 | { |
---|
2507 | 2553 | TextureData texturedata = null; |
---|
2508 | 2554 | |
---|
.. | .. |
---|
2510 | 2556 | { |
---|
2511 | 2557 | texturedata = |
---|
2512 | 2558 | com.sun.opengl.util.texture.TextureIO.newTextureData( |
---|
2513 | | - name, |
---|
| 2559 | + bim, |
---|
2514 | 2560 | true); |
---|
2515 | 2561 | } catch (Exception e) |
---|
2516 | 2562 | { |
---|
.. | .. |
---|
2519 | 2565 | |
---|
2520 | 2566 | if (bump) |
---|
2521 | 2567 | texturedata = ConvertBump(texturedata, false); |
---|
2522 | | - |
---|
2523 | | - com.sun.opengl.util.texture.Texture texture = |
---|
2524 | | - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); |
---|
2525 | | - |
---|
2526 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); |
---|
2527 | | - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); |
---|
2528 | | - |
---|
2529 | | - return texture; |
---|
| 2568 | + |
---|
| 2569 | + return texturedata; |
---|
2530 | 2570 | } |
---|
2531 | 2571 | |
---|
2532 | 2572 | boolean HUESMOOTH = true; // wrap around bug... true; |
---|
.. | .. |
---|
8014 | 8054 | pigment = null; |
---|
8015 | 8055 | } |
---|
8016 | 8056 | |
---|
8017 | | - ReleaseTexture(bump, true); |
---|
8018 | | - ReleaseTexture(pigment, false); |
---|
| 8057 | + ReleaseTexture(tex, true); |
---|
| 8058 | + ReleaseTexture(tex, false); |
---|
8019 | 8059 | } |
---|
8020 | 8060 | |
---|
8021 | 8061 | public void ReleasePigmentTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
8044 | 8084 | pigment = null; |
---|
8045 | 8085 | } |
---|
8046 | 8086 | |
---|
8047 | | - ReleaseTexture(pigment, false); |
---|
| 8087 | + ReleaseTexture(tex, false); |
---|
8048 | 8088 | } |
---|
8049 | 8089 | |
---|
8050 | 8090 | public void ReleaseBumpTexture(cTexture tex) // INTERFACE |
---|
.. | .. |
---|
8073 | 8113 | bump = null; |
---|
8074 | 8114 | } |
---|
8075 | 8115 | |
---|
8076 | | - ReleaseTexture(bump, true); |
---|
| 8116 | + ReleaseTexture(tex, true); |
---|
8077 | 8117 | } |
---|
8078 | 8118 | |
---|
8079 | | - void ReleaseTexture(String tex, boolean bump) |
---|
| 8119 | + void ReleaseTexture(cTexture tex, boolean bump) |
---|
8080 | 8120 | { |
---|
8081 | 8121 | if (// DrawMode() != 0 || /*tex == null ||*/ |
---|
8082 | 8122 | ambientOcclusion ) // || !textureon) |
---|
.. | .. |
---|
8087 | 8127 | CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; |
---|
8088 | 8128 | |
---|
8089 | 8129 | if (tex != null) |
---|
8090 | | - texture = textures.get(tex); |
---|
| 8130 | + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8091 | 8131 | |
---|
8092 | 8132 | // //assert( texture != null ); |
---|
8093 | 8133 | // if (texture == null) |
---|
.. | .. |
---|
8237 | 8277 | |
---|
8238 | 8278 | if (tex == null) |
---|
8239 | 8279 | { |
---|
8240 | | - BindTexture(null, null,false,resolution); |
---|
| 8280 | + BindTexture(null,false,resolution); |
---|
8241 | 8281 | return; |
---|
8242 | 8282 | } |
---|
8243 | 8283 | |
---|
8244 | 8284 | String pigment = Object3D.GetPigment(tex); |
---|
8245 | 8285 | |
---|
8246 | | - usedtextures.add(pigment); |
---|
| 8286 | + usedtextures.add(tex); |
---|
8247 | 8287 | |
---|
8248 | 8288 | //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8249 | 8289 | { |
---|
.. | .. |
---|
8257 | 8297 | } |
---|
8258 | 8298 | |
---|
8259 | 8299 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8260 | | - BindTexture(tex.pigmenttexture, pigment, false, resolution); |
---|
| 8300 | + BindTexture(tex, false, resolution); |
---|
8261 | 8301 | } |
---|
8262 | 8302 | |
---|
8263 | 8303 | /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE |
---|
.. | .. |
---|
8270 | 8310 | |
---|
8271 | 8311 | if (tex == null) |
---|
8272 | 8312 | { |
---|
8273 | | - BindTexture(null, null,true,resolution); |
---|
| 8313 | + BindTexture(null,true,resolution); |
---|
8274 | 8314 | return; |
---|
8275 | 8315 | } |
---|
8276 | 8316 | |
---|
8277 | 8317 | String bump = Object3D.GetBump(tex); |
---|
8278 | 8318 | |
---|
8279 | | - usedtextures.add(bump); |
---|
| 8319 | + usedtextures.add(tex); |
---|
8280 | 8320 | |
---|
8281 | 8321 | //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) |
---|
8282 | 8322 | { |
---|
.. | .. |
---|
8290 | 8330 | } |
---|
8291 | 8331 | |
---|
8292 | 8332 | GetGL().glActiveTexture(GetGL().GL_TEXTURE2); |
---|
8293 | | - BindTexture(tex.bumptexture, bump, true, resolution); |
---|
| 8333 | + BindTexture(tex, true, resolution); |
---|
8294 | 8334 | GetGL().glActiveTexture(GetGL().GL_TEXTURE0); |
---|
8295 | 8335 | } |
---|
8296 | 8336 | |
---|
.. | .. |
---|
8314 | 8354 | return fileExists; |
---|
8315 | 8355 | } |
---|
8316 | 8356 | |
---|
8317 | | - CacheTexture GetCacheTexture(java.awt.image.BufferedImage bim, String tex, boolean bump, int resolution) throws Exception |
---|
| 8357 | + CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8318 | 8358 | { |
---|
8319 | 8359 | CacheTexture texturecache = null; |
---|
8320 | 8360 | |
---|
8321 | 8361 | if (tex != null) |
---|
8322 | 8362 | { |
---|
8323 | | - String texname = tex; |
---|
| 8363 | + String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex); |
---|
| 8364 | + byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata; |
---|
| 8365 | + |
---|
| 8366 | + if (texname.equals("") && texdata == null) |
---|
| 8367 | + { |
---|
| 8368 | + return null; |
---|
| 8369 | + } |
---|
8324 | 8370 | |
---|
8325 | 8371 | String fallbackTextureName = defaultDirectory + "/Textures/" + texname; |
---|
8326 | 8372 | |
---|
.. | .. |
---|
8330 | 8376 | // else |
---|
8331 | 8377 | // if (!texname.startsWith("/")) |
---|
8332 | 8378 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8333 | | - if (!FileExists(tex)) |
---|
| 8379 | + if (!FileExists(texname) && !texname.startsWith("@")) |
---|
8334 | 8380 | { |
---|
8335 | 8381 | texname = fallbackTextureName; |
---|
8336 | 8382 | } |
---|
8337 | 8383 | |
---|
8338 | 8384 | if (CACHETEXTURE) |
---|
8339 | 8385 | { |
---|
8340 | | - if (bim == null) |
---|
8341 | | - texturecache = textures.get(texname); // TEXTURE CACHE |
---|
| 8386 | + if (texdata == null) |
---|
| 8387 | + texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex); |
---|
8342 | 8388 | else |
---|
8343 | | - texturecache = bimtextures.get(bim); // TEXTURE CACHE |
---|
| 8389 | + texturecache = bimtextures.get(texdata); |
---|
8344 | 8390 | } |
---|
8345 | 8391 | |
---|
8346 | | - if (texturecache == null || texturecache.resolution < resolution) |
---|
| 8392 | + if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution) |
---|
8347 | 8393 | { |
---|
8348 | 8394 | TextureData texturedata = null; |
---|
8349 | 8395 | |
---|
8350 | | - if (bim != null) |
---|
| 8396 | + if (texdata != null && textureon) |
---|
8351 | 8397 | { |
---|
| 8398 | + BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8399 | + |
---|
| 8400 | + try |
---|
| 8401 | + { |
---|
| 8402 | + bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8403 | + } |
---|
| 8404 | + catch (Exception e) |
---|
| 8405 | + { |
---|
| 8406 | + bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); |
---|
| 8407 | + } |
---|
| 8408 | + |
---|
8352 | 8409 | texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); |
---|
| 8410 | + bimtextures.put(texdata, texturecache); |
---|
| 8411 | + |
---|
| 8412 | + //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); |
---|
| 8413 | + |
---|
| 8414 | + //Object bim2 = CreateBim(texturecache.texturedata); |
---|
| 8415 | + //bim2 = bim; |
---|
8353 | 8416 | } |
---|
8354 | 8417 | else |
---|
8355 | | - if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
| 8418 | + if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) |
---|
8356 | 8419 | { |
---|
8357 | 8420 | assert(!bump); |
---|
8358 | 8421 | // if (bump) |
---|
.. | .. |
---|
8363 | 8426 | // } |
---|
8364 | 8427 | // else |
---|
8365 | 8428 | // { |
---|
8366 | | - texturecache = textures.get(tex); |
---|
| 8429 | + // texturecache = textures.get(texname); // suspicious |
---|
8367 | 8430 | if (texturecache == null) |
---|
8368 | 8431 | { |
---|
8369 | 8432 | texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
.. | .. |
---|
8372 | 8435 | new Exception().printStackTrace(); |
---|
8373 | 8436 | // } |
---|
8374 | 8437 | } else |
---|
8375 | | - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
| 8438 | + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) |
---|
8376 | 8439 | { |
---|
8377 | 8440 | assert(bump); |
---|
8378 | | - texturecache = textures.get(tex); |
---|
| 8441 | + // texturecache = textures.get(texname); // suspicious |
---|
8379 | 8442 | if (texturecache == null) |
---|
8380 | 8443 | texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); |
---|
8381 | 8444 | else |
---|
.. | .. |
---|
8387 | 8450 | // texture = GetResourceTexture("default.png"); |
---|
8388 | 8451 | //} else |
---|
8389 | 8452 | //{ |
---|
8390 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 8453 | + if (texname.endsWith("WHITE_NOISE")) |
---|
8391 | 8454 | { |
---|
8392 | | - texturecache = textures.get(tex); |
---|
| 8455 | + // texturecache = textures.get(texname); // suspicious |
---|
8393 | 8456 | if (texturecache == null) |
---|
8394 | 8457 | texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); |
---|
| 8458 | + else |
---|
| 8459 | + new Exception().printStackTrace(); |
---|
| 8460 | + } else |
---|
| 8461 | + { |
---|
| 8462 | + if (texname.startsWith("@")) |
---|
| 8463 | + { |
---|
| 8464 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8465 | + if (texturecache == null) |
---|
| 8466 | + texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution); |
---|
8395 | 8467 | else |
---|
8396 | 8468 | new Exception().printStackTrace(); |
---|
8397 | 8469 | } else |
---|
.. | .. |
---|
8452 | 8524 | if (texturedata == null) |
---|
8453 | 8525 | throw new Exception(); |
---|
8454 | 8526 | |
---|
8455 | | - texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); |
---|
| 8527 | + texturecache = new CacheTexture(texturedata,resolution); |
---|
8456 | 8528 | //texture = GetTexture(tex, bump); |
---|
8457 | 8529 | } |
---|
| 8530 | + } |
---|
8458 | 8531 | } |
---|
8459 | 8532 | //} |
---|
8460 | 8533 | } |
---|
8461 | 8534 | |
---|
8462 | | - if (/*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
| 8535 | + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) |
---|
8463 | 8536 | { |
---|
8464 | 8537 | //return false; |
---|
8465 | | - assert(bim == null); |
---|
8466 | 8538 | |
---|
8467 | 8539 | // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")"); |
---|
8468 | 8540 | if (texturedata != null && texname.toLowerCase().endsWith(".jpg")) |
---|
.. | .. |
---|
8509 | 8581 | } |
---|
8510 | 8582 | } |
---|
8511 | 8583 | } |
---|
8512 | | - |
---|
| 8584 | + |
---|
| 8585 | + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; |
---|
| 8586 | + |
---|
8513 | 8587 | //System.out.println("Texture = " + tex); |
---|
8514 | | - if (textures.containsKey(texname)) |
---|
| 8588 | + if (textures.containsKey(tex)) |
---|
8515 | 8589 | { |
---|
8516 | | - CacheTexture thetex = textures.get(texname); |
---|
| 8590 | + CacheTexture thetex = textures.get(tex); |
---|
8517 | 8591 | thetex.texture.disable(); |
---|
8518 | 8592 | thetex.texture.dispose(); |
---|
8519 | | - textures.remove(texname); |
---|
| 8593 | + textures.remove(tex); |
---|
8520 | 8594 | } |
---|
8521 | 8595 | |
---|
8522 | 8596 | //texture.texturedata = texturedata; |
---|
8523 | | - textures.put(texname, texturecache); |
---|
| 8597 | + textures.put(tex, texturecache); |
---|
8524 | 8598 | |
---|
8525 | 8599 | // newtex = true; |
---|
8526 | 8600 | } |
---|
.. | .. |
---|
8541 | 8615 | |
---|
8542 | 8616 | static void EmbedTextures(cTexture tex) |
---|
8543 | 8617 | { |
---|
| 8618 | + if (tex.pigmentdata == null) |
---|
| 8619 | + { |
---|
| 8620 | + //String texname = Object3D.GetPigment(tex); |
---|
| 8621 | + |
---|
| 8622 | + CacheTexture texturecache = texturepigment.get(tex); |
---|
| 8623 | + |
---|
| 8624 | + if (texturecache != null) |
---|
| 8625 | + { |
---|
| 8626 | + tex.pw = texturecache.texturedata.getWidth(); |
---|
| 8627 | + tex.ph = texturecache.texturedata.getHeight(); |
---|
| 8628 | + tex.pigmentdata = //CompressJPEG(CreateBim |
---|
| 8629 | + ((ByteBuffer)texturecache.texturedata.getBuffer()).array() |
---|
| 8630 | + ; |
---|
| 8631 | + //, tex.pw, tex.ph), 0.5f); |
---|
| 8632 | + } |
---|
| 8633 | + } |
---|
8544 | 8634 | |
---|
| 8635 | + if (tex.bumpdata == null) |
---|
| 8636 | + { |
---|
| 8637 | + //String texname = Object3D.GetBump(tex); |
---|
| 8638 | + |
---|
| 8639 | + CacheTexture texturecache = texturebump.get(tex); |
---|
| 8640 | + |
---|
| 8641 | + if (texturecache != null) |
---|
| 8642 | + { |
---|
| 8643 | + tex.bw = texturecache.texturedata.getWidth(); |
---|
| 8644 | + tex.bh = texturecache.texturedata.getHeight(); |
---|
| 8645 | + tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f); |
---|
| 8646 | + } |
---|
| 8647 | + } |
---|
8545 | 8648 | } |
---|
8546 | 8649 | |
---|
8547 | | - com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8650 | + com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8548 | 8651 | { |
---|
8549 | | - CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|
| 8652 | + CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8550 | 8653 | |
---|
8551 | 8654 | if (bump) |
---|
8552 | 8655 | { |
---|
.. | .. |
---|
8562 | 8665 | return texture!=null?texture.texture:null; |
---|
8563 | 8666 | } |
---|
8564 | 8667 | |
---|
8565 | | - public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8668 | + public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8566 | 8669 | { |
---|
8567 | | - CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); |
---|
| 8670 | + CacheTexture texture = GetCacheTexture(tex, bump, resolution); |
---|
8568 | 8671 | |
---|
8569 | 8672 | return texture!=null?texture.texturedata:null; |
---|
8570 | 8673 | } |
---|
8571 | 8674 | |
---|
8572 | | - boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception |
---|
| 8675 | + boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception |
---|
8573 | 8676 | { |
---|
8574 | 8677 | if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) |
---|
8575 | 8678 | { |
---|
.. | .. |
---|
8578 | 8681 | |
---|
8579 | 8682 | //boolean newtex = false; |
---|
8580 | 8683 | |
---|
8581 | | - com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution); |
---|
| 8684 | + com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); |
---|
8582 | 8685 | |
---|
8583 | 8686 | if (texture == null) |
---|
8584 | 8687 | return false; |
---|
.. | .. |
---|
8611 | 8714 | return true; // Warning: not used. |
---|
8612 | 8715 | } |
---|
8613 | 8716 | |
---|
| 8717 | + public static byte[] CompressJPEG(BufferedImage image, float quality) |
---|
| 8718 | + { |
---|
| 8719 | + try |
---|
| 8720 | + { |
---|
| 8721 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
---|
| 8722 | + Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg"); |
---|
| 8723 | + ImageWriter writer = writers.next(); |
---|
| 8724 | + |
---|
| 8725 | + ImageWriteParam param = writer.getDefaultWriteParam(); |
---|
| 8726 | + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); |
---|
| 8727 | + param.setCompressionQuality(quality); |
---|
| 8728 | + |
---|
| 8729 | + ImageOutputStream ios = ImageIO.createImageOutputStream(baos); |
---|
| 8730 | + writer.setOutput(ios); |
---|
| 8731 | + writer.write(null, new IIOImage(image, null, null), param); |
---|
| 8732 | + |
---|
| 8733 | + byte[] data = baos.toByteArray(); |
---|
| 8734 | + writer.dispose(); |
---|
| 8735 | + return data; |
---|
| 8736 | + } |
---|
| 8737 | + catch (Exception e) |
---|
| 8738 | + { |
---|
| 8739 | + e.printStackTrace(); |
---|
| 8740 | + return null; |
---|
| 8741 | + } |
---|
| 8742 | + } |
---|
| 8743 | + |
---|
| 8744 | + public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException |
---|
| 8745 | + { |
---|
| 8746 | + ByteArrayInputStream baos = new ByteArrayInputStream(image); |
---|
| 8747 | + Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg"); |
---|
| 8748 | + ImageReader reader = writers.next(); |
---|
| 8749 | + |
---|
| 8750 | + BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); |
---|
| 8751 | + |
---|
| 8752 | + ImageReadParam param = reader.getDefaultReadParam(); |
---|
| 8753 | + param.setDestination(bim); |
---|
| 8754 | + //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB)); |
---|
| 8755 | + |
---|
| 8756 | + ImageInputStream ios = ImageIO.createImageInputStream(baos); |
---|
| 8757 | + reader.setInput(ios); |
---|
| 8758 | + BufferedImage bim2 = reader.read(0, param); |
---|
| 8759 | + reader.dispose(); |
---|
| 8760 | + |
---|
| 8761 | +// WritableRaster raster = bim2.getRaster(); |
---|
| 8762 | +// DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); |
---|
| 8763 | +// byte[] bytes = data.getData(); |
---|
| 8764 | +// |
---|
| 8765 | +// int[] pixels = new int[bytes.length/3]; |
---|
| 8766 | +// for (int i=pixels.length; --i>=0;) |
---|
| 8767 | +// { |
---|
| 8768 | +// int i3 = i*3; |
---|
| 8769 | +// pixels[i] = 0xFF; |
---|
| 8770 | +// pixels[i] <<= 8; |
---|
| 8771 | +// pixels[i] |= bytes[i3+2] & 0xFF; |
---|
| 8772 | +// pixels[i] <<= 8; |
---|
| 8773 | +// pixels[i] |= bytes[i3+1] & 0xFF; |
---|
| 8774 | +// pixels[i] <<= 8; |
---|
| 8775 | +// pixels[i] |= bytes[i3] & 0xFF; |
---|
| 8776 | +// } |
---|
| 8777 | +// |
---|
| 8778 | +// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w); |
---|
| 8779 | + |
---|
| 8780 | + return bim; |
---|
| 8781 | + } |
---|
| 8782 | + |
---|
8614 | 8783 | ShadowBuffer shadowPBuf; |
---|
8615 | 8784 | AntialiasBuffer antialiasPBuf; |
---|
8616 | 8785 | int MAXSTACK; |
---|
.. | .. |
---|
8627 | 8796 | |
---|
8628 | 8797 | gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0); |
---|
8629 | 8798 | MAXSTACK = temp[0]; |
---|
8630 | | - System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
| 8799 | + if (Globals.DEBUG) |
---|
| 8800 | + System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK); |
---|
8631 | 8801 | gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0); |
---|
8632 | 8802 | MAXSTACK = temp[0]; |
---|
8633 | | - System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
| 8803 | + if (Globals.DEBUG) |
---|
| 8804 | + System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK); |
---|
8634 | 8805 | |
---|
8635 | 8806 | // Use debug pipeline |
---|
8636 | 8807 | //drawable.setGL(new DebugGL(gl)); // |
---|
.. | .. |
---|
8638 | 8809 | gl = drawable.getGL(); // |
---|
8639 | 8810 | |
---|
8640 | 8811 | GL gl3 = getGL(); |
---|
8641 | | - System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
| 8812 | + if (Globals.DEBUG) |
---|
| 8813 | + System.out.println("INIT GL IS: " + gl.getClass().getName()); |
---|
8642 | 8814 | |
---|
8643 | 8815 | |
---|
8644 | 8816 | //float pos[] = { 100, 100, 100, 0 }; |
---|
.. | .. |
---|
8803 | 8975 | |
---|
8804 | 8976 | if (cubemap == null) |
---|
8805 | 8977 | { |
---|
8806 | | - LoadEnvy(5); |
---|
| 8978 | + //LoadEnvy(1); |
---|
8807 | 8979 | } |
---|
8808 | 8980 | |
---|
8809 | 8981 | //cubemap.enable(); |
---|
.. | .. |
---|
9079 | 9251 | |
---|
9080 | 9252 | void LoadEnvy(int which) |
---|
9081 | 9253 | { |
---|
| 9254 | + assert(false); |
---|
| 9255 | + |
---|
9082 | 9256 | String name; |
---|
9083 | 9257 | String ext; |
---|
9084 | 9258 | |
---|
.. | .. |
---|
9090 | 9264 | cubemap = null; |
---|
9091 | 9265 | return; |
---|
9092 | 9266 | case 1: |
---|
9093 | | - name = "cubemaps/box_"; |
---|
9094 | | - ext = "png"; |
---|
| 9267 | + name = "cubemaps/rgb/"; |
---|
| 9268 | + ext = "jpg"; |
---|
9095 | 9269 | reverseUP = false; |
---|
9096 | 9270 | break; |
---|
9097 | 9271 | case 2: |
---|
9098 | | - name = "cubemaps/uffizi_"; |
---|
9099 | | - ext = "png"; |
---|
9100 | | - break; // reverseUP = true; break; |
---|
| 9272 | + name = "cubemaps/uffizi/"; |
---|
| 9273 | + ext = "jpg"; |
---|
| 9274 | + reverseUP = false; |
---|
| 9275 | + break; |
---|
9101 | 9276 | case 3: |
---|
9102 | | - name = "cubemaps/CloudyHills_"; |
---|
9103 | | - ext = "tga"; |
---|
| 9277 | + name = "cubemaps/CloudyHills/"; |
---|
| 9278 | + ext = "jpg"; |
---|
9104 | 9279 | reverseUP = false; |
---|
9105 | 9280 | break; |
---|
9106 | 9281 | case 4: |
---|
9107 | | - name = "cubemaps/cornell_"; |
---|
| 9282 | + name = "cubemaps/cornell/"; |
---|
9108 | 9283 | ext = "png"; |
---|
9109 | 9284 | reverseUP = false; |
---|
9110 | 9285 | break; |
---|
| 9286 | + case 5: |
---|
| 9287 | + name = "cubemaps/skycube/"; |
---|
| 9288 | + ext = "jpg"; |
---|
| 9289 | + reverseUP = false; |
---|
| 9290 | + break; |
---|
| 9291 | + case 6: |
---|
| 9292 | + name = "cubemaps/SaintLazarusChurch3/"; |
---|
| 9293 | + ext = "jpg"; |
---|
| 9294 | + reverseUP = false; |
---|
| 9295 | + break; |
---|
| 9296 | + case 7: |
---|
| 9297 | + name = "cubemaps/Sodermalmsallen/"; |
---|
| 9298 | + ext = "jpg"; |
---|
| 9299 | + reverseUP = false; |
---|
| 9300 | + break; |
---|
| 9301 | + case 8: |
---|
| 9302 | + name = "cubemaps/Sodermalmsallen2/"; |
---|
| 9303 | + ext = "jpg"; |
---|
| 9304 | + reverseUP = false; |
---|
| 9305 | + break; |
---|
| 9306 | + case 9: |
---|
| 9307 | + name = "cubemaps/UnionSquare/"; |
---|
| 9308 | + ext = "jpg"; |
---|
| 9309 | + reverseUP = false; |
---|
| 9310 | + break; |
---|
9111 | 9311 | default: |
---|
9112 | | - name = "cubemaps/rgb_"; |
---|
9113 | | - ext = "png"; /*mipmap = true;*/ reverseUP = false; |
---|
| 9312 | + name = "cubemaps/box/"; |
---|
| 9313 | + ext = "png"; /*mipmap = true;*/ |
---|
| 9314 | + reverseUP = false; |
---|
9114 | 9315 | break; |
---|
9115 | 9316 | } |
---|
9116 | | - |
---|
9117 | | - try |
---|
9118 | | - { |
---|
9119 | | - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
9120 | | - } catch (IOException e) |
---|
9121 | | - { |
---|
9122 | | - throw new RuntimeException(e); |
---|
9123 | | - } |
---|
| 9317 | + |
---|
| 9318 | + LoadSkybox(name, ext, mipmap); |
---|
9124 | 9319 | } |
---|
9125 | 9320 | |
---|
9126 | 9321 | public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) |
---|
.. | .. |
---|
9152 | 9347 | static double[] model = new double[16]; |
---|
9153 | 9348 | double[] camera2light = new double[16]; |
---|
9154 | 9349 | double[] light2camera = new double[16]; |
---|
9155 | | - int newenvy = -1; |
---|
9156 | | - boolean envyoff = true; // false; |
---|
| 9350 | + |
---|
| 9351 | + //int newenvy = -1; |
---|
| 9352 | + //boolean envyoff = false; |
---|
| 9353 | + |
---|
| 9354 | + String loadedskyboxname; |
---|
| 9355 | + |
---|
9157 | 9356 | cVector light0 = new cVector(0, 0, 0); // 1,3,2); |
---|
9158 | 9357 | //float[] light0 = { 0,0,0 }; |
---|
9159 | 9358 | cVector dirlight = new cVector(0, 0, 1); // 1,3,2); |
---|
.. | .. |
---|
9571 | 9770 | |
---|
9572 | 9771 | if (renderCamera != lightCamera) |
---|
9573 | 9772 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9574 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 9773 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9575 | 9774 | |
---|
9576 | 9775 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9577 | 9776 | |
---|
.. | .. |
---|
9587 | 9786 | |
---|
9588 | 9787 | if (renderCamera != lightCamera) |
---|
9589 | 9788 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9590 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 9789 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9591 | 9790 | |
---|
9592 | 9791 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9593 | 9792 | |
---|
.. | .. |
---|
9633 | 9832 | rati = 1 / rati; |
---|
9634 | 9833 | gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000); |
---|
9635 | 9834 | } |
---|
9636 | | - assert (newenvy == -1); |
---|
| 9835 | + |
---|
| 9836 | + //assert (newenvy == -1); |
---|
| 9837 | + |
---|
9637 | 9838 | gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9638 | 9839 | gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9639 | | - DrawSkyBox(gl); |
---|
| 9840 | + DrawSkyBox(gl, (float)rati); |
---|
9640 | 9841 | gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9641 | 9842 | gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9642 | 9843 | accPerspective(gl, renderCamera.shaper_fovy / ratio, |
---|
.. | .. |
---|
10502 | 10703 | static boolean init = false; |
---|
10503 | 10704 | |
---|
10504 | 10705 | double[][] matrix = LA.newMatrix(); |
---|
| 10706 | + |
---|
| 10707 | + // This is to refresh the UI of the material panel. |
---|
| 10708 | + ObjEditor patchMaterial; |
---|
10505 | 10709 | |
---|
10506 | 10710 | public void display(GLAutoDrawable drawable) |
---|
10507 | 10711 | { |
---|
| 10712 | + if (patchMaterial.patchMaterial) |
---|
| 10713 | + { |
---|
| 10714 | + patchMaterial.patchMaterial = false; |
---|
| 10715 | + patchMaterial.objectPanel.setSelectedIndex(1); |
---|
| 10716 | + } |
---|
| 10717 | + |
---|
10508 | 10718 | if (Grafreed.savesound && Grafreed.hassound) |
---|
10509 | 10719 | { |
---|
10510 | 10720 | Grafreed.wav.save(); |
---|
.. | .. |
---|
10673 | 10883 | |
---|
10674 | 10884 | if (wait) |
---|
10675 | 10885 | { |
---|
10676 | | - Sleep(500); |
---|
| 10886 | + Sleep(200); // blocks everything |
---|
10677 | 10887 | |
---|
10678 | 10888 | wait = false; |
---|
10679 | 10889 | } |
---|
.. | .. |
---|
10788 | 10998 | // if (parentcam != renderCamera) // not a light |
---|
10789 | 10999 | if (cam != lightCamera) |
---|
10790 | 11000 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10791 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 11001 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10792 | 11002 | |
---|
10793 | 11003 | for (int j = 0; j < 4; j++) |
---|
10794 | 11004 | { |
---|
.. | .. |
---|
10803 | 11013 | // if (parentcam != renderCamera) // not a light |
---|
10804 | 11014 | if (cam != lightCamera) |
---|
10805 | 11015 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10806 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 11016 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10807 | 11017 | |
---|
10808 | 11018 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10809 | 11019 | |
---|
.. | .. |
---|
10889 | 11099 | gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); |
---|
10890 | 11100 | } |
---|
10891 | 11101 | |
---|
10892 | | - if (newenvy > -1) |
---|
| 11102 | +// if (newenvy > -1) |
---|
| 11103 | +// { |
---|
| 11104 | +// LoadEnvy(newenvy); |
---|
| 11105 | +// } |
---|
| 11106 | +// |
---|
| 11107 | +// newenvy = -1; |
---|
| 11108 | + |
---|
| 11109 | + if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb")) |
---|
10893 | 11110 | { |
---|
10894 | | - LoadEnvy(newenvy); |
---|
| 11111 | + if (cubemaprgb == null) |
---|
| 11112 | + { |
---|
| 11113 | + cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false); |
---|
| 11114 | + } |
---|
| 11115 | + |
---|
| 11116 | + cubemap = cubemaprgb; |
---|
10895 | 11117 | } |
---|
10896 | | - |
---|
10897 | | - newenvy = -1; |
---|
10898 | | - |
---|
| 11118 | + else |
---|
| 11119 | + { |
---|
| 11120 | + if (object.skyboxname != null) |
---|
| 11121 | + { |
---|
| 11122 | + if (!object.skyboxname.equals(this.loadedskyboxname)) |
---|
| 11123 | + { |
---|
| 11124 | + if (cubemap != null && cubemap != cubemaprgb) |
---|
| 11125 | + cubemap.dispose(); |
---|
| 11126 | + cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11127 | + loadedskyboxname = object.skyboxname; |
---|
| 11128 | + } |
---|
| 11129 | + } |
---|
| 11130 | + else |
---|
| 11131 | + { |
---|
| 11132 | + cubemapcustom = null; |
---|
| 11133 | + loadedskyboxname = null; |
---|
| 11134 | + } |
---|
| 11135 | + |
---|
| 11136 | + cubemap = cubemapcustom; |
---|
| 11137 | + } |
---|
| 11138 | + |
---|
10899 | 11139 | ratio = ((double) getWidth()) / getHeight(); |
---|
10900 | 11140 | //System.out.println("ratio = " + ratio); |
---|
10901 | 11141 | |
---|
.. | .. |
---|
10911 | 11151 | |
---|
10912 | 11152 | if (!IsFrozen() && !ambientOcclusion) |
---|
10913 | 11153 | { |
---|
10914 | | - DrawSkyBox(gl); |
---|
| 11154 | + DrawSkyBox(gl, (float)ratio); |
---|
10915 | 11155 | } |
---|
10916 | 11156 | |
---|
10917 | 11157 | //if (selection_view == -1) |
---|
.. | .. |
---|
11065 | 11305 | |
---|
11066 | 11306 | try |
---|
11067 | 11307 | { |
---|
11068 | | - BindTexture(null, NOISE_TEXTURE, false, 2); |
---|
| 11308 | + BindTexture(NOISE_TEXTURE, false, 2); |
---|
11069 | 11309 | } |
---|
11070 | 11310 | catch (Exception e) |
---|
11071 | 11311 | { |
---|
.. | .. |
---|
11197 | 11437 | |
---|
11198 | 11438 | // if (cam != lightCamera) |
---|
11199 | 11439 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
11200 | | - LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 |
---|
| 11440 | + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 |
---|
11201 | 11441 | } |
---|
11202 | 11442 | |
---|
11203 | 11443 | LA.xformDir(lightposition, cam.toScreen, lightposition); |
---|
.. | .. |
---|
11356 | 11596 | } |
---|
11357 | 11597 | } |
---|
11358 | 11598 | |
---|
11359 | | - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
| 11599 | + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) |
---|
11360 | 11600 | { |
---|
11361 | 11601 | //gl.glDepthFunc(GL.GL_LEQUAL); |
---|
11362 | 11602 | //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); |
---|
.. | .. |
---|
11364 | 11604 | |
---|
11365 | 11605 | boolean texon = textureon; |
---|
11366 | 11606 | |
---|
11367 | | - if (RENDERPROGRAM > 0) |
---|
11368 | | - { |
---|
11369 | | - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11370 | | - textureon = false; |
---|
11371 | | - } |
---|
| 11607 | + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11608 | + textureon = false; |
---|
| 11609 | + |
---|
11372 | 11610 | //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
11373 | 11611 | //System.out.println("ALLO"); |
---|
11374 | 11612 | gl.glColorMask(false, false, false, false); |
---|
11375 | 11613 | DrawObject(gl); |
---|
11376 | | - if (RENDERPROGRAM > 0) |
---|
11377 | | - { |
---|
11378 | | - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
11379 | | - textureon = texon; |
---|
11380 | | - } |
---|
| 11614 | + |
---|
| 11615 | + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
| 11616 | + textureon = texon; |
---|
| 11617 | + |
---|
11381 | 11618 | gl.glColorMask(true, true, true, true); |
---|
11382 | 11619 | |
---|
11383 | 11620 | gl.glDepthFunc(GL.GL_EQUAL); |
---|
11384 | | - //gl.glDepthMask(false); |
---|
| 11621 | + gl.glDepthMask(false); |
---|
11385 | 11622 | } |
---|
11386 | 11623 | |
---|
11387 | 11624 | if (false) // DrawMode() == SHADOW) |
---|
.. | .. |
---|
11721 | 11958 | ReleaseTextures(DEFAULT_TEXTURES); |
---|
11722 | 11959 | |
---|
11723 | 11960 | if (CLEANCACHE) |
---|
11724 | | - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) |
---|
| 11961 | + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) |
---|
11725 | 11962 | { |
---|
11726 | | - String tex = e.nextElement(); |
---|
| 11963 | + cTexture tex = e.nextElement(); |
---|
11727 | 11964 | |
---|
11728 | 11965 | // System.out.println("Texture --------- " + tex); |
---|
11729 | 11966 | |
---|
11730 | | - if (tex.equals("WHITE_NOISE")) |
---|
| 11967 | + if (tex.equals("WHITE_NOISE:")) |
---|
11731 | 11968 | continue; |
---|
11732 | 11969 | |
---|
11733 | 11970 | if (!usedtextures.contains(tex)) |
---|
11734 | 11971 | { |
---|
| 11972 | + CacheTexture gettex = texturepigment.get(tex); |
---|
11735 | 11973 | // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
11736 | | - textures.get(tex).texture.dispose(); |
---|
11737 | | - textures.remove(tex); |
---|
| 11974 | + if (gettex != null) |
---|
| 11975 | + { |
---|
| 11976 | + gettex.texture.dispose(); |
---|
| 11977 | + texturepigment.remove(tex); |
---|
| 11978 | + } |
---|
| 11979 | + |
---|
| 11980 | + gettex = texturebump.get(tex); |
---|
| 11981 | + // System.out.println("DISPOSE +++++++++++++++ " + tex); |
---|
| 11982 | + if (gettex != null) |
---|
| 11983 | + { |
---|
| 11984 | + gettex.texture.dispose(); |
---|
| 11985 | + texturebump.remove(tex); |
---|
| 11986 | + } |
---|
11738 | 11987 | } |
---|
11739 | 11988 | } |
---|
11740 | 11989 | } |
---|
.. | .. |
---|
12262 | 12511 | |
---|
12263 | 12512 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12264 | 12513 | |
---|
12265 | | - String program = |
---|
| 12514 | + String programmin = |
---|
| 12515 | + // Min shader |
---|
12266 | 12516 | "!!ARBfp1.0\n" + |
---|
| 12517 | + "PARAM zero12t = { 0.0, 1.0, 2, 1.25 };" + |
---|
| 12518 | + "PARAM pow_2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
| 12519 | + "PARAM pow2 = { 2, 4, 8, 0.0 };" + |
---|
| 12520 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
| 12521 | + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
| 12522 | + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12523 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12524 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12525 | + "PARAM light2cam2 = program.env[12];" + |
---|
| 12526 | + "TEMP temp;" + |
---|
| 12527 | + "TEMP light;" + |
---|
| 12528 | + "TEMP ndotl;" + |
---|
| 12529 | + "TEMP normal;" + |
---|
| 12530 | + "TEMP depth;" + |
---|
| 12531 | + "TEMP eye;" + |
---|
| 12532 | + "TEMP pos;" + |
---|
| 12533 | + |
---|
| 12534 | + "MAD normal, fragment.color, zero12t.z, -zero12t.y;" + |
---|
| 12535 | + Normalize("normal") + |
---|
| 12536 | + "MOV light, state.light[0].position;" + |
---|
| 12537 | + "DP3 ndotl.x, light, normal;" + |
---|
| 12538 | + "MAX ndotl.x, ndotl.x, zero12t.x;" + |
---|
| 12539 | + |
---|
| 12540 | + // shadow |
---|
| 12541 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12542 | + "MOV temp, pos;" + |
---|
| 12543 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
| 12544 | + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
| 12545 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
| 12546 | + |
---|
| 12547 | + // No shadow when out of frustum |
---|
| 12548 | + //"SGE temp.y, depth.z, zero123.y;" + |
---|
| 12549 | + //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
| 12550 | + |
---|
| 12551 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
| 12552 | + |
---|
| 12553 | + // Backlit |
---|
| 12554 | + "MOV pos.w, zero12t.y;" + // one |
---|
| 12555 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12556 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12557 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12558 | + Normalize("eye") + |
---|
| 12559 | + |
---|
| 12560 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12561 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12562 | + "POW ndotl.y, ndotl.y, pow2.x;" + // backlit |
---|
| 12563 | + "SUB ndotl.y, zero12t.y, ndotl.y;" + // 1 - y |
---|
| 12564 | + //"POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12565 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12566 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12567 | + "ADD ndotl.y, ndotl.y, one.x;" + |
---|
| 12568 | + "MUL ndotl.y, ndotl.y, pow_2.x;" + |
---|
| 12569 | + |
---|
| 12570 | + //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12571 | + //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient |
---|
| 12572 | + |
---|
| 12573 | + // Pigment |
---|
| 12574 | + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
| 12575 | + "LRP temp, zero12t.w, temp, one;" + // texture proportion |
---|
| 12576 | + "MUL temp, temp, zero12t.w;" + // Times x |
---|
| 12577 | + |
---|
| 12578 | + //"MUL temp, temp, ndotl.y;" + |
---|
| 12579 | + "MAD ndotl.x, pow_2.xxxx, ndotl.yyyy, ndotl.x;" + |
---|
| 12580 | + |
---|
| 12581 | + "MUL temp, temp, ndotl.x;" + // lambert |
---|
| 12582 | + |
---|
| 12583 | + "MOV temp.w, zero12t.y;" + // reset alpha |
---|
| 12584 | + "MOV result.color, temp;" + |
---|
| 12585 | + "END"; |
---|
| 12586 | + |
---|
| 12587 | + String programmax = |
---|
| 12588 | + "!!ARBfp1.0\n" + |
---|
| 12589 | + |
---|
12267 | 12590 | //"OPTION ARB_fragment_program_shadow;" + |
---|
12268 | 12591 | "PARAM light2cam0 = program.env[10];" + |
---|
12269 | 12592 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12289 | 12612 | "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow |
---|
12290 | 12613 | "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias |
---|
12291 | 12614 | "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough |
---|
12292 | | - "PARAM params7 = program.env[7];" + // noise power, opacity power |
---|
| 12615 | + "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax |
---|
12293 | 12616 | "PARAM options0 = program.env[63];" + // fog density, intensity, elevation |
---|
12294 | 12617 | "PARAM options1 = program.env[62];" + // fog rgb color |
---|
12295 | 12618 | "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen |
---|
.. | .. |
---|
12378 | 12701 | "TEMP shininess;" + |
---|
12379 | 12702 | "\n" + |
---|
12380 | 12703 | "MOV texSamp, one;" + |
---|
12381 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12382 | | - |
---|
| 12704 | + |
---|
12383 | 12705 | "MOV mapgrid.x, one2048th.x;" + |
---|
12384 | 12706 | "MOV temp, fragment.texcoord[1];" + |
---|
12385 | 12707 | /* |
---|
.. | .. |
---|
12400 | 12722 | "MUL temp, floor, mapgrid.x;" + |
---|
12401 | 12723 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12402 | 12724 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12403 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12725 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12404 | 12726 | "") + |
---|
12405 | 12727 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12406 | 12728 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12407 | 12729 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12408 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12730 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12409 | 12731 | "") + |
---|
12410 | 12732 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12411 | 12733 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12412 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12734 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12413 | 12735 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12414 | 12736 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12415 | 12737 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12416 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12738 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12417 | 12739 | "") + |
---|
12418 | 12740 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12419 | 12741 | //"MOV params, material;" + |
---|
.. | .. |
---|
12535 | 12857 | "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut |
---|
12536 | 12858 | // mar 2013 ??? "KIL alpha.a;" + |
---|
12537 | 12859 | "MOV alpha, texSamp.aaaa;" + // y;" + |
---|
12538 | | - "KIL alpha.a;" + |
---|
| 12860 | + "KIL alpha.a;" + // not sure with parallax mapping |
---|
12539 | 12861 | /* |
---|
12540 | 12862 | "MUL temp.xy, temp, two;" + |
---|
12541 | 12863 | "TXB bump, temp, texture[0], 2D;" + |
---|
.. | .. |
---|
12621 | 12943 | "SUB bump0, bump0, half;" + |
---|
12622 | 12944 | "ADD bump, bump, bump0;" + |
---|
12623 | 12945 | |
---|
12624 | | - "MOV temp.x, texSamp.a;" + |
---|
12625 | | - "LRP texSamp, params5.x, texSamp, one;" + // texture proportion |
---|
12626 | | - //"LRP texSamp0, params5.x, texSamp0, one;" + |
---|
12627 | | - "MOV texSamp.a, temp.x;" + |
---|
12628 | | - |
---|
12629 | 12946 | // double-sided |
---|
12630 | 12947 | /**/ |
---|
12631 | 12948 | (doublesided?"DP3 temp.z, normal, eye;" + |
---|
.. | .. |
---|
12642 | 12959 | "MOV normald, normal;" + |
---|
12643 | 12960 | "MOV normals, normal;" + |
---|
12644 | 12961 | |
---|
| 12962 | + "MOV temp, fragment.texcoord[4];" + |
---|
| 12963 | + |
---|
12645 | 12964 | // UV base |
---|
12646 | 12965 | //"DP3 UP.x,state.matrix.modelview.row[0],Y;" + |
---|
12647 | 12966 | //"DP3 UP.y,state.matrix.modelview.row[1],Y;" + |
---|
12648 | 12967 | //"DP3 UP.z,state.matrix.modelview.row[2],Y;" + |
---|
12649 | | - "DP3 UP.x,state.matrix.texture[7].row[0],Y;" + |
---|
12650 | | - "DP3 UP.y,state.matrix.texture[7].row[1],Y;" + |
---|
12651 | | - "DP3 UP.z,state.matrix.texture[7].row[2],Y;" + |
---|
| 12968 | + "DP3 UP.x,state.matrix.texture[7].row[0],temp;" + |
---|
| 12969 | + "DP3 UP.y,state.matrix.texture[7].row[1],temp;" + |
---|
| 12970 | + "DP3 UP.z,state.matrix.texture[7].row[2],temp;" + |
---|
| 12971 | + Normalize("UP") + |
---|
| 12972 | + |
---|
12652 | 12973 | "XPD V, normal, UP;" + |
---|
12653 | 12974 | Normalize("V") + |
---|
12654 | 12975 | "XPD U, V, normal;" + |
---|
12655 | 12976 | Normalize("U") + |
---|
12656 | 12977 | |
---|
12657 | 12978 | // parallax mapping |
---|
| 12979 | + |
---|
| 12980 | + "DP3 temp2.x, V, eye;" + |
---|
| 12981 | + "DP3 temp2.y, U, eye;" + |
---|
| 12982 | + "DP3 temp2.z, normal, eye;" + |
---|
| 12983 | + "RCP temp2.z, temp2.z;" + |
---|
| 12984 | + |
---|
| 12985 | + "DP3 temp2.w, texSamp, texSamp;" + // Height |
---|
| 12986 | + "RSQ temp2.w, temp2.w;" + |
---|
| 12987 | + "RCP temp2.w, temp2.w;" + |
---|
| 12988 | + |
---|
| 12989 | + "SUB temp2.w, temp2.w, half;" + |
---|
| 12990 | +// "SGE temp.x, temp2.w, eps.x;" + |
---|
| 12991 | +// "MUL temp2.w, temp2.w, temp.x;" + |
---|
| 12992 | + |
---|
| 12993 | + //"MOV texSamp, U;" + |
---|
| 12994 | + |
---|
| 12995 | + "MUL temp2.z, temp2.z, temp2.w;" + |
---|
| 12996 | + "MUL temp2.z, temp2.z, params7.z;" + // parallax |
---|
| 12997 | + |
---|
| 12998 | + "MUL temp2, temp2, temp2.z;" + |
---|
| 12999 | + |
---|
| 13000 | + "MOV temp, fragment.texcoord[0];" + |
---|
| 13001 | + |
---|
| 13002 | + "SUB temp, temp, temp2;" + |
---|
| 13003 | + |
---|
| 13004 | + "TEX temp, temp, texture[0], 2D;" + |
---|
| 13005 | + "POW temp.a, temp.a, params6.w;" + // punch through |
---|
| 13006 | + |
---|
| 13007 | + "ADD texSamp, temp, texSamp;" + |
---|
| 13008 | + "MUL texSamp.xyz, half, texSamp;" + |
---|
| 13009 | + |
---|
| 13010 | + "MOV alpha, texSamp.aaaa;" + |
---|
| 13011 | + |
---|
| 13012 | +// parallax mapping |
---|
| 13013 | + |
---|
| 13014 | + "MOV temp.x, texSamp.a;" + |
---|
| 13015 | + "LRP texSamp, params5.x, texSamp, one;" + // texture proportion |
---|
| 13016 | + //"LRP texSamp0, params5.x, texSamp0, one;" + |
---|
| 13017 | + "MOV texSamp.a, temp.x;" + |
---|
12658 | 13018 | |
---|
12659 | 13019 | //"MOV temp, fragment.texcoord[0];" + |
---|
12660 | 13020 | // |
---|
.. | .. |
---|
12784 | 13144 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12785 | 13145 | "") + |
---|
12786 | 13146 | |
---|
12787 | | - // display shadow only (bump == 0) |
---|
| 13147 | + // display shadow only (fakedepth == 0) |
---|
12788 | 13148 | "SUB temp.x, half.x, shadow.x;" + |
---|
12789 | 13149 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12790 | | - "SLT temp.z, temp.y, -one2048th.x;" + |
---|
| 13150 | + "SLT temp.z, temp.y, -c256i.x;" + |
---|
12791 | 13151 | "SUB temp.y, one.x, temp.z;" + |
---|
12792 | 13152 | "MUL temp.x, temp.x, temp.y;" + |
---|
12793 | 13153 | "KIL temp.x;" + |
---|
.. | .. |
---|
13118 | 13478 | //once = true; |
---|
13119 | 13479 | } |
---|
13120 | 13480 | |
---|
13121 | | - System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
13122 | | - System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
| 13481 | + String program = programmax; |
---|
| 13482 | + |
---|
| 13483 | + if (Globals.MINSHADER) |
---|
| 13484 | + { |
---|
| 13485 | + program = programmin; |
---|
| 13486 | + } |
---|
| 13487 | + |
---|
| 13488 | + if (Globals.DEBUG) |
---|
| 13489 | + { |
---|
| 13490 | + System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
| 13491 | + System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
| 13492 | + } |
---|
| 13493 | + |
---|
13123 | 13494 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
13124 | 13495 | |
---|
13125 | 13496 | //gl.glNewList(displayListID, GL.GL_COMPILE); |
---|
.. | .. |
---|
13166 | 13537 | "\n" + |
---|
13167 | 13538 | "END\n"; |
---|
13168 | 13539 | |
---|
13169 | | - System.out.println("Program shadow #" + 0 + "; length = " + program.length()); |
---|
| 13540 | + if (Globals.DEBUG) |
---|
| 13541 | + System.out.println("Program shadow #" + 0 + "; length = " + program.length()); |
---|
13170 | 13542 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
13171 | 13543 | |
---|
13172 | 13544 | //gl.glNewList(displayListID, GL.GL_COMPILE); |
---|
.. | .. |
---|
13211 | 13583 | return out; |
---|
13212 | 13584 | } |
---|
13213 | 13585 | |
---|
13214 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13586 | + // Also does frustum culling |
---|
| 13587 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
13215 | 13588 | { |
---|
13216 | 13589 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
13217 | 13590 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
13218 | 13591 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13592 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13593 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
13219 | 13594 | "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
13220 | | - "SLT " + src + ".z, " + src + ".x, one.x;" + |
---|
13221 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
13222 | | - "SLT " + src + ".z, " + src + ".y, one.x;" + |
---|
13223 | | - "MUL " + src + ".w, " + src + ".z, " + src + ".w;" + |
---|
| 13595 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13596 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
13224 | 13597 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
13225 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13598 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
13226 | 13599 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
13227 | 13600 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
13228 | 13601 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
13229 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13602 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13230 | 13603 | |
---|
13231 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
13232 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13604 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13605 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13233 | 13606 | } |
---|
13234 | 13607 | |
---|
13235 | 13608 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
13276 | 13649 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
13277 | 13650 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13278 | 13651 | |
---|
13279 | | - // No shadow when out of frustrum |
---|
| 13652 | + // No shadow when out of frustum |
---|
13280 | 13653 | "SGE temp.x, " + depth + ".z, one.z;" + |
---|
13281 | 13654 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13282 | 13655 | ""; |
---|
.. | .. |
---|
13423 | 13796 | /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow |
---|
13424 | 13797 | /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias |
---|
13425 | 13798 | /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough |
---|
13426 | | - /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power |
---|
| 13799 | + /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax |
---|
13427 | 13800 | |
---|
13428 | 13801 | //Object3D.cVector2[] vector2buffer; |
---|
13429 | 13802 | |
---|
.. | .. |
---|
13590 | 13963 | "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" + |
---|
13591 | 13964 | "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" + |
---|
13592 | 13965 | "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" + |
---|
13593 | | - "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" + |
---|
| 13966 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
13594 | 13967 | "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" + |
---|
13595 | 13968 | "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" + |
---|
13596 | 13969 | //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" + |
---|
.. | .. |
---|
13651 | 14024 | "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" + |
---|
13652 | 14025 | "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" + |
---|
13653 | 14026 | "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" + |
---|
13654 | | - //"MOV result.texcoord, vertex.texcoord;" + |
---|
| 14027 | + //"MOV result.texcoord, vertex.fogcoord;" + |
---|
13655 | 14028 | "MOV result.texcoord, temp;" + |
---|
13656 | 14029 | // border fade |
---|
13657 | 14030 | "MOV result.texcoord[3], vertex.texcoord;" + |
---|
.. | .. |
---|
13698 | 14071 | |
---|
13699 | 14072 | //"ADD temp.z, temp.z, one;" + |
---|
13700 | 14073 | |
---|
13701 | | - "MOV result.color, temp;" |
---|
| 14074 | + "MOV result.texcoord[4], vertex.attrib[4];" + // U dir |
---|
| 14075 | + |
---|
| 14076 | + "MOV result.color, temp;" // Normal |
---|
13702 | 14077 | : "MOV result.color, vertex.color;") + |
---|
13703 | 14078 | ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;" |
---|
13704 | 14079 | : "") + |
---|
.. | .. |
---|
14074 | 14449 | drag = false; |
---|
14075 | 14450 | //System.out.println("Mouse DOWN"); |
---|
14076 | 14451 | editObj = false; |
---|
14077 | | - ClickInfo info = new ClickInfo(); |
---|
14078 | | - info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14079 | | - info.pane = this; |
---|
14080 | | - info.camera = renderCamera; |
---|
14081 | | - info.x = x; |
---|
14082 | | - info.y = y; |
---|
14083 | | - info.modifiers = modifiersex; |
---|
14084 | | - editObj = object.doEditClick(info, 0); |
---|
| 14452 | + //ClickInfo info = new ClickInfo(); |
---|
| 14453 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14454 | + object.clickInfo.pane = this; |
---|
| 14455 | + object.clickInfo.camera = renderCamera; |
---|
| 14456 | + object.clickInfo.x = x; |
---|
| 14457 | + object.clickInfo.y = y; |
---|
| 14458 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14459 | + editObj = object.doEditClick(//info, |
---|
| 14460 | + 0); |
---|
14085 | 14461 | if (!editObj) |
---|
14086 | 14462 | { |
---|
14087 | 14463 | hasMarquee = true; |
---|
.. | .. |
---|
14363 | 14739 | void GoDown(int mod) |
---|
14364 | 14740 | { |
---|
14365 | 14741 | MODIFIERS |= COMMAND; |
---|
| 14742 | + boolean isVR = (mouseMode&VR)!=0; |
---|
14366 | 14743 | /**/ |
---|
14367 | 14744 | if((mod&SHIFT) == SHIFT) |
---|
14368 | | - manipCamera.RotatePosition(0, -speed); |
---|
| 14745 | + { |
---|
| 14746 | + if (isVR) |
---|
| 14747 | + manipCamera.RotateInterest(0, -speed); |
---|
| 14748 | + else |
---|
| 14749 | + manipCamera.RotatePosition(0, -speed); |
---|
| 14750 | + } |
---|
14369 | 14751 | else |
---|
14370 | | - manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); |
---|
| 14752 | + manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth()); |
---|
14371 | 14753 | /**/ |
---|
14372 | 14754 | if ((mod & SHIFT) == SHIFT) |
---|
14373 | 14755 | { |
---|
.. | .. |
---|
14377 | 14759 | mouseMode |= BACKFORTH; |
---|
14378 | 14760 | } |
---|
14379 | 14761 | |
---|
| 14762 | + targetLookAt.set(manipCamera.lookAt); |
---|
| 14763 | + |
---|
14380 | 14764 | //prevX = X = anchorX; |
---|
14381 | 14765 | prevY = Y = anchorY - (int) (renderCamera.Distance()); |
---|
14382 | 14766 | } |
---|
.. | .. |
---|
14385 | 14769 | { |
---|
14386 | 14770 | MODIFIERS |= COMMAND; |
---|
14387 | 14771 | /**/ |
---|
| 14772 | + boolean isVR = (mouseMode&VR)!=0; |
---|
| 14773 | + |
---|
14388 | 14774 | if((mod&SHIFT) == SHIFT) |
---|
14389 | | - manipCamera.RotatePosition(0, speed); |
---|
| 14775 | + { |
---|
| 14776 | + if (isVR) |
---|
| 14777 | + manipCamera.RotateInterest(0, speed); |
---|
| 14778 | + else |
---|
| 14779 | + manipCamera.RotatePosition(0, speed); |
---|
| 14780 | + } |
---|
14390 | 14781 | else |
---|
14391 | | - manipCamera.BackForth(0, speed*delta, 0); // getWidth()); |
---|
| 14782 | + manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth()); |
---|
14392 | 14783 | /**/ |
---|
14393 | 14784 | if ((mod & SHIFT) == SHIFT) |
---|
14394 | 14785 | { |
---|
.. | .. |
---|
14398 | 14789 | mouseMode |= BACKFORTH; |
---|
14399 | 14790 | } |
---|
14400 | 14791 | |
---|
| 14792 | + targetLookAt.set(manipCamera.lookAt); |
---|
| 14793 | + |
---|
14401 | 14794 | //prevX = X = anchorX; |
---|
14402 | 14795 | prevY = Y = anchorY + (int) (renderCamera.Distance()); |
---|
14403 | 14796 | } |
---|
.. | .. |
---|
14407 | 14800 | MODIFIERS |= COMMAND; |
---|
14408 | 14801 | /**/ |
---|
14409 | 14802 | if((mod&SHIFT) == SHIFT) |
---|
14410 | | - manipCamera.Translate(speed*delta, 0, getWidth()); |
---|
| 14803 | + manipCamera.Translate(speed*delta, 0, getWidth()); |
---|
14411 | 14804 | else |
---|
14412 | | - manipCamera.RotatePosition(speed, 0); |
---|
| 14805 | + { |
---|
| 14806 | + if ((mouseMode&VR)!=0) |
---|
| 14807 | + manipCamera.RotateInterest(-speed, 0); |
---|
| 14808 | + else |
---|
| 14809 | + manipCamera.RotatePosition(speed, 0); |
---|
| 14810 | + } |
---|
14413 | 14811 | /**/ |
---|
14414 | 14812 | if ((mod & SHIFT) == SHIFT) |
---|
14415 | 14813 | { |
---|
.. | .. |
---|
14419 | 14817 | mouseMode |= ROTATE; |
---|
14420 | 14818 | } // TRANSLATE; |
---|
14421 | 14819 | |
---|
| 14820 | + targetLookAt.set(manipCamera.lookAt); |
---|
| 14821 | + |
---|
14422 | 14822 | prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance()); |
---|
14423 | 14823 | prevY = Y = anchorY; |
---|
14424 | 14824 | } |
---|
.. | .. |
---|
14428 | 14828 | MODIFIERS |= COMMAND; |
---|
14429 | 14829 | /**/ |
---|
14430 | 14830 | if((mod&SHIFT) == SHIFT) |
---|
14431 | | - manipCamera.Translate(-speed*delta, 0, getWidth()); |
---|
| 14831 | + manipCamera.Translate(-speed*delta, 0, getWidth()); |
---|
14432 | 14832 | else |
---|
14433 | | - manipCamera.RotatePosition(-speed, 0); |
---|
| 14833 | + { |
---|
| 14834 | + if ((mouseMode&VR)!=0) |
---|
| 14835 | + manipCamera.RotateInterest(speed, 0); |
---|
| 14836 | + else |
---|
| 14837 | + manipCamera.RotatePosition(-speed, 0); |
---|
| 14838 | + } |
---|
| 14839 | + |
---|
14434 | 14840 | /**/ |
---|
14435 | 14841 | if ((mod & SHIFT) == SHIFT) |
---|
14436 | 14842 | { |
---|
.. | .. |
---|
14440 | 14846 | mouseMode |= ROTATE; |
---|
14441 | 14847 | } // TRANSLATE; |
---|
14442 | 14848 | |
---|
| 14849 | + targetLookAt.set(manipCamera.lookAt); |
---|
| 14850 | + |
---|
14443 | 14851 | prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance()); |
---|
14444 | 14852 | prevY = Y = anchorY; |
---|
14445 | 14853 | } |
---|
.. | .. |
---|
14481 | 14889 | if (editObj) |
---|
14482 | 14890 | { |
---|
14483 | 14891 | drag = true; |
---|
14484 | | - ClickInfo info = new ClickInfo(); |
---|
14485 | | - info.bounds.setBounds(0, 0, |
---|
| 14892 | + //ClickInfo info = new ClickInfo(); |
---|
| 14893 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14486 | 14894 | (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14487 | | - info.pane = this; |
---|
14488 | | - info.camera = renderCamera; |
---|
14489 | | - info.x = x; |
---|
14490 | | - info.y = y; |
---|
14491 | | - object.GetWindow().copy |
---|
14492 | | - .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
| 14895 | + object.clickInfo.pane = this; |
---|
| 14896 | + object.clickInfo.camera = renderCamera; |
---|
| 14897 | + object.clickInfo.x = x; |
---|
| 14898 | + object.clickInfo.y = y; |
---|
| 14899 | + object //.GetWindow().copy |
---|
| 14900 | + .doEditDrag(//info, |
---|
| 14901 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14493 | 14902 | } else |
---|
14494 | 14903 | { |
---|
14495 | 14904 | if (x < startX) |
---|
.. | .. |
---|
14638 | 15047 | } |
---|
14639 | 15048 | } |
---|
14640 | 15049 | |
---|
| 15050 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 15051 | + |
---|
14641 | 15052 | public void mouseMoved(MouseEvent e) |
---|
14642 | 15053 | { |
---|
14643 | 15054 | //System.out.println("mouseMoved: " + e); |
---|
14644 | 15055 | if (isRenderer) |
---|
14645 | 15056 | return; |
---|
14646 | 15057 | |
---|
14647 | | - ClickInfo ci = new ClickInfo(); |
---|
14648 | | - ci.x = e.getX(); |
---|
14649 | | - ci.y = e.getY(); |
---|
14650 | | - ci.modifiers = e.getModifiersEx(); |
---|
14651 | | - ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
14652 | | - ci.pane = this; |
---|
14653 | | - ci.camera = renderCamera; |
---|
| 15058 | + // Mouse cursor feedback |
---|
| 15059 | + object.clickInfo.x = e.getX(); |
---|
| 15060 | + object.clickInfo.y = e.getY(); |
---|
| 15061 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 15062 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 15063 | + object.clickInfo.pane = this; |
---|
| 15064 | + object.clickInfo.camera = renderCamera; |
---|
14654 | 15065 | if (!isRenderer) |
---|
14655 | 15066 | { |
---|
14656 | 15067 | //ObjEditor editWindow = object.editWindow; |
---|
14657 | 15068 | //Object3D copy = editWindow.copy; |
---|
14658 | | - if (object.doEditClick(ci, 0)) |
---|
| 15069 | + if (object.doEditClick(//clickInfo, |
---|
| 15070 | + 0)) |
---|
14659 | 15071 | { |
---|
14660 | 15072 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14661 | 15073 | } else |
---|
.. | .. |
---|
14927 | 15339 | // break; |
---|
14928 | 15340 | case 'T': |
---|
14929 | 15341 | CACHETEXTURE ^= true; |
---|
14930 | | - textures.clear(); |
---|
| 15342 | + texturepigment.clear(); |
---|
| 15343 | + texturebump.clear(); |
---|
14931 | 15344 | // repaint(); |
---|
14932 | 15345 | break; |
---|
14933 | 15346 | case 'Y': |
---|
.. | .. |
---|
14937 | 15350 | case 'K': |
---|
14938 | 15351 | KOMPACTTEXTURE ^= true; |
---|
14939 | 15352 | //textures.clear(); |
---|
14940 | | - break; |
---|
14941 | | - case 'P': // Texture Projection macros |
---|
| 15353 | + // break; |
---|
| 15354 | + //case 'P': // Texture Projection macros |
---|
14942 | 15355 | // SAVETEXTURE ^= true; |
---|
14943 | 15356 | macromode = true; |
---|
14944 | 15357 | Udebug = Vdebug = NORMALdebug = false; programInitialized = false; |
---|
.. | .. |
---|
15059 | 15472 | targetLookAt.set(manipCamera.lookAt); |
---|
15060 | 15473 | repaint(); |
---|
15061 | 15474 | break; |
---|
15062 | | - case 'p': |
---|
| 15475 | + case 'P': // p': |
---|
15063 | 15476 | // c'est quoi ca au juste? spherical ^= true; |
---|
15064 | 15477 | Skinshader ^= true; programInitialized = false; |
---|
15065 | 15478 | repaint(); |
---|
.. | .. |
---|
15097 | 15510 | repaint(); |
---|
15098 | 15511 | break; |
---|
15099 | 15512 | case 'O': |
---|
15100 | | - Globals.drawMode = OCCLUSION; // WARNING |
---|
| 15513 | + // Too dangerous. Use menu. Globals.drawMode = OCCLUSION; // WARNING |
---|
15101 | 15514 | repaint(); |
---|
15102 | 15515 | break; |
---|
15103 | 15516 | case 'o': |
---|
15104 | 15517 | OCCLUSION_CULLING ^= true; |
---|
15105 | 15518 | System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); |
---|
15106 | 15519 | break; |
---|
15107 | | - case '0': envyoff ^= true; repaint(); break; |
---|
| 15520 | + //case '0': envyoff ^= true; repaint(); break; |
---|
15108 | 15521 | case '1': |
---|
15109 | 15522 | case '2': |
---|
15110 | 15523 | case '3': |
---|
15111 | 15524 | case '4': |
---|
15112 | 15525 | case '5': |
---|
15113 | | - newenvy = Character.getNumericValue(key); |
---|
15114 | | - repaint(); |
---|
15115 | | - break; |
---|
15116 | 15526 | case '6': |
---|
15117 | 15527 | case '7': |
---|
15118 | 15528 | case '8': |
---|
15119 | 15529 | case '9': |
---|
15120 | | - BGcolor = (key - '6')/3.f; |
---|
| 15530 | + if (true) // envyoff) |
---|
| 15531 | + { |
---|
| 15532 | + BGcolor = (key - '1')/8.f; |
---|
| 15533 | + } |
---|
| 15534 | + else |
---|
| 15535 | + { |
---|
| 15536 | + //newenvy = Character.getNumericValue(key); |
---|
| 15537 | + } |
---|
15121 | 15538 | repaint(); |
---|
15122 | 15539 | break; |
---|
15123 | 15540 | case '!': |
---|
.. | .. |
---|
15680 | 16097 | |
---|
15681 | 16098 | int width = getBounds().width; |
---|
15682 | 16099 | int height = getBounds().height; |
---|
15683 | | - ClickInfo info = new ClickInfo(); |
---|
15684 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15685 | 16100 | //Image img = CreateImage(width, height); |
---|
15686 | 16101 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15687 | 16102 | |
---|
.. | .. |
---|
15758 | 16173 | } |
---|
15759 | 16174 | if (object != null && !hasMarquee) |
---|
15760 | 16175 | { |
---|
| 16176 | + if (object.clickInfo == null) |
---|
| 16177 | + object.clickInfo = new ClickInfo(); |
---|
| 16178 | + ClickInfo info = object.clickInfo; |
---|
| 16179 | + //ClickInfo info = new ClickInfo(); |
---|
| 16180 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 16181 | + |
---|
15761 | 16182 | if (isRenderer) |
---|
15762 | 16183 | { |
---|
15763 | | - info.flags++; |
---|
| 16184 | + object.clickInfo.flags++; |
---|
15764 | 16185 | double frameAspect = (double) width / (double) height; |
---|
15765 | 16186 | if (frameAspect > renderCamera.aspect) |
---|
15766 | 16187 | { |
---|
15767 | 16188 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15768 | | - info.bounds.width -= width - desired; |
---|
15769 | | - info.bounds.x += (width - desired) / 2; |
---|
| 16189 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 16190 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15770 | 16191 | } else |
---|
15771 | 16192 | { |
---|
15772 | 16193 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15773 | | - info.bounds.height -= height - desired; |
---|
15774 | | - info.bounds.y += (height - desired) / 2; |
---|
| 16194 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 16195 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15775 | 16196 | } |
---|
15776 | 16197 | } |
---|
15777 | 16198 | |
---|
15778 | | - info.g = gr; |
---|
15779 | | - info.camera = renderCamera; |
---|
| 16199 | + object.clickInfo.g = gr; |
---|
| 16200 | + object.clickInfo.camera = renderCamera; |
---|
15780 | 16201 | /* |
---|
15781 | 16202 | // Memory intensive (brep.verticescopy) |
---|
15782 | 16203 | if (!(object instanceof Composite)) |
---|
15783 | 16204 | object.draw(info, 0, false); // SLOW : |
---|
15784 | 16205 | */ |
---|
15785 | | - if (!isRenderer) |
---|
| 16206 | + if (!isRenderer) // && drag) |
---|
15786 | 16207 | { |
---|
15787 | 16208 | Grafreed.Assert(object != null); |
---|
15788 | 16209 | Grafreed.Assert(object.selection != null); |
---|
.. | .. |
---|
15790 | 16211 | { |
---|
15791 | 16212 | int hitSomething = object.selection.get(0).hitSomething; |
---|
15792 | 16213 | |
---|
15793 | | - info.DX = 0; |
---|
15794 | | - info.DY = 0; |
---|
15795 | | - info.W = 1; |
---|
| 16214 | + object.clickInfo.DX = 0; |
---|
| 16215 | + object.clickInfo.DY = 0; |
---|
| 16216 | + object.clickInfo.W = 1; |
---|
15796 | 16217 | if (hitSomething == Object3D.hitCenter) |
---|
15797 | 16218 | { |
---|
15798 | 16219 | info.DX = X; |
---|
.. | .. |
---|
15804 | 16225 | info.DY -= info.bounds.height/2; |
---|
15805 | 16226 | } |
---|
15806 | 16227 | |
---|
15807 | | - object.drawEditHandles(info, 0); |
---|
| 16228 | + object.drawEditHandles(//info, |
---|
| 16229 | + 0); |
---|
15808 | 16230 | |
---|
15809 | 16231 | if (drag && (X != 0 || Y != 0)) |
---|
15810 | 16232 | { |
---|
15811 | 16233 | switch (hitSomething) |
---|
15812 | 16234 | { |
---|
15813 | | - case Object3D.hitCenter: gr.setColor(Color.pink); |
---|
| 16235 | + case Object3D.hitCenter: gr.setColor(Color.white); |
---|
15814 | 16236 | gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2); |
---|
15815 | 16237 | break; |
---|
15816 | 16238 | case Object3D.hitRotate: gr.setColor(Color.yellow); |
---|
.. | .. |
---|
15836 | 16258 | if (hasMarquee) |
---|
15837 | 16259 | { |
---|
15838 | 16260 | gr.setXORMode(Color.white); |
---|
15839 | | - gr.setColor(Color.red); |
---|
| 16261 | + gr.setColor(Color.white); |
---|
15840 | 16262 | if (!firstime) |
---|
15841 | 16263 | { |
---|
15842 | 16264 | gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH); |
---|
.. | .. |
---|
16303 | 16725 | private /*static*/ boolean firstime; |
---|
16304 | 16726 | private /*static*/ cVector newView = new cVector(); |
---|
16305 | 16727 | private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; |
---|
| 16728 | + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; |
---|
| 16729 | + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; |
---|
16306 | 16730 | private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
---|
16307 | 16731 | GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
---|
16308 | 16732 | GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
---|
.. | .. |
---|
16315 | 16739 | { |
---|
16316 | 16740 | com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); |
---|
16317 | 16741 | |
---|
| 16742 | + int usedsuf = 0; |
---|
| 16743 | + |
---|
16318 | 16744 | for (int i = 0; i < suffixes.length; i++) |
---|
16319 | 16745 | { |
---|
16320 | | - String resourceName = basename + suffixes[i] + "." + suffix; |
---|
16321 | | - TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
16322 | | - mipmapped, |
---|
16323 | | - FileUtil.getFileSuffix(resourceName)); |
---|
16324 | | - if (data == null) |
---|
| 16746 | + String[] suffixe = suffixes; |
---|
| 16747 | + String[] fallback = suffixes2; |
---|
| 16748 | + String[] fallfallback = suffixes3; |
---|
| 16749 | + |
---|
| 16750 | + for (int c=usedsuf; --c>=0;) |
---|
16325 | 16751 | { |
---|
16326 | | - throw new IOException("Unable to load texture " + resourceName); |
---|
| 16752 | +// String[] temp = suffixe; |
---|
| 16753 | +// suffixe = fallback; |
---|
| 16754 | +// fallback = fallfallback; |
---|
| 16755 | +// fallfallback = temp; |
---|
16327 | 16756 | } |
---|
| 16757 | + |
---|
| 16758 | + String resourceName = basename + suffixe[i] + "." + suffix; |
---|
| 16759 | + TextureData data; |
---|
| 16760 | + |
---|
| 16761 | + try |
---|
| 16762 | + { |
---|
| 16763 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16764 | + mipmapped, |
---|
| 16765 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16766 | + } |
---|
| 16767 | + catch (Exception e) |
---|
| 16768 | + { |
---|
| 16769 | + try |
---|
| 16770 | + { |
---|
| 16771 | + resourceName = basename + fallback[i] + "." + suffix; |
---|
| 16772 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16773 | + mipmapped, |
---|
| 16774 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16775 | + } |
---|
| 16776 | + catch (Exception e2) |
---|
| 16777 | + { |
---|
| 16778 | + resourceName = basename + fallfallback[i] + "." + suffix; |
---|
| 16779 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16780 | + mipmapped, |
---|
| 16781 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16782 | + } |
---|
| 16783 | + } |
---|
| 16784 | + |
---|
16328 | 16785 | //System.out.println("Target = " + targets[i]); |
---|
16329 | 16786 | cubemap.updateImage(data, targets[i]); |
---|
16330 | 16787 | } |
---|
16331 | 16788 | |
---|
16332 | 16789 | return cubemap; |
---|
16333 | 16790 | } |
---|
| 16791 | + |
---|
16334 | 16792 | int bigsphere = -1; |
---|
16335 | 16793 | |
---|
16336 | 16794 | float BGcolor = 0.5f; |
---|
16337 | 16795 | |
---|
16338 | | - private void DrawSkyBox(GL gl) |
---|
| 16796 | + float ambientLight[] = {1f, 1f, 1f, 1.0f}; |
---|
| 16797 | + |
---|
| 16798 | + private void DrawSkyBox(GL gl, float ratio) |
---|
16339 | 16799 | { |
---|
16340 | | - if (envyoff || cubemap == null) |
---|
| 16800 | + if (//envyoff || |
---|
| 16801 | + WIREFRAME || |
---|
| 16802 | + cubemap == null) |
---|
16341 | 16803 | { |
---|
16342 | 16804 | gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); |
---|
16343 | 16805 | gl.glClear(gl.GL_COLOR_BUFFER_BIT); |
---|
.. | .. |
---|
16352 | 16814 | // Compensates for ExaminerViewer's modification of modelview matrix |
---|
16353 | 16815 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
16354 | 16816 | gl.glLoadIdentity(); |
---|
| 16817 | + gl.glScalef(1,ratio,1); |
---|
16355 | 16818 | |
---|
| 16819 | +// colorV[0] = 2; |
---|
| 16820 | +// colorV[1] = 2; |
---|
| 16821 | +// colorV[2] = 2; |
---|
| 16822 | +// colorV[3] = 1; |
---|
| 16823 | +// gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
| 16824 | +// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
| 16825 | +// |
---|
| 16826 | +// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); |
---|
| 16827 | + |
---|
16356 | 16828 | //gl.glActiveTexture(GL.GL_TEXTURE1); |
---|
16357 | 16829 | //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); |
---|
16358 | 16830 | |
---|
.. | .. |
---|
16384 | 16856 | { |
---|
16385 | 16857 | gl.glScalef(1.0f, -1.0f, 1.0f); |
---|
16386 | 16858 | } |
---|
| 16859 | + gl.glScalef(-1.0f, 1.0f, 1.0f); |
---|
16387 | 16860 | gl.glMultMatrixd(viewrot_1, 0); |
---|
16388 | 16861 | gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); |
---|
16389 | 16862 | //viewer.updateInverseRotation(gl); |
---|
.. | .. |
---|
16424 | 16897 | gl.glDisable(GL.GL_TEXTURE_GEN_R); |
---|
16425 | 16898 | |
---|
16426 | 16899 | cubemap.disable(); |
---|
16427 | | - ////cubemap.unbind(); |
---|
| 16900 | + //cubemap.dispose(); |
---|
| 16901 | + |
---|
16428 | 16902 | if (CULLFACE) |
---|
16429 | 16903 | { |
---|
16430 | 16904 | gl.glEnable(gl.GL_CULL_FACE); |
---|
.. | .. |
---|
16480 | 16954 | gl.glScalef(1.0f, -1.0f, 1.0f); |
---|
16481 | 16955 | } |
---|
16482 | 16956 | |
---|
16483 | | - gl.glNormal3f(0.0f, 0.0f, 1.0f); |
---|
| 16957 | + SetGLNormal(gl, 0.0f, 0.0f, 1.0f); |
---|
16484 | 16958 | |
---|
16485 | 16959 | float step = 2; // 0.1666f; //0.25f; |
---|
16486 | 16960 | float stepv = 2; // step * 1652 / 998; |
---|
.. | .. |
---|
16642 | 17116 | //new Exception().printStackTrace(); |
---|
16643 | 17117 | System.out.println("select buffer init"); |
---|
16644 | 17118 | // Use debug pipeline |
---|
16645 | | - drawable.setGL(new DebugGL(drawable.getGL())); |
---|
| 17119 | + //drawable.setGL(new DebugGL(drawable.getGL())); |
---|
16646 | 17120 | |
---|
16647 | 17121 | GL gl = drawable.getGL(); |
---|
16648 | 17122 | |
---|
.. | .. |
---|
16960 | 17434 | |
---|
16961 | 17435 | public void init(GLAutoDrawable drawable) |
---|
16962 | 17436 | { |
---|
| 17437 | + if (Globals.DEBUG) |
---|
16963 | 17438 | System.out.println("shadow buffer init"); |
---|
16964 | 17439 | |
---|
16965 | 17440 | GL gl = drawable.getGL(); |
---|
.. | .. |
---|
17188 | 17663 | gl.glFlush(); |
---|
17189 | 17664 | |
---|
17190 | 17665 | /**/ |
---|
17191 | | - gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer); |
---|
| 17666 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer); |
---|
17192 | 17667 | |
---|
17193 | | - float[] pixels = occlusionsizebuffer.array(); |
---|
| 17668 | + float[] depths = occlusiondepthbuffer.array(); |
---|
17194 | 17669 | |
---|
| 17670 | + gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer); |
---|
| 17671 | + |
---|
| 17672 | + int[] pixels = selectsizebuffer.array(); |
---|
| 17673 | + |
---|
17195 | 17674 | double r = 0, g = 0, b = 0; |
---|
17196 | 17675 | |
---|
17197 | 17676 | double count = 0; |
---|
.. | .. |
---|
17202 | 17681 | |
---|
17203 | 17682 | double FACTOR = 1; |
---|
17204 | 17683 | |
---|
17205 | | - for (int i = 0; i < pixels.length; i++) |
---|
| 17684 | + for (int i = 0; i < depths.length; i++) |
---|
17206 | 17685 | { |
---|
17207 | 17686 | int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
17208 | 17687 | int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2; |
---|
.. | .. |
---|
17285 | 17764 | |
---|
17286 | 17765 | double scale = ray.z; // 1; // cos |
---|
17287 | 17766 | |
---|
17288 | | - float depth = pixels[newindex]; |
---|
| 17767 | + float depth = depths[newindex]; |
---|
17289 | 17768 | |
---|
17290 | 17769 | /* |
---|
17291 | 17770 | int newindex2 = (x + 1) * OCCLUSION_SIZE + y; |
---|
.. | .. |
---|
17482 | 17961 | static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE); |
---|
17483 | 17962 | static IntBuffer bigAAbuffer; |
---|
17484 | 17963 | static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3); |
---|
17485 | | - static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
| 17964 | + //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE); |
---|
17486 | 17965 | static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17487 | 17966 | static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE); |
---|
17488 | 17967 | //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
17489 | | - static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17968 | + static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17969 | + |
---|
| 17970 | + static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE); |
---|
| 17971 | + |
---|
17490 | 17972 | static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB); |
---|
17491 | 17973 | static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); |
---|
17492 | 17974 | static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>(); |
---|