Normand Briere
2019-08-13 c67de8aca04d988179191ccb52461af00125920e
CameraPane.java
....@@ -110,7 +110,9 @@
110110 //private Mat4f spotlightTransform = new Mat4f();
111111 //private Mat4f spotlightInverseTransform = new Mat4f();
112112 static GLContext glcontext = null;
113
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
114116 boolean reverseUP = false;
115117 static boolean frozen = false;
116118 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -173,7 +175,7 @@
173175 static boolean doublesided = false; // true; // reversed normals are awful for conformance
174176 boolean anisotropy = true;
175177 boolean softshadow = true; // slower but better false;
176
- boolean opacityhalo = false;
178
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
177179
178180 boolean macromode = false;
179181
....@@ -187,6 +189,19 @@
187189 }
188190
189191 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
192
+
193
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
194
+ {
195
+ try
196
+ {
197
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
198
+ } catch (IOException e)
199
+ {
200
+ System.out.println("NAME = " + name);
201
+ e.printStackTrace(); // throw new RuntimeException(e);
202
+ return null;
203
+ }
204
+ }
190205
191206 void SetAsGLRenderer(boolean b)
192207 {
....@@ -206,7 +221,8 @@
206221
207222 SetCamera(cam);
208223
209
- SetLight(new Camera(new cVector(10, 10, -20)));
224
+ // Warning: not used.
225
+ SetLight(new Camera(new cVector(15, 10, -20)));
210226
211227 object = o;
212228
....@@ -1484,6 +1500,8 @@
14841500 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14851501 }
14861502
1503
+ float[] colorV = new float[4];
1504
+
14871505 void SetColor(Object3D obj, Vertex p0)
14881506 {
14891507 CameraPane display = this;
....@@ -1551,8 +1569,6 @@
15511569 {
15521570 return;
15531571 }
1554
-
1555
- float[] colorV = new float[3];
15561572
15571573 if (false) // marked)
15581574 {
....@@ -8345,7 +8361,7 @@
83458361 // else
83468362 // if (!texname.startsWith("/"))
83478363 // texname = "/Users/nbriere/Textures/" + texname;
8348
- if (!FileExists(texname))
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
83498365 {
83508366 texname = fallbackTextureName;
83518367 }
....@@ -8428,6 +8444,15 @@
84288444 new Exception().printStackTrace();
84298445 } else
84308446 {
8447
+ if (texname.startsWith("@"))
8448
+ {
8449
+ // texturecache = textures.get(texname); // suspicious
8450
+ if (texturecache == null)
8451
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8452
+ else
8453
+ new Exception().printStackTrace();
8454
+ } else
8455
+ {
84318456 if (textureon)
84328457 {
84338458 String cachename = texname;
....@@ -8487,6 +8512,7 @@
84878512 texturecache = new CacheTexture(texturedata,resolution);
84888513 //texture = GetTexture(tex, bump);
84898514 }
8515
+ }
84908516 }
84918517 //}
84928518 }
....@@ -8755,10 +8781,12 @@
87558781
87568782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
87578783 MAXSTACK = temp[0];
8758
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
87598786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
87608787 MAXSTACK = temp[0];
8761
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
87628790
87638791 // Use debug pipeline
87648792 //drawable.setGL(new DebugGL(gl)); //
....@@ -8766,7 +8794,8 @@
87668794 gl = drawable.getGL(); //
87678795
87688796 GL gl3 = getGL();
8769
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
87708799
87718800
87728801 //float pos[] = { 100, 100, 100, 0 };
....@@ -8931,7 +8960,7 @@
89318960
89328961 if (cubemap == null)
89338962 {
8934
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
89358964 }
89368965
89378966 //cubemap.enable();
....@@ -9207,6 +9236,8 @@
92079236
92089237 void LoadEnvy(int which)
92099238 {
9239
+ assert(false);
9240
+
92109241 String name;
92119242 String ext;
92129243
....@@ -9218,37 +9249,58 @@
92189249 cubemap = null;
92199250 return;
92209251 case 1:
9221
- name = "cubemaps/box_";
9222
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
92239254 reverseUP = false;
92249255 break;
92259256 case 2:
9226
- name = "cubemaps/uffizi_";
9227
- ext = "png";
9228
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
92299261 case 3:
9230
- name = "cubemaps/CloudyHills_";
9231
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
92329264 reverseUP = false;
92339265 break;
92349266 case 4:
9235
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
92369268 ext = "png";
92379269 reverseUP = false;
92389270 break;
9271
+ case 5:
9272
+ name = "cubemaps/skycube/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 6:
9277
+ name = "cubemaps/SaintLazarusChurch3/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 7:
9282
+ name = "cubemaps/Sodermalmsallen/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 8:
9287
+ name = "cubemaps/Sodermalmsallen2/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 9:
9292
+ name = "cubemaps/UnionSquare/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
92399296 default:
9240
- name = "cubemaps/rgb_";
9241
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
92429300 break;
92439301 }
9244
-
9245
- try
9246
- {
9247
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9248
- } catch (IOException e)
9249
- {
9250
- throw new RuntimeException(e);
9251
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
92529304 }
92539305
92549306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9280,8 +9332,12 @@
92809332 static double[] model = new double[16];
92819333 double[] camera2light = new double[16];
92829334 double[] light2camera = new double[16];
9283
- int newenvy = -1;
9284
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
92859341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
92869342 //float[] light0 = { 0,0,0 };
92879343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9699,7 +9755,7 @@
96999755
97009756 if (renderCamera != lightCamera)
97019757 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9702
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9758
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
97039759
97049760 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
97059761
....@@ -9715,7 +9771,7 @@
97159771
97169772 if (renderCamera != lightCamera)
97179773 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9718
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9774
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
97199775
97209776 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
97219777
....@@ -9761,10 +9817,12 @@
97619817 rati = 1 / rati;
97629818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
97639819 }
9764
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
97659823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
97669824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9767
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
97689826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
97699827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
97709828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10801,7 +10859,7 @@
1080110859
1080210860 if (wait)
1080310861 {
10804
- Sleep(500);
10862
+ Sleep(200); // blocks everything
1080510863
1080610864 wait = false;
1080710865 }
....@@ -10916,7 +10974,7 @@
1091610974 // if (parentcam != renderCamera) // not a light
1091710975 if (cam != lightCamera)
1091810976 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10919
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10977
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1092010978
1092110979 for (int j = 0; j < 4; j++)
1092210980 {
....@@ -10931,7 +10989,7 @@
1093110989 // if (parentcam != renderCamera) // not a light
1093210990 if (cam != lightCamera)
1093310991 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10992
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1093510993
1093610994 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1093710995
....@@ -11017,13 +11075,41 @@
1101711075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1101811076 }
1101911077
11020
- if (newenvy > -1)
11078
+// if (newenvy > -1)
11079
+// {
11080
+// LoadEnvy(newenvy);
11081
+// }
11082
+//
11083
+// newenvy = -1;
11084
+
11085
+ if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1102111086 {
11022
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
1102311093 }
11024
-
11025
- newenvy = -1;
11026
-
11094
+ else
11095
+ {
11096
+ if (object.skyboxname != null)
11097
+ {
11098
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11099
+ {
11100
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11101
+ loadedskyboxname = object.skyboxname;
11102
+ }
11103
+ }
11104
+ else
11105
+ {
11106
+ cubemapcustom = null;
11107
+ loadedskyboxname = null;
11108
+ }
11109
+
11110
+ cubemap = cubemapcustom;
11111
+ }
11112
+
1102711113 ratio = ((double) getWidth()) / getHeight();
1102811114 //System.out.println("ratio = " + ratio);
1102911115
....@@ -11039,7 +11125,7 @@
1103911125
1104011126 if (!IsFrozen() && !ambientOcclusion)
1104111127 {
11042
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
1104311129 }
1104411130
1104511131 //if (selection_view == -1)
....@@ -11325,7 +11411,7 @@
1132511411
1132611412 // if (cam != lightCamera)
1132711413 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11328
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11414
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1132911415 }
1133011416
1133111417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -12399,51 +12485,74 @@
1239912485
1240012486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1240112487
12402
- String program =
12488
+ String programmin =
1240312489 // Min shader
1240412490 "!!ARBfp1.0\n" +
12405
- "PARAM zero123 = { 0.0, 1.0, 2.0, 1.25 };" +
12491
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
1240612492 "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
1240712493 "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1240812494 "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
1240912495 "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12496
+ "PARAM light2cam0 = program.env[10];" +
12497
+ "PARAM light2cam1 = program.env[11];" +
12498
+ "PARAM light2cam2 = program.env[12];" +
1241012499 "TEMP temp;" +
1241112500 "TEMP light;" +
1241212501 "TEMP ndotl;" +
1241312502 "TEMP normal;" +
1241412503 "TEMP depth;" +
12504
+ "TEMP eye;" +
12505
+ "TEMP pos;" +
1241512506
1241612507 "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12417
-
12508
+ Normalize("normal") +
1241812509 "MOV light, state.light[0].position;" +
1241912510 "DP3 ndotl.x, light, normal;" +
1242012511
1242112512 // shadow
12422
- "MOV temp, fragment.texcoord[1];" +
12423
- TextureFetch("depth", "temp", "1") +
12513
+ "MOV pos, fragment.texcoord[1];" +
12514
+ "MOV temp, pos;" +
12515
+ ShadowTextureFetch("depth", "temp", "1") +
1242412516 //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12425
- "SLT temp.x, fragment.texcoord[1].z, depth.z;" +
12426
-
12517
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
1242712518
1242812519 // No shadow when out of frustum
1242912520 //"SGE temp.y, depth.z, zero123.y;" +
1243012521 //"LRP temp.x, temp.y, zero123.y, temp.x;" +
1243112522
12432
- "MUL ndotl.x, ndotl.x, temp.x;" +
12433
- "MAX ndotl.x, ndotl.x, pow2.y;" +
12523
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
1243412524
12525
+ // Backlit
12526
+ "MOV pos.w, zero123.y;" +
12527
+ "DP4 eye.x, pos, light2cam0;" +
12528
+ "DP4 eye.y, pos, light2cam1;" +
12529
+ "DP4 eye.z, pos, light2cam2;" +
12530
+ Normalize("eye") +
12531
+
12532
+ "DP3 ndotl.y, -eye, normal;" +
12533
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12534
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12535
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12536
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12537
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12538
+
12539
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12540
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12541
+
12542
+ // Pigment
1243512543 "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
1243612544 "LRP temp, zero123.w, temp, one;" + // texture proportion
1243712545 "MUL temp, temp, ndotl.x;" +
1243812546
1243912547 "MUL temp, temp, zero123.z;" +
1244012548
12441
- "MOV temp.w, zero123.y;" + // reset alpha
12549
+ //"MUL temp, temp, ndotl.y;" +
1244212550
12551
+ "MOV temp.w, zero123.y;" + // reset alpha
1244312552 "MOV result.color, temp;" +
1244412553 "END";
1244512554
12446
- String program2 =
12555
+ String programmax =
1244712556 "!!ARBfp1.0\n" +
1244812557
1244912558 //"OPTION ARB_fragment_program_shadow;" +
....@@ -12581,20 +12690,20 @@
1258112690 "MUL temp, floor, mapgrid.x;" +
1258212691 //"TEX depth0, temp, texture[1], 2D;" +
1258312692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12584
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1258512694 "") +
1258612695 "ADD temp.x, temp.x, mapgrid.x;" +
1258712696 //"TEX depth1, temp, texture[1], 2D;" +
1258812697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12589
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1259012699 "") +
1259112700 "ADD temp.y, temp.y, mapgrid.x;" +
1259212701 //"TEX depth2, temp, texture[1], 2D;" +
12593
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1259412703 "SUB temp.x, temp.x, mapgrid.x;" +
1259512704 //"TEX depth3, temp, texture[1], 2D;" +
1259612705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12597
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1259812707 "") +
1259912708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1260012709 //"MOV params, material;" +
....@@ -12968,7 +13077,7 @@
1296813077 // display shadow only (fakedepth == 0)
1296913078 "SUB temp.x, half.x, shadow.x;" +
1297013079 "MOV temp.y, -params5.z;" + // params6.x;" +
12971
- "SLT temp.z, temp.y, -one2048th.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1297213081 "SUB temp.y, one.x, temp.z;" +
1297313082 "MUL temp.x, temp.x, temp.y;" +
1297413083 "KIL temp.x;" +
....@@ -13299,6 +13408,13 @@
1329913408 //once = true;
1330013409 }
1330113410
13411
+ String program = programmax;
13412
+
13413
+ if (Globals.MINSHADER)
13414
+ {
13415
+ program = programmin;
13416
+ }
13417
+
1330213418 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1330313419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1330413420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13392,7 +13508,8 @@
1339213508 return out;
1339313509 }
1339413510
13395
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1339613513 {
1339713514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1339813515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
....@@ -14547,9 +14664,9 @@
1454714664 MODIFIERS |= COMMAND;
1454814665 /**/
1454914666 if((mod&SHIFT) == SHIFT)
14550
- manipCamera.RotatePosition(0, -speed);
14551
- else
1455214667 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14668
+ else
14669
+ manipCamera.RotatePosition(0, -speed);
1455314670 /**/
1455414671 if ((mod & SHIFT) == SHIFT)
1455514672 {
....@@ -14568,9 +14685,9 @@
1456814685 MODIFIERS |= COMMAND;
1456914686 /**/
1457014687 if((mod&SHIFT) == SHIFT)
14571
- manipCamera.RotatePosition(0, speed);
14572
- else
1457314688 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14689
+ else
14690
+ manipCamera.RotatePosition(0, speed);
1457414691 /**/
1457514692 if ((mod & SHIFT) == SHIFT)
1457614693 {
....@@ -15291,20 +15408,24 @@
1529115408 OCCLUSION_CULLING ^= true;
1529215409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1529315410 break;
15294
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1529515412 case '1':
1529615413 case '2':
1529715414 case '3':
1529815415 case '4':
1529915416 case '5':
15300
- newenvy = Character.getNumericValue(key);
15301
- repaint();
15302
- break;
1530315417 case '6':
1530415418 case '7':
1530515419 case '8':
1530615420 case '9':
15307
- BGcolor = (key - '6')/3.f;
15421
+ if (true) // envyoff)
15422
+ {
15423
+ BGcolor = (key - '1')/8.f;
15424
+ }
15425
+ else
15426
+ {
15427
+ //newenvy = Character.getNumericValue(key);
15428
+ }
1530815429 repaint();
1530915430 break;
1531015431 case '!':
....@@ -16009,7 +16130,7 @@
1600916130 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1601016131 break;
1601116132 case Object3D.hitScale: gr.setColor(Color.cyan);
16012
- gr.drawLine(X, Y, 0, 0);
16133
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1601316134 break;
1601416135 }
1601516136
....@@ -16495,6 +16616,8 @@
1649516616 private /*static*/ boolean firstime;
1649616617 private /*static*/ cVector newView = new cVector();
1649716618 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16619
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16620
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1649816621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1649916622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1650016623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16507,29 +16630,67 @@
1650716630 {
1650816631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1650916632
16633
+ int usedsuf = 0;
16634
+
1651016635 for (int i = 0; i < suffixes.length; i++)
1651116636 {
16512
- String resourceName = basename + suffixes[i] + "." + suffix;
16513
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16514
- mipmapped,
16515
- FileUtil.getFileSuffix(resourceName));
16516
- if (data == null)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1651716642 {
16518
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1651916647 }
16648
+
16649
+ String resourceName = basename + suffixe[i] + "." + suffix;
16650
+ TextureData data;
16651
+
16652
+ try
16653
+ {
16654
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16655
+ mipmapped,
16656
+ FileUtil.getFileSuffix(resourceName));
16657
+ }
16658
+ catch (Exception e)
16659
+ {
16660
+ try
16661
+ {
16662
+ resourceName = basename + fallback[i] + "." + suffix;
16663
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16664
+ mipmapped,
16665
+ FileUtil.getFileSuffix(resourceName));
16666
+ }
16667
+ catch (Exception e2)
16668
+ {
16669
+ resourceName = basename + fallfallback[i] + "." + suffix;
16670
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16671
+ mipmapped,
16672
+ FileUtil.getFileSuffix(resourceName));
16673
+ }
16674
+ }
16675
+
1652016676 //System.out.println("Target = " + targets[i]);
1652116677 cubemap.updateImage(data, targets[i]);
1652216678 }
1652316679
1652416680 return cubemap;
1652516681 }
16682
+
1652616683 int bigsphere = -1;
1652716684
1652816685 float BGcolor = 0.5f;
1652916686
16530
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1653116690 {
16532
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1653316694 {
1653416695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1653516696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16544,7 +16705,17 @@
1654416705 // Compensates for ExaminerViewer's modification of modelview matrix
1654516706 gl.glMatrixMode(GL.GL_MODELVIEW);
1654616707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1654716709
16710
+// colorV[0] = 2;
16711
+// colorV[1] = 2;
16712
+// colorV[2] = 2;
16713
+// colorV[3] = 1;
16714
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16715
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16716
+//
16717
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16718
+
1654816719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1654916720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1655016721
....@@ -16576,6 +16747,7 @@
1657616747 {
1657716748 gl.glScalef(1.0f, -1.0f, 1.0f);
1657816749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1657916751 gl.glMultMatrixd(viewrot_1, 0);
1658016752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1658116753 //viewer.updateInverseRotation(gl);
....@@ -16834,7 +17006,7 @@
1683417006 //new Exception().printStackTrace();
1683517007 System.out.println("select buffer init");
1683617008 // Use debug pipeline
16837
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1683817010
1683917011 GL gl = drawable.getGL();
1684017012
....@@ -17380,10 +17552,14 @@
1738017552 gl.glFlush();
1738117553
1738217554 /**/
17383
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17555
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1738417556
17385
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1738617558
17559
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17560
+
17561
+ int[] pixels = selectsizebuffer.array();
17562
+
1738717563 double r = 0, g = 0, b = 0;
1738817564
1738917565 double count = 0;
....@@ -17394,7 +17570,7 @@
1739417570
1739517571 double FACTOR = 1;
1739617572
17397
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1739817574 {
1739917575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1740017576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17477,7 +17653,7 @@
1747717653
1747817654 double scale = ray.z; // 1; // cos
1747917655
17480
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1748117657
1748217658 /*
1748317659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17674,11 +17850,14 @@
1767417850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1767517851 static IntBuffer bigAAbuffer;
1767617852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17677
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1767817854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1767917855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1768017856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17681
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17857
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17858
+
17859
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17860
+
1768217861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1768317862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1768417863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();