Normand Briere
2019-08-22 0c7b833be7d86598a6813cd1c6db0ca9e1b17966
CameraPane.java
....@@ -110,7 +110,11 @@
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;
116
+ boolean transformMode;
117
+
114118 boolean reverseUP = false;
115119 static boolean frozen = false;
116120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -164,7 +168,7 @@
164168
165169
166170 // OPTIONS
167
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
168172 boolean cameraLight = false;
169173 boolean UVdebug = false;
170174 boolean Udebug = false;
....@@ -173,7 +177,7 @@
173177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
174178 boolean anisotropy = true;
175179 boolean softshadow = true; // slower but better false;
176
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
177181
178182 boolean macromode = false;
179183
....@@ -187,6 +191,19 @@
187191 }
188192
189193 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
194
+
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
196
+ {
197
+ try
198
+ {
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
200
+ } catch (IOException e)
201
+ {
202
+ System.out.println("NAME = " + name);
203
+ e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
205
+ }
206
+ }
190207
191208 void SetAsGLRenderer(boolean b)
192209 {
....@@ -525,7 +542,8 @@
525542 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
526543 LA.vecCross(obj.v0, obj.v1, obj.v2);
527544 LA.vecNormalize(obj.v2);
528
- gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
545
+
546
+ SetGLNormal(gl, (float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
529547 }
530548
531549 // P
....@@ -547,7 +565,7 @@
547565 y += ny * obj.NORMALPUSH;
548566 z += nz * obj.NORMALPUSH;
549567
550
- gl.glNormal3f(nx, ny, nz);
568
+ SetGLNormal(gl, nx, ny, nz);
551569 }
552570 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
553571 SetColor(obj, pv);
....@@ -579,7 +597,7 @@
579597 y += ny * obj.NORMALPUSH;
580598 z += nz * obj.NORMALPUSH;
581599
582
- gl.glNormal3f(nx, ny, nz);
600
+ SetGLNormal(gl, nx, ny, nz);
583601 }
584602 //System.out.println("vertexq = " + qv.s + ", " + qv.t);
585603 // boolean locked = false;
....@@ -627,7 +645,7 @@
627645 y += ny * obj.NORMALPUSH;
628646 z += nz * obj.NORMALPUSH;
629647
630
- gl.glNormal3f(nx, ny, nz);
648
+ SetGLNormal(gl, nx, ny, nz);
631649 }
632650
633651 // if ((dot&4) == 0)
....@@ -1233,10 +1251,10 @@
12331251 {
12341252 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12351253 {
1236
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1254
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12371255 } else
12381256 {
1239
- gl.glNormal3f(0, 0, 1);
1257
+ SetGLNormal(gl, 0, 0, 1);
12401258 }
12411259
12421260 if (c != null)
....@@ -1260,10 +1278,10 @@
12601278 {
12611279 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12621280 {
1263
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1281
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12641282 } else
12651283 {
1266
- gl.glNormal3f(0, 0, 1);
1284
+ SetGLNormal(gl, 0, 0, 1);
12671285 }
12681286 if (c != null)
12691287 {
....@@ -1288,10 +1306,10 @@
12881306 {
12891307 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12901308 {
1291
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1309
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12921310 } else
12931311 {
1294
- gl.glNormal3f(0, 0, 1);
1312
+ SetGLNormal(gl, 0, 0, 1);
12951313 }
12961314 if (c != null)
12971315 {
....@@ -1473,7 +1491,7 @@
14731491 {
14741492 if (!selectmode)
14751493 {
1476
- gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1494
+ SetGLNormal(gl, (float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
14771495 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
14781496
14791497 if (flipV)
....@@ -1485,6 +1503,8 @@
14851503 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14861504 }
14871505
1506
+ float[] colorV = new float[4];
1507
+
14881508 void SetColor(Object3D obj, Vertex p0)
14891509 {
14901510 CameraPane display = this;
....@@ -1552,8 +1572,6 @@
15521572 {
15531573 return;
15541574 }
1555
-
1556
- float[] colorV = new float[3];
15571575
15581576 if (false) // marked)
15591577 {
....@@ -1802,7 +1820,7 @@
18021820
18031821 display.modelParams7[0] = 0;
18041822 display.modelParams7[1] = 1000;
1805
- display.modelParams7[2] = 0;
1823
+ display.modelParams7[2] = material.parallax;
18061824 display.modelParams7[3] = 0;
18071825
18081826 //display.modelParams6[0] = 100; // criss de bug de bump
....@@ -2035,9 +2053,9 @@
20352053 switch(viewcode)
20362054 {
20372055 case 0: return "main";
2038
- case 1: return "one";
2039
- case 2: return "two";
2040
- case 3: return "three";
2056
+ case 1: return "Red";
2057
+ case 2: return "Green";
2058
+ case 3: return "Blue";
20412059 case 4: return "light";
20422060 }
20432061
....@@ -2458,6 +2476,18 @@
24582476 return CreateBim(bytes, width, height);
24592477 }
24602478
2479
+ private void SetGLNormal(javax.media.opengl.GL gl, float nx, float ny, float nz)
2480
+ {
2481
+ gl.glNormal3f(nx, ny, nz);
2482
+
2483
+ if (ny > 0.9 || ny < -0.9)
2484
+ // Ground or ceiling
2485
+ gl.glVertexAttrib3f(4, 1, 0, 0);
2486
+ else
2487
+ // Walls
2488
+ gl.glVertexAttrib3f(4, 0, 1, 0);
2489
+ }
2490
+
24612491 /**/
24622492 class CacheTexture
24632493 {
....@@ -2500,7 +2530,7 @@
25002530 com.sun.opengl.util.texture.TextureIO.newTextureData(
25012531 getClass().getClassLoader().getResourceAsStream(name),
25022532 true,
2503
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
25042534 } catch (java.io.IOException e)
25052535 {
25062536 throw new javax.media.opengl.GLException(e);
....@@ -8346,7 +8376,7 @@
83468376 // else
83478377 // if (!texname.startsWith("/"))
83488378 // texname = "/Users/nbriere/Textures/" + texname;
8349
- if (!FileExists(texname))
8379
+ if (!FileExists(texname) && !texname.startsWith("@"))
83508380 {
83518381 texname = fallbackTextureName;
83528382 }
....@@ -8429,6 +8459,15 @@
84298459 new Exception().printStackTrace();
84308460 } else
84318461 {
8462
+ if (texname.startsWith("@"))
8463
+ {
8464
+ // texturecache = textures.get(texname); // suspicious
8465
+ if (texturecache == null)
8466
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8467
+ else
8468
+ new Exception().printStackTrace();
8469
+ } else
8470
+ {
84328471 if (textureon)
84338472 {
84348473 String cachename = texname;
....@@ -8488,6 +8527,7 @@
84888527 texturecache = new CacheTexture(texturedata,resolution);
84898528 //texture = GetTexture(tex, bump);
84908529 }
8530
+ }
84918531 }
84928532 //}
84938533 }
....@@ -8756,10 +8796,12 @@
87568796
87578797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
87588798 MAXSTACK = temp[0];
8759
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
87608801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
87618802 MAXSTACK = temp[0];
8762
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
87638805
87648806 // Use debug pipeline
87658807 //drawable.setGL(new DebugGL(gl)); //
....@@ -8767,7 +8809,8 @@
87678809 gl = drawable.getGL(); //
87688810
87698811 GL gl3 = getGL();
8770
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
87718814
87728815
87738816 //float pos[] = { 100, 100, 100, 0 };
....@@ -8932,7 +8975,7 @@
89328975
89338976 if (cubemap == null)
89348977 {
8935
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
89368979 }
89378980
89388981 //cubemap.enable();
....@@ -9208,6 +9251,8 @@
92089251
92099252 void LoadEnvy(int which)
92109253 {
9254
+ assert(false);
9255
+
92119256 String name;
92129257 String ext;
92139258
....@@ -9219,37 +9264,58 @@
92199264 cubemap = null;
92209265 return;
92219266 case 1:
9222
- name = "cubemaps/box_";
9223
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
92249269 reverseUP = false;
92259270 break;
92269271 case 2:
9227
- name = "cubemaps/uffizi_";
9228
- ext = "png";
9229
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
92309276 case 3:
9231
- name = "cubemaps/CloudyHills_";
9232
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
92339279 reverseUP = false;
92349280 break;
92359281 case 4:
9236
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
92379283 ext = "png";
92389284 reverseUP = false;
92399285 break;
9286
+ case 5:
9287
+ name = "cubemaps/skycube/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 6:
9292
+ name = "cubemaps/SaintLazarusChurch3/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
9296
+ case 7:
9297
+ name = "cubemaps/Sodermalmsallen/";
9298
+ ext = "jpg";
9299
+ reverseUP = false;
9300
+ break;
9301
+ case 8:
9302
+ name = "cubemaps/Sodermalmsallen2/";
9303
+ ext = "jpg";
9304
+ reverseUP = false;
9305
+ break;
9306
+ case 9:
9307
+ name = "cubemaps/UnionSquare/";
9308
+ ext = "jpg";
9309
+ reverseUP = false;
9310
+ break;
92409311 default:
9241
- name = "cubemaps/rgb_";
9242
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
92439315 break;
92449316 }
9245
-
9246
- try
9247
- {
9248
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9249
- } catch (IOException e)
9250
- {
9251
- throw new RuntimeException(e);
9252
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
92539319 }
92549320
92559321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9281,8 +9347,12 @@
92819347 static double[] model = new double[16];
92829348 double[] camera2light = new double[16];
92839349 double[] light2camera = new double[16];
9284
- int newenvy = -1;
9285
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
92869356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
92879357 //float[] light0 = { 0,0,0 };
92889358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9762,10 +9832,12 @@
97629832 rati = 1 / rati;
97639833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
97649834 }
9765
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
97669838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
97679839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9768
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
97699841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
97709842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
97719843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10631,9 +10703,18 @@
1063110703 static boolean init = false;
1063210704
1063310705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
1063410709
1063510710 public void display(GLAutoDrawable drawable)
1063610711 {
10712
+ if (patchMaterial.patchMaterial)
10713
+ {
10714
+ patchMaterial.patchMaterial = false;
10715
+ patchMaterial.objectPanel.setSelectedIndex(1);
10716
+ }
10717
+
1063710718 if (Grafreed.savesound && Grafreed.hassound)
1063810719 {
1063910720 Grafreed.wav.save();
....@@ -10802,7 +10883,7 @@
1080210883
1080310884 if (wait)
1080410885 {
10805
- Sleep(500);
10886
+ Sleep(200); // blocks everything
1080610887
1080710888 wait = false;
1080810889 }
....@@ -11018,13 +11099,43 @@
1101811099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1101911100 }
1102011101
11021
- if (newenvy > -1)
11102
+// if (newenvy > -1)
11103
+// {
11104
+// LoadEnvy(newenvy);
11105
+// }
11106
+//
11107
+// newenvy = -1;
11108
+
11109
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1102211110 {
11023
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
1102411117 }
11025
-
11026
- newenvy = -1;
11027
-
11118
+ else
11119
+ {
11120
+ if (object.skyboxname != null)
11121
+ {
11122
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11123
+ {
11124
+ if (cubemap != null && cubemap != cubemaprgb)
11125
+ cubemap.dispose();
11126
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11127
+ loadedskyboxname = object.skyboxname;
11128
+ }
11129
+ }
11130
+ else
11131
+ {
11132
+ cubemapcustom = null;
11133
+ loadedskyboxname = null;
11134
+ }
11135
+
11136
+ cubemap = cubemapcustom;
11137
+ }
11138
+
1102811139 ratio = ((double) getWidth()) / getHeight();
1102911140 //System.out.println("ratio = " + ratio);
1103011141
....@@ -11040,7 +11151,7 @@
1104011151
1104111152 if (!IsFrozen() && !ambientOcclusion)
1104211153 {
11043
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
1104411155 }
1104511156
1104611157 //if (selection_view == -1)
....@@ -11326,7 +11437,7 @@
1132611437
1132711438 // if (cam != lightCamera)
1132811439 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11329
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11440
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1133011441 }
1133111442
1133211443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -12400,7 +12511,7 @@
1240012511
1240112512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1240212513
12403
- String program =
12514
+ String programmin =
1240412515 // Min shader
1240512516 "!!ARBfp1.0\n" +
1240612517 "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
....@@ -12451,7 +12562,8 @@
1245112562 //"SUB ndotl.y, zero123.y, ndotl.y;" +
1245212563 //"MUL ndotl.y, ndotl.y, pow2.z;" +
1245312564
12454
- "MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12565
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12566
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
1245512567
1245612568 // Pigment
1245712569 "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
....@@ -12466,7 +12578,7 @@
1246612578 "MOV result.color, temp;" +
1246712579 "END";
1246812580
12469
- String program2 =
12581
+ String programmax =
1247012582 "!!ARBfp1.0\n" +
1247112583
1247212584 //"OPTION ARB_fragment_program_shadow;" +
....@@ -12494,7 +12606,7 @@
1249412606 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1249512607 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1249612608 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
12497
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12609
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1249812610 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1249912611 "PARAM options1 = program.env[62];" + // fog rgb color
1250012612 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12739,7 +12851,7 @@
1273912851 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1274012852 // mar 2013 ??? "KIL alpha.a;" +
1274112853 "MOV alpha, texSamp.aaaa;" + // y;" +
12742
- "KIL alpha.a;" +
12854
+ "KIL alpha.a;" + // not sure with parallax mapping
1274312855 /*
1274412856 "MUL temp.xy, temp, two;" +
1274512857 "TXB bump, temp, texture[0], 2D;" +
....@@ -12825,11 +12937,6 @@
1282512937 "SUB bump0, bump0, half;" +
1282612938 "ADD bump, bump, bump0;" +
1282712939
12828
- "MOV temp.x, texSamp.a;" +
12829
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12830
- //"LRP texSamp0, params5.x, texSamp0, one;" +
12831
- "MOV texSamp.a, temp.x;" +
12832
-
1283312940 // double-sided
1283412941 /**/
1283512942 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12846,19 +12953,62 @@
1284612953 "MOV normald, normal;" +
1284712954 "MOV normals, normal;" +
1284812955
12956
+ "MOV temp, fragment.texcoord[4];" +
12957
+
1284912958 // UV base
1285012959 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1285112960 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1285212961 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
12853
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
12854
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
12855
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
12962
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12963
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12964
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12965
+ Normalize("UP") +
12966
+
1285612967 "XPD V, normal, UP;" +
1285712968 Normalize("V") +
1285812969 "XPD U, V, normal;" +
1285912970 Normalize("U") +
1286012971
1286112972 // parallax mapping
12973
+
12974
+ "DP3 temp2.x, V, eye;" +
12975
+ "DP3 temp2.y, U, eye;" +
12976
+ "DP3 temp2.z, normal, eye;" +
12977
+ "RCP temp2.z, temp2.z;" +
12978
+
12979
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12980
+ "RSQ temp2.w, temp2.w;" +
12981
+ "RCP temp2.w, temp2.w;" +
12982
+
12983
+ "SUB temp2.w, temp2.w, half;" +
12984
+// "SGE temp.x, temp2.w, eps.x;" +
12985
+// "MUL temp2.w, temp2.w, temp.x;" +
12986
+
12987
+ //"MOV texSamp, U;" +
12988
+
12989
+ "MUL temp2.z, temp2.z, temp2.w;" +
12990
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12991
+
12992
+ "MUL temp2, temp2, temp2.z;" +
12993
+
12994
+ "MOV temp, fragment.texcoord[0];" +
12995
+
12996
+ "SUB temp, temp, temp2;" +
12997
+
12998
+ "TEX temp, temp, texture[0], 2D;" +
12999
+ "POW temp.a, temp.a, params6.w;" + // punch through
13000
+
13001
+ "ADD texSamp, temp, texSamp;" +
13002
+ "MUL texSamp.xyz, half, texSamp;" +
13003
+
13004
+ "MOV alpha, texSamp.aaaa;" +
13005
+
13006
+// parallax mapping
13007
+
13008
+ "MOV temp.x, texSamp.a;" +
13009
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13010
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13011
+ "MOV texSamp.a, temp.x;" +
1286213012
1286313013 //"MOV temp, fragment.texcoord[0];" +
1286413014 //
....@@ -12991,7 +13141,7 @@
1299113141 // display shadow only (fakedepth == 0)
1299213142 "SUB temp.x, half.x, shadow.x;" +
1299313143 "MOV temp.y, -params5.z;" + // params6.x;" +
12994
- "SLT temp.z, temp.y, -one2048th.x;" +
13144
+ "SLT temp.z, temp.y, -c256i.x;" +
1299513145 "SUB temp.y, one.x, temp.z;" +
1299613146 "MUL temp.x, temp.x, temp.y;" +
1299713147 "KIL temp.x;" +
....@@ -13322,8 +13472,19 @@
1332213472 //once = true;
1332313473 }
1332413474
13325
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13326
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13475
+ String program = programmax;
13476
+
13477
+ if (Globals.MINSHADER)
13478
+ {
13479
+ program = programmin;
13480
+ }
13481
+
13482
+ if (Globals.DEBUG)
13483
+ {
13484
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13485
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13486
+ }
13487
+
1332713488 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1332813489
1332913490 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13370,7 +13531,8 @@
1337013531 "\n" +
1337113532 "END\n";
1337213533
13373
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13534
+ if (Globals.DEBUG)
13535
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1337413536 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1337513537
1337613538 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13628,7 +13790,7 @@
1362813790 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1362913791 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1363013792 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13631
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13793
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
1363213794
1363313795 //Object3D.cVector2[] vector2buffer;
1363413796
....@@ -13795,7 +13957,7 @@
1379513957 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1379613958 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1379713959 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
13798
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13960
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1379913961 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1380013962 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1380113963 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -13856,7 +14018,7 @@
1385614018 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1385714019 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1385814020 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
13859
- //"MOV result.texcoord, vertex.texcoord;" +
14021
+ //"MOV result.texcoord, vertex.fogcoord;" +
1386014022 "MOV result.texcoord, temp;" +
1386114023 // border fade
1386214024 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -13903,7 +14065,9 @@
1390314065
1390414066 //"ADD temp.z, temp.z, one;" +
1390514067
13906
- "MOV result.color, temp;"
14068
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14069
+
14070
+ "MOV result.color, temp;" // Normal
1390714071 : "MOV result.color, vertex.color;") +
1390814072 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1390914073 : "") +
....@@ -14569,11 +14733,17 @@
1456914733 void GoDown(int mod)
1457014734 {
1457114735 MODIFIERS |= COMMAND;
14736
+ boolean isVR = (mouseMode&VR)!=0;
1457214737 /**/
1457314738 if((mod&SHIFT) == SHIFT)
14574
- manipCamera.RotatePosition(0, -speed);
14739
+ {
14740
+ if (isVR)
14741
+ manipCamera.RotateInterest(0, -speed);
14742
+ else
14743
+ manipCamera.RotatePosition(0, -speed);
14744
+ }
1457514745 else
14576
- manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14746
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
1457714747 /**/
1457814748 if ((mod & SHIFT) == SHIFT)
1457914749 {
....@@ -14583,6 +14753,8 @@
1458314753 mouseMode |= BACKFORTH;
1458414754 }
1458514755
14756
+ targetLookAt.set(manipCamera.lookAt);
14757
+
1458614758 //prevX = X = anchorX;
1458714759 prevY = Y = anchorY - (int) (renderCamera.Distance());
1458814760 }
....@@ -14591,10 +14763,17 @@
1459114763 {
1459214764 MODIFIERS |= COMMAND;
1459314765 /**/
14766
+ boolean isVR = (mouseMode&VR)!=0;
14767
+
1459414768 if((mod&SHIFT) == SHIFT)
14595
- manipCamera.RotatePosition(0, speed);
14769
+ {
14770
+ if (isVR)
14771
+ manipCamera.RotateInterest(0, speed);
14772
+ else
14773
+ manipCamera.RotatePosition(0, speed);
14774
+ }
1459614775 else
14597
- manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14776
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
1459814777 /**/
1459914778 if ((mod & SHIFT) == SHIFT)
1460014779 {
....@@ -14604,6 +14783,8 @@
1460414783 mouseMode |= BACKFORTH;
1460514784 }
1460614785
14786
+ targetLookAt.set(manipCamera.lookAt);
14787
+
1460714788 //prevX = X = anchorX;
1460814789 prevY = Y = anchorY + (int) (renderCamera.Distance());
1460914790 }
....@@ -14613,9 +14794,14 @@
1461314794 MODIFIERS |= COMMAND;
1461414795 /**/
1461514796 if((mod&SHIFT) == SHIFT)
14616
- manipCamera.Translate(speed*delta, 0, getWidth());
14797
+ manipCamera.Translate(speed*delta, 0, getWidth());
1461714798 else
14618
- manipCamera.RotatePosition(speed, 0);
14799
+ {
14800
+ if ((mouseMode&VR)!=0)
14801
+ manipCamera.RotateInterest(-speed, 0);
14802
+ else
14803
+ manipCamera.RotatePosition(speed, 0);
14804
+ }
1461914805 /**/
1462014806 if ((mod & SHIFT) == SHIFT)
1462114807 {
....@@ -14625,6 +14811,8 @@
1462514811 mouseMode |= ROTATE;
1462614812 } // TRANSLATE;
1462714813
14814
+ targetLookAt.set(manipCamera.lookAt);
14815
+
1462814816 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1462914817 prevY = Y = anchorY;
1463014818 }
....@@ -14634,9 +14822,15 @@
1463414822 MODIFIERS |= COMMAND;
1463514823 /**/
1463614824 if((mod&SHIFT) == SHIFT)
14637
- manipCamera.Translate(-speed*delta, 0, getWidth());
14825
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1463814826 else
14639
- manipCamera.RotatePosition(-speed, 0);
14827
+ {
14828
+ if ((mouseMode&VR)!=0)
14829
+ manipCamera.RotateInterest(speed, 0);
14830
+ else
14831
+ manipCamera.RotatePosition(-speed, 0);
14832
+ }
14833
+
1464014834 /**/
1464114835 if ((mod & SHIFT) == SHIFT)
1464214836 {
....@@ -14646,6 +14840,8 @@
1464614840 mouseMode |= ROTATE;
1464714841 } // TRANSLATE;
1464814842
14843
+ targetLookAt.set(manipCamera.lookAt);
14844
+
1464914845 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1465014846 prevY = Y = anchorY;
1465114847 }
....@@ -15148,8 +15344,8 @@
1514815344 case 'K':
1514915345 KOMPACTTEXTURE ^= true;
1515015346 //textures.clear();
15151
- break;
15152
- case 'P': // Texture Projection macros
15347
+ // break;
15348
+ //case 'P': // Texture Projection macros
1515315349 // SAVETEXTURE ^= true;
1515415350 macromode = true;
1515515351 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -15270,7 +15466,7 @@
1527015466 targetLookAt.set(manipCamera.lookAt);
1527115467 repaint();
1527215468 break;
15273
- case 'p':
15469
+ case 'P': // p':
1527415470 // c'est quoi ca au juste? spherical ^= true;
1527515471 Skinshader ^= true; programInitialized = false;
1527615472 repaint();
....@@ -15308,27 +15504,31 @@
1530815504 repaint();
1530915505 break;
1531015506 case 'O':
15311
- Globals.drawMode = OCCLUSION; // WARNING
15507
+ // Too dangerous. Use menu. Globals.drawMode = OCCLUSION; // WARNING
1531215508 repaint();
1531315509 break;
1531415510 case 'o':
1531515511 OCCLUSION_CULLING ^= true;
1531615512 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1531715513 break;
15318
- case '0': envyoff ^= true; repaint(); break;
15514
+ //case '0': envyoff ^= true; repaint(); break;
1531915515 case '1':
1532015516 case '2':
1532115517 case '3':
1532215518 case '4':
1532315519 case '5':
15324
- newenvy = Character.getNumericValue(key);
15325
- repaint();
15326
- break;
1532715520 case '6':
1532815521 case '7':
1532915522 case '8':
1533015523 case '9':
15331
- BGcolor = (key - '6')/3.f;
15524
+ if (true) // envyoff)
15525
+ {
15526
+ BGcolor = (key - '1')/8.f;
15527
+ }
15528
+ else
15529
+ {
15530
+ //newenvy = Character.getNumericValue(key);
15531
+ }
1533215532 repaint();
1533315533 break;
1533415534 case '!':
....@@ -16026,14 +16226,14 @@
1602616226 {
1602716227 switch (hitSomething)
1602816228 {
16029
- case Object3D.hitCenter: gr.setColor(Color.pink);
16229
+ case Object3D.hitCenter: gr.setColor(Color.white);
1603016230 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1603116231 break;
1603216232 case Object3D.hitRotate: gr.setColor(Color.yellow);
1603316233 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1603416234 break;
1603516235 case Object3D.hitScale: gr.setColor(Color.cyan);
16036
- gr.drawLine(X, Y, 0, 0);
16236
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1603716237 break;
1603816238 }
1603916239
....@@ -16052,7 +16252,7 @@
1605216252 if (hasMarquee)
1605316253 {
1605416254 gr.setXORMode(Color.white);
16055
- gr.setColor(Color.red);
16255
+ gr.setColor(Color.white);
1605616256 if (!firstime)
1605716257 {
1605816258 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16519,6 +16719,8 @@
1651916719 private /*static*/ boolean firstime;
1652016720 private /*static*/ cVector newView = new cVector();
1652116721 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16722
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16723
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1652216724 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1652316725 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1652416726 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16531,29 +16733,67 @@
1653116733 {
1653216734 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1653316735
16736
+ int usedsuf = 0;
16737
+
1653416738 for (int i = 0; i < suffixes.length; i++)
1653516739 {
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)
16740
+ String[] suffixe = suffixes;
16741
+ String[] fallback = suffixes2;
16742
+ String[] fallfallback = suffixes3;
16743
+
16744
+ for (int c=usedsuf; --c>=0;)
1654116745 {
16542
- throw new IOException("Unable to load texture " + resourceName);
16746
+// String[] temp = suffixe;
16747
+// suffixe = fallback;
16748
+// fallback = fallfallback;
16749
+// fallfallback = temp;
1654316750 }
16751
+
16752
+ String resourceName = basename + suffixe[i] + "." + suffix;
16753
+ TextureData data;
16754
+
16755
+ try
16756
+ {
16757
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16758
+ mipmapped,
16759
+ FileUtil.getFileSuffix(resourceName));
16760
+ }
16761
+ catch (Exception e)
16762
+ {
16763
+ try
16764
+ {
16765
+ resourceName = basename + fallback[i] + "." + suffix;
16766
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16767
+ mipmapped,
16768
+ FileUtil.getFileSuffix(resourceName));
16769
+ }
16770
+ catch (Exception e2)
16771
+ {
16772
+ resourceName = basename + fallfallback[i] + "." + suffix;
16773
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16774
+ mipmapped,
16775
+ FileUtil.getFileSuffix(resourceName));
16776
+ }
16777
+ }
16778
+
1654416779 //System.out.println("Target = " + targets[i]);
1654516780 cubemap.updateImage(data, targets[i]);
1654616781 }
1654716782
1654816783 return cubemap;
1654916784 }
16785
+
1655016786 int bigsphere = -1;
1655116787
1655216788 float BGcolor = 0.5f;
1655316789
16554
- private void DrawSkyBox(GL gl)
16790
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16791
+
16792
+ private void DrawSkyBox(GL gl, float ratio)
1655516793 {
16556
- if (envyoff || cubemap == null)
16794
+ if (//envyoff ||
16795
+ WIREFRAME ||
16796
+ cubemap == null)
1655716797 {
1655816798 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1655916799 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16568,7 +16808,17 @@
1656816808 // Compensates for ExaminerViewer's modification of modelview matrix
1656916809 gl.glMatrixMode(GL.GL_MODELVIEW);
1657016810 gl.glLoadIdentity();
16811
+ gl.glScalef(1,ratio,1);
1657116812
16813
+// colorV[0] = 2;
16814
+// colorV[1] = 2;
16815
+// colorV[2] = 2;
16816
+// colorV[3] = 1;
16817
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16818
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16819
+//
16820
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16821
+
1657216822 //gl.glActiveTexture(GL.GL_TEXTURE1);
1657316823 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1657416824
....@@ -16600,6 +16850,7 @@
1660016850 {
1660116851 gl.glScalef(1.0f, -1.0f, 1.0f);
1660216852 }
16853
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1660316854 gl.glMultMatrixd(viewrot_1, 0);
1660416855 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1660516856 //viewer.updateInverseRotation(gl);
....@@ -16640,7 +16891,8 @@
1664016891 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1664116892
1664216893 cubemap.disable();
16643
- ////cubemap.unbind();
16894
+ //cubemap.dispose();
16895
+
1664416896 if (CULLFACE)
1664516897 {
1664616898 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16696,7 +16948,7 @@
1669616948 gl.glScalef(1.0f, -1.0f, 1.0f);
1669716949 }
1669816950
16699
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16951
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1670016952
1670116953 float step = 2; // 0.1666f; //0.25f;
1670216954 float stepv = 2; // step * 1652 / 998;
....@@ -16858,7 +17110,7 @@
1685817110 //new Exception().printStackTrace();
1685917111 System.out.println("select buffer init");
1686017112 // Use debug pipeline
16861
- drawable.setGL(new DebugGL(drawable.getGL()));
17113
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1686217114
1686317115 GL gl = drawable.getGL();
1686417116
....@@ -17176,6 +17428,7 @@
1717617428
1717717429 public void init(GLAutoDrawable drawable)
1717817430 {
17431
+ if (Globals.DEBUG)
1717917432 System.out.println("shadow buffer init");
1718017433
1718117434 GL gl = drawable.getGL();
....@@ -17404,10 +17657,14 @@
1740417657 gl.glFlush();
1740517658
1740617659 /**/
17407
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17660
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1740817661
17409
- float[] pixels = occlusionsizebuffer.array();
17662
+ float[] depths = occlusiondepthbuffer.array();
1741017663
17664
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17665
+
17666
+ int[] pixels = selectsizebuffer.array();
17667
+
1741117668 double r = 0, g = 0, b = 0;
1741217669
1741317670 double count = 0;
....@@ -17418,7 +17675,7 @@
1741817675
1741917676 double FACTOR = 1;
1742017677
17421
- for (int i = 0; i < pixels.length; i++)
17678
+ for (int i = 0; i < depths.length; i++)
1742217679 {
1742317680 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1742417681 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17501,7 +17758,7 @@
1750117758
1750217759 double scale = ray.z; // 1; // cos
1750317760
17504
- float depth = pixels[newindex];
17761
+ float depth = depths[newindex];
1750517762
1750617763 /*
1750717764 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17698,11 +17955,14 @@
1769817955 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1769917956 static IntBuffer bigAAbuffer;
1770017957 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17701
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17958
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1770217959 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1770317960 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1770417961 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17705
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17962
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17963
+
17964
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17965
+
1770617966 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1770717967 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1770817968 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();