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
....@@ -12402,43 +12403,66 @@
1240212403 String program =
1240312404 // Min shader
1240412405 "!!ARBfp1.0\n" +
12405
- "PARAM zero123 = { 0.0, 1.0, 2.0, 3.0 };" +
12406
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
1240612407 "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
1240712408 "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1240812409 "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
1240912410 "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];" +
1241012414 "TEMP temp;" +
1241112415 "TEMP light;" +
1241212416 "TEMP ndotl;" +
1241312417 "TEMP normal;" +
1241412418 "TEMP depth;" +
12419
+ "TEMP eye;" +
12420
+ "TEMP pos;" +
1241512421
1241612422 "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12417
-
12423
+ Normalize("normal") +
1241812424 "MOV light, state.light[0].position;" +
1241912425 "DP3 ndotl.x, light, normal;" +
1242012426
1242112427 // shadow
12422
- "MOV temp, fragment.texcoord[1];" +
12423
- TextureFetch("depth", "temp", "1") +
12428
+ "MOV pos, fragment.texcoord[1];" +
12429
+ "MOV temp, pos;" +
12430
+ ShadowTextureFetch("depth", "temp", "1") +
1242412431 //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12425
- "SLT temp.x, fragment.texcoord[1].z, depth.z;" +
12426
-
12432
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
1242712433
1242812434 // No shadow when out of frustum
1242912435 //"SGE temp.y, depth.z, zero123.y;" +
1243012436 //"LRP temp.x, temp.y, zero123.y, temp.x;" +
1243112437
12432
- "MUL ndotl.x, ndotl.x, temp.x;" +
12433
- "MAX ndotl.x, ndotl.x, pow2.y;" +
12438
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
1243412439
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
1243512457 "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12458
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
1243612459 "MUL temp, temp, ndotl.x;" +
1243712460
1243812461 "MUL temp, temp, zero123.z;" +
1243912462
12440
- "MOV temp.w, zero123.y;" + // reset alpha
12463
+ //"MUL temp, temp, ndotl.y;" +
1244112464
12465
+ "MOV temp.w, zero123.y;" + // reset alpha
1244212466 "MOV result.color, temp;" +
1244312467 "END";
1244412468
....@@ -12580,20 +12604,20 @@
1258012604 "MUL temp, floor, mapgrid.x;" +
1258112605 //"TEX depth0, temp, texture[1], 2D;" +
1258212606 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12583
- TextureFetch("depth0", "temp", "1") +
12607
+ ShadowTextureFetch("depth0", "temp", "1") +
1258412608 "") +
1258512609 "ADD temp.x, temp.x, mapgrid.x;" +
1258612610 //"TEX depth1, temp, texture[1], 2D;" +
1258712611 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12588
- TextureFetch("depth1", "temp", "1") +
12612
+ ShadowTextureFetch("depth1", "temp", "1") +
1258912613 "") +
1259012614 "ADD temp.y, temp.y, mapgrid.x;" +
1259112615 //"TEX depth2, temp, texture[1], 2D;" +
12592
- TextureFetch("depth2", "temp", "1") +
12616
+ ShadowTextureFetch("depth2", "temp", "1") +
1259312617 "SUB temp.x, temp.x, mapgrid.x;" +
1259412618 //"TEX depth3, temp, texture[1], 2D;" +
1259512619 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12596
- TextureFetch("depth3", "temp", "1") +
12620
+ ShadowTextureFetch("depth3", "temp", "1") +
1259712621 "") +
1259812622 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1259912623 //"MOV params, material;" +
....@@ -13391,25 +13415,26 @@
1339113415 return out;
1339213416 }
1339313417
13394
- String TextureFetch(String dest, String src, String unit)
13418
+ // Also does frustum culling
13419
+ String ShadowTextureFetch(String dest, String src, String unit)
1339513420 {
1339613421 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1339713422 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1339813423 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13424
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13425
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1339913426 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13400
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13401
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13402
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13403
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13427
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13428
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1340413429 //"SWZ buffer, temp, w,w,w,w;";
13405
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13430
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1340613431 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1340713432 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1340813433 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13409
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13434
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1341013435
13411
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13412
- //"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;";
1341313438 }
1341413439
1341513440 String Shadow(String depth, String shadow)
....@@ -14254,14 +14279,15 @@
1425414279 drag = false;
1425514280 //System.out.println("Mouse DOWN");
1425614281 editObj = false;
14257
- ClickInfo info = new ClickInfo();
14258
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14259
- info.pane = this;
14260
- info.camera = renderCamera;
14261
- info.x = x;
14262
- info.y = y;
14263
- info.modifiers = modifiersex;
14264
- 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);
1426514291 if (!editObj)
1426614292 {
1426714293 hasMarquee = true;
....@@ -14661,15 +14687,16 @@
1466114687 if (editObj)
1466214688 {
1466314689 drag = true;
14664
- ClickInfo info = new ClickInfo();
14665
- info.bounds.setBounds(0, 0,
14690
+ //ClickInfo info = new ClickInfo();
14691
+ object.clickInfo.bounds.setBounds(0, 0,
1466614692 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14667
- info.pane = this;
14668
- info.camera = renderCamera;
14669
- info.x = x;
14670
- info.y = y;
14671
- object.GetWindow().copy
14672
- .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);
1467314700 } else
1467414701 {
1467514702 if (x < startX)
....@@ -14818,24 +14845,27 @@
1481814845 }
1481914846 }
1482014847
14848
+// ClickInfo clickInfo = new ClickInfo();
14849
+
1482114850 public void mouseMoved(MouseEvent e)
1482214851 {
1482314852 //System.out.println("mouseMoved: " + e);
1482414853 if (isRenderer)
1482514854 return;
1482614855
14827
- ClickInfo ci = new ClickInfo();
14828
- ci.x = e.getX();
14829
- ci.y = e.getY();
14830
- ci.modifiers = e.getModifiersEx();
14831
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14832
- ci.pane = this;
14833
- 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;
1483414863 if (!isRenderer)
1483514864 {
1483614865 //ObjEditor editWindow = object.editWindow;
1483714866 //Object3D copy = editWindow.copy;
14838
- if (object.doEditClick(ci, 0))
14867
+ if (object.doEditClick(//clickInfo,
14868
+ 0))
1483914869 {
1484014870 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1484114871 } else
....@@ -15861,8 +15891,6 @@
1586115891
1586215892 int width = getBounds().width;
1586315893 int height = getBounds().height;
15864
- ClickInfo info = new ClickInfo();
15865
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1586615894 //Image img = CreateImage(width, height);
1586715895 //System.out.println("width = " + width + "; height = " + height + "\n");
1586815896
....@@ -15939,31 +15967,37 @@
1593915967 }
1594015968 if (object != null && !hasMarquee)
1594115969 {
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
+
1594215976 if (isRenderer)
1594315977 {
15944
- info.flags++;
15978
+ object.clickInfo.flags++;
1594515979 double frameAspect = (double) width / (double) height;
1594615980 if (frameAspect > renderCamera.aspect)
1594715981 {
1594815982 int desired = (int) ((double) height * renderCamera.aspect);
15949
- info.bounds.width -= width - desired;
15950
- info.bounds.x += (width - desired) / 2;
15983
+ object.clickInfo.bounds.width -= width - desired;
15984
+ object.clickInfo.bounds.x += (width - desired) / 2;
1595115985 } else
1595215986 {
1595315987 int desired = (int) ((double) width / renderCamera.aspect);
15954
- info.bounds.height -= height - desired;
15955
- info.bounds.y += (height - desired) / 2;
15988
+ object.clickInfo.bounds.height -= height - desired;
15989
+ object.clickInfo.bounds.y += (height - desired) / 2;
1595615990 }
1595715991 }
1595815992
15959
- info.g = gr;
15960
- info.camera = renderCamera;
15993
+ object.clickInfo.g = gr;
15994
+ object.clickInfo.camera = renderCamera;
1596115995 /*
1596215996 // Memory intensive (brep.verticescopy)
1596315997 if (!(object instanceof Composite))
1596415998 object.draw(info, 0, false); // SLOW :
1596515999 */
15966
- if (!isRenderer)
16000
+ if (!isRenderer) // && drag)
1596716001 {
1596816002 Grafreed.Assert(object != null);
1596916003 Grafreed.Assert(object.selection != null);
....@@ -15971,9 +16005,9 @@
1597116005 {
1597216006 int hitSomething = object.selection.get(0).hitSomething;
1597316007
15974
- info.DX = 0;
15975
- info.DY = 0;
15976
- info.W = 1;
16008
+ object.clickInfo.DX = 0;
16009
+ object.clickInfo.DY = 0;
16010
+ object.clickInfo.W = 1;
1597716011 if (hitSomething == Object3D.hitCenter)
1597816012 {
1597916013 info.DX = X;
....@@ -15985,7 +16019,8 @@
1598516019 info.DY -= info.bounds.height/2;
1598616020 }
1598716021
15988
- object.drawEditHandles(info, 0);
16022
+ object.drawEditHandles(//info,
16023
+ 0);
1598916024
1599016025 if (drag && (X != 0 || Y != 0))
1599116026 {
....@@ -15998,7 +16033,7 @@
1599816033 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1599916034 break;
1600016035 case Object3D.hitScale: gr.setColor(Color.cyan);
16001
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16036
+ gr.drawLine(X, Y, 0, 0);
1600216037 break;
1600316038 }
1600416039