Normand Briere
2019-07-30 475f8cbdbd96fdbf8f5b216ffebb31a51f25c2f9
CameraPane.java
....@@ -187,6 +187,18 @@
187187 }
188188
189189 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
+ }
190202
191203 void SetAsGLRenderer(boolean b)
192204 {
....@@ -206,7 +218,8 @@
206218
207219 SetCamera(cam);
208220
209
- SetLight(new Camera(new cVector(10, 10, -20)));
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
210223
211224 object = o;
212225
....@@ -1484,6 +1497,8 @@
14841497 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14851498 }
14861499
1500
+ float[] colorV = new float[4];
1501
+
14871502 void SetColor(Object3D obj, Vertex p0)
14881503 {
14891504 CameraPane display = this;
....@@ -1551,8 +1566,6 @@
15511566 {
15521567 return;
15531568 }
1554
-
1555
- float[] colorV = new float[3];
15561569
15571570 if (false) // marked)
15581571 {
....@@ -8931,7 +8944,7 @@
89318944
89328945 if (cubemap == null)
89338946 {
8934
- LoadEnvy(5);
8947
+ //LoadEnvy(1);
89358948 }
89368949
89378950 //cubemap.enable();
....@@ -9218,37 +9231,58 @@
92189231 cubemap = null;
92199232 return;
92209233 case 1:
9221
- name = "cubemaps/box_";
9222
- ext = "png";
9234
+ name = "cubemaps/rgb/";
9235
+ ext = "jpg";
92239236 reverseUP = false;
92249237 break;
92259238 case 2:
9226
- name = "cubemaps/uffizi_";
9227
- ext = "png";
9228
- break; // reverseUP = true; break;
9239
+ name = "cubemaps/uffizi/";
9240
+ ext = "jpg";
9241
+ reverseUP = false;
9242
+ break;
92299243 case 3:
9230
- name = "cubemaps/CloudyHills_";
9231
- ext = "tga";
9244
+ name = "cubemaps/CloudyHills/";
9245
+ ext = "jpg";
92329246 reverseUP = false;
92339247 break;
92349248 case 4:
9235
- name = "cubemaps/cornell_";
9249
+ name = "cubemaps/cornell/";
92369250 ext = "png";
92379251 reverseUP = false;
92389252 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;
92399278 default:
9240
- name = "cubemaps/rgb_";
9241
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9279
+ name = "cubemaps/box/";
9280
+ ext = "png"; /*mipmap = true;*/
9281
+ reverseUP = false;
92429282 break;
92439283 }
9244
-
9245
- try
9246
- {
9247
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9248
- } catch (IOException e)
9249
- {
9250
- throw new RuntimeException(e);
9251
- }
9284
+
9285
+ LoadSkybox(name, ext, mipmap);
92529286 }
92539287
92549288 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9280,8 +9314,12 @@
92809314 static double[] model = new double[16];
92819315 double[] camera2light = new double[16];
92829316 double[] light2camera = new double[16];
9283
- int newenvy = -1;
9284
- boolean envyoff = true; // false;
9317
+
9318
+ //int newenvy = -1;
9319
+ //boolean envyoff = false;
9320
+
9321
+ String loadedskyboxname;
9322
+
92859323 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
92869324 //float[] light0 = { 0,0,0 };
92879325 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9761,10 +9799,12 @@
97619799 rati = 1 / rati;
97629800 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
97639801 }
9764
- assert (newenvy == -1);
9802
+
9803
+ //assert (newenvy == -1);
9804
+
97659805 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
97669806 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9767
- DrawSkyBox(gl);
9807
+ DrawSkyBox(gl, (float)rati);
97689808 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
97699809 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
97709810 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -11017,13 +11057,27 @@
1101711057 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1101811058 }
1101911059
11020
- if (newenvy > -1)
11060
+// if (newenvy > -1)
11061
+// {
11062
+// LoadEnvy(newenvy);
11063
+// }
11064
+//
11065
+// newenvy = -1;
11066
+
11067
+ if (object.skyboxname != null)
1102111068 {
11022
- LoadEnvy(newenvy);
11069
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11070
+ {
11071
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11072
+ loadedskyboxname = object.skyboxname;
11073
+ }
1102311074 }
11024
-
11025
- newenvy = -1;
11026
-
11075
+ else
11076
+ {
11077
+ cubemap = null;
11078
+ loadedskyboxname = null;
11079
+ }
11080
+
1102711081 ratio = ((double) getWidth()) / getHeight();
1102811082 //System.out.println("ratio = " + ratio);
1102911083
....@@ -11039,7 +11093,7 @@
1103911093
1104011094 if (!IsFrozen() && !ambientOcclusion)
1104111095 {
11042
- DrawSkyBox(gl);
11096
+ DrawSkyBox(gl, (float)ratio);
1104311097 }
1104411098
1104511099 //if (selection_view == -1)
....@@ -12399,51 +12453,74 @@
1239912453
1240012454 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1240112455
12402
- String program =
12456
+ String program0 =
1240312457 // Min shader
1240412458 "!!ARBfp1.0\n" +
12405
- "PARAM zero123 = { 0.0, 1.0, 2.0, 1.25 };" +
12459
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
1240612460 "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
1240712461 "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1240812462 "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
1240912463 "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];" +
1241012467 "TEMP temp;" +
1241112468 "TEMP light;" +
1241212469 "TEMP ndotl;" +
1241312470 "TEMP normal;" +
1241412471 "TEMP depth;" +
12472
+ "TEMP eye;" +
12473
+ "TEMP pos;" +
1241512474
1241612475 "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12417
-
12476
+ Normalize("normal") +
1241812477 "MOV light, state.light[0].position;" +
1241912478 "DP3 ndotl.x, light, normal;" +
1242012479
1242112480 // shadow
12422
- "MOV temp, fragment.texcoord[1];" +
12423
- TextureFetch("depth", "temp", "1") +
12481
+ "MOV pos, fragment.texcoord[1];" +
12482
+ "MOV temp, pos;" +
12483
+ ShadowTextureFetch("depth", "temp", "1") +
1242412484 //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12425
- "SLT temp.x, fragment.texcoord[1].z, depth.z;" +
12426
-
12485
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
1242712486
1242812487 // No shadow when out of frustum
1242912488 //"SGE temp.y, depth.z, zero123.y;" +
1243012489 //"LRP temp.x, temp.y, zero123.y, temp.x;" +
1243112490
12432
- "MUL ndotl.x, ndotl.x, temp.x;" +
12433
- "MAX ndotl.x, ndotl.x, pow2.y;" +
12491
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
1243412492
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
1243512511 "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
1243612512 "LRP temp, zero123.w, temp, one;" + // texture proportion
1243712513 "MUL temp, temp, ndotl.x;" +
1243812514
1243912515 "MUL temp, temp, zero123.z;" +
1244012516
12441
- "MOV temp.w, zero123.y;" + // reset alpha
12517
+ //"MUL temp, temp, ndotl.y;" +
1244212518
12519
+ "MOV temp.w, zero123.y;" + // reset alpha
1244312520 "MOV result.color, temp;" +
1244412521 "END";
1244512522
12446
- String program2 =
12523
+ String program =
1244712524 "!!ARBfp1.0\n" +
1244812525
1244912526 //"OPTION ARB_fragment_program_shadow;" +
....@@ -12581,20 +12658,20 @@
1258112658 "MUL temp, floor, mapgrid.x;" +
1258212659 //"TEX depth0, temp, texture[1], 2D;" +
1258312660 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12584
- TextureFetch("depth0", "temp", "1") +
12661
+ ShadowTextureFetch("depth0", "temp", "1") +
1258512662 "") +
1258612663 "ADD temp.x, temp.x, mapgrid.x;" +
1258712664 //"TEX depth1, temp, texture[1], 2D;" +
1258812665 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12589
- TextureFetch("depth1", "temp", "1") +
12666
+ ShadowTextureFetch("depth1", "temp", "1") +
1259012667 "") +
1259112668 "ADD temp.y, temp.y, mapgrid.x;" +
1259212669 //"TEX depth2, temp, texture[1], 2D;" +
12593
- TextureFetch("depth2", "temp", "1") +
12670
+ ShadowTextureFetch("depth2", "temp", "1") +
1259412671 "SUB temp.x, temp.x, mapgrid.x;" +
1259512672 //"TEX depth3, temp, texture[1], 2D;" +
1259612673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12597
- TextureFetch("depth3", "temp", "1") +
12674
+ ShadowTextureFetch("depth3", "temp", "1") +
1259812675 "") +
1259912676 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1260012677 //"MOV params, material;" +
....@@ -12968,7 +13045,7 @@
1296813045 // display shadow only (fakedepth == 0)
1296913046 "SUB temp.x, half.x, shadow.x;" +
1297013047 "MOV temp.y, -params5.z;" + // params6.x;" +
12971
- "SLT temp.z, temp.y, -one2048th.x;" +
13048
+ "SLT temp.z, temp.y, -c256i.x;" +
1297213049 "SUB temp.y, one.x, temp.z;" +
1297313050 "MUL temp.x, temp.x, temp.y;" +
1297413051 "KIL temp.x;" +
....@@ -13392,7 +13469,8 @@
1339213469 return out;
1339313470 }
1339413471
13395
- String TextureFetch(String dest, String src, String unit)
13472
+ // Also does frustum culling
13473
+ String ShadowTextureFetch(String dest, String src, String unit)
1339613474 {
1339713475 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1339813476 "SGE " + src + ".w, " + src + ".x, eps.x;" +
....@@ -15291,20 +15369,24 @@
1529115369 OCCLUSION_CULLING ^= true;
1529215370 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1529315371 break;
15294
- case '0': envyoff ^= true; repaint(); break;
15372
+ //case '0': envyoff ^= true; repaint(); break;
1529515373 case '1':
1529615374 case '2':
1529715375 case '3':
1529815376 case '4':
1529915377 case '5':
15300
- newenvy = Character.getNumericValue(key);
15301
- repaint();
15302
- break;
1530315378 case '6':
1530415379 case '7':
1530515380 case '8':
1530615381 case '9':
15307
- 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
+ }
1530815390 repaint();
1530915391 break;
1531015392 case '!':
....@@ -16495,6 +16577,8 @@
1649516577 private /*static*/ boolean firstime;
1649616578 private /*static*/ cVector newView = new cVector();
1649716579 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"};
1649816582 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1649916583 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1650016584 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16507,29 +16591,66 @@
1650716591 {
1650816592 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1650916593
16594
+ int usedsuf = 0;
16595
+
1651016596 for (int i = 0; i < suffixes.length; i++)
1651116597 {
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)
16598
+ String[] suffixe = suffixes;
16599
+ String[] fallback = suffixes2;
16600
+ String[] fallfallback = suffixes3;
16601
+
16602
+ for (int c=usedsuf; --c>=0;)
1651716603 {
16518
- throw new IOException("Unable to load texture " + resourceName);
16604
+// String[] temp = suffixe;
16605
+// suffixe = fallback;
16606
+// fallback = fallfallback;
16607
+// fallfallback = temp;
1651916608 }
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
+
1652016637 //System.out.println("Target = " + targets[i]);
1652116638 cubemap.updateImage(data, targets[i]);
1652216639 }
1652316640
1652416641 return cubemap;
1652516642 }
16643
+
1652616644 int bigsphere = -1;
1652716645
1652816646 float BGcolor = 0.5f;
1652916647
16530
- private void DrawSkyBox(GL gl)
16648
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16649
+
16650
+ private void DrawSkyBox(GL gl, float ratio)
1653116651 {
16532
- if (envyoff || cubemap == null)
16652
+ if (//envyoff ||
16653
+ cubemap == null)
1653316654 {
1653416655 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1653516656 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16544,7 +16665,17 @@
1654416665 // Compensates for ExaminerViewer's modification of modelview matrix
1654516666 gl.glMatrixMode(GL.GL_MODELVIEW);
1654616667 gl.glLoadIdentity();
16668
+ gl.glScalef(1,ratio,1);
1654716669
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
+
1654816679 //gl.glActiveTexture(GL.GL_TEXTURE1);
1654916680 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1655016681
....@@ -16557,7 +16688,7 @@
1655716688 // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting
1655816689 // causes the normals to be sent down. Thanks to Ken Dyke.
1655916690 //gl.glEnable(GL.GL_LIGHTING);
16560
- gl.glDisable(GL.GL_LIGHTING);
16691
+ gl.glEnable(GL.GL_LIGHTING);
1656116692
1656216693 gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
1656316694 gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
....@@ -16576,6 +16707,7 @@
1657616707 {
1657716708 gl.glScalef(1.0f, -1.0f, 1.0f);
1657816709 }
16710
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1657916711 gl.glMultMatrixd(viewrot_1, 0);
1658016712 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1658116713 //viewer.updateInverseRotation(gl);
....@@ -16834,7 +16966,7 @@
1683416966 //new Exception().printStackTrace();
1683516967 System.out.println("select buffer init");
1683616968 // Use debug pipeline
16837
- drawable.setGL(new DebugGL(drawable.getGL()));
16969
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1683816970
1683916971 GL gl = drawable.getGL();
1684016972