Normand Briere
2019-08-01 29d5516687020263d3ae0454ce81879a3a450af0
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 {
....@@ -1485,6 +1497,8 @@
14851497 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14861498 }
14871499
1500
+ float[] colorV = new float[4];
1501
+
14881502 void SetColor(Object3D obj, Vertex p0)
14891503 {
14901504 CameraPane display = this;
....@@ -1552,8 +1566,6 @@
15521566 {
15531567 return;
15541568 }
1555
-
1556
- float[] colorV = new float[3];
15571569
15581570 if (false) // marked)
15591571 {
....@@ -8932,7 +8944,7 @@
89328944
89338945 if (cubemap == null)
89348946 {
8935
- LoadEnvy(5);
8947
+ //LoadEnvy(1);
89368948 }
89378949
89388950 //cubemap.enable();
....@@ -9219,37 +9231,58 @@
92199231 cubemap = null;
92209232 return;
92219233 case 1:
9222
- name = "cubemaps/box_";
9223
- ext = "png";
9234
+ name = "cubemaps/rgb/";
9235
+ ext = "jpg";
92249236 reverseUP = false;
92259237 break;
92269238 case 2:
9227
- name = "cubemaps/uffizi_";
9228
- ext = "png";
9229
- break; // reverseUP = true; break;
9239
+ name = "cubemaps/uffizi/";
9240
+ ext = "jpg";
9241
+ reverseUP = false;
9242
+ break;
92309243 case 3:
9231
- name = "cubemaps/CloudyHills_";
9232
- ext = "tga";
9244
+ name = "cubemaps/CloudyHills/";
9245
+ ext = "jpg";
92339246 reverseUP = false;
92349247 break;
92359248 case 4:
9236
- name = "cubemaps/cornell_";
9249
+ name = "cubemaps/cornell/";
92379250 ext = "png";
92389251 reverseUP = false;
92399252 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;
92409278 default:
9241
- name = "cubemaps/rgb_";
9242
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9279
+ name = "cubemaps/box/";
9280
+ ext = "png"; /*mipmap = true;*/
9281
+ reverseUP = false;
92439282 break;
92449283 }
9245
-
9246
- try
9247
- {
9248
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9249
- } catch (IOException e)
9250
- {
9251
- throw new RuntimeException(e);
9252
- }
9284
+
9285
+ LoadSkybox(name, ext, mipmap);
92539286 }
92549287
92559288 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9281,8 +9314,12 @@
92819314 static double[] model = new double[16];
92829315 double[] camera2light = new double[16];
92839316 double[] light2camera = new double[16];
9284
- int newenvy = -1;
9285
- boolean envyoff = true; // false;
9317
+
9318
+ //int newenvy = -1;
9319
+ //boolean envyoff = false;
9320
+
9321
+ String loadedskyboxname;
9322
+
92869323 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
92879324 //float[] light0 = { 0,0,0 };
92889325 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9762,10 +9799,12 @@
97629799 rati = 1 / rati;
97639800 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
97649801 }
9765
- assert (newenvy == -1);
9802
+
9803
+ //assert (newenvy == -1);
9804
+
97669805 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
97679806 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9768
- DrawSkyBox(gl);
9807
+ DrawSkyBox(gl, (float)rati);
97699808 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
97709809 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
97719810 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -11018,13 +11057,27 @@
1101811057 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1101911058 }
1102011059
11021
- if (newenvy > -1)
11060
+// if (newenvy > -1)
11061
+// {
11062
+// LoadEnvy(newenvy);
11063
+// }
11064
+//
11065
+// newenvy = -1;
11066
+
11067
+ if (object.skyboxname != null)
1102211068 {
11023
- LoadEnvy(newenvy);
11069
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11070
+ {
11071
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11072
+ loadedskyboxname = object.skyboxname;
11073
+ }
1102411074 }
11025
-
11026
- newenvy = -1;
11027
-
11075
+ else
11076
+ {
11077
+ cubemap = null;
11078
+ loadedskyboxname = null;
11079
+ }
11080
+
1102811081 ratio = ((double) getWidth()) / getHeight();
1102911082 //System.out.println("ratio = " + ratio);
1103011083
....@@ -11040,7 +11093,7 @@
1104011093
1104111094 if (!IsFrozen() && !ambientOcclusion)
1104211095 {
11043
- DrawSkyBox(gl);
11096
+ DrawSkyBox(gl, (float)ratio);
1104411097 }
1104511098
1104611099 //if (selection_view == -1)
....@@ -12400,7 +12453,7 @@
1240012453
1240112454 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1240212455
12403
- String program =
12456
+ String programmin =
1240412457 // Min shader
1240512458 "!!ARBfp1.0\n" +
1240612459 "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
....@@ -12451,7 +12504,8 @@
1245112504 //"SUB ndotl.y, zero123.y, ndotl.y;" +
1245212505 //"MUL ndotl.y, ndotl.y, pow2.z;" +
1245312506
12454
- "MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12507
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12508
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
1245512509
1245612510 // Pigment
1245712511 "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
....@@ -12466,7 +12520,7 @@
1246612520 "MOV result.color, temp;" +
1246712521 "END";
1246812522
12469
- String program2 =
12523
+ String programmax =
1247012524 "!!ARBfp1.0\n" +
1247112525
1247212526 //"OPTION ARB_fragment_program_shadow;" +
....@@ -12991,7 +13045,7 @@
1299113045 // display shadow only (fakedepth == 0)
1299213046 "SUB temp.x, half.x, shadow.x;" +
1299313047 "MOV temp.y, -params5.z;" + // params6.x;" +
12994
- "SLT temp.z, temp.y, -one2048th.x;" +
13048
+ "SLT temp.z, temp.y, -c256i.x;" +
1299513049 "SUB temp.y, one.x, temp.z;" +
1299613050 "MUL temp.x, temp.x, temp.y;" +
1299713051 "KIL temp.x;" +
....@@ -13322,6 +13376,13 @@
1332213376 //once = true;
1332313377 }
1332413378
13379
+ String program = programmax;
13380
+
13381
+ if (Globals.MINSHADER)
13382
+ {
13383
+ program = programmin;
13384
+ }
13385
+
1332513386 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1332613387 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1332713388 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -15315,20 +15376,24 @@
1531515376 OCCLUSION_CULLING ^= true;
1531615377 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1531715378 break;
15318
- case '0': envyoff ^= true; repaint(); break;
15379
+ //case '0': envyoff ^= true; repaint(); break;
1531915380 case '1':
1532015381 case '2':
1532115382 case '3':
1532215383 case '4':
1532315384 case '5':
15324
- newenvy = Character.getNumericValue(key);
15325
- repaint();
15326
- break;
1532715385 case '6':
1532815386 case '7':
1532915387 case '8':
1533015388 case '9':
15331
- BGcolor = (key - '6')/3.f;
15389
+ if (true) // envyoff)
15390
+ {
15391
+ BGcolor = (key - '1')/8.f;
15392
+ }
15393
+ else
15394
+ {
15395
+ //newenvy = Character.getNumericValue(key);
15396
+ }
1533215397 repaint();
1533315398 break;
1533415399 case '!':
....@@ -16033,7 +16098,7 @@
1603316098 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1603416099 break;
1603516100 case Object3D.hitScale: gr.setColor(Color.cyan);
16036
- gr.drawLine(X, Y, 0, 0);
16101
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1603716102 break;
1603816103 }
1603916104
....@@ -16519,6 +16584,8 @@
1651916584 private /*static*/ boolean firstime;
1652016585 private /*static*/ cVector newView = new cVector();
1652116586 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16587
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16588
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1652216589 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1652316590 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1652416591 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16531,29 +16598,66 @@
1653116598 {
1653216599 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1653316600
16601
+ int usedsuf = 0;
16602
+
1653416603 for (int i = 0; i < suffixes.length; i++)
1653516604 {
16536
- String resourceName = basename + suffixes[i] + "." + suffix;
16537
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16538
- mipmapped,
16539
- FileUtil.getFileSuffix(resourceName));
16540
- if (data == null)
16605
+ String[] suffixe = suffixes;
16606
+ String[] fallback = suffixes2;
16607
+ String[] fallfallback = suffixes3;
16608
+
16609
+ for (int c=usedsuf; --c>=0;)
1654116610 {
16542
- throw new IOException("Unable to load texture " + resourceName);
16611
+// String[] temp = suffixe;
16612
+// suffixe = fallback;
16613
+// fallback = fallfallback;
16614
+// fallfallback = temp;
1654316615 }
16616
+
16617
+ String resourceName = basename + suffixe[i] + "." + suffix;
16618
+ TextureData data;
16619
+
16620
+ try
16621
+ {
16622
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16623
+ mipmapped,
16624
+ FileUtil.getFileSuffix(resourceName));
16625
+ }
16626
+ catch (Exception e)
16627
+ {
16628
+ try
16629
+ {
16630
+ resourceName = basename + fallback[i] + "." + suffix;
16631
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16632
+ mipmapped,
16633
+ FileUtil.getFileSuffix(resourceName));
16634
+ }
16635
+ catch (Exception e2)
16636
+ {
16637
+ resourceName = basename + fallfallback[i] + "." + suffix;
16638
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16639
+ mipmapped,
16640
+ FileUtil.getFileSuffix(resourceName));
16641
+ }
16642
+ }
16643
+
1654416644 //System.out.println("Target = " + targets[i]);
1654516645 cubemap.updateImage(data, targets[i]);
1654616646 }
1654716647
1654816648 return cubemap;
1654916649 }
16650
+
1655016651 int bigsphere = -1;
1655116652
1655216653 float BGcolor = 0.5f;
1655316654
16554
- private void DrawSkyBox(GL gl)
16655
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16656
+
16657
+ private void DrawSkyBox(GL gl, float ratio)
1655516658 {
16556
- if (envyoff || cubemap == null)
16659
+ if (//envyoff ||
16660
+ cubemap == null)
1655716661 {
1655816662 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1655916663 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16568,7 +16672,17 @@
1656816672 // Compensates for ExaminerViewer's modification of modelview matrix
1656916673 gl.glMatrixMode(GL.GL_MODELVIEW);
1657016674 gl.glLoadIdentity();
16675
+ gl.glScalef(1,ratio,1);
1657116676
16677
+// colorV[0] = 2;
16678
+// colorV[1] = 2;
16679
+// colorV[2] = 2;
16680
+// colorV[3] = 1;
16681
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16682
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16683
+//
16684
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16685
+
1657216686 //gl.glActiveTexture(GL.GL_TEXTURE1);
1657316687 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1657416688
....@@ -16600,6 +16714,7 @@
1660016714 {
1660116715 gl.glScalef(1.0f, -1.0f, 1.0f);
1660216716 }
16717
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1660316718 gl.glMultMatrixd(viewrot_1, 0);
1660416719 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1660516720 //viewer.updateInverseRotation(gl);
....@@ -16858,7 +16973,7 @@
1685816973 //new Exception().printStackTrace();
1685916974 System.out.println("select buffer init");
1686016975 // Use debug pipeline
16861
- drawable.setGL(new DebugGL(drawable.getGL()));
16976
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1686216977
1686316978 GL gl = drawable.getGL();
1686416979