Normand Briere
2019-08-23 60cec91731a350fe67e9b5ffe7a00d70e9026314
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 {
....@@ -206,7 +223,8 @@
206223
207224 SetCamera(cam);
208225
209
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
210228
211229 object = o;
212230
....@@ -524,7 +542,8 @@
524542 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
525543 LA.vecCross(obj.v0, obj.v1, obj.v2);
526544 LA.vecNormalize(obj.v2);
527
- 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);
528547 }
529548
530549 // P
....@@ -546,7 +565,7 @@
546565 y += ny * obj.NORMALPUSH;
547566 z += nz * obj.NORMALPUSH;
548567
549
- gl.glNormal3f(nx, ny, nz);
568
+ SetGLNormal(gl, nx, ny, nz);
550569 }
551570 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
552571 SetColor(obj, pv);
....@@ -578,7 +597,7 @@
578597 y += ny * obj.NORMALPUSH;
579598 z += nz * obj.NORMALPUSH;
580599
581
- gl.glNormal3f(nx, ny, nz);
600
+ SetGLNormal(gl, nx, ny, nz);
582601 }
583602 //System.out.println("vertexq = " + qv.s + ", " + qv.t);
584603 // boolean locked = false;
....@@ -626,7 +645,7 @@
626645 y += ny * obj.NORMALPUSH;
627646 z += nz * obj.NORMALPUSH;
628647
629
- gl.glNormal3f(nx, ny, nz);
648
+ SetGLNormal(gl, nx, ny, nz);
630649 }
631650
632651 // if ((dot&4) == 0)
....@@ -862,7 +881,7 @@
862881 //// tris.postdraw(this);
863882 }
864883
865
- static Camera localcamera = new Camera();
884
+ static Camera localAOcamera = new Camera();
866885 static cVector from = new cVector();
867886 static cVector to = new cVector();
868887
....@@ -871,7 +890,7 @@
871890 CameraPane cp = this;
872891
873892 Camera keep = cp.RenderCamera();
874
- cp.renderCamera = localcamera;
893
+ cp.renderCamera = localAOcamera;
875894
876895 if (br.trimmed)
877896 {
....@@ -889,7 +908,7 @@
889908 br.positions[i3 + 2] + br.normals[i3 + 2]);
890909 LA.xformPos(from, transform, from);
891910 LA.xformPos(to, transform, to); // RIGID ONLY
892
- localcamera.setAim(from, to);
911
+ localAOcamera.setAim(from, to);
893912
894913 CameraPane.occlusionbuffer.display();
895914
....@@ -923,7 +942,7 @@
923942 to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
924943 LA.xformPos(from, transform, from);
925944 LA.xformPos(to, transform, to); // RIGID ONLY
926
- localcamera.setAim(from, to);
945
+ localAOcamera.setAim(from, to);
927946
928947 CameraPane.occlusionbuffer.display();
929948
....@@ -1232,10 +1251,10 @@
12321251 {
12331252 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12341253 {
1235
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1254
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12361255 } else
12371256 {
1238
- gl.glNormal3f(0, 0, 1);
1257
+ SetGLNormal(gl, 0, 0, 1);
12391258 }
12401259
12411260 if (c != null)
....@@ -1259,10 +1278,10 @@
12591278 {
12601279 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12611280 {
1262
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1281
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12631282 } else
12641283 {
1265
- gl.glNormal3f(0, 0, 1);
1284
+ SetGLNormal(gl, 0, 0, 1);
12661285 }
12671286 if (c != null)
12681287 {
....@@ -1287,10 +1306,10 @@
12871306 {
12881307 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
12891308 {
1290
- gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1309
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
12911310 } else
12921311 {
1293
- gl.glNormal3f(0, 0, 1);
1312
+ SetGLNormal(gl, 0, 0, 1);
12941313 }
12951314 if (c != null)
12961315 {
....@@ -1472,7 +1491,7 @@
14721491 {
14731492 if (!selectmode)
14741493 {
1475
- 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);
14761495 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
14771496
14781497 if (flipV)
....@@ -1484,6 +1503,8 @@
14841503 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14851504 }
14861505
1506
+ float[] colorV = new float[4];
1507
+
14871508 void SetColor(Object3D obj, Vertex p0)
14881509 {
14891510 CameraPane display = this;
....@@ -1551,8 +1572,6 @@
15511572 {
15521573 return;
15531574 }
1554
-
1555
- float[] colorV = new float[3];
15561575
15571576 if (false) // marked)
15581577 {
....@@ -1801,7 +1820,7 @@
18011820
18021821 display.modelParams7[0] = 0;
18031822 display.modelParams7[1] = 1000;
1804
- display.modelParams7[2] = 0;
1823
+ display.modelParams7[2] = material.parallax;
18051824 display.modelParams7[3] = 0;
18061825
18071826 //display.modelParams6[0] = 100; // criss de bug de bump
....@@ -2034,9 +2053,9 @@
20342053 switch(viewcode)
20352054 {
20362055 case 0: return "main";
2037
- case 1: return "one";
2038
- case 2: return "two";
2039
- case 3: return "three";
2056
+ case 1: return "Red";
2057
+ case 2: return "Green";
2058
+ case 3: return "Blue";
20402059 case 4: return "light";
20412060 }
20422061
....@@ -2457,6 +2476,18 @@
24572476 return CreateBim(bytes, width, height);
24582477 }
24592478
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
+
24602491 /**/
24612492 class CacheTexture
24622493 {
....@@ -2499,7 +2530,7 @@
24992530 com.sun.opengl.util.texture.TextureIO.newTextureData(
25002531 getClass().getClassLoader().getResourceAsStream(name),
25012532 true,
2502
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
25032534 } catch (java.io.IOException e)
25042535 {
25052536 throw new javax.media.opengl.GLException(e);
....@@ -8345,7 +8376,7 @@
83458376 // else
83468377 // if (!texname.startsWith("/"))
83478378 // texname = "/Users/nbriere/Textures/" + texname;
8348
- if (!FileExists(texname))
8379
+ if (!FileExists(texname) && !texname.startsWith("@"))
83498380 {
83508381 texname = fallbackTextureName;
83518382 }
....@@ -8428,6 +8459,15 @@
84288459 new Exception().printStackTrace();
84298460 } else
84308461 {
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
+ {
84318471 if (textureon)
84328472 {
84338473 String cachename = texname;
....@@ -8487,6 +8527,7 @@
84878527 texturecache = new CacheTexture(texturedata,resolution);
84888528 //texture = GetTexture(tex, bump);
84898529 }
8530
+ }
84908531 }
84918532 //}
84928533 }
....@@ -8755,10 +8796,12 @@
87558796
87568797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
87578798 MAXSTACK = temp[0];
8758
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
87598801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
87608802 MAXSTACK = temp[0];
8761
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
87628805
87638806 // Use debug pipeline
87648807 //drawable.setGL(new DebugGL(gl)); //
....@@ -8766,7 +8809,8 @@
87668809 gl = drawable.getGL(); //
87678810
87688811 GL gl3 = getGL();
8769
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
87708814
87718815
87728816 //float pos[] = { 100, 100, 100, 0 };
....@@ -8931,7 +8975,7 @@
89318975
89328976 if (cubemap == null)
89338977 {
8934
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
89358979 }
89368980
89378981 //cubemap.enable();
....@@ -9207,6 +9251,8 @@
92079251
92089252 void LoadEnvy(int which)
92099253 {
9254
+ assert(false);
9255
+
92109256 String name;
92119257 String ext;
92129258
....@@ -9218,37 +9264,58 @@
92189264 cubemap = null;
92199265 return;
92209266 case 1:
9221
- name = "cubemaps/box_";
9222
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
92239269 reverseUP = false;
92249270 break;
92259271 case 2:
9226
- name = "cubemaps/uffizi_";
9227
- ext = "png";
9228
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
92299276 case 3:
9230
- name = "cubemaps/CloudyHills_";
9231
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
92329279 reverseUP = false;
92339280 break;
92349281 case 4:
9235
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
92369283 ext = "png";
92379284 reverseUP = false;
92389285 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;
92399311 default:
9240
- name = "cubemaps/rgb_";
9241
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
92429315 break;
92439316 }
9244
-
9245
- try
9246
- {
9247
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9248
- } catch (IOException e)
9249
- {
9250
- throw new RuntimeException(e);
9251
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
92529319 }
92539320
92549321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9280,8 +9347,12 @@
92809347 static double[] model = new double[16];
92819348 double[] camera2light = new double[16];
92829349 double[] light2camera = new double[16];
9283
- int newenvy = -1;
9284
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
92859356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
92869357 //float[] light0 = { 0,0,0 };
92879358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9699,7 +9770,7 @@
96999770
97009771 if (renderCamera != lightCamera)
97019772 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9702
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
97039774
97049775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
97059776
....@@ -9715,7 +9786,7 @@
97159786
97169787 if (renderCamera != lightCamera)
97179788 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9718
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
97199790
97209791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
97219792
....@@ -9761,10 +9832,12 @@
97619832 rati = 1 / rati;
97629833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
97639834 }
9764
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
97659838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
97669839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9767
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
97689841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
97699842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
97709843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10630,9 +10703,18 @@
1063010703 static boolean init = false;
1063110704
1063210705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
1063310709
1063410710 public void display(GLAutoDrawable drawable)
1063510711 {
10712
+ if (patchMaterial.patchMaterial)
10713
+ {
10714
+ patchMaterial.patchMaterial = false;
10715
+ patchMaterial.objectPanel.setSelectedIndex(1);
10716
+ }
10717
+
1063610718 if (Grafreed.savesound && Grafreed.hassound)
1063710719 {
1063810720 Grafreed.wav.save();
....@@ -10801,7 +10883,7 @@
1080110883
1080210884 if (wait)
1080310885 {
10804
- Sleep(500);
10886
+ Sleep(200); // blocks everything
1080510887
1080610888 wait = false;
1080710889 }
....@@ -10916,7 +10998,7 @@
1091610998 // if (parentcam != renderCamera) // not a light
1091710999 if (cam != lightCamera)
1091811000 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10919
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1092011002
1092111003 for (int j = 0; j < 4; j++)
1092211004 {
....@@ -10931,7 +11013,7 @@
1093111013 // if (parentcam != renderCamera) // not a light
1093211014 if (cam != lightCamera)
1093311015 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1093511017
1093611018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1093711019
....@@ -11017,13 +11099,43 @@
1101711099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1101811100 }
1101911101
11020
- 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"))
1102111110 {
11022
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
1102311117 }
11024
-
11025
- newenvy = -1;
11026
-
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
+
1102711139 ratio = ((double) getWidth()) / getHeight();
1102811140 //System.out.println("ratio = " + ratio);
1102911141
....@@ -11039,7 +11151,7 @@
1103911151
1104011152 if (!IsFrozen() && !ambientOcclusion)
1104111153 {
11042
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
1104311155 }
1104411156
1104511157 //if (selection_view == -1)
....@@ -11325,7 +11437,7 @@
1132511437
1132611438 // if (cam != lightCamera)
1132711439 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11328
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11440
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1132911441 }
1133011442
1133111443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -12399,51 +12511,80 @@
1239912511
1240012512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1240112513
12402
- String program =
12514
+ String programmin =
1240312515 // Min shader
1240412516 "!!ARBfp1.0\n" +
12405
- "PARAM zero123 = { 0.0, 1.0, 2.0, 1.25 };" +
12406
- "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12517
+ "PARAM zero12t = { 0.0, 1.0, 2, 1.25 };" +
12518
+ "PARAM pow_2 = { 0.5, 0.25, 0.125, 0.0 };" +
12519
+ "PARAM pow2 = { 2, 4, 8, 0.0 };" +
1240712520 "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1240812521 "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
1240912522 "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12523
+ "PARAM light2cam0 = program.env[10];" +
12524
+ "PARAM light2cam1 = program.env[11];" +
12525
+ "PARAM light2cam2 = program.env[12];" +
1241012526 "TEMP temp;" +
1241112527 "TEMP light;" +
1241212528 "TEMP ndotl;" +
1241312529 "TEMP normal;" +
1241412530 "TEMP depth;" +
12531
+ "TEMP eye;" +
12532
+ "TEMP pos;" +
1241512533
12416
- "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12417
-
12534
+ "MAD normal, fragment.color, zero12t.z, -zero12t.y;" +
12535
+ Normalize("normal") +
1241812536 "MOV light, state.light[0].position;" +
1241912537 "DP3 ndotl.x, light, normal;" +
12538
+ "MAX ndotl.x, ndotl.x, zero12t.x;" +
1242012539
1242112540 // shadow
12422
- "MOV temp, fragment.texcoord[1];" +
12423
- TextureFetch("depth", "temp", "1") +
12541
+ "MOV pos, fragment.texcoord[1];" +
12542
+ "MOV temp, pos;" +
12543
+ ShadowTextureFetch("depth", "temp", "1") +
1242412544 //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12425
- "SLT temp.x, fragment.texcoord[1].z, depth.z;" +
12426
-
12545
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
1242712546
1242812547 // No shadow when out of frustum
1242912548 //"SGE temp.y, depth.z, zero123.y;" +
1243012549 //"LRP temp.x, temp.y, zero123.y, temp.x;" +
1243112550
12432
- "MUL ndotl.x, ndotl.x, temp.x;" +
12433
- "MAX ndotl.x, ndotl.x, pow2.y;" +
12551
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
1243412552
12553
+ // Backlit
12554
+ "MOV pos.w, zero12t.y;" + // one
12555
+ "DP4 eye.x, pos, light2cam0;" +
12556
+ "DP4 eye.y, pos, light2cam1;" +
12557
+ "DP4 eye.z, pos, light2cam2;" +
12558
+ Normalize("eye") +
12559
+
12560
+ "DP3 ndotl.y, -eye, normal;" +
12561
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12562
+ "POW ndotl.y, ndotl.y, pow2.x;" + // backlit
12563
+ "SUB ndotl.y, zero12t.y, ndotl.y;" + // 1 - y
12564
+ //"POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12565
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12566
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12567
+ "ADD ndotl.y, ndotl.y, one.x;" +
12568
+ "MUL ndotl.y, ndotl.y, pow_2.x;" +
12569
+
12570
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12571
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12572
+
12573
+ // Pigment
1243512574 "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12436
- "LRP temp, zero123.w, temp, one;" + // texture proportion
12437
- "MUL temp, temp, ndotl.x;" +
12575
+ "LRP temp, zero12t.w, temp, one;" + // texture proportion
12576
+ "MUL temp, temp, zero12t.w;" + // Times x
1243812577
12439
- "MUL temp, temp, zero123.z;" +
12578
+ //"MUL temp, temp, ndotl.y;" +
12579
+ "MAD ndotl.x, pow_2.xxxx, ndotl.yyyy, ndotl.x;" +
1244012580
12441
- "MOV temp.w, zero123.y;" + // reset alpha
12581
+ "MUL temp, temp, ndotl.x;" + // lambert
1244212582
12583
+ "MOV temp.w, zero12t.y;" + // reset alpha
1244312584 "MOV result.color, temp;" +
1244412585 "END";
1244512586
12446
- String program2 =
12587
+ String programmax =
1244712588 "!!ARBfp1.0\n" +
1244812589
1244912590 //"OPTION ARB_fragment_program_shadow;" +
....@@ -12471,7 +12612,7 @@
1247112612 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1247212613 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1247312614 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
12474
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12615
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1247512616 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1247612617 "PARAM options1 = program.env[62];" + // fog rgb color
1247712618 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12581,20 +12722,20 @@
1258112722 "MUL temp, floor, mapgrid.x;" +
1258212723 //"TEX depth0, temp, texture[1], 2D;" +
1258312724 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12584
- TextureFetch("depth0", "temp", "1") +
12725
+ ShadowTextureFetch("depth0", "temp", "1") +
1258512726 "") +
1258612727 "ADD temp.x, temp.x, mapgrid.x;" +
1258712728 //"TEX depth1, temp, texture[1], 2D;" +
1258812729 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12589
- TextureFetch("depth1", "temp", "1") +
12730
+ ShadowTextureFetch("depth1", "temp", "1") +
1259012731 "") +
1259112732 "ADD temp.y, temp.y, mapgrid.x;" +
1259212733 //"TEX depth2, temp, texture[1], 2D;" +
12593
- TextureFetch("depth2", "temp", "1") +
12734
+ ShadowTextureFetch("depth2", "temp", "1") +
1259412735 "SUB temp.x, temp.x, mapgrid.x;" +
1259512736 //"TEX depth3, temp, texture[1], 2D;" +
1259612737 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12597
- TextureFetch("depth3", "temp", "1") +
12738
+ ShadowTextureFetch("depth3", "temp", "1") +
1259812739 "") +
1259912740 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1260012741 //"MOV params, material;" +
....@@ -12716,7 +12857,7 @@
1271612857 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1271712858 // mar 2013 ??? "KIL alpha.a;" +
1271812859 "MOV alpha, texSamp.aaaa;" + // y;" +
12719
- "KIL alpha.a;" +
12860
+ "KIL alpha.a;" + // not sure with parallax mapping
1272012861 /*
1272112862 "MUL temp.xy, temp, two;" +
1272212863 "TXB bump, temp, texture[0], 2D;" +
....@@ -12802,11 +12943,6 @@
1280212943 "SUB bump0, bump0, half;" +
1280312944 "ADD bump, bump, bump0;" +
1280412945
12805
- "MOV temp.x, texSamp.a;" +
12806
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12807
- //"LRP texSamp0, params5.x, texSamp0, one;" +
12808
- "MOV texSamp.a, temp.x;" +
12809
-
1281012946 // double-sided
1281112947 /**/
1281212948 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12823,19 +12959,62 @@
1282312959 "MOV normald, normal;" +
1282412960 "MOV normals, normal;" +
1282512961
12962
+ "MOV temp, fragment.texcoord[4];" +
12963
+
1282612964 // UV base
1282712965 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1282812966 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1282912967 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
12830
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
12831
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
12832
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
12968
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12969
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12970
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12971
+ Normalize("UP") +
12972
+
1283312973 "XPD V, normal, UP;" +
1283412974 Normalize("V") +
1283512975 "XPD U, V, normal;" +
1283612976 Normalize("U") +
1283712977
1283812978 // parallax mapping
12979
+
12980
+ "DP3 temp2.x, V, eye;" +
12981
+ "DP3 temp2.y, U, eye;" +
12982
+ "DP3 temp2.z, normal, eye;" +
12983
+ "RCP temp2.z, temp2.z;" +
12984
+
12985
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12986
+ "RSQ temp2.w, temp2.w;" +
12987
+ "RCP temp2.w, temp2.w;" +
12988
+
12989
+ "SUB temp2.w, temp2.w, half;" +
12990
+// "SGE temp.x, temp2.w, eps.x;" +
12991
+// "MUL temp2.w, temp2.w, temp.x;" +
12992
+
12993
+ //"MOV texSamp, U;" +
12994
+
12995
+ "MUL temp2.z, temp2.z, temp2.w;" +
12996
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12997
+
12998
+ "MUL temp2, temp2, temp2.z;" +
12999
+
13000
+ "MOV temp, fragment.texcoord[0];" +
13001
+
13002
+ "SUB temp, temp, temp2;" +
13003
+
13004
+ "TEX temp, temp, texture[0], 2D;" +
13005
+ "POW temp.a, temp.a, params6.w;" + // punch through
13006
+
13007
+ "ADD texSamp, temp, texSamp;" +
13008
+ "MUL texSamp.xyz, half, texSamp;" +
13009
+
13010
+ "MOV alpha, texSamp.aaaa;" +
13011
+
13012
+// parallax mapping
13013
+
13014
+ "MOV temp.x, texSamp.a;" +
13015
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13016
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13017
+ "MOV texSamp.a, temp.x;" +
1283913018
1284013019 //"MOV temp, fragment.texcoord[0];" +
1284113020 //
....@@ -12968,7 +13147,7 @@
1296813147 // display shadow only (fakedepth == 0)
1296913148 "SUB temp.x, half.x, shadow.x;" +
1297013149 "MOV temp.y, -params5.z;" + // params6.x;" +
12971
- "SLT temp.z, temp.y, -one2048th.x;" +
13150
+ "SLT temp.z, temp.y, -c256i.x;" +
1297213151 "SUB temp.y, one.x, temp.z;" +
1297313152 "MUL temp.x, temp.x, temp.y;" +
1297413153 "KIL temp.x;" +
....@@ -13299,8 +13478,19 @@
1329913478 //once = true;
1330013479 }
1330113480
13302
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13303
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13481
+ String program = programmax;
13482
+
13483
+ if (Globals.MINSHADER)
13484
+ {
13485
+ program = programmin;
13486
+ }
13487
+
13488
+ if (Globals.DEBUG)
13489
+ {
13490
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13491
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13492
+ }
13493
+
1330413494 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1330513495
1330613496 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13347,7 +13537,8 @@
1334713537 "\n" +
1334813538 "END\n";
1334913539
13350
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13540
+ if (Globals.DEBUG)
13541
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1335113542 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1335213543
1335313544 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13392,7 +13583,8 @@
1339213583 return out;
1339313584 }
1339413585
13395
- String TextureFetch(String dest, String src, String unit)
13586
+ // Also does frustum culling
13587
+ String ShadowTextureFetch(String dest, String src, String unit)
1339613588 {
1339713589 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1339813590 "SGE " + src + ".w, " + src + ".x, eps.x;" +
....@@ -13604,7 +13796,7 @@
1360413796 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1360513797 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1360613798 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13607
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13799
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
1360813800
1360913801 //Object3D.cVector2[] vector2buffer;
1361013802
....@@ -13771,7 +13963,7 @@
1377113963 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1377213964 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1377313965 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
13774
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13966
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1377513967 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1377613968 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1377713969 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -13832,7 +14024,7 @@
1383214024 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1383314025 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1383414026 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
13835
- //"MOV result.texcoord, vertex.texcoord;" +
14027
+ //"MOV result.texcoord, vertex.fogcoord;" +
1383614028 "MOV result.texcoord, temp;" +
1383714029 // border fade
1383814030 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -13879,7 +14071,9 @@
1387914071
1388014072 //"ADD temp.z, temp.z, one;" +
1388114073
13882
- "MOV result.color, temp;"
14074
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14075
+
14076
+ "MOV result.color, temp;" // Normal
1388314077 : "MOV result.color, vertex.color;") +
1388414078 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1388514079 : "") +
....@@ -14255,14 +14449,15 @@
1425514449 drag = false;
1425614450 //System.out.println("Mouse DOWN");
1425714451 editObj = false;
14258
- ClickInfo info = new ClickInfo();
14259
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14260
- info.pane = this;
14261
- info.camera = renderCamera;
14262
- info.x = x;
14263
- info.y = y;
14264
- info.modifiers = modifiersex;
14265
- editObj = object.doEditClick(info, 0);
14452
+ //ClickInfo info = new ClickInfo();
14453
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14454
+ object.clickInfo.pane = this;
14455
+ object.clickInfo.camera = renderCamera;
14456
+ object.clickInfo.x = x;
14457
+ object.clickInfo.y = y;
14458
+ object.clickInfo.modifiers = modifiersex;
14459
+ editObj = object.doEditClick(//info,
14460
+ 0);
1426614461 if (!editObj)
1426714462 {
1426814463 hasMarquee = true;
....@@ -14544,11 +14739,17 @@
1454414739 void GoDown(int mod)
1454514740 {
1454614741 MODIFIERS |= COMMAND;
14742
+ boolean isVR = (mouseMode&VR)!=0;
1454714743 /**/
1454814744 if((mod&SHIFT) == SHIFT)
14549
- manipCamera.RotatePosition(0, -speed);
14745
+ {
14746
+ if (isVR)
14747
+ manipCamera.RotateInterest(0, -speed);
14748
+ else
14749
+ manipCamera.RotatePosition(0, -speed);
14750
+ }
1455014751 else
14551
- manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14752
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
1455214753 /**/
1455314754 if ((mod & SHIFT) == SHIFT)
1455414755 {
....@@ -14558,6 +14759,8 @@
1455814759 mouseMode |= BACKFORTH;
1455914760 }
1456014761
14762
+ targetLookAt.set(manipCamera.lookAt);
14763
+
1456114764 //prevX = X = anchorX;
1456214765 prevY = Y = anchorY - (int) (renderCamera.Distance());
1456314766 }
....@@ -14566,10 +14769,17 @@
1456614769 {
1456714770 MODIFIERS |= COMMAND;
1456814771 /**/
14772
+ boolean isVR = (mouseMode&VR)!=0;
14773
+
1456914774 if((mod&SHIFT) == SHIFT)
14570
- manipCamera.RotatePosition(0, speed);
14775
+ {
14776
+ if (isVR)
14777
+ manipCamera.RotateInterest(0, speed);
14778
+ else
14779
+ manipCamera.RotatePosition(0, speed);
14780
+ }
1457114781 else
14572
- manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14782
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
1457314783 /**/
1457414784 if ((mod & SHIFT) == SHIFT)
1457514785 {
....@@ -14579,6 +14789,8 @@
1457914789 mouseMode |= BACKFORTH;
1458014790 }
1458114791
14792
+ targetLookAt.set(manipCamera.lookAt);
14793
+
1458214794 //prevX = X = anchorX;
1458314795 prevY = Y = anchorY + (int) (renderCamera.Distance());
1458414796 }
....@@ -14588,9 +14800,14 @@
1458814800 MODIFIERS |= COMMAND;
1458914801 /**/
1459014802 if((mod&SHIFT) == SHIFT)
14591
- manipCamera.Translate(speed*delta, 0, getWidth());
14803
+ manipCamera.Translate(speed*delta, 0, getWidth());
1459214804 else
14593
- manipCamera.RotatePosition(speed, 0);
14805
+ {
14806
+ if ((mouseMode&VR)!=0)
14807
+ manipCamera.RotateInterest(-speed, 0);
14808
+ else
14809
+ manipCamera.RotatePosition(speed, 0);
14810
+ }
1459414811 /**/
1459514812 if ((mod & SHIFT) == SHIFT)
1459614813 {
....@@ -14600,6 +14817,8 @@
1460014817 mouseMode |= ROTATE;
1460114818 } // TRANSLATE;
1460214819
14820
+ targetLookAt.set(manipCamera.lookAt);
14821
+
1460314822 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1460414823 prevY = Y = anchorY;
1460514824 }
....@@ -14609,9 +14828,15 @@
1460914828 MODIFIERS |= COMMAND;
1461014829 /**/
1461114830 if((mod&SHIFT) == SHIFT)
14612
- manipCamera.Translate(-speed*delta, 0, getWidth());
14831
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1461314832 else
14614
- manipCamera.RotatePosition(-speed, 0);
14833
+ {
14834
+ if ((mouseMode&VR)!=0)
14835
+ manipCamera.RotateInterest(speed, 0);
14836
+ else
14837
+ manipCamera.RotatePosition(-speed, 0);
14838
+ }
14839
+
1461514840 /**/
1461614841 if ((mod & SHIFT) == SHIFT)
1461714842 {
....@@ -14621,6 +14846,8 @@
1462114846 mouseMode |= ROTATE;
1462214847 } // TRANSLATE;
1462314848
14849
+ targetLookAt.set(manipCamera.lookAt);
14850
+
1462414851 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1462514852 prevY = Y = anchorY;
1462614853 }
....@@ -14662,15 +14889,16 @@
1466214889 if (editObj)
1466314890 {
1466414891 drag = true;
14665
- ClickInfo info = new ClickInfo();
14666
- info.bounds.setBounds(0, 0,
14892
+ //ClickInfo info = new ClickInfo();
14893
+ object.clickInfo.bounds.setBounds(0, 0,
1466714894 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14668
- info.pane = this;
14669
- info.camera = renderCamera;
14670
- info.x = x;
14671
- info.y = y;
14672
- object.GetWindow().copy
14673
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14895
+ object.clickInfo.pane = this;
14896
+ object.clickInfo.camera = renderCamera;
14897
+ object.clickInfo.x = x;
14898
+ object.clickInfo.y = y;
14899
+ object //.GetWindow().copy
14900
+ .doEditDrag(//info,
14901
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1467414902 } else
1467514903 {
1467614904 if (x < startX)
....@@ -14819,24 +15047,27 @@
1481915047 }
1482015048 }
1482115049
15050
+// ClickInfo clickInfo = new ClickInfo();
15051
+
1482215052 public void mouseMoved(MouseEvent e)
1482315053 {
1482415054 //System.out.println("mouseMoved: " + e);
1482515055 if (isRenderer)
1482615056 return;
1482715057
14828
- ClickInfo ci = new ClickInfo();
14829
- ci.x = e.getX();
14830
- ci.y = e.getY();
14831
- ci.modifiers = e.getModifiersEx();
14832
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14833
- ci.pane = this;
14834
- ci.camera = renderCamera;
15058
+ // Mouse cursor feedback
15059
+ object.clickInfo.x = e.getX();
15060
+ object.clickInfo.y = e.getY();
15061
+ object.clickInfo.modifiers = e.getModifiersEx();
15062
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15063
+ object.clickInfo.pane = this;
15064
+ object.clickInfo.camera = renderCamera;
1483515065 if (!isRenderer)
1483615066 {
1483715067 //ObjEditor editWindow = object.editWindow;
1483815068 //Object3D copy = editWindow.copy;
14839
- if (object.doEditClick(ci, 0))
15069
+ if (object.doEditClick(//clickInfo,
15070
+ 0))
1484015071 {
1484115072 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1484215073 } else
....@@ -15119,8 +15350,8 @@
1511915350 case 'K':
1512015351 KOMPACTTEXTURE ^= true;
1512115352 //textures.clear();
15122
- break;
15123
- case 'P': // Texture Projection macros
15353
+ // break;
15354
+ //case 'P': // Texture Projection macros
1512415355 // SAVETEXTURE ^= true;
1512515356 macromode = true;
1512615357 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -15241,7 +15472,7 @@
1524115472 targetLookAt.set(manipCamera.lookAt);
1524215473 repaint();
1524315474 break;
15244
- case 'p':
15475
+ case 'P': // p':
1524515476 // c'est quoi ca au juste? spherical ^= true;
1524615477 Skinshader ^= true; programInitialized = false;
1524715478 repaint();
....@@ -15279,27 +15510,31 @@
1527915510 repaint();
1528015511 break;
1528115512 case 'O':
15282
- Globals.drawMode = OCCLUSION; // WARNING
15513
+ // Too dangerous. Use menu. Globals.drawMode = OCCLUSION; // WARNING
1528315514 repaint();
1528415515 break;
1528515516 case 'o':
1528615517 OCCLUSION_CULLING ^= true;
1528715518 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1528815519 break;
15289
- case '0': envyoff ^= true; repaint(); break;
15520
+ //case '0': envyoff ^= true; repaint(); break;
1529015521 case '1':
1529115522 case '2':
1529215523 case '3':
1529315524 case '4':
1529415525 case '5':
15295
- newenvy = Character.getNumericValue(key);
15296
- repaint();
15297
- break;
1529815526 case '6':
1529915527 case '7':
1530015528 case '8':
1530115529 case '9':
15302
- BGcolor = (key - '6')/3.f;
15530
+ if (true) // envyoff)
15531
+ {
15532
+ BGcolor = (key - '1')/8.f;
15533
+ }
15534
+ else
15535
+ {
15536
+ //newenvy = Character.getNumericValue(key);
15537
+ }
1530315538 repaint();
1530415539 break;
1530515540 case '!':
....@@ -15862,8 +16097,6 @@
1586216097
1586316098 int width = getBounds().width;
1586416099 int height = getBounds().height;
15865
- ClickInfo info = new ClickInfo();
15866
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1586716100 //Image img = CreateImage(width, height);
1586816101 //System.out.println("width = " + width + "; height = " + height + "\n");
1586916102
....@@ -15940,31 +16173,37 @@
1594016173 }
1594116174 if (object != null && !hasMarquee)
1594216175 {
16176
+ if (object.clickInfo == null)
16177
+ object.clickInfo = new ClickInfo();
16178
+ ClickInfo info = object.clickInfo;
16179
+ //ClickInfo info = new ClickInfo();
16180
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16181
+
1594316182 if (isRenderer)
1594416183 {
15945
- info.flags++;
16184
+ object.clickInfo.flags++;
1594616185 double frameAspect = (double) width / (double) height;
1594716186 if (frameAspect > renderCamera.aspect)
1594816187 {
1594916188 int desired = (int) ((double) height * renderCamera.aspect);
15950
- info.bounds.width -= width - desired;
15951
- info.bounds.x += (width - desired) / 2;
16189
+ object.clickInfo.bounds.width -= width - desired;
16190
+ object.clickInfo.bounds.x += (width - desired) / 2;
1595216191 } else
1595316192 {
1595416193 int desired = (int) ((double) width / renderCamera.aspect);
15955
- info.bounds.height -= height - desired;
15956
- info.bounds.y += (height - desired) / 2;
16194
+ object.clickInfo.bounds.height -= height - desired;
16195
+ object.clickInfo.bounds.y += (height - desired) / 2;
1595716196 }
1595816197 }
1595916198
15960
- info.g = gr;
15961
- info.camera = renderCamera;
16199
+ object.clickInfo.g = gr;
16200
+ object.clickInfo.camera = renderCamera;
1596216201 /*
1596316202 // Memory intensive (brep.verticescopy)
1596416203 if (!(object instanceof Composite))
1596516204 object.draw(info, 0, false); // SLOW :
1596616205 */
15967
- if (!isRenderer)
16206
+ if (!isRenderer) // && drag)
1596816207 {
1596916208 Grafreed.Assert(object != null);
1597016209 Grafreed.Assert(object.selection != null);
....@@ -15972,9 +16211,9 @@
1597216211 {
1597316212 int hitSomething = object.selection.get(0).hitSomething;
1597416213
15975
- info.DX = 0;
15976
- info.DY = 0;
15977
- info.W = 1;
16214
+ object.clickInfo.DX = 0;
16215
+ object.clickInfo.DY = 0;
16216
+ object.clickInfo.W = 1;
1597816217 if (hitSomething == Object3D.hitCenter)
1597916218 {
1598016219 info.DX = X;
....@@ -15986,13 +16225,14 @@
1598616225 info.DY -= info.bounds.height/2;
1598716226 }
1598816227
15989
- object.drawEditHandles(info, 0);
16228
+ object.drawEditHandles(//info,
16229
+ 0);
1599016230
1599116231 if (drag && (X != 0 || Y != 0))
1599216232 {
1599316233 switch (hitSomething)
1599416234 {
15995
- case Object3D.hitCenter: gr.setColor(Color.pink);
16235
+ case Object3D.hitCenter: gr.setColor(Color.white);
1599616236 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1599716237 break;
1599816238 case Object3D.hitRotate: gr.setColor(Color.yellow);
....@@ -16018,7 +16258,7 @@
1601816258 if (hasMarquee)
1601916259 {
1602016260 gr.setXORMode(Color.white);
16021
- gr.setColor(Color.red);
16261
+ gr.setColor(Color.white);
1602216262 if (!firstime)
1602316263 {
1602416264 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16485,6 +16725,8 @@
1648516725 private /*static*/ boolean firstime;
1648616726 private /*static*/ cVector newView = new cVector();
1648716727 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16728
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16729
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1648816730 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1648916731 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1649016732 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16497,29 +16739,67 @@
1649716739 {
1649816740 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1649916741
16742
+ int usedsuf = 0;
16743
+
1650016744 for (int i = 0; i < suffixes.length; i++)
1650116745 {
16502
- String resourceName = basename + suffixes[i] + "." + suffix;
16503
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16504
- mipmapped,
16505
- FileUtil.getFileSuffix(resourceName));
16506
- if (data == null)
16746
+ String[] suffixe = suffixes;
16747
+ String[] fallback = suffixes2;
16748
+ String[] fallfallback = suffixes3;
16749
+
16750
+ for (int c=usedsuf; --c>=0;)
1650716751 {
16508
- throw new IOException("Unable to load texture " + resourceName);
16752
+// String[] temp = suffixe;
16753
+// suffixe = fallback;
16754
+// fallback = fallfallback;
16755
+// fallfallback = temp;
1650916756 }
16757
+
16758
+ String resourceName = basename + suffixe[i] + "." + suffix;
16759
+ TextureData data;
16760
+
16761
+ try
16762
+ {
16763
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16764
+ mipmapped,
16765
+ FileUtil.getFileSuffix(resourceName));
16766
+ }
16767
+ catch (Exception e)
16768
+ {
16769
+ try
16770
+ {
16771
+ resourceName = basename + fallback[i] + "." + suffix;
16772
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16773
+ mipmapped,
16774
+ FileUtil.getFileSuffix(resourceName));
16775
+ }
16776
+ catch (Exception e2)
16777
+ {
16778
+ resourceName = basename + fallfallback[i] + "." + suffix;
16779
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16780
+ mipmapped,
16781
+ FileUtil.getFileSuffix(resourceName));
16782
+ }
16783
+ }
16784
+
1651016785 //System.out.println("Target = " + targets[i]);
1651116786 cubemap.updateImage(data, targets[i]);
1651216787 }
1651316788
1651416789 return cubemap;
1651516790 }
16791
+
1651616792 int bigsphere = -1;
1651716793
1651816794 float BGcolor = 0.5f;
1651916795
16520
- private void DrawSkyBox(GL gl)
16796
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16797
+
16798
+ private void DrawSkyBox(GL gl, float ratio)
1652116799 {
16522
- if (envyoff || cubemap == null)
16800
+ if (//envyoff ||
16801
+ WIREFRAME ||
16802
+ cubemap == null)
1652316803 {
1652416804 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1652516805 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16534,7 +16814,17 @@
1653416814 // Compensates for ExaminerViewer's modification of modelview matrix
1653516815 gl.glMatrixMode(GL.GL_MODELVIEW);
1653616816 gl.glLoadIdentity();
16817
+ gl.glScalef(1,ratio,1);
1653716818
16819
+// colorV[0] = 2;
16820
+// colorV[1] = 2;
16821
+// colorV[2] = 2;
16822
+// colorV[3] = 1;
16823
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16824
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16825
+//
16826
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16827
+
1653816828 //gl.glActiveTexture(GL.GL_TEXTURE1);
1653916829 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1654016830
....@@ -16566,6 +16856,7 @@
1656616856 {
1656716857 gl.glScalef(1.0f, -1.0f, 1.0f);
1656816858 }
16859
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1656916860 gl.glMultMatrixd(viewrot_1, 0);
1657016861 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1657116862 //viewer.updateInverseRotation(gl);
....@@ -16606,7 +16897,8 @@
1660616897 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1660716898
1660816899 cubemap.disable();
16609
- ////cubemap.unbind();
16900
+ //cubemap.dispose();
16901
+
1661016902 if (CULLFACE)
1661116903 {
1661216904 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16662,7 +16954,7 @@
1666216954 gl.glScalef(1.0f, -1.0f, 1.0f);
1666316955 }
1666416956
16665
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16957
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1666616958
1666716959 float step = 2; // 0.1666f; //0.25f;
1666816960 float stepv = 2; // step * 1652 / 998;
....@@ -16824,7 +17116,7 @@
1682417116 //new Exception().printStackTrace();
1682517117 System.out.println("select buffer init");
1682617118 // Use debug pipeline
16827
- drawable.setGL(new DebugGL(drawable.getGL()));
17119
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1682817120
1682917121 GL gl = drawable.getGL();
1683017122
....@@ -17142,6 +17434,7 @@
1714217434
1714317435 public void init(GLAutoDrawable drawable)
1714417436 {
17437
+ if (Globals.DEBUG)
1714517438 System.out.println("shadow buffer init");
1714617439
1714717440 GL gl = drawable.getGL();
....@@ -17370,10 +17663,14 @@
1737017663 gl.glFlush();
1737117664
1737217665 /**/
17373
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17666
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1737417667
17375
- float[] pixels = occlusionsizebuffer.array();
17668
+ float[] depths = occlusiondepthbuffer.array();
1737617669
17670
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17671
+
17672
+ int[] pixels = selectsizebuffer.array();
17673
+
1737717674 double r = 0, g = 0, b = 0;
1737817675
1737917676 double count = 0;
....@@ -17384,7 +17681,7 @@
1738417681
1738517682 double FACTOR = 1;
1738617683
17387
- for (int i = 0; i < pixels.length; i++)
17684
+ for (int i = 0; i < depths.length; i++)
1738817685 {
1738917686 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1739017687 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17467,7 +17764,7 @@
1746717764
1746817765 double scale = ray.z; // 1; // cos
1746917766
17470
- float depth = pixels[newindex];
17767
+ float depth = depths[newindex];
1747117768
1747217769 /*
1747317770 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17664,11 +17961,14 @@
1766417961 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1766517962 static IntBuffer bigAAbuffer;
1766617963 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17667
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17964
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1766817965 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1766917966 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1767017967 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17671
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17968
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17969
+
17970
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17971
+
1767217972 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1767317973 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1767417974 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();