Normand Briere
2019-07-30 475f8cbdbd96fdbf8f5b216ffebb31a51f25c2f9
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -93,7 +97,7 @@
9397 //boolean REDUCETEXTURE = true;
9498 boolean CACHETEXTURE = true;
9599 boolean CLEANCACHE = false; // true;
96
- boolean MIPMAP = true; // false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
97101 boolean COMPRESSTEXTURE = false;
98102 boolean KOMPACTTEXTURE = false; // true;
99103 boolean RESIZETEXTURE = false;
....@@ -183,6 +187,18 @@
183187 }
184188
185189 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
191
+ public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192
+ {
193
+ try
194
+ {
195
+ cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196
+ } catch (IOException e)
197
+ {
198
+ System.out.println("NAME = " + name);
199
+ e.printStackTrace(); // throw new RuntimeException(e);
200
+ }
201
+ }
186202
187203 void SetAsGLRenderer(boolean b)
188204 {
....@@ -202,7 +218,8 @@
202218
203219 SetCamera(cam);
204220
205
- SetLight(new Camera(new cVector(10, 10, -20)));
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
206223
207224 object = o;
208225
....@@ -1480,6 +1497,8 @@
14801497 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14811498 }
14821499
1500
+ float[] colorV = new float[4];
1501
+
14831502 void SetColor(Object3D obj, Vertex p0)
14841503 {
14851504 CameraPane display = this;
....@@ -1547,8 +1566,6 @@
15471566 {
15481567 return;
15491568 }
1550
-
1551
- float[] colorV = new float[3];
15521569
15531570 if (false) // marked)
15541571 {
....@@ -8358,14 +8375,26 @@
83588375 {
83598376 TextureData texturedata = null;
83608377
8361
- if (texdata != null)
8378
+ if (texdata != null && textureon)
83628379 {
8363
- BufferedImage bim = //new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8380
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
83648381
8365
- CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8382
+ try
8383
+ {
8384
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8385
+ }
8386
+ catch (Exception e)
8387
+ {
8388
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8389
+ }
83668390
83678391 texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
83688392 bimtextures.put(texdata, texturecache);
8393
+
8394
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8395
+
8396
+ //Object bim2 = CreateBim(texturecache.texturedata);
8397
+ //bim2 = bim;
83698398 }
83708399 else
83718400 if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
....@@ -8560,29 +8589,32 @@
85608589 {
85618590 if (tex.pigmentdata == null)
85628591 {
8563
- String texname = Object3D.GetPigment(tex);
8592
+ //String texname = Object3D.GetPigment(tex);
85648593
85658594 CacheTexture texturecache = texturepigment.get(tex);
85668595
85678596 if (texturecache != null)
85688597 {
8569
- tex.pigmentdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
85708598 tex.pw = texturecache.texturedata.getWidth();
85718599 tex.ph = texturecache.texturedata.getHeight();
8600
+ tex.pigmentdata = //CompressJPEG(CreateBim
8601
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8602
+ ;
8603
+ //, tex.pw, tex.ph), 0.5f);
85728604 }
85738605 }
85748606
85758607 if (tex.bumpdata == null)
85768608 {
8577
- String texname = Object3D.GetBump(tex);
8609
+ //String texname = Object3D.GetBump(tex);
85788610
85798611 CacheTexture texturecache = texturebump.get(tex);
85808612
85818613 if (texturecache != null)
85828614 {
8583
- tex.bumpdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
85848615 tex.bw = texturecache.texturedata.getWidth();
85858616 tex.bh = texturecache.texturedata.getHeight();
8617
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
85868618 }
85878619 }
85888620 }
....@@ -8654,6 +8686,72 @@
86548686 return true; // Warning: not used.
86558687 }
86568688
8689
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8690
+ {
8691
+ try
8692
+ {
8693
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8694
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8695
+ ImageWriter writer = writers.next();
8696
+
8697
+ ImageWriteParam param = writer.getDefaultWriteParam();
8698
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8699
+ param.setCompressionQuality(quality);
8700
+
8701
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8702
+ writer.setOutput(ios);
8703
+ writer.write(null, new IIOImage(image, null, null), param);
8704
+
8705
+ byte[] data = baos.toByteArray();
8706
+ writer.dispose();
8707
+ return data;
8708
+ }
8709
+ catch (Exception e)
8710
+ {
8711
+ e.printStackTrace();
8712
+ return null;
8713
+ }
8714
+ }
8715
+
8716
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8717
+ {
8718
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8719
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8720
+ ImageReader reader = writers.next();
8721
+
8722
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8723
+
8724
+ ImageReadParam param = reader.getDefaultReadParam();
8725
+ param.setDestination(bim);
8726
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8727
+
8728
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8729
+ reader.setInput(ios);
8730
+ BufferedImage bim2 = reader.read(0, param);
8731
+ reader.dispose();
8732
+
8733
+// WritableRaster raster = bim2.getRaster();
8734
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8735
+// byte[] bytes = data.getData();
8736
+//
8737
+// int[] pixels = new int[bytes.length/3];
8738
+// for (int i=pixels.length; --i>=0;)
8739
+// {
8740
+// int i3 = i*3;
8741
+// pixels[i] = 0xFF;
8742
+// pixels[i] <<= 8;
8743
+// pixels[i] |= bytes[i3+2] & 0xFF;
8744
+// pixels[i] <<= 8;
8745
+// pixels[i] |= bytes[i3+1] & 0xFF;
8746
+// pixels[i] <<= 8;
8747
+// pixels[i] |= bytes[i3] & 0xFF;
8748
+// }
8749
+//
8750
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8751
+
8752
+ return bim;
8753
+ }
8754
+
86578755 ShadowBuffer shadowPBuf;
86588756 AntialiasBuffer antialiasPBuf;
86598757 int MAXSTACK;
....@@ -8846,7 +8944,7 @@
88468944
88478945 if (cubemap == null)
88488946 {
8849
- LoadEnvy(5);
8947
+ //LoadEnvy(1);
88508948 }
88518949
88528950 //cubemap.enable();
....@@ -9133,37 +9231,58 @@
91339231 cubemap = null;
91349232 return;
91359233 case 1:
9136
- name = "cubemaps/box_";
9137
- ext = "png";
9234
+ name = "cubemaps/rgb/";
9235
+ ext = "jpg";
91389236 reverseUP = false;
91399237 break;
91409238 case 2:
9141
- name = "cubemaps/uffizi_";
9142
- ext = "png";
9143
- break; // reverseUP = true; break;
9239
+ name = "cubemaps/uffizi/";
9240
+ ext = "jpg";
9241
+ reverseUP = false;
9242
+ break;
91449243 case 3:
9145
- name = "cubemaps/CloudyHills_";
9146
- ext = "tga";
9244
+ name = "cubemaps/CloudyHills/";
9245
+ ext = "jpg";
91479246 reverseUP = false;
91489247 break;
91499248 case 4:
9150
- name = "cubemaps/cornell_";
9249
+ name = "cubemaps/cornell/";
91519250 ext = "png";
91529251 reverseUP = false;
91539252 break;
9253
+ case 5:
9254
+ name = "cubemaps/skycube/";
9255
+ ext = "jpg";
9256
+ reverseUP = false;
9257
+ break;
9258
+ case 6:
9259
+ name = "cubemaps/SaintLazarusChurch3/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
9263
+ case 7:
9264
+ name = "cubemaps/Sodermalmsallen/";
9265
+ ext = "jpg";
9266
+ reverseUP = false;
9267
+ break;
9268
+ case 8:
9269
+ name = "cubemaps/Sodermalmsallen2/";
9270
+ ext = "jpg";
9271
+ reverseUP = false;
9272
+ break;
9273
+ case 9:
9274
+ name = "cubemaps/UnionSquare/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
91549278 default:
9155
- name = "cubemaps/rgb_";
9156
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9279
+ name = "cubemaps/box/";
9280
+ ext = "png"; /*mipmap = true;*/
9281
+ reverseUP = false;
91579282 break;
91589283 }
9159
-
9160
- try
9161
- {
9162
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9163
- } catch (IOException e)
9164
- {
9165
- throw new RuntimeException(e);
9166
- }
9284
+
9285
+ LoadSkybox(name, ext, mipmap);
91679286 }
91689287
91699288 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9195,8 +9314,12 @@
91959314 static double[] model = new double[16];
91969315 double[] camera2light = new double[16];
91979316 double[] light2camera = new double[16];
9198
- int newenvy = -1;
9199
- boolean envyoff = true; // false;
9317
+
9318
+ //int newenvy = -1;
9319
+ //boolean envyoff = false;
9320
+
9321
+ String loadedskyboxname;
9322
+
92009323 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
92019324 //float[] light0 = { 0,0,0 };
92029325 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9614,7 +9737,7 @@
96149737
96159738 if (renderCamera != lightCamera)
96169739 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9617
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9740
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
96189741
96199742 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
96209743
....@@ -9630,7 +9753,7 @@
96309753
96319754 if (renderCamera != lightCamera)
96329755 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9633
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9756
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
96349757
96359758 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
96369759
....@@ -9676,10 +9799,12 @@
96769799 rati = 1 / rati;
96779800 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
96789801 }
9679
- assert (newenvy == -1);
9802
+
9803
+ //assert (newenvy == -1);
9804
+
96809805 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
96819806 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9682
- DrawSkyBox(gl);
9807
+ DrawSkyBox(gl, (float)rati);
96839808 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
96849809 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
96859810 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10831,7 +10956,7 @@
1083110956 // if (parentcam != renderCamera) // not a light
1083210957 if (cam != lightCamera)
1083310958 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10834
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10959
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1083510960
1083610961 for (int j = 0; j < 4; j++)
1083710962 {
....@@ -10846,7 +10971,7 @@
1084610971 // if (parentcam != renderCamera) // not a light
1084710972 if (cam != lightCamera)
1084810973 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10849
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10974
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1085010975
1085110976 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1085210977
....@@ -10932,13 +11057,27 @@
1093211057 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1093311058 }
1093411059
10935
- if (newenvy > -1)
11060
+// if (newenvy > -1)
11061
+// {
11062
+// LoadEnvy(newenvy);
11063
+// }
11064
+//
11065
+// newenvy = -1;
11066
+
11067
+ if (object.skyboxname != null)
1093611068 {
10937
- LoadEnvy(newenvy);
11069
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11070
+ {
11071
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11072
+ loadedskyboxname = object.skyboxname;
11073
+ }
1093811074 }
10939
-
10940
- newenvy = -1;
10941
-
11075
+ else
11076
+ {
11077
+ cubemap = null;
11078
+ loadedskyboxname = null;
11079
+ }
11080
+
1094211081 ratio = ((double) getWidth()) / getHeight();
1094311082 //System.out.println("ratio = " + ratio);
1094411083
....@@ -10954,7 +11093,7 @@
1095411093
1095511094 if (!IsFrozen() && !ambientOcclusion)
1095611095 {
10957
- DrawSkyBox(gl);
11096
+ DrawSkyBox(gl, (float)ratio);
1095811097 }
1095911098
1096011099 //if (selection_view == -1)
....@@ -11399,7 +11538,7 @@
1139911538 }
1140011539 }
1140111540
11402
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11541
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1140311542 {
1140411543 //gl.glDepthFunc(GL.GL_LEQUAL);
1140511544 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11407,24 +11546,21 @@
1140711546
1140811547 boolean texon = textureon;
1140911548
11410
- if (RENDERPROGRAM > 0)
11411
- {
11412
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11413
- textureon = false;
11414
- }
11549
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11550
+ textureon = false;
11551
+
1141511552 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1141611553 //System.out.println("ALLO");
1141711554 gl.glColorMask(false, false, false, false);
1141811555 DrawObject(gl);
11419
- if (RENDERPROGRAM > 0)
11420
- {
11421
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11422
- textureon = texon;
11423
- }
11556
+
11557
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11558
+ textureon = texon;
11559
+
1142411560 gl.glColorMask(true, true, true, true);
1142511561
1142611562 gl.glDepthFunc(GL.GL_EQUAL);
11427
- //gl.glDepthMask(false);
11563
+ gl.glDepthMask(false);
1142811564 }
1142911565
1143011566 if (false) // DrawMode() == SHADOW)
....@@ -12317,8 +12453,76 @@
1231712453
1231812454 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1231912455
12456
+ String program0 =
12457
+ // Min shader
12458
+ "!!ARBfp1.0\n" +
12459
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12460
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12461
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12462
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12463
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12464
+ "PARAM light2cam0 = program.env[10];" +
12465
+ "PARAM light2cam1 = program.env[11];" +
12466
+ "PARAM light2cam2 = program.env[12];" +
12467
+ "TEMP temp;" +
12468
+ "TEMP light;" +
12469
+ "TEMP ndotl;" +
12470
+ "TEMP normal;" +
12471
+ "TEMP depth;" +
12472
+ "TEMP eye;" +
12473
+ "TEMP pos;" +
12474
+
12475
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12476
+ Normalize("normal") +
12477
+ "MOV light, state.light[0].position;" +
12478
+ "DP3 ndotl.x, light, normal;" +
12479
+
12480
+ // shadow
12481
+ "MOV pos, fragment.texcoord[1];" +
12482
+ "MOV temp, pos;" +
12483
+ ShadowTextureFetch("depth", "temp", "1") +
12484
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12485
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12486
+
12487
+ // No shadow when out of frustum
12488
+ //"SGE temp.y, depth.z, zero123.y;" +
12489
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12490
+
12491
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12492
+
12493
+ // Backlit
12494
+ "MOV pos.w, zero123.y;" +
12495
+ "DP4 eye.x, pos, light2cam0;" +
12496
+ "DP4 eye.y, pos, light2cam1;" +
12497
+ "DP4 eye.z, pos, light2cam2;" +
12498
+ Normalize("eye") +
12499
+
12500
+ "DP3 ndotl.y, -eye, normal;" +
12501
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12502
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12503
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12504
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12505
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12506
+
12507
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12508
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12509
+
12510
+ // Pigment
12511
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12512
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12513
+ "MUL temp, temp, ndotl.x;" +
12514
+
12515
+ "MUL temp, temp, zero123.z;" +
12516
+
12517
+ //"MUL temp, temp, ndotl.y;" +
12518
+
12519
+ "MOV temp.w, zero123.y;" + // reset alpha
12520
+ "MOV result.color, temp;" +
12521
+ "END";
12522
+
1232012523 String program =
1232112524 "!!ARBfp1.0\n" +
12525
+
1232212526 //"OPTION ARB_fragment_program_shadow;" +
1232312527 "PARAM light2cam0 = program.env[10];" +
1232412528 "PARAM light2cam1 = program.env[11];" +
....@@ -12433,8 +12637,7 @@
1243312637 "TEMP shininess;" +
1243412638 "\n" +
1243512639 "MOV texSamp, one;" +
12436
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12437
-
12640
+
1243812641 "MOV mapgrid.x, one2048th.x;" +
1243912642 "MOV temp, fragment.texcoord[1];" +
1244012643 /*
....@@ -12455,20 +12658,20 @@
1245512658 "MUL temp, floor, mapgrid.x;" +
1245612659 //"TEX depth0, temp, texture[1], 2D;" +
1245712660 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12458
- TextureFetch("depth0", "temp", "1") +
12661
+ ShadowTextureFetch("depth0", "temp", "1") +
1245912662 "") +
1246012663 "ADD temp.x, temp.x, mapgrid.x;" +
1246112664 //"TEX depth1, temp, texture[1], 2D;" +
1246212665 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12463
- TextureFetch("depth1", "temp", "1") +
12666
+ ShadowTextureFetch("depth1", "temp", "1") +
1246412667 "") +
1246512668 "ADD temp.y, temp.y, mapgrid.x;" +
1246612669 //"TEX depth2, temp, texture[1], 2D;" +
12467
- TextureFetch("depth2", "temp", "1") +
12670
+ ShadowTextureFetch("depth2", "temp", "1") +
1246812671 "SUB temp.x, temp.x, mapgrid.x;" +
1246912672 //"TEX depth3, temp, texture[1], 2D;" +
1247012673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12471
- TextureFetch("depth3", "temp", "1") +
12674
+ ShadowTextureFetch("depth3", "temp", "1") +
1247212675 "") +
1247312676 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1247412677 //"MOV params, material;" +
....@@ -12839,10 +13042,10 @@
1283913042 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1284013043 "") +
1284113044
12842
- // display shadow only (bump == 0)
13045
+ // display shadow only (fakedepth == 0)
1284313046 "SUB temp.x, half.x, shadow.x;" +
1284413047 "MOV temp.y, -params5.z;" + // params6.x;" +
12845
- "SLT temp.z, temp.y, -one2048th.x;" +
13048
+ "SLT temp.z, temp.y, -c256i.x;" +
1284613049 "SUB temp.y, one.x, temp.z;" +
1284713050 "MUL temp.x, temp.x, temp.y;" +
1284813051 "KIL temp.x;" +
....@@ -13266,25 +13469,26 @@
1326613469 return out;
1326713470 }
1326813471
13269
- String TextureFetch(String dest, String src, String unit)
13472
+ // Also does frustum culling
13473
+ String ShadowTextureFetch(String dest, String src, String unit)
1327013474 {
1327113475 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1327213476 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1327313477 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13478
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13479
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1327413480 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13275
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13276
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13277
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13278
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13481
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13482
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1327913483 //"SWZ buffer, temp, w,w,w,w;";
13280
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13484
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1328113485 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1328213486 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1328313487 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13284
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13488
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1328513489
13286
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13287
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13490
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13491
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1328813492 }
1328913493
1329013494 String Shadow(String depth, String shadow)
....@@ -13331,7 +13535,7 @@
1333113535 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1333213536 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333313537
13334
- // No shadow when out of frustrum
13538
+ // No shadow when out of frustum
1333513539 "SGE temp.x, " + depth + ".z, one.z;" +
1333613540 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333713541 "";
....@@ -14129,14 +14333,15 @@
1412914333 drag = false;
1413014334 //System.out.println("Mouse DOWN");
1413114335 editObj = false;
14132
- ClickInfo info = new ClickInfo();
14133
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14134
- info.pane = this;
14135
- info.camera = renderCamera;
14136
- info.x = x;
14137
- info.y = y;
14138
- info.modifiers = modifiersex;
14139
- editObj = object.doEditClick(info, 0);
14336
+ //ClickInfo info = new ClickInfo();
14337
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14338
+ object.clickInfo.pane = this;
14339
+ object.clickInfo.camera = renderCamera;
14340
+ object.clickInfo.x = x;
14341
+ object.clickInfo.y = y;
14342
+ object.clickInfo.modifiers = modifiersex;
14343
+ editObj = object.doEditClick(//info,
14344
+ 0);
1414014345 if (!editObj)
1414114346 {
1414214347 hasMarquee = true;
....@@ -14536,15 +14741,16 @@
1453614741 if (editObj)
1453714742 {
1453814743 drag = true;
14539
- ClickInfo info = new ClickInfo();
14540
- info.bounds.setBounds(0, 0,
14744
+ //ClickInfo info = new ClickInfo();
14745
+ object.clickInfo.bounds.setBounds(0, 0,
1454114746 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14542
- info.pane = this;
14543
- info.camera = renderCamera;
14544
- info.x = x;
14545
- info.y = y;
14546
- object.GetWindow().copy
14547
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14747
+ object.clickInfo.pane = this;
14748
+ object.clickInfo.camera = renderCamera;
14749
+ object.clickInfo.x = x;
14750
+ object.clickInfo.y = y;
14751
+ object //.GetWindow().copy
14752
+ .doEditDrag(//info,
14753
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1454814754 } else
1454914755 {
1455014756 if (x < startX)
....@@ -14693,24 +14899,27 @@
1469314899 }
1469414900 }
1469514901
14902
+// ClickInfo clickInfo = new ClickInfo();
14903
+
1469614904 public void mouseMoved(MouseEvent e)
1469714905 {
1469814906 //System.out.println("mouseMoved: " + e);
1469914907 if (isRenderer)
1470014908 return;
1470114909
14702
- ClickInfo ci = new ClickInfo();
14703
- ci.x = e.getX();
14704
- ci.y = e.getY();
14705
- ci.modifiers = e.getModifiersEx();
14706
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14707
- ci.pane = this;
14708
- ci.camera = renderCamera;
14910
+ // Mouse cursor feedback
14911
+ object.clickInfo.x = e.getX();
14912
+ object.clickInfo.y = e.getY();
14913
+ object.clickInfo.modifiers = e.getModifiersEx();
14914
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14915
+ object.clickInfo.pane = this;
14916
+ object.clickInfo.camera = renderCamera;
1470914917 if (!isRenderer)
1471014918 {
1471114919 //ObjEditor editWindow = object.editWindow;
1471214920 //Object3D copy = editWindow.copy;
14713
- if (object.doEditClick(ci, 0))
14921
+ if (object.doEditClick(//clickInfo,
14922
+ 0))
1471414923 {
1471514924 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1471614925 } else
....@@ -15160,20 +15369,24 @@
1516015369 OCCLUSION_CULLING ^= true;
1516115370 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1516215371 break;
15163
- case '0': envyoff ^= true; repaint(); break;
15372
+ //case '0': envyoff ^= true; repaint(); break;
1516415373 case '1':
1516515374 case '2':
1516615375 case '3':
1516715376 case '4':
1516815377 case '5':
15169
- newenvy = Character.getNumericValue(key);
15170
- repaint();
15171
- break;
1517215378 case '6':
1517315379 case '7':
1517415380 case '8':
1517515381 case '9':
15176
- BGcolor = (key - '6')/3.f;
15382
+ if (true) // envyoff)
15383
+ {
15384
+ BGcolor = (key - '1')/8.f;
15385
+ }
15386
+ else
15387
+ {
15388
+ //newenvy = Character.getNumericValue(key);
15389
+ }
1517715390 repaint();
1517815391 break;
1517915392 case '!':
....@@ -15736,8 +15949,6 @@
1573615949
1573715950 int width = getBounds().width;
1573815951 int height = getBounds().height;
15739
- ClickInfo info = new ClickInfo();
15740
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1574115952 //Image img = CreateImage(width, height);
1574215953 //System.out.println("width = " + width + "; height = " + height + "\n");
1574315954
....@@ -15814,31 +16025,37 @@
1581416025 }
1581516026 if (object != null && !hasMarquee)
1581616027 {
16028
+ if (object.clickInfo == null)
16029
+ object.clickInfo = new ClickInfo();
16030
+ ClickInfo info = object.clickInfo;
16031
+ //ClickInfo info = new ClickInfo();
16032
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16033
+
1581716034 if (isRenderer)
1581816035 {
15819
- info.flags++;
16036
+ object.clickInfo.flags++;
1582016037 double frameAspect = (double) width / (double) height;
1582116038 if (frameAspect > renderCamera.aspect)
1582216039 {
1582316040 int desired = (int) ((double) height * renderCamera.aspect);
15824
- info.bounds.width -= width - desired;
15825
- info.bounds.x += (width - desired) / 2;
16041
+ object.clickInfo.bounds.width -= width - desired;
16042
+ object.clickInfo.bounds.x += (width - desired) / 2;
1582616043 } else
1582716044 {
1582816045 int desired = (int) ((double) width / renderCamera.aspect);
15829
- info.bounds.height -= height - desired;
15830
- info.bounds.y += (height - desired) / 2;
16046
+ object.clickInfo.bounds.height -= height - desired;
16047
+ object.clickInfo.bounds.y += (height - desired) / 2;
1583116048 }
1583216049 }
1583316050
15834
- info.g = gr;
15835
- info.camera = renderCamera;
16051
+ object.clickInfo.g = gr;
16052
+ object.clickInfo.camera = renderCamera;
1583616053 /*
1583716054 // Memory intensive (brep.verticescopy)
1583816055 if (!(object instanceof Composite))
1583916056 object.draw(info, 0, false); // SLOW :
1584016057 */
15841
- if (!isRenderer)
16058
+ if (!isRenderer) // && drag)
1584216059 {
1584316060 Grafreed.Assert(object != null);
1584416061 Grafreed.Assert(object.selection != null);
....@@ -15846,9 +16063,9 @@
1584616063 {
1584716064 int hitSomething = object.selection.get(0).hitSomething;
1584816065
15849
- info.DX = 0;
15850
- info.DY = 0;
15851
- info.W = 1;
16066
+ object.clickInfo.DX = 0;
16067
+ object.clickInfo.DY = 0;
16068
+ object.clickInfo.W = 1;
1585216069 if (hitSomething == Object3D.hitCenter)
1585316070 {
1585416071 info.DX = X;
....@@ -15860,7 +16077,8 @@
1586016077 info.DY -= info.bounds.height/2;
1586116078 }
1586216079
15863
- object.drawEditHandles(info, 0);
16080
+ object.drawEditHandles(//info,
16081
+ 0);
1586416082
1586516083 if (drag && (X != 0 || Y != 0))
1586616084 {
....@@ -15873,7 +16091,7 @@
1587316091 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1587416092 break;
1587516093 case Object3D.hitScale: gr.setColor(Color.cyan);
15876
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16094
+ gr.drawLine(X, Y, 0, 0);
1587716095 break;
1587816096 }
1587916097
....@@ -16359,6 +16577,8 @@
1635916577 private /*static*/ boolean firstime;
1636016578 private /*static*/ cVector newView = new cVector();
1636116579 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16580
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16581
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1636216582 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1636316583 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1636416584 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16371,29 +16591,66 @@
1637116591 {
1637216592 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1637316593
16594
+ int usedsuf = 0;
16595
+
1637416596 for (int i = 0; i < suffixes.length; i++)
1637516597 {
16376
- String resourceName = basename + suffixes[i] + "." + suffix;
16377
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16378
- mipmapped,
16379
- FileUtil.getFileSuffix(resourceName));
16380
- if (data == null)
16598
+ String[] suffixe = suffixes;
16599
+ String[] fallback = suffixes2;
16600
+ String[] fallfallback = suffixes3;
16601
+
16602
+ for (int c=usedsuf; --c>=0;)
1638116603 {
16382
- throw new IOException("Unable to load texture " + resourceName);
16604
+// String[] temp = suffixe;
16605
+// suffixe = fallback;
16606
+// fallback = fallfallback;
16607
+// fallfallback = temp;
1638316608 }
16609
+
16610
+ String resourceName = basename + suffixe[i] + "." + suffix;
16611
+ TextureData data;
16612
+
16613
+ try
16614
+ {
16615
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16616
+ mipmapped,
16617
+ FileUtil.getFileSuffix(resourceName));
16618
+ }
16619
+ catch (Exception e)
16620
+ {
16621
+ try
16622
+ {
16623
+ resourceName = basename + fallback[i] + "." + suffix;
16624
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16625
+ mipmapped,
16626
+ FileUtil.getFileSuffix(resourceName));
16627
+ }
16628
+ catch (Exception e2)
16629
+ {
16630
+ resourceName = basename + fallfallback[i] + "." + suffix;
16631
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16632
+ mipmapped,
16633
+ FileUtil.getFileSuffix(resourceName));
16634
+ }
16635
+ }
16636
+
1638416637 //System.out.println("Target = " + targets[i]);
1638516638 cubemap.updateImage(data, targets[i]);
1638616639 }
1638716640
1638816641 return cubemap;
1638916642 }
16643
+
1639016644 int bigsphere = -1;
1639116645
1639216646 float BGcolor = 0.5f;
1639316647
16394
- private void DrawSkyBox(GL gl)
16648
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16649
+
16650
+ private void DrawSkyBox(GL gl, float ratio)
1639516651 {
16396
- if (envyoff || cubemap == null)
16652
+ if (//envyoff ||
16653
+ cubemap == null)
1639716654 {
1639816655 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1639916656 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16408,7 +16665,17 @@
1640816665 // Compensates for ExaminerViewer's modification of modelview matrix
1640916666 gl.glMatrixMode(GL.GL_MODELVIEW);
1641016667 gl.glLoadIdentity();
16668
+ gl.glScalef(1,ratio,1);
1641116669
16670
+ colorV[0] = 2;
16671
+ colorV[1] = 2;
16672
+ colorV[2] = 2;
16673
+ colorV[3] = 1;
16674
+ gl.glDisable(gl.GL_COLOR_MATERIAL);
16675
+ gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16676
+
16677
+ gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16678
+
1641216679 //gl.glActiveTexture(GL.GL_TEXTURE1);
1641316680 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1641416681
....@@ -16421,7 +16688,7 @@
1642116688 // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting
1642216689 // causes the normals to be sent down. Thanks to Ken Dyke.
1642316690 //gl.glEnable(GL.GL_LIGHTING);
16424
- gl.glDisable(GL.GL_LIGHTING);
16691
+ gl.glEnable(GL.GL_LIGHTING);
1642516692
1642616693 gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
1642716694 gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
....@@ -16440,6 +16707,7 @@
1644016707 {
1644116708 gl.glScalef(1.0f, -1.0f, 1.0f);
1644216709 }
16710
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1644316711 gl.glMultMatrixd(viewrot_1, 0);
1644416712 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1644516713 //viewer.updateInverseRotation(gl);
....@@ -16698,7 +16966,7 @@
1669816966 //new Exception().printStackTrace();
1669916967 System.out.println("select buffer init");
1670016968 // Use debug pipeline
16701
- drawable.setGL(new DebugGL(drawable.getGL()));
16969
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1670216970
1670316971 GL gl = drawable.getGL();
1670416972