Normand Briere
2019-08-20 564f4d12d93813b5d680fc24d4f118c3886d96ed
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
....@@ -188,15 +192,16 @@
188192
189193 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190194
191
- public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192196 {
193197 try
194198 {
195
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196200 } catch (IOException e)
197201 {
198202 System.out.println("NAME = " + name);
199203 e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
200205 }
201206 }
202207
....@@ -1814,7 +1819,7 @@
18141819
18151820 display.modelParams7[0] = 0;
18161821 display.modelParams7[1] = 1000;
1817
- display.modelParams7[2] = 0;
1822
+ display.modelParams7[2] = material.parallax;
18181823 display.modelParams7[3] = 0;
18191824
18201825 //display.modelParams6[0] = 100; // criss de bug de bump
....@@ -2047,9 +2052,9 @@
20472052 switch(viewcode)
20482053 {
20492054 case 0: return "main";
2050
- case 1: return "one";
2051
- case 2: return "two";
2052
- case 3: return "three";
2055
+ case 1: return "Red";
2056
+ case 2: return "Green";
2057
+ case 3: return "Blue";
20532058 case 4: return "light";
20542059 }
20552060
....@@ -2512,7 +2517,7 @@
25122517 com.sun.opengl.util.texture.TextureIO.newTextureData(
25132518 getClass().getClassLoader().getResourceAsStream(name),
25142519 true,
2515
- com.sun.opengl.util.texture.TextureIO.PNG);
2520
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
25162521 } catch (java.io.IOException e)
25172522 {
25182523 throw new javax.media.opengl.GLException(e);
....@@ -9233,6 +9238,8 @@
92339238
92349239 void LoadEnvy(int which)
92359240 {
9241
+ assert(false);
9242
+
92369243 String name;
92379244 String ext;
92389245
....@@ -10683,9 +10690,18 @@
1068310690 static boolean init = false;
1068410691
1068510692 double[][] matrix = LA.newMatrix();
10693
+
10694
+ // This is to refresh the UI of the material panel.
10695
+ ObjEditor patchMaterial;
1068610696
1068710697 public void display(GLAutoDrawable drawable)
1068810698 {
10699
+ if (patchMaterial.patchMaterial)
10700
+ {
10701
+ patchMaterial.patchMaterial = false;
10702
+ patchMaterial.objectPanel.setSelectedIndex(1);
10703
+ }
10704
+
1068910705 if (Grafreed.savesound && Grafreed.hassound)
1069010706 {
1069110707 Grafreed.wav.save();
....@@ -11077,18 +11093,34 @@
1107711093 //
1107811094 // newenvy = -1;
1107911095
11080
- if (object.skyboxname != null)
11096
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1108111097 {
11082
- if (!object.skyboxname.equals(this.loadedskyboxname))
11098
+ if (cubemaprgb == null)
1108311099 {
11084
- LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11085
- loadedskyboxname = object.skyboxname;
11100
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
1108611101 }
11102
+
11103
+ cubemap = cubemaprgb;
1108711104 }
1108811105 else
1108911106 {
11090
- cubemap = null;
11091
- loadedskyboxname = null;
11107
+ if (object.skyboxname != null)
11108
+ {
11109
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11110
+ {
11111
+ if (cubemap != null && cubemap != cubemaprgb)
11112
+ cubemap.dispose();
11113
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11114
+ loadedskyboxname = object.skyboxname;
11115
+ }
11116
+ }
11117
+ else
11118
+ {
11119
+ cubemapcustom = null;
11120
+ loadedskyboxname = null;
11121
+ }
11122
+
11123
+ cubemap = cubemapcustom;
1109211124 }
1109311125
1109411126 ratio = ((double) getWidth()) / getHeight();
....@@ -12561,7 +12593,7 @@
1256112593 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1256212594 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1256312595 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
12564
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12596
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1256512597 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1256612598 "PARAM options1 = program.env[62];" + // fog rgb color
1256712599 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -12806,7 +12838,7 @@
1280612838 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1280712839 // mar 2013 ??? "KIL alpha.a;" +
1280812840 "MOV alpha, texSamp.aaaa;" + // y;" +
12809
- "KIL alpha.a;" +
12841
+ "KIL alpha.a;" + // not sure with parallax mapping
1281012842 /*
1281112843 "MUL temp.xy, temp, two;" +
1281212844 "TXB bump, temp, texture[0], 2D;" +
....@@ -12892,11 +12924,6 @@
1289212924 "SUB bump0, bump0, half;" +
1289312925 "ADD bump, bump, bump0;" +
1289412926
12895
- "MOV temp.x, texSamp.a;" +
12896
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12897
- //"LRP texSamp0, params5.x, texSamp0, one;" +
12898
- "MOV texSamp.a, temp.x;" +
12899
-
1290012927 // double-sided
1290112928 /**/
1290212929 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -12926,6 +12953,41 @@
1292612953 Normalize("U") +
1292712954
1292812955 // parallax mapping
12956
+
12957
+ "DP3 temp2.x, V, eye;" +
12958
+ "DP3 temp2.y, U, eye;" +
12959
+ "DP3 temp2.z, normal, eye;" +
12960
+ "RCP temp2.z, temp2.z;" +
12961
+
12962
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12963
+ "RSQ temp2.w, temp2.w;" +
12964
+ "RCP temp2.w, temp2.w;" +
12965
+
12966
+ "SUB temp2.w, temp2.w, half;" +
12967
+// "SGE temp.x, temp2.w, eps.x;" +
12968
+// "MUL temp2.w, temp2.w, temp.x;" +
12969
+
12970
+ //"MOV texSamp, U;" +
12971
+
12972
+ "MUL temp2.z, temp2.z, temp2.w;" +
12973
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12974
+
12975
+ "MUL temp2, temp2, temp2.z;" +
12976
+
12977
+ "MOV temp, fragment.texcoord[0];" +
12978
+
12979
+ "SUB temp, temp, temp2;" +
12980
+
12981
+ "TEX texSamp, temp, texture[0], 2D;" +
12982
+ "POW texSamp.a, texSamp.a, params6.w;" + // punch through
12983
+ "MOV alpha, texSamp.aaaa;" +
12984
+
12985
+// parallax mapping
12986
+
12987
+ "MOV temp.x, texSamp.a;" +
12988
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
12989
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
12990
+ "MOV texSamp.a, temp.x;" +
1292912991
1293012992 //"MOV temp, fragment.texcoord[0];" +
1293112993 //
....@@ -13396,8 +13458,12 @@
1339613458 program = programmin;
1339713459 }
1339813460
13399
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13400
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13461
+ if (Globals.DEBUG)
13462
+ {
13463
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13464
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13465
+ }
13466
+
1340113467 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1340213468
1340313469 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13444,7 +13510,8 @@
1344413510 "\n" +
1344513511 "END\n";
1344613512
13447
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13513
+ if (Globals.DEBUG)
13514
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1344813515 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1344913516
1345013517 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13702,7 +13769,7 @@
1370213769 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1370313770 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1370413771 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
13705
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
13772
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
1370613773
1370713774 //Object3D.cVector2[] vector2buffer;
1370813775
....@@ -14643,11 +14710,17 @@
1464314710 void GoDown(int mod)
1464414711 {
1464514712 MODIFIERS |= COMMAND;
14713
+ boolean isVR = (mouseMode&VR)!=0;
1464614714 /**/
1464714715 if((mod&SHIFT) == SHIFT)
14648
- manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14716
+ {
14717
+ if (isVR)
14718
+ manipCamera.RotateInterest(0, -speed);
14719
+ else
14720
+ manipCamera.RotatePosition(0, -speed);
14721
+ }
1464914722 else
14650
- manipCamera.RotatePosition(0, -speed);
14723
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
1465114724 /**/
1465214725 if ((mod & SHIFT) == SHIFT)
1465314726 {
....@@ -14657,6 +14730,8 @@
1465714730 mouseMode |= BACKFORTH;
1465814731 }
1465914732
14733
+ targetLookAt.set(manipCamera.lookAt);
14734
+
1466014735 //prevX = X = anchorX;
1466114736 prevY = Y = anchorY - (int) (renderCamera.Distance());
1466214737 }
....@@ -14665,10 +14740,17 @@
1466514740 {
1466614741 MODIFIERS |= COMMAND;
1466714742 /**/
14743
+ boolean isVR = (mouseMode&VR)!=0;
14744
+
1466814745 if((mod&SHIFT) == SHIFT)
14669
- manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14746
+ {
14747
+ if (isVR)
14748
+ manipCamera.RotateInterest(0, speed);
14749
+ else
14750
+ manipCamera.RotatePosition(0, speed);
14751
+ }
1467014752 else
14671
- manipCamera.RotatePosition(0, speed);
14753
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
1467214754 /**/
1467314755 if ((mod & SHIFT) == SHIFT)
1467414756 {
....@@ -14678,6 +14760,8 @@
1467814760 mouseMode |= BACKFORTH;
1467914761 }
1468014762
14763
+ targetLookAt.set(manipCamera.lookAt);
14764
+
1468114765 //prevX = X = anchorX;
1468214766 prevY = Y = anchorY + (int) (renderCamera.Distance());
1468314767 }
....@@ -14687,9 +14771,14 @@
1468714771 MODIFIERS |= COMMAND;
1468814772 /**/
1468914773 if((mod&SHIFT) == SHIFT)
14690
- manipCamera.Translate(speed*delta, 0, getWidth());
14774
+ manipCamera.Translate(speed*delta, 0, getWidth());
1469114775 else
14692
- manipCamera.RotatePosition(speed, 0);
14776
+ {
14777
+ if ((mouseMode&VR)!=0)
14778
+ manipCamera.RotateInterest(-speed, 0);
14779
+ else
14780
+ manipCamera.RotatePosition(speed, 0);
14781
+ }
1469314782 /**/
1469414783 if ((mod & SHIFT) == SHIFT)
1469514784 {
....@@ -14699,6 +14788,8 @@
1469914788 mouseMode |= ROTATE;
1470014789 } // TRANSLATE;
1470114790
14791
+ targetLookAt.set(manipCamera.lookAt);
14792
+
1470214793 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1470314794 prevY = Y = anchorY;
1470414795 }
....@@ -14708,9 +14799,15 @@
1470814799 MODIFIERS |= COMMAND;
1470914800 /**/
1471014801 if((mod&SHIFT) == SHIFT)
14711
- manipCamera.Translate(-speed*delta, 0, getWidth());
14802
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1471214803 else
14713
- manipCamera.RotatePosition(-speed, 0);
14804
+ {
14805
+ if ((mouseMode&VR)!=0)
14806
+ manipCamera.RotateInterest(speed, 0);
14807
+ else
14808
+ manipCamera.RotatePosition(-speed, 0);
14809
+ }
14810
+
1471414811 /**/
1471514812 if ((mod & SHIFT) == SHIFT)
1471614813 {
....@@ -14720,6 +14817,8 @@
1472014817 mouseMode |= ROTATE;
1472114818 } // TRANSLATE;
1472214819
14820
+ targetLookAt.set(manipCamera.lookAt);
14821
+
1472314822 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1472414823 prevY = Y = anchorY;
1472514824 }
....@@ -15222,8 +15321,8 @@
1522215321 case 'K':
1522315322 KOMPACTTEXTURE ^= true;
1522415323 //textures.clear();
15225
- break;
15226
- case 'P': // Texture Projection macros
15324
+ // break;
15325
+ //case 'P': // Texture Projection macros
1522715326 // SAVETEXTURE ^= true;
1522815327 macromode = true;
1522915328 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -15344,7 +15443,7 @@
1534415443 targetLookAt.set(manipCamera.lookAt);
1534515444 repaint();
1534615445 break;
15347
- case 'p':
15446
+ case 'P': // p':
1534815447 // c'est quoi ca au juste? spherical ^= true;
1534915448 Skinshader ^= true; programInitialized = false;
1535015449 repaint();
....@@ -16104,7 +16203,7 @@
1610416203 {
1610516204 switch (hitSomething)
1610616205 {
16107
- case Object3D.hitCenter: gr.setColor(Color.pink);
16206
+ case Object3D.hitCenter: gr.setColor(Color.white);
1610816207 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1610916208 break;
1611016209 case Object3D.hitRotate: gr.setColor(Color.yellow);
....@@ -16130,7 +16229,7 @@
1613016229 if (hasMarquee)
1613116230 {
1613216231 gr.setXORMode(Color.white);
16133
- gr.setColor(Color.red);
16232
+ gr.setColor(Color.white);
1613416233 if (!firstime)
1613516234 {
1613616235 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16769,7 +16868,8 @@
1676916868 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1677016869
1677116870 cubemap.disable();
16772
- ////cubemap.unbind();
16871
+ //cubemap.dispose();
16872
+
1677316873 if (CULLFACE)
1677416874 {
1677516875 gl.glEnable(gl.GL_CULL_FACE);
....@@ -17305,6 +17405,7 @@
1730517405
1730617406 public void init(GLAutoDrawable drawable)
1730717407 {
17408
+ if (Globals.DEBUG)
1730817409 System.out.println("shadow buffer init");
1730917410
1731017411 GL gl = drawable.getGL();
....@@ -17533,10 +17634,14 @@
1753317634 gl.glFlush();
1753417635
1753517636 /**/
17536
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17637
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1753717638
17538
- float[] pixels = occlusionsizebuffer.array();
17639
+ float[] depths = occlusiondepthbuffer.array();
1753917640
17641
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17642
+
17643
+ int[] pixels = selectsizebuffer.array();
17644
+
1754017645 double r = 0, g = 0, b = 0;
1754117646
1754217647 double count = 0;
....@@ -17547,7 +17652,7 @@
1754717652
1754817653 double FACTOR = 1;
1754917654
17550
- for (int i = 0; i < pixels.length; i++)
17655
+ for (int i = 0; i < depths.length; i++)
1755117656 {
1755217657 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1755317658 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17630,7 +17735,7 @@
1763017735
1763117736 double scale = ray.z; // 1; // cos
1763217737
17633
- float depth = pixels[newindex];
17738
+ float depth = depths[newindex];
1763417739
1763517740 /*
1763617741 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17827,11 +17932,14 @@
1782717932 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1782817933 static IntBuffer bigAAbuffer;
1782917934 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17830
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17935
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1783117936 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1783217937 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1783317938 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17834
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17939
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17940
+
17941
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17942
+
1783517943 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1783617944 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1783717945 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();