Normand Briere
2019-07-25 7058eef32e524cae08a7373d8bc1061e373b223c
CameraPane.java
....@@ -206,7 +206,8 @@
206206
207207 SetCamera(cam);
208208
209
- SetLight(new Camera(new cVector(10, 10, -20)));
209
+ // Warning: not used.
210
+ SetLight(new Camera(new cVector(15, 10, -20)));
210211
211212 object = o;
212213
....@@ -9699,7 +9700,7 @@
96999700
97009701 if (renderCamera != lightCamera)
97019702 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9702
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9703
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
97039704
97049705 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
97059706
....@@ -9715,7 +9716,7 @@
97159716
97169717 if (renderCamera != lightCamera)
97179718 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9718
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9719
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
97199720
97209721 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
97219722
....@@ -10916,7 +10917,7 @@
1091610917 // if (parentcam != renderCamera) // not a light
1091710918 if (cam != lightCamera)
1091810919 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10919
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10920
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1092010921
1092110922 for (int j = 0; j < 4; j++)
1092210923 {
....@@ -10931,7 +10932,7 @@
1093110932 // if (parentcam != renderCamera) // not a light
1093210933 if (cam != lightCamera)
1093310934 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10935
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1093510936
1093610937 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1093710938
....@@ -12400,7 +12401,74 @@
1240012401 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1240112402
1240212403 String program =
12404
+ // Min shader
1240312405 "!!ARBfp1.0\n" +
12406
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12407
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12408
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12409
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12410
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12411
+ "PARAM light2cam0 = program.env[10];" +
12412
+ "PARAM light2cam1 = program.env[11];" +
12413
+ "PARAM light2cam2 = program.env[12];" +
12414
+ "TEMP temp;" +
12415
+ "TEMP light;" +
12416
+ "TEMP ndotl;" +
12417
+ "TEMP normal;" +
12418
+ "TEMP depth;" +
12419
+ "TEMP eye;" +
12420
+ "TEMP pos;" +
12421
+
12422
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12423
+ Normalize("normal") +
12424
+ "MOV light, state.light[0].position;" +
12425
+ "DP3 ndotl.x, light, normal;" +
12426
+
12427
+ // shadow
12428
+ "MOV pos, fragment.texcoord[1];" +
12429
+ "MOV temp, pos;" +
12430
+ ShadowTextureFetch("depth", "temp", "1") +
12431
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12432
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12433
+
12434
+ // No shadow when out of frustum
12435
+ //"SGE temp.y, depth.z, zero123.y;" +
12436
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12437
+
12438
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12439
+
12440
+ // Backlit
12441
+ "MOV pos.w, zero123.y;" +
12442
+ "DP4 eye.x, pos, light2cam0;" +
12443
+ "DP4 eye.y, pos, light2cam1;" +
12444
+ "DP4 eye.z, pos, light2cam2;" +
12445
+ Normalize("eye") +
12446
+
12447
+ "DP3 ndotl.y, -eye, normal;" +
12448
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12449
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12450
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12451
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12452
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12453
+
12454
+ "MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12455
+
12456
+ // Pigment
12457
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12458
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12459
+ "MUL temp, temp, ndotl.x;" +
12460
+
12461
+ "MUL temp, temp, zero123.z;" +
12462
+
12463
+ //"MUL temp, temp, ndotl.y;" +
12464
+
12465
+ "MOV temp.w, zero123.y;" + // reset alpha
12466
+ "MOV result.color, temp;" +
12467
+ "END";
12468
+
12469
+ String program2 =
12470
+ "!!ARBfp1.0\n" +
12471
+
1240412472 //"OPTION ARB_fragment_program_shadow;" +
1240512473 "PARAM light2cam0 = program.env[10];" +
1240612474 "PARAM light2cam1 = program.env[11];" +
....@@ -12515,8 +12583,7 @@
1251512583 "TEMP shininess;" +
1251612584 "\n" +
1251712585 "MOV texSamp, one;" +
12518
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12519
-
12586
+
1252012587 "MOV mapgrid.x, one2048th.x;" +
1252112588 "MOV temp, fragment.texcoord[1];" +
1252212589 /*
....@@ -12537,20 +12604,20 @@
1253712604 "MUL temp, floor, mapgrid.x;" +
1253812605 //"TEX depth0, temp, texture[1], 2D;" +
1253912606 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12540
- TextureFetch("depth0", "temp", "1") +
12607
+ ShadowTextureFetch("depth0", "temp", "1") +
1254112608 "") +
1254212609 "ADD temp.x, temp.x, mapgrid.x;" +
1254312610 //"TEX depth1, temp, texture[1], 2D;" +
1254412611 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12545
- TextureFetch("depth1", "temp", "1") +
12612
+ ShadowTextureFetch("depth1", "temp", "1") +
1254612613 "") +
1254712614 "ADD temp.y, temp.y, mapgrid.x;" +
1254812615 //"TEX depth2, temp, texture[1], 2D;" +
12549
- TextureFetch("depth2", "temp", "1") +
12616
+ ShadowTextureFetch("depth2", "temp", "1") +
1255012617 "SUB temp.x, temp.x, mapgrid.x;" +
1255112618 //"TEX depth3, temp, texture[1], 2D;" +
1255212619 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12553
- TextureFetch("depth3", "temp", "1") +
12620
+ ShadowTextureFetch("depth3", "temp", "1") +
1255412621 "") +
1255512622 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1255612623 //"MOV params, material;" +
....@@ -12921,7 +12988,7 @@
1292112988 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1292212989 "") +
1292312990
12924
- // display shadow only (bump == 0)
12991
+ // display shadow only (fakedepth == 0)
1292512992 "SUB temp.x, half.x, shadow.x;" +
1292612993 "MOV temp.y, -params5.z;" + // params6.x;" +
1292712994 "SLT temp.z, temp.y, -one2048th.x;" +
....@@ -13348,25 +13415,26 @@
1334813415 return out;
1334913416 }
1335013417
13351
- String TextureFetch(String dest, String src, String unit)
13418
+ // Also does frustum culling
13419
+ String ShadowTextureFetch(String dest, String src, String unit)
1335213420 {
1335313421 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1335413422 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1335513423 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13424
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13425
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1335613426 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13357
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13358
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13359
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13360
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13427
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13428
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1336113429 //"SWZ buffer, temp, w,w,w,w;";
13362
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13430
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1336313431 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1336413432 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1336513433 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13366
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13434
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1336713435
13368
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13369
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13436
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13437
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1337013438 }
1337113439
1337213440 String Shadow(String depth, String shadow)
....@@ -13413,7 +13481,7 @@
1341313481 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1341413482 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1341513483
13416
- // No shadow when out of frustrum
13484
+ // No shadow when out of frustum
1341713485 "SGE temp.x, " + depth + ".z, one.z;" +
1341813486 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1341913487 "";
....@@ -14211,14 +14279,15 @@
1421114279 drag = false;
1421214280 //System.out.println("Mouse DOWN");
1421314281 editObj = false;
14214
- ClickInfo info = new ClickInfo();
14215
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14216
- info.pane = this;
14217
- info.camera = renderCamera;
14218
- info.x = x;
14219
- info.y = y;
14220
- info.modifiers = modifiersex;
14221
- editObj = object.doEditClick(info, 0);
14282
+ //ClickInfo info = new ClickInfo();
14283
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14284
+ object.clickInfo.pane = this;
14285
+ object.clickInfo.camera = renderCamera;
14286
+ object.clickInfo.x = x;
14287
+ object.clickInfo.y = y;
14288
+ object.clickInfo.modifiers = modifiersex;
14289
+ editObj = object.doEditClick(//info,
14290
+ 0);
1422214291 if (!editObj)
1422314292 {
1422414293 hasMarquee = true;
....@@ -14618,15 +14687,16 @@
1461814687 if (editObj)
1461914688 {
1462014689 drag = true;
14621
- ClickInfo info = new ClickInfo();
14622
- info.bounds.setBounds(0, 0,
14690
+ //ClickInfo info = new ClickInfo();
14691
+ object.clickInfo.bounds.setBounds(0, 0,
1462314692 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14624
- info.pane = this;
14625
- info.camera = renderCamera;
14626
- info.x = x;
14627
- info.y = y;
14628
- object.GetWindow().copy
14629
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14693
+ object.clickInfo.pane = this;
14694
+ object.clickInfo.camera = renderCamera;
14695
+ object.clickInfo.x = x;
14696
+ object.clickInfo.y = y;
14697
+ object //.GetWindow().copy
14698
+ .doEditDrag(//info,
14699
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1463014700 } else
1463114701 {
1463214702 if (x < startX)
....@@ -14775,24 +14845,27 @@
1477514845 }
1477614846 }
1477714847
14848
+// ClickInfo clickInfo = new ClickInfo();
14849
+
1477814850 public void mouseMoved(MouseEvent e)
1477914851 {
1478014852 //System.out.println("mouseMoved: " + e);
1478114853 if (isRenderer)
1478214854 return;
1478314855
14784
- ClickInfo ci = new ClickInfo();
14785
- ci.x = e.getX();
14786
- ci.y = e.getY();
14787
- ci.modifiers = e.getModifiersEx();
14788
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14789
- ci.pane = this;
14790
- ci.camera = renderCamera;
14856
+ // Mouse cursor feedback
14857
+ object.clickInfo.x = e.getX();
14858
+ object.clickInfo.y = e.getY();
14859
+ object.clickInfo.modifiers = e.getModifiersEx();
14860
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14861
+ object.clickInfo.pane = this;
14862
+ object.clickInfo.camera = renderCamera;
1479114863 if (!isRenderer)
1479214864 {
1479314865 //ObjEditor editWindow = object.editWindow;
1479414866 //Object3D copy = editWindow.copy;
14795
- if (object.doEditClick(ci, 0))
14867
+ if (object.doEditClick(//clickInfo,
14868
+ 0))
1479614869 {
1479714870 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1479814871 } else
....@@ -15818,8 +15891,6 @@
1581815891
1581915892 int width = getBounds().width;
1582015893 int height = getBounds().height;
15821
- ClickInfo info = new ClickInfo();
15822
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1582315894 //Image img = CreateImage(width, height);
1582415895 //System.out.println("width = " + width + "; height = " + height + "\n");
1582515896
....@@ -15896,31 +15967,37 @@
1589615967 }
1589715968 if (object != null && !hasMarquee)
1589815969 {
15970
+ if (object.clickInfo == null)
15971
+ object.clickInfo = new ClickInfo();
15972
+ ClickInfo info = object.clickInfo;
15973
+ //ClickInfo info = new ClickInfo();
15974
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
15975
+
1589915976 if (isRenderer)
1590015977 {
15901
- info.flags++;
15978
+ object.clickInfo.flags++;
1590215979 double frameAspect = (double) width / (double) height;
1590315980 if (frameAspect > renderCamera.aspect)
1590415981 {
1590515982 int desired = (int) ((double) height * renderCamera.aspect);
15906
- info.bounds.width -= width - desired;
15907
- info.bounds.x += (width - desired) / 2;
15983
+ object.clickInfo.bounds.width -= width - desired;
15984
+ object.clickInfo.bounds.x += (width - desired) / 2;
1590815985 } else
1590915986 {
1591015987 int desired = (int) ((double) width / renderCamera.aspect);
15911
- info.bounds.height -= height - desired;
15912
- info.bounds.y += (height - desired) / 2;
15988
+ object.clickInfo.bounds.height -= height - desired;
15989
+ object.clickInfo.bounds.y += (height - desired) / 2;
1591315990 }
1591415991 }
1591515992
15916
- info.g = gr;
15917
- info.camera = renderCamera;
15993
+ object.clickInfo.g = gr;
15994
+ object.clickInfo.camera = renderCamera;
1591815995 /*
1591915996 // Memory intensive (brep.verticescopy)
1592015997 if (!(object instanceof Composite))
1592115998 object.draw(info, 0, false); // SLOW :
1592215999 */
15923
- if (!isRenderer)
16000
+ if (!isRenderer) // && drag)
1592416001 {
1592516002 Grafreed.Assert(object != null);
1592616003 Grafreed.Assert(object.selection != null);
....@@ -15928,9 +16005,9 @@
1592816005 {
1592916006 int hitSomething = object.selection.get(0).hitSomething;
1593016007
15931
- info.DX = 0;
15932
- info.DY = 0;
15933
- info.W = 1;
16008
+ object.clickInfo.DX = 0;
16009
+ object.clickInfo.DY = 0;
16010
+ object.clickInfo.W = 1;
1593416011 if (hitSomething == Object3D.hitCenter)
1593516012 {
1593616013 info.DX = X;
....@@ -15942,7 +16019,8 @@
1594216019 info.DY -= info.bounds.height/2;
1594316020 }
1594416021
15945
- object.drawEditHandles(info, 0);
16022
+ object.drawEditHandles(//info,
16023
+ 0);
1594616024
1594716025 if (drag && (X != 0 || Y != 0))
1594816026 {
....@@ -15955,7 +16033,7 @@
1595516033 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1595616034 break;
1595716035 case Object3D.hitScale: gr.setColor(Color.cyan);
15958
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16036
+ gr.drawLine(X, Y, 0, 0);
1595916037 break;
1596016038 }
1596116039