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,44 +12403,66 @@
1240212403 String program =
1240312404 // Min shader
1240412405 "!!ARBfp1.0\n" +
12405
- "PARAM zero123 = { 0.0, 1.0, 2.0, 1.25 };" +
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;" +
1243612458 "LRP temp, zero123.w, temp, one;" + // texture proportion
1243712459 "MUL temp, temp, ndotl.x;" +
1243812460
1243912461 "MUL temp, temp, zero123.z;" +
1244012462
12441
- "MOV temp.w, zero123.y;" + // reset alpha
12463
+ //"MUL temp, temp, ndotl.y;" +
1244212464
12465
+ "MOV temp.w, zero123.y;" + // reset alpha
1244312466 "MOV result.color, temp;" +
1244412467 "END";
1244512468
....@@ -12581,20 +12604,20 @@
1258112604 "MUL temp, floor, mapgrid.x;" +
1258212605 //"TEX depth0, temp, texture[1], 2D;" +
1258312606 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12584
- TextureFetch("depth0", "temp", "1") +
12607
+ ShadowTextureFetch("depth0", "temp", "1") +
1258512608 "") +
1258612609 "ADD temp.x, temp.x, mapgrid.x;" +
1258712610 //"TEX depth1, temp, texture[1], 2D;" +
1258812611 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12589
- TextureFetch("depth1", "temp", "1") +
12612
+ ShadowTextureFetch("depth1", "temp", "1") +
1259012613 "") +
1259112614 "ADD temp.y, temp.y, mapgrid.x;" +
1259212615 //"TEX depth2, temp, texture[1], 2D;" +
12593
- TextureFetch("depth2", "temp", "1") +
12616
+ ShadowTextureFetch("depth2", "temp", "1") +
1259412617 "SUB temp.x, temp.x, mapgrid.x;" +
1259512618 //"TEX depth3, temp, texture[1], 2D;" +
1259612619 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12597
- TextureFetch("depth3", "temp", "1") +
12620
+ ShadowTextureFetch("depth3", "temp", "1") +
1259812621 "") +
1259912622 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1260012623 //"MOV params, material;" +
....@@ -13392,7 +13415,8 @@
1339213415 return out;
1339313416 }
1339413417
13395
- String TextureFetch(String dest, String src, String unit)
13418
+ // Also does frustum culling
13419
+ String ShadowTextureFetch(String dest, String src, String unit)
1339613420 {
1339713421 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1339813422 "SGE " + src + ".w, " + src + ".x, eps.x;" +
....@@ -14255,14 +14279,15 @@
1425514279 drag = false;
1425614280 //System.out.println("Mouse DOWN");
1425714281 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);
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);
1426614291 if (!editObj)
1426714292 {
1426814293 hasMarquee = true;
....@@ -14662,15 +14687,16 @@
1466214687 if (editObj)
1466314688 {
1466414689 drag = true;
14665
- ClickInfo info = new ClickInfo();
14666
- info.bounds.setBounds(0, 0,
14690
+ //ClickInfo info = new ClickInfo();
14691
+ object.clickInfo.bounds.setBounds(0, 0,
1466714692 (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);
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);
1467414700 } else
1467514701 {
1467614702 if (x < startX)
....@@ -14819,24 +14845,27 @@
1481914845 }
1482014846 }
1482114847
14848
+// ClickInfo clickInfo = new ClickInfo();
14849
+
1482214850 public void mouseMoved(MouseEvent e)
1482314851 {
1482414852 //System.out.println("mouseMoved: " + e);
1482514853 if (isRenderer)
1482614854 return;
1482714855
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;
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;
1483514863 if (!isRenderer)
1483614864 {
1483714865 //ObjEditor editWindow = object.editWindow;
1483814866 //Object3D copy = editWindow.copy;
14839
- if (object.doEditClick(ci, 0))
14867
+ if (object.doEditClick(//clickInfo,
14868
+ 0))
1484014869 {
1484114870 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1484214871 } else
....@@ -15862,8 +15891,6 @@
1586215891
1586315892 int width = getBounds().width;
1586415893 int height = getBounds().height;
15865
- ClickInfo info = new ClickInfo();
15866
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1586715894 //Image img = CreateImage(width, height);
1586815895 //System.out.println("width = " + width + "; height = " + height + "\n");
1586915896
....@@ -15940,31 +15967,37 @@
1594015967 }
1594115968 if (object != null && !hasMarquee)
1594215969 {
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
+
1594315976 if (isRenderer)
1594415977 {
15945
- info.flags++;
15978
+ object.clickInfo.flags++;
1594615979 double frameAspect = (double) width / (double) height;
1594715980 if (frameAspect > renderCamera.aspect)
1594815981 {
1594915982 int desired = (int) ((double) height * renderCamera.aspect);
15950
- info.bounds.width -= width - desired;
15951
- info.bounds.x += (width - desired) / 2;
15983
+ object.clickInfo.bounds.width -= width - desired;
15984
+ object.clickInfo.bounds.x += (width - desired) / 2;
1595215985 } else
1595315986 {
1595415987 int desired = (int) ((double) width / renderCamera.aspect);
15955
- info.bounds.height -= height - desired;
15956
- info.bounds.y += (height - desired) / 2;
15988
+ object.clickInfo.bounds.height -= height - desired;
15989
+ object.clickInfo.bounds.y += (height - desired) / 2;
1595715990 }
1595815991 }
1595915992
15960
- info.g = gr;
15961
- info.camera = renderCamera;
15993
+ object.clickInfo.g = gr;
15994
+ object.clickInfo.camera = renderCamera;
1596215995 /*
1596315996 // Memory intensive (brep.verticescopy)
1596415997 if (!(object instanceof Composite))
1596515998 object.draw(info, 0, false); // SLOW :
1596615999 */
15967
- if (!isRenderer)
16000
+ if (!isRenderer) // && drag)
1596816001 {
1596916002 Grafreed.Assert(object != null);
1597016003 Grafreed.Assert(object.selection != null);
....@@ -15972,9 +16005,9 @@
1597216005 {
1597316006 int hitSomething = object.selection.get(0).hitSomething;
1597416007
15975
- info.DX = 0;
15976
- info.DY = 0;
15977
- info.W = 1;
16008
+ object.clickInfo.DX = 0;
16009
+ object.clickInfo.DY = 0;
16010
+ object.clickInfo.W = 1;
1597816011 if (hitSomething == Object3D.hitCenter)
1597916012 {
1598016013 info.DX = X;
....@@ -15986,7 +16019,8 @@
1598616019 info.DY -= info.bounds.height/2;
1598716020 }
1598816021
15989
- object.drawEditHandles(info, 0);
16022
+ object.drawEditHandles(//info,
16023
+ 0);
1599016024
1599116025 if (drag && (X != 0 || Y != 0))
1599216026 {
....@@ -15999,7 +16033,7 @@
1599916033 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1600016034 break;
1600116035 case Object3D.hitScale: gr.setColor(Color.cyan);
16002
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16036
+ gr.drawLine(X, Y, 0, 0);
1600316037 break;
1600416038 }
1600516039