Normand Briere
2019-08-13 c67de8aca04d988179191ccb52461af00125920e
CameraPane.java
....@@ -110,7 +110,9 @@
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;
114116 boolean reverseUP = false;
115117 static boolean frozen = false;
116118 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -173,7 +175,7 @@
173175 static boolean doublesided = false; // true; // reversed normals are awful for conformance
174176 boolean anisotropy = true;
175177 boolean softshadow = true; // slower but better false;
176
- boolean opacityhalo = false;
178
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
177179
178180 boolean macromode = false;
179181
....@@ -188,15 +190,16 @@
188190
189191 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190192
191
- public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
193
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192194 {
193195 try
194196 {
195
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
197
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196198 } catch (IOException e)
197199 {
198200 System.out.println("NAME = " + name);
199201 e.printStackTrace(); // throw new RuntimeException(e);
202
+ return null;
200203 }
201204 }
202205
....@@ -8358,7 +8361,7 @@
83588361 // else
83598362 // if (!texname.startsWith("/"))
83608363 // texname = "/Users/nbriere/Textures/" + texname;
8361
- if (!FileExists(texname))
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
83628365 {
83638366 texname = fallbackTextureName;
83648367 }
....@@ -8441,6 +8444,15 @@
84418444 new Exception().printStackTrace();
84428445 } else
84438446 {
8447
+ if (texname.startsWith("@"))
8448
+ {
8449
+ // texturecache = textures.get(texname); // suspicious
8450
+ if (texturecache == null)
8451
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8452
+ else
8453
+ new Exception().printStackTrace();
8454
+ } else
8455
+ {
84448456 if (textureon)
84458457 {
84468458 String cachename = texname;
....@@ -8500,6 +8512,7 @@
85008512 texturecache = new CacheTexture(texturedata,resolution);
85018513 //texture = GetTexture(tex, bump);
85028514 }
8515
+ }
85038516 }
85048517 //}
85058518 }
....@@ -8768,10 +8781,12 @@
87688781
87698782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
87708783 MAXSTACK = temp[0];
8771
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
87728786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
87738787 MAXSTACK = temp[0];
8774
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
87758790
87768791 // Use debug pipeline
87778792 //drawable.setGL(new DebugGL(gl)); //
....@@ -8779,7 +8794,8 @@
87798794 gl = drawable.getGL(); //
87808795
87818796 GL gl3 = getGL();
8782
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
87838799
87848800
87858801 //float pos[] = { 100, 100, 100, 0 };
....@@ -9220,6 +9236,8 @@
92209236
92219237 void LoadEnvy(int which)
92229238 {
9239
+ assert(false);
9240
+
92239241 String name;
92249242 String ext;
92259243
....@@ -9316,10 +9334,9 @@
93169334 double[] light2camera = new double[16];
93179335
93189336 //int newenvy = -1;
9319
- boolean envyoff = true; // false;
9320
- String skyboxname = "";
9321
- String skyboxext;
9322
- String loadedskyboxname = "";
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
93239340
93249341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
93259342 //float[] light0 = { 0,0,0 };
....@@ -10842,7 +10859,7 @@
1084210859
1084310860 if (wait)
1084410861 {
10845
- Sleep(500);
10862
+ Sleep(200); // blocks everything
1084610863
1084710864 wait = false;
1084810865 }
....@@ -11065,10 +11082,32 @@
1106511082 //
1106611083 // newenvy = -1;
1106711084
11068
- if (!skyboxname.equals(this.loadedskyboxname))
11085
+ if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1106911086 {
11070
- LoadSkybox(skyboxname + "/", skyboxext, false);
11071
- loadedskyboxname = skyboxname;
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
11093
+ }
11094
+ else
11095
+ {
11096
+ if (object.skyboxname != null)
11097
+ {
11098
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11099
+ {
11100
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11101
+ loadedskyboxname = object.skyboxname;
11102
+ }
11103
+ }
11104
+ else
11105
+ {
11106
+ cubemapcustom = null;
11107
+ loadedskyboxname = null;
11108
+ }
11109
+
11110
+ cubemap = cubemapcustom;
1107211111 }
1107311112
1107411113 ratio = ((double) getWidth()) / getHeight();
....@@ -11372,7 +11411,7 @@
1137211411
1137311412 // if (cam != lightCamera)
1137411413 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11375
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11414
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1137611415 }
1137711416
1137811417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -12446,7 +12485,7 @@
1244612485
1244712486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1244812487
12449
- String program0 =
12488
+ String programmin =
1245012489 // Min shader
1245112490 "!!ARBfp1.0\n" +
1245212491 "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
....@@ -12513,7 +12552,7 @@
1251312552 "MOV result.color, temp;" +
1251412553 "END";
1251512554
12516
- String program =
12555
+ String programmax =
1251712556 "!!ARBfp1.0\n" +
1251812557
1251912558 //"OPTION ARB_fragment_program_shadow;" +
....@@ -13369,6 +13408,13 @@
1336913408 //once = true;
1337013409 }
1337113410
13411
+ String program = programmax;
13412
+
13413
+ if (Globals.MINSHADER)
13414
+ {
13415
+ program = programmin;
13416
+ }
13417
+
1337213418 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1337313419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1337413420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -14618,9 +14664,9 @@
1461814664 MODIFIERS |= COMMAND;
1461914665 /**/
1462014666 if((mod&SHIFT) == SHIFT)
14621
- manipCamera.RotatePosition(0, -speed);
14622
- else
1462314667 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14668
+ else
14669
+ manipCamera.RotatePosition(0, -speed);
1462414670 /**/
1462514671 if ((mod & SHIFT) == SHIFT)
1462614672 {
....@@ -14639,9 +14685,9 @@
1463914685 MODIFIERS |= COMMAND;
1464014686 /**/
1464114687 if((mod&SHIFT) == SHIFT)
14642
- manipCamera.RotatePosition(0, speed);
14643
- else
1464414688 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14689
+ else
14690
+ manipCamera.RotatePosition(0, speed);
1464514691 /**/
1464614692 if ((mod & SHIFT) == SHIFT)
1464714693 {
....@@ -15362,7 +15408,7 @@
1536215408 OCCLUSION_CULLING ^= true;
1536315409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1536415410 break;
15365
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1536615412 case '1':
1536715413 case '2':
1536815414 case '3':
....@@ -15372,7 +15418,7 @@
1537215418 case '7':
1537315419 case '8':
1537415420 case '9':
15375
- if (envyoff)
15421
+ if (true) // envyoff)
1537615422 {
1537715423 BGcolor = (key - '1')/8.f;
1537815424 }
....@@ -16084,7 +16130,7 @@
1608416130 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1608516131 break;
1608616132 case Object3D.hitScale: gr.setColor(Color.cyan);
16087
- gr.drawLine(X, Y, 0, 0);
16133
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1608816134 break;
1608916135 }
1609016136
....@@ -16633,6 +16679,7 @@
1663316679
1663416680 return cubemap;
1663516681 }
16682
+
1663616683 int bigsphere = -1;
1663716684
1663816685 float BGcolor = 0.5f;
....@@ -16641,7 +16688,9 @@
1664116688
1664216689 private void DrawSkyBox(GL gl, float ratio)
1664316690 {
16644
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1664516694 {
1664616695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1664716696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16658,14 +16707,14 @@
1665816707 gl.glLoadIdentity();
1665916708 gl.glScalef(1,ratio,1);
1666016709
16661
- colorV[0] = 2;
16662
- colorV[1] = 2;
16663
- colorV[2] = 2;
16664
- colorV[3] = 1;
16665
- gl.glDisable(gl.GL_COLOR_MATERIAL);
16666
- gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16667
-
16668
- gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16710
+// colorV[0] = 2;
16711
+// colorV[1] = 2;
16712
+// colorV[2] = 2;
16713
+// colorV[3] = 1;
16714
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16715
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16716
+//
16717
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
1666916718
1667016719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1667116720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
....@@ -16679,7 +16728,7 @@
1667916728 // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting
1668016729 // causes the normals to be sent down. Thanks to Ken Dyke.
1668116730 //gl.glEnable(GL.GL_LIGHTING);
16682
- gl.glEnable(GL.GL_LIGHTING);
16731
+ gl.glDisable(GL.GL_LIGHTING);
1668316732
1668416733 gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
1668516734 gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
....@@ -17503,10 +17552,14 @@
1750317552 gl.glFlush();
1750417553
1750517554 /**/
17506
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17555
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1750717556
17508
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1750917558
17559
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17560
+
17561
+ int[] pixels = selectsizebuffer.array();
17562
+
1751017563 double r = 0, g = 0, b = 0;
1751117564
1751217565 double count = 0;
....@@ -17517,7 +17570,7 @@
1751717570
1751817571 double FACTOR = 1;
1751917572
17520
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1752117574 {
1752217575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1752317576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17600,7 +17653,7 @@
1760017653
1760117654 double scale = ray.z; // 1; // cos
1760217655
17603
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1760417657
1760517658 /*
1760617659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17797,11 +17850,14 @@
1779717850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1779817851 static IntBuffer bigAAbuffer;
1779917852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17800
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1780117854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1780217855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1780317856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17804
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17857
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17858
+
17859
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17860
+
1780517861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1780617862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1780717863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();