Normand Briere
2019-08-12 8f1afe25ea8fc8801aab66331c32a50859a758c2
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 {
....@@ -8341,7 +8358,7 @@
83418358 // else
83428359 // if (!texname.startsWith("/"))
83438360 // texname = "/Users/nbriere/Textures/" + texname;
8344
- if (!FileExists(texname))
8361
+ if (!FileExists(texname) && !texname.startsWith("@"))
83458362 {
83468363 texname = fallbackTextureName;
83478364 }
....@@ -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(""))
....@@ -8408,6 +8437,15 @@
84088437 // texturecache = textures.get(texname); // suspicious
84098438 if (texturecache == null)
84108439 texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ else
8441
+ new Exception().printStackTrace();
8442
+ } else
8443
+ {
8444
+ if (texname.startsWith("@"))
8445
+ {
8446
+ // texturecache = textures.get(texname); // suspicious
8447
+ if (texturecache == null)
8448
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
84118449 else
84128450 new Exception().printStackTrace();
84138451 } else
....@@ -8471,6 +8509,7 @@
84718509 texturecache = new CacheTexture(texturedata,resolution);
84728510 //texture = GetTexture(tex, bump);
84738511 }
8512
+ }
84748513 }
84758514 //}
84768515 }
....@@ -8560,29 +8599,32 @@
85608599 {
85618600 if (tex.pigmentdata == null)
85628601 {
8563
- String texname = Object3D.GetPigment(tex);
8602
+ //String texname = Object3D.GetPigment(tex);
85648603
85658604 CacheTexture texturecache = texturepigment.get(tex);
85668605
85678606 if (texturecache != null)
85688607 {
8569
- tex.pigmentdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
85708608 tex.pw = texturecache.texturedata.getWidth();
85718609 tex.ph = texturecache.texturedata.getHeight();
8610
+ tex.pigmentdata = //CompressJPEG(CreateBim
8611
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8612
+ ;
8613
+ //, tex.pw, tex.ph), 0.5f);
85728614 }
85738615 }
85748616
85758617 if (tex.bumpdata == null)
85768618 {
8577
- String texname = Object3D.GetBump(tex);
8619
+ //String texname = Object3D.GetBump(tex);
85788620
85798621 CacheTexture texturecache = texturebump.get(tex);
85808622
85818623 if (texturecache != null)
85828624 {
8583
- tex.bumpdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
85848625 tex.bw = texturecache.texturedata.getWidth();
85858626 tex.bh = texturecache.texturedata.getHeight();
8627
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
85868628 }
85878629 }
85888630 }
....@@ -8654,6 +8696,72 @@
86548696 return true; // Warning: not used.
86558697 }
86568698
8699
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8700
+ {
8701
+ try
8702
+ {
8703
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8704
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8705
+ ImageWriter writer = writers.next();
8706
+
8707
+ ImageWriteParam param = writer.getDefaultWriteParam();
8708
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8709
+ param.setCompressionQuality(quality);
8710
+
8711
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8712
+ writer.setOutput(ios);
8713
+ writer.write(null, new IIOImage(image, null, null), param);
8714
+
8715
+ byte[] data = baos.toByteArray();
8716
+ writer.dispose();
8717
+ return data;
8718
+ }
8719
+ catch (Exception e)
8720
+ {
8721
+ e.printStackTrace();
8722
+ return null;
8723
+ }
8724
+ }
8725
+
8726
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8727
+ {
8728
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8729
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8730
+ ImageReader reader = writers.next();
8731
+
8732
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8733
+
8734
+ ImageReadParam param = reader.getDefaultReadParam();
8735
+ param.setDestination(bim);
8736
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8737
+
8738
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8739
+ reader.setInput(ios);
8740
+ BufferedImage bim2 = reader.read(0, param);
8741
+ reader.dispose();
8742
+
8743
+// WritableRaster raster = bim2.getRaster();
8744
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8745
+// byte[] bytes = data.getData();
8746
+//
8747
+// int[] pixels = new int[bytes.length/3];
8748
+// for (int i=pixels.length; --i>=0;)
8749
+// {
8750
+// int i3 = i*3;
8751
+// pixels[i] = 0xFF;
8752
+// pixels[i] <<= 8;
8753
+// pixels[i] |= bytes[i3+2] & 0xFF;
8754
+// pixels[i] <<= 8;
8755
+// pixels[i] |= bytes[i3+1] & 0xFF;
8756
+// pixels[i] <<= 8;
8757
+// pixels[i] |= bytes[i3] & 0xFF;
8758
+// }
8759
+//
8760
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8761
+
8762
+ return bim;
8763
+ }
8764
+
86578765 ShadowBuffer shadowPBuf;
86588766 AntialiasBuffer antialiasPBuf;
86598767 int MAXSTACK;
....@@ -8670,10 +8778,12 @@
86708778
86718779 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
86728780 MAXSTACK = temp[0];
8673
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8781
+ if (Globals.DEBUG)
8782
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
86748783 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
86758784 MAXSTACK = temp[0];
8676
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8785
+ if (Globals.DEBUG)
8786
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
86778787
86788788 // Use debug pipeline
86798789 //drawable.setGL(new DebugGL(gl)); //
....@@ -8681,7 +8791,8 @@
86818791 gl = drawable.getGL(); //
86828792
86838793 GL gl3 = getGL();
8684
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8794
+ if (Globals.DEBUG)
8795
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
86858796
86868797
86878798 //float pos[] = { 100, 100, 100, 0 };
....@@ -8846,7 +8957,7 @@
88468957
88478958 if (cubemap == null)
88488959 {
8849
- LoadEnvy(5);
8960
+ //LoadEnvy(1);
88508961 }
88518962
88528963 //cubemap.enable();
....@@ -9133,37 +9244,58 @@
91339244 cubemap = null;
91349245 return;
91359246 case 1:
9136
- name = "cubemaps/box_";
9137
- ext = "png";
9247
+ name = "cubemaps/rgb/";
9248
+ ext = "jpg";
91389249 reverseUP = false;
91399250 break;
91409251 case 2:
9141
- name = "cubemaps/uffizi_";
9142
- ext = "png";
9143
- break; // reverseUP = true; break;
9252
+ name = "cubemaps/uffizi/";
9253
+ ext = "jpg";
9254
+ reverseUP = false;
9255
+ break;
91449256 case 3:
9145
- name = "cubemaps/CloudyHills_";
9146
- ext = "tga";
9257
+ name = "cubemaps/CloudyHills/";
9258
+ ext = "jpg";
91479259 reverseUP = false;
91489260 break;
91499261 case 4:
9150
- name = "cubemaps/cornell_";
9262
+ name = "cubemaps/cornell/";
91519263 ext = "png";
91529264 reverseUP = false;
91539265 break;
9266
+ case 5:
9267
+ name = "cubemaps/skycube/";
9268
+ ext = "jpg";
9269
+ reverseUP = false;
9270
+ break;
9271
+ case 6:
9272
+ name = "cubemaps/SaintLazarusChurch3/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 7:
9277
+ name = "cubemaps/Sodermalmsallen/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 8:
9282
+ name = "cubemaps/Sodermalmsallen2/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 9:
9287
+ name = "cubemaps/UnionSquare/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
91549291 default:
9155
- name = "cubemaps/rgb_";
9156
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9292
+ name = "cubemaps/box/";
9293
+ ext = "png"; /*mipmap = true;*/
9294
+ reverseUP = false;
91579295 break;
91589296 }
9159
-
9160
- try
9161
- {
9162
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9163
- } catch (IOException e)
9164
- {
9165
- throw new RuntimeException(e);
9166
- }
9297
+
9298
+ LoadSkybox(name, ext, mipmap);
91679299 }
91689300
91699301 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9195,8 +9327,12 @@
91959327 static double[] model = new double[16];
91969328 double[] camera2light = new double[16];
91979329 double[] light2camera = new double[16];
9198
- int newenvy = -1;
9199
- boolean envyoff = true; // false;
9330
+
9331
+ //int newenvy = -1;
9332
+ //boolean envyoff = false;
9333
+
9334
+ String loadedskyboxname;
9335
+
92009336 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
92019337 //float[] light0 = { 0,0,0 };
92029338 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9614,7 +9750,7 @@
96149750
96159751 if (renderCamera != lightCamera)
96169752 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9617
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9753
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
96189754
96199755 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
96209756
....@@ -9630,7 +9766,7 @@
96309766
96319767 if (renderCamera != lightCamera)
96329768 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9633
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9769
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
96349770
96359771 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
96369772
....@@ -9676,10 +9812,12 @@
96769812 rati = 1 / rati;
96779813 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
96789814 }
9679
- assert (newenvy == -1);
9815
+
9816
+ //assert (newenvy == -1);
9817
+
96809818 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
96819819 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9682
- DrawSkyBox(gl);
9820
+ DrawSkyBox(gl, (float)rati);
96839821 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
96849822 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
96859823 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10716,7 +10854,7 @@
1071610854
1071710855 if (wait)
1071810856 {
10719
- Sleep(500);
10857
+ Sleep(200); // blocks everything
1072010858
1072110859 wait = false;
1072210860 }
....@@ -10831,7 +10969,7 @@
1083110969 // if (parentcam != renderCamera) // not a light
1083210970 if (cam != lightCamera)
1083310971 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10834
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10972
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1083510973
1083610974 for (int j = 0; j < 4; j++)
1083710975 {
....@@ -10846,7 +10984,7 @@
1084610984 // if (parentcam != renderCamera) // not a light
1084710985 if (cam != lightCamera)
1084810986 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10849
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10987
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1085010988
1085110989 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1085210990
....@@ -10932,13 +11070,27 @@
1093211070 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1093311071 }
1093411072
10935
- if (newenvy > -1)
11073
+// if (newenvy > -1)
11074
+// {
11075
+// LoadEnvy(newenvy);
11076
+// }
11077
+//
11078
+// newenvy = -1;
11079
+
11080
+ if (object.skyboxname != null)
1093611081 {
10937
- LoadEnvy(newenvy);
11082
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11083
+ {
11084
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11085
+ loadedskyboxname = object.skyboxname;
11086
+ }
1093811087 }
10939
-
10940
- newenvy = -1;
10941
-
11088
+ else
11089
+ {
11090
+ cubemap = null;
11091
+ loadedskyboxname = null;
11092
+ }
11093
+
1094211094 ratio = ((double) getWidth()) / getHeight();
1094311095 //System.out.println("ratio = " + ratio);
1094411096
....@@ -10954,7 +11106,7 @@
1095411106
1095511107 if (!IsFrozen() && !ambientOcclusion)
1095611108 {
10957
- DrawSkyBox(gl);
11109
+ DrawSkyBox(gl, (float)ratio);
1095811110 }
1095911111
1096011112 //if (selection_view == -1)
....@@ -11240,7 +11392,7 @@
1124011392
1124111393 // if (cam != lightCamera)
1124211394 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11243
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11395
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1124411396 }
1124511397
1124611398 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -11399,7 +11551,7 @@
1139911551 }
1140011552 }
1140111553
11402
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11554
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1140311555 {
1140411556 //gl.glDepthFunc(GL.GL_LEQUAL);
1140511557 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -11407,24 +11559,21 @@
1140711559
1140811560 boolean texon = textureon;
1140911561
11410
- if (RENDERPROGRAM > 0)
11411
- {
11412
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11413
- textureon = false;
11414
- }
11562
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11563
+ textureon = false;
11564
+
1141511565 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1141611566 //System.out.println("ALLO");
1141711567 gl.glColorMask(false, false, false, false);
1141811568 DrawObject(gl);
11419
- if (RENDERPROGRAM > 0)
11420
- {
11421
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11422
- textureon = texon;
11423
- }
11569
+
11570
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11571
+ textureon = texon;
11572
+
1142411573 gl.glColorMask(true, true, true, true);
1142511574
1142611575 gl.glDepthFunc(GL.GL_EQUAL);
11427
- //gl.glDepthMask(false);
11576
+ gl.glDepthMask(false);
1142811577 }
1142911578
1143011579 if (false) // DrawMode() == SHADOW)
....@@ -12317,8 +12466,76 @@
1231712466
1231812467 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1231912468
12320
- String program =
12469
+ String programmin =
12470
+ // Min shader
1232112471 "!!ARBfp1.0\n" +
12472
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12473
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12474
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12475
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12476
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12477
+ "PARAM light2cam0 = program.env[10];" +
12478
+ "PARAM light2cam1 = program.env[11];" +
12479
+ "PARAM light2cam2 = program.env[12];" +
12480
+ "TEMP temp;" +
12481
+ "TEMP light;" +
12482
+ "TEMP ndotl;" +
12483
+ "TEMP normal;" +
12484
+ "TEMP depth;" +
12485
+ "TEMP eye;" +
12486
+ "TEMP pos;" +
12487
+
12488
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12489
+ Normalize("normal") +
12490
+ "MOV light, state.light[0].position;" +
12491
+ "DP3 ndotl.x, light, normal;" +
12492
+
12493
+ // shadow
12494
+ "MOV pos, fragment.texcoord[1];" +
12495
+ "MOV temp, pos;" +
12496
+ ShadowTextureFetch("depth", "temp", "1") +
12497
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12498
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12499
+
12500
+ // No shadow when out of frustum
12501
+ //"SGE temp.y, depth.z, zero123.y;" +
12502
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12503
+
12504
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12505
+
12506
+ // Backlit
12507
+ "MOV pos.w, zero123.y;" +
12508
+ "DP4 eye.x, pos, light2cam0;" +
12509
+ "DP4 eye.y, pos, light2cam1;" +
12510
+ "DP4 eye.z, pos, light2cam2;" +
12511
+ Normalize("eye") +
12512
+
12513
+ "DP3 ndotl.y, -eye, normal;" +
12514
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12515
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12516
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12517
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12518
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12519
+
12520
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12521
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12522
+
12523
+ // Pigment
12524
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12525
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12526
+ "MUL temp, temp, ndotl.x;" +
12527
+
12528
+ "MUL temp, temp, zero123.z;" +
12529
+
12530
+ //"MUL temp, temp, ndotl.y;" +
12531
+
12532
+ "MOV temp.w, zero123.y;" + // reset alpha
12533
+ "MOV result.color, temp;" +
12534
+ "END";
12535
+
12536
+ String programmax =
12537
+ "!!ARBfp1.0\n" +
12538
+
1232212539 //"OPTION ARB_fragment_program_shadow;" +
1232312540 "PARAM light2cam0 = program.env[10];" +
1232412541 "PARAM light2cam1 = program.env[11];" +
....@@ -12433,8 +12650,7 @@
1243312650 "TEMP shininess;" +
1243412651 "\n" +
1243512652 "MOV texSamp, one;" +
12436
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12437
-
12653
+
1243812654 "MOV mapgrid.x, one2048th.x;" +
1243912655 "MOV temp, fragment.texcoord[1];" +
1244012656 /*
....@@ -12455,20 +12671,20 @@
1245512671 "MUL temp, floor, mapgrid.x;" +
1245612672 //"TEX depth0, temp, texture[1], 2D;" +
1245712673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12458
- TextureFetch("depth0", "temp", "1") +
12674
+ ShadowTextureFetch("depth0", "temp", "1") +
1245912675 "") +
1246012676 "ADD temp.x, temp.x, mapgrid.x;" +
1246112677 //"TEX depth1, temp, texture[1], 2D;" +
1246212678 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12463
- TextureFetch("depth1", "temp", "1") +
12679
+ ShadowTextureFetch("depth1", "temp", "1") +
1246412680 "") +
1246512681 "ADD temp.y, temp.y, mapgrid.x;" +
1246612682 //"TEX depth2, temp, texture[1], 2D;" +
12467
- TextureFetch("depth2", "temp", "1") +
12683
+ ShadowTextureFetch("depth2", "temp", "1") +
1246812684 "SUB temp.x, temp.x, mapgrid.x;" +
1246912685 //"TEX depth3, temp, texture[1], 2D;" +
1247012686 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12471
- TextureFetch("depth3", "temp", "1") +
12687
+ ShadowTextureFetch("depth3", "temp", "1") +
1247212688 "") +
1247312689 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1247412690 //"MOV params, material;" +
....@@ -12839,10 +13055,10 @@
1283913055 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1284013056 "") +
1284113057
12842
- // display shadow only (bump == 0)
13058
+ // display shadow only (fakedepth == 0)
1284313059 "SUB temp.x, half.x, shadow.x;" +
1284413060 "MOV temp.y, -params5.z;" + // params6.x;" +
12845
- "SLT temp.z, temp.y, -one2048th.x;" +
13061
+ "SLT temp.z, temp.y, -c256i.x;" +
1284613062 "SUB temp.y, one.x, temp.z;" +
1284713063 "MUL temp.x, temp.x, temp.y;" +
1284813064 "KIL temp.x;" +
....@@ -13173,6 +13389,13 @@
1317313389 //once = true;
1317413390 }
1317513391
13392
+ String program = programmax;
13393
+
13394
+ if (Globals.MINSHADER)
13395
+ {
13396
+ program = programmin;
13397
+ }
13398
+
1317613399 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1317713400 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1317813401 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13266,25 +13489,26 @@
1326613489 return out;
1326713490 }
1326813491
13269
- String TextureFetch(String dest, String src, String unit)
13492
+ // Also does frustum culling
13493
+ String ShadowTextureFetch(String dest, String src, String unit)
1327013494 {
1327113495 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1327213496 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1327313497 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13498
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13499
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1327413500 "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;" +
13501
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13502
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1327913503 //"SWZ buffer, temp, w,w,w,w;";
13280
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13504
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1328113505 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1328213506 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1328313507 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13284
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13508
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1328513509
13286
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13287
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13510
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13511
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1328813512 }
1328913513
1329013514 String Shadow(String depth, String shadow)
....@@ -13331,7 +13555,7 @@
1333113555 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1333213556 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333313557
13334
- // No shadow when out of frustrum
13558
+ // No shadow when out of frustum
1333513559 "SGE temp.x, " + depth + ".z, one.z;" +
1333613560 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1333713561 "";
....@@ -14129,14 +14353,15 @@
1412914353 drag = false;
1413014354 //System.out.println("Mouse DOWN");
1413114355 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);
14356
+ //ClickInfo info = new ClickInfo();
14357
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14358
+ object.clickInfo.pane = this;
14359
+ object.clickInfo.camera = renderCamera;
14360
+ object.clickInfo.x = x;
14361
+ object.clickInfo.y = y;
14362
+ object.clickInfo.modifiers = modifiersex;
14363
+ editObj = object.doEditClick(//info,
14364
+ 0);
1414014365 if (!editObj)
1414114366 {
1414214367 hasMarquee = true;
....@@ -14420,9 +14645,9 @@
1442014645 MODIFIERS |= COMMAND;
1442114646 /**/
1442214647 if((mod&SHIFT) == SHIFT)
14423
- manipCamera.RotatePosition(0, -speed);
14424
- else
1442514648 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14649
+ else
14650
+ manipCamera.RotatePosition(0, -speed);
1442614651 /**/
1442714652 if ((mod & SHIFT) == SHIFT)
1442814653 {
....@@ -14441,9 +14666,9 @@
1444114666 MODIFIERS |= COMMAND;
1444214667 /**/
1444314668 if((mod&SHIFT) == SHIFT)
14444
- manipCamera.RotatePosition(0, speed);
14445
- else
1444614669 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14670
+ else
14671
+ manipCamera.RotatePosition(0, speed);
1444714672 /**/
1444814673 if ((mod & SHIFT) == SHIFT)
1444914674 {
....@@ -14536,15 +14761,16 @@
1453614761 if (editObj)
1453714762 {
1453814763 drag = true;
14539
- ClickInfo info = new ClickInfo();
14540
- info.bounds.setBounds(0, 0,
14764
+ //ClickInfo info = new ClickInfo();
14765
+ object.clickInfo.bounds.setBounds(0, 0,
1454114766 (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);
14767
+ object.clickInfo.pane = this;
14768
+ object.clickInfo.camera = renderCamera;
14769
+ object.clickInfo.x = x;
14770
+ object.clickInfo.y = y;
14771
+ object //.GetWindow().copy
14772
+ .doEditDrag(//info,
14773
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1454814774 } else
1454914775 {
1455014776 if (x < startX)
....@@ -14693,24 +14919,27 @@
1469314919 }
1469414920 }
1469514921
14922
+// ClickInfo clickInfo = new ClickInfo();
14923
+
1469614924 public void mouseMoved(MouseEvent e)
1469714925 {
1469814926 //System.out.println("mouseMoved: " + e);
1469914927 if (isRenderer)
1470014928 return;
1470114929
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;
14930
+ // Mouse cursor feedback
14931
+ object.clickInfo.x = e.getX();
14932
+ object.clickInfo.y = e.getY();
14933
+ object.clickInfo.modifiers = e.getModifiersEx();
14934
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14935
+ object.clickInfo.pane = this;
14936
+ object.clickInfo.camera = renderCamera;
1470914937 if (!isRenderer)
1471014938 {
1471114939 //ObjEditor editWindow = object.editWindow;
1471214940 //Object3D copy = editWindow.copy;
14713
- if (object.doEditClick(ci, 0))
14941
+ if (object.doEditClick(//clickInfo,
14942
+ 0))
1471414943 {
1471514944 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1471614945 } else
....@@ -15160,20 +15389,24 @@
1516015389 OCCLUSION_CULLING ^= true;
1516115390 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1516215391 break;
15163
- case '0': envyoff ^= true; repaint(); break;
15392
+ //case '0': envyoff ^= true; repaint(); break;
1516415393 case '1':
1516515394 case '2':
1516615395 case '3':
1516715396 case '4':
1516815397 case '5':
15169
- newenvy = Character.getNumericValue(key);
15170
- repaint();
15171
- break;
1517215398 case '6':
1517315399 case '7':
1517415400 case '8':
1517515401 case '9':
15176
- BGcolor = (key - '6')/3.f;
15402
+ if (true) // envyoff)
15403
+ {
15404
+ BGcolor = (key - '1')/8.f;
15405
+ }
15406
+ else
15407
+ {
15408
+ //newenvy = Character.getNumericValue(key);
15409
+ }
1517715410 repaint();
1517815411 break;
1517915412 case '!':
....@@ -15736,8 +15969,6 @@
1573615969
1573715970 int width = getBounds().width;
1573815971 int height = getBounds().height;
15739
- ClickInfo info = new ClickInfo();
15740
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1574115972 //Image img = CreateImage(width, height);
1574215973 //System.out.println("width = " + width + "; height = " + height + "\n");
1574315974
....@@ -15814,31 +16045,37 @@
1581416045 }
1581516046 if (object != null && !hasMarquee)
1581616047 {
16048
+ if (object.clickInfo == null)
16049
+ object.clickInfo = new ClickInfo();
16050
+ ClickInfo info = object.clickInfo;
16051
+ //ClickInfo info = new ClickInfo();
16052
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16053
+
1581716054 if (isRenderer)
1581816055 {
15819
- info.flags++;
16056
+ object.clickInfo.flags++;
1582016057 double frameAspect = (double) width / (double) height;
1582116058 if (frameAspect > renderCamera.aspect)
1582216059 {
1582316060 int desired = (int) ((double) height * renderCamera.aspect);
15824
- info.bounds.width -= width - desired;
15825
- info.bounds.x += (width - desired) / 2;
16061
+ object.clickInfo.bounds.width -= width - desired;
16062
+ object.clickInfo.bounds.x += (width - desired) / 2;
1582616063 } else
1582716064 {
1582816065 int desired = (int) ((double) width / renderCamera.aspect);
15829
- info.bounds.height -= height - desired;
15830
- info.bounds.y += (height - desired) / 2;
16066
+ object.clickInfo.bounds.height -= height - desired;
16067
+ object.clickInfo.bounds.y += (height - desired) / 2;
1583116068 }
1583216069 }
1583316070
15834
- info.g = gr;
15835
- info.camera = renderCamera;
16071
+ object.clickInfo.g = gr;
16072
+ object.clickInfo.camera = renderCamera;
1583616073 /*
1583716074 // Memory intensive (brep.verticescopy)
1583816075 if (!(object instanceof Composite))
1583916076 object.draw(info, 0, false); // SLOW :
1584016077 */
15841
- if (!isRenderer)
16078
+ if (!isRenderer) // && drag)
1584216079 {
1584316080 Grafreed.Assert(object != null);
1584416081 Grafreed.Assert(object.selection != null);
....@@ -15846,9 +16083,9 @@
1584616083 {
1584716084 int hitSomething = object.selection.get(0).hitSomething;
1584816085
15849
- info.DX = 0;
15850
- info.DY = 0;
15851
- info.W = 1;
16086
+ object.clickInfo.DX = 0;
16087
+ object.clickInfo.DY = 0;
16088
+ object.clickInfo.W = 1;
1585216089 if (hitSomething == Object3D.hitCenter)
1585316090 {
1585416091 info.DX = X;
....@@ -15860,7 +16097,8 @@
1586016097 info.DY -= info.bounds.height/2;
1586116098 }
1586216099
15863
- object.drawEditHandles(info, 0);
16100
+ object.drawEditHandles(//info,
16101
+ 0);
1586416102
1586516103 if (drag && (X != 0 || Y != 0))
1586616104 {
....@@ -16359,6 +16597,8 @@
1635916597 private /*static*/ boolean firstime;
1636016598 private /*static*/ cVector newView = new cVector();
1636116599 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16600
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16601
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1636216602 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1636316603 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1636416604 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16371,29 +16611,67 @@
1637116611 {
1637216612 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1637316613
16614
+ int usedsuf = 0;
16615
+
1637416616 for (int i = 0; i < suffixes.length; i++)
1637516617 {
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)
16618
+ String[] suffixe = suffixes;
16619
+ String[] fallback = suffixes2;
16620
+ String[] fallfallback = suffixes3;
16621
+
16622
+ for (int c=usedsuf; --c>=0;)
1638116623 {
16382
- throw new IOException("Unable to load texture " + resourceName);
16624
+// String[] temp = suffixe;
16625
+// suffixe = fallback;
16626
+// fallback = fallfallback;
16627
+// fallfallback = temp;
1638316628 }
16629
+
16630
+ String resourceName = basename + suffixe[i] + "." + suffix;
16631
+ TextureData data;
16632
+
16633
+ try
16634
+ {
16635
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16636
+ mipmapped,
16637
+ FileUtil.getFileSuffix(resourceName));
16638
+ }
16639
+ catch (Exception e)
16640
+ {
16641
+ try
16642
+ {
16643
+ resourceName = basename + fallback[i] + "." + suffix;
16644
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16645
+ mipmapped,
16646
+ FileUtil.getFileSuffix(resourceName));
16647
+ }
16648
+ catch (Exception e2)
16649
+ {
16650
+ resourceName = basename + fallfallback[i] + "." + suffix;
16651
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16652
+ mipmapped,
16653
+ FileUtil.getFileSuffix(resourceName));
16654
+ }
16655
+ }
16656
+
1638416657 //System.out.println("Target = " + targets[i]);
1638516658 cubemap.updateImage(data, targets[i]);
1638616659 }
1638716660
1638816661 return cubemap;
1638916662 }
16663
+
1639016664 int bigsphere = -1;
1639116665
1639216666 float BGcolor = 0.5f;
1639316667
16394
- private void DrawSkyBox(GL gl)
16668
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16669
+
16670
+ private void DrawSkyBox(GL gl, float ratio)
1639516671 {
16396
- if (envyoff || cubemap == null)
16672
+ if (//envyoff ||
16673
+ WIREFRAME ||
16674
+ cubemap == null)
1639716675 {
1639816676 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1639916677 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16408,7 +16686,17 @@
1640816686 // Compensates for ExaminerViewer's modification of modelview matrix
1640916687 gl.glMatrixMode(GL.GL_MODELVIEW);
1641016688 gl.glLoadIdentity();
16689
+ gl.glScalef(1,ratio,1);
1641116690
16691
+// colorV[0] = 2;
16692
+// colorV[1] = 2;
16693
+// colorV[2] = 2;
16694
+// colorV[3] = 1;
16695
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16696
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16697
+//
16698
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16699
+
1641216700 //gl.glActiveTexture(GL.GL_TEXTURE1);
1641316701 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1641416702
....@@ -16440,6 +16728,7 @@
1644016728 {
1644116729 gl.glScalef(1.0f, -1.0f, 1.0f);
1644216730 }
16731
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1644316732 gl.glMultMatrixd(viewrot_1, 0);
1644416733 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1644516734 //viewer.updateInverseRotation(gl);
....@@ -16698,7 +16987,7 @@
1669816987 //new Exception().printStackTrace();
1669916988 System.out.println("select buffer init");
1670016989 // Use debug pipeline
16701
- drawable.setGL(new DebugGL(drawable.getGL()));
16990
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1670216991
1670316992 GL gl = drawable.getGL();
1670416993