.. | .. |
---|
187 | 187 | } |
---|
188 | 188 | |
---|
189 | 189 | private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory(); |
---|
| 190 | + |
---|
| 191 | + public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException |
---|
| 192 | + { |
---|
| 193 | + try |
---|
| 194 | + { |
---|
| 195 | + cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
| 196 | + } catch (IOException e) |
---|
| 197 | + { |
---|
| 198 | + System.out.println("NAME = " + name); |
---|
| 199 | + e.printStackTrace(); // throw new RuntimeException(e); |
---|
| 200 | + } |
---|
| 201 | + } |
---|
190 | 202 | |
---|
191 | 203 | void SetAsGLRenderer(boolean b) |
---|
192 | 204 | { |
---|
.. | .. |
---|
206 | 218 | |
---|
207 | 219 | SetCamera(cam); |
---|
208 | 220 | |
---|
209 | | - SetLight(new Camera(new cVector(10, 10, -20))); |
---|
| 221 | + // Warning: not used. |
---|
| 222 | + SetLight(new Camera(new cVector(15, 10, -20))); |
---|
210 | 223 | |
---|
211 | 224 | object = o; |
---|
212 | 225 | |
---|
.. | .. |
---|
1484 | 1497 | gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z); |
---|
1485 | 1498 | } |
---|
1486 | 1499 | |
---|
| 1500 | + float[] colorV = new float[4]; |
---|
| 1501 | + |
---|
1487 | 1502 | void SetColor(Object3D obj, Vertex p0) |
---|
1488 | 1503 | { |
---|
1489 | 1504 | CameraPane display = this; |
---|
.. | .. |
---|
1551 | 1566 | { |
---|
1552 | 1567 | return; |
---|
1553 | 1568 | } |
---|
1554 | | - |
---|
1555 | | - float[] colorV = new float[3]; |
---|
1556 | 1569 | |
---|
1557 | 1570 | if (false) // marked) |
---|
1558 | 1571 | { |
---|
.. | .. |
---|
8345 | 8358 | // else |
---|
8346 | 8359 | // if (!texname.startsWith("/")) |
---|
8347 | 8360 | // texname = "/Users/nbriere/Textures/" + texname; |
---|
8348 | | - if (!FileExists(texname)) |
---|
| 8361 | + if (!FileExists(texname) && !texname.startsWith("@")) |
---|
8349 | 8362 | { |
---|
8350 | 8363 | texname = fallbackTextureName; |
---|
8351 | 8364 | } |
---|
.. | .. |
---|
8428 | 8441 | new Exception().printStackTrace(); |
---|
8429 | 8442 | } else |
---|
8430 | 8443 | { |
---|
| 8444 | + if (texname.startsWith("@")) |
---|
| 8445 | + { |
---|
| 8446 | + // texturecache = textures.get(texname); // suspicious |
---|
| 8447 | + if (texturecache == null) |
---|
| 8448 | + texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution); |
---|
| 8449 | + else |
---|
| 8450 | + new Exception().printStackTrace(); |
---|
| 8451 | + } else |
---|
| 8452 | + { |
---|
8431 | 8453 | if (textureon) |
---|
8432 | 8454 | { |
---|
8433 | 8455 | String cachename = texname; |
---|
.. | .. |
---|
8487 | 8509 | texturecache = new CacheTexture(texturedata,resolution); |
---|
8488 | 8510 | //texture = GetTexture(tex, bump); |
---|
8489 | 8511 | } |
---|
| 8512 | + } |
---|
8490 | 8513 | } |
---|
8491 | 8514 | //} |
---|
8492 | 8515 | } |
---|
.. | .. |
---|
8931 | 8954 | |
---|
8932 | 8955 | if (cubemap == null) |
---|
8933 | 8956 | { |
---|
8934 | | - LoadEnvy(5); |
---|
| 8957 | + //LoadEnvy(1); |
---|
8935 | 8958 | } |
---|
8936 | 8959 | |
---|
8937 | 8960 | //cubemap.enable(); |
---|
.. | .. |
---|
9218 | 9241 | cubemap = null; |
---|
9219 | 9242 | return; |
---|
9220 | 9243 | case 1: |
---|
9221 | | - name = "cubemaps/box_"; |
---|
9222 | | - ext = "png"; |
---|
| 9244 | + name = "cubemaps/rgb/"; |
---|
| 9245 | + ext = "jpg"; |
---|
9223 | 9246 | reverseUP = false; |
---|
9224 | 9247 | break; |
---|
9225 | 9248 | case 2: |
---|
9226 | | - name = "cubemaps/uffizi_"; |
---|
9227 | | - ext = "png"; |
---|
9228 | | - break; // reverseUP = true; break; |
---|
| 9249 | + name = "cubemaps/uffizi/"; |
---|
| 9250 | + ext = "jpg"; |
---|
| 9251 | + reverseUP = false; |
---|
| 9252 | + break; |
---|
9229 | 9253 | case 3: |
---|
9230 | | - name = "cubemaps/CloudyHills_"; |
---|
9231 | | - ext = "tga"; |
---|
| 9254 | + name = "cubemaps/CloudyHills/"; |
---|
| 9255 | + ext = "jpg"; |
---|
9232 | 9256 | reverseUP = false; |
---|
9233 | 9257 | break; |
---|
9234 | 9258 | case 4: |
---|
9235 | | - name = "cubemaps/cornell_"; |
---|
| 9259 | + name = "cubemaps/cornell/"; |
---|
9236 | 9260 | ext = "png"; |
---|
9237 | 9261 | reverseUP = false; |
---|
9238 | 9262 | break; |
---|
| 9263 | + case 5: |
---|
| 9264 | + name = "cubemaps/skycube/"; |
---|
| 9265 | + ext = "jpg"; |
---|
| 9266 | + reverseUP = false; |
---|
| 9267 | + break; |
---|
| 9268 | + case 6: |
---|
| 9269 | + name = "cubemaps/SaintLazarusChurch3/"; |
---|
| 9270 | + ext = "jpg"; |
---|
| 9271 | + reverseUP = false; |
---|
| 9272 | + break; |
---|
| 9273 | + case 7: |
---|
| 9274 | + name = "cubemaps/Sodermalmsallen/"; |
---|
| 9275 | + ext = "jpg"; |
---|
| 9276 | + reverseUP = false; |
---|
| 9277 | + break; |
---|
| 9278 | + case 8: |
---|
| 9279 | + name = "cubemaps/Sodermalmsallen2/"; |
---|
| 9280 | + ext = "jpg"; |
---|
| 9281 | + reverseUP = false; |
---|
| 9282 | + break; |
---|
| 9283 | + case 9: |
---|
| 9284 | + name = "cubemaps/UnionSquare/"; |
---|
| 9285 | + ext = "jpg"; |
---|
| 9286 | + reverseUP = false; |
---|
| 9287 | + break; |
---|
9239 | 9288 | default: |
---|
9240 | | - name = "cubemaps/rgb_"; |
---|
9241 | | - ext = "png"; /*mipmap = true;*/ reverseUP = false; |
---|
| 9289 | + name = "cubemaps/box/"; |
---|
| 9290 | + ext = "png"; /*mipmap = true;*/ |
---|
| 9291 | + reverseUP = false; |
---|
9242 | 9292 | break; |
---|
9243 | 9293 | } |
---|
9244 | | - |
---|
9245 | | - try |
---|
9246 | | - { |
---|
9247 | | - cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap); |
---|
9248 | | - } catch (IOException e) |
---|
9249 | | - { |
---|
9250 | | - throw new RuntimeException(e); |
---|
9251 | | - } |
---|
| 9294 | + |
---|
| 9295 | + LoadSkybox(name, ext, mipmap); |
---|
9252 | 9296 | } |
---|
9253 | 9297 | |
---|
9254 | 9298 | public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) |
---|
.. | .. |
---|
9280 | 9324 | static double[] model = new double[16]; |
---|
9281 | 9325 | double[] camera2light = new double[16]; |
---|
9282 | 9326 | double[] light2camera = new double[16]; |
---|
9283 | | - int newenvy = -1; |
---|
9284 | | - boolean envyoff = true; // false; |
---|
| 9327 | + |
---|
| 9328 | + //int newenvy = -1; |
---|
| 9329 | + //boolean envyoff = false; |
---|
| 9330 | + |
---|
| 9331 | + String loadedskyboxname; |
---|
| 9332 | + |
---|
9285 | 9333 | cVector light0 = new cVector(0, 0, 0); // 1,3,2); |
---|
9286 | 9334 | //float[] light0 = { 0,0,0 }; |
---|
9287 | 9335 | cVector dirlight = new cVector(0, 0, 1); // 1,3,2); |
---|
.. | .. |
---|
9699 | 9747 | |
---|
9700 | 9748 | if (renderCamera != lightCamera) |
---|
9701 | 9749 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9702 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 9750 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
9703 | 9751 | |
---|
9704 | 9752 | // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix); |
---|
9705 | 9753 | |
---|
.. | .. |
---|
9715 | 9763 | |
---|
9716 | 9764 | if (renderCamera != lightCamera) |
---|
9717 | 9765 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
9718 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 9766 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
9719 | 9767 | |
---|
9720 | 9768 | // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix); |
---|
9721 | 9769 | |
---|
.. | .. |
---|
9761 | 9809 | rati = 1 / rati; |
---|
9762 | 9810 | gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000); |
---|
9763 | 9811 | } |
---|
9764 | | - assert (newenvy == -1); |
---|
| 9812 | + |
---|
| 9813 | + //assert (newenvy == -1); |
---|
| 9814 | + |
---|
9765 | 9815 | gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9766 | 9816 | gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9767 | | - DrawSkyBox(gl); |
---|
| 9817 | + DrawSkyBox(gl, (float)rati); |
---|
9768 | 9818 | gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); |
---|
9769 | 9819 | gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB); |
---|
9770 | 9820 | accPerspective(gl, renderCamera.shaper_fovy / ratio, |
---|
.. | .. |
---|
10801 | 10851 | |
---|
10802 | 10852 | if (wait) |
---|
10803 | 10853 | { |
---|
10804 | | - Sleep(500); |
---|
| 10854 | + Sleep(200); // blocks everything |
---|
10805 | 10855 | |
---|
10806 | 10856 | wait = false; |
---|
10807 | 10857 | } |
---|
.. | .. |
---|
10916 | 10966 | // if (parentcam != renderCamera) // not a light |
---|
10917 | 10967 | if (cam != lightCamera) |
---|
10918 | 10968 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10919 | | - LA.matConcat(matrix, parentcam.GlobalTransform(), matrix); |
---|
| 10969 | + LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix); |
---|
10920 | 10970 | |
---|
10921 | 10971 | for (int j = 0; j < 4; j++) |
---|
10922 | 10972 | { |
---|
.. | .. |
---|
10931 | 10981 | // if (parentcam != renderCamera) // not a light |
---|
10932 | 10982 | if (cam != lightCamera) |
---|
10933 | 10983 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
10934 | | - LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix); |
---|
| 10984 | + LA.matConcat(parentcam.GlobalTransform(), matrix, matrix); |
---|
10935 | 10985 | |
---|
10936 | 10986 | //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix); |
---|
10937 | 10987 | |
---|
.. | .. |
---|
11017 | 11067 | gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000); |
---|
11018 | 11068 | } |
---|
11019 | 11069 | |
---|
11020 | | - if (newenvy > -1) |
---|
| 11070 | +// if (newenvy > -1) |
---|
| 11071 | +// { |
---|
| 11072 | +// LoadEnvy(newenvy); |
---|
| 11073 | +// } |
---|
| 11074 | +// |
---|
| 11075 | +// newenvy = -1; |
---|
| 11076 | + |
---|
| 11077 | + if (object.skyboxname != null) |
---|
11021 | 11078 | { |
---|
11022 | | - LoadEnvy(newenvy); |
---|
| 11079 | + if (!object.skyboxname.equals(this.loadedskyboxname)) |
---|
| 11080 | + { |
---|
| 11081 | + LoadSkybox(object.skyboxname + "/", object.skyboxext, false); |
---|
| 11082 | + loadedskyboxname = object.skyboxname; |
---|
| 11083 | + } |
---|
11023 | 11084 | } |
---|
11024 | | - |
---|
11025 | | - newenvy = -1; |
---|
11026 | | - |
---|
| 11085 | + else |
---|
| 11086 | + { |
---|
| 11087 | + cubemap = null; |
---|
| 11088 | + loadedskyboxname = null; |
---|
| 11089 | + } |
---|
| 11090 | + |
---|
11027 | 11091 | ratio = ((double) getWidth()) / getHeight(); |
---|
11028 | 11092 | //System.out.println("ratio = " + ratio); |
---|
11029 | 11093 | |
---|
.. | .. |
---|
11039 | 11103 | |
---|
11040 | 11104 | if (!IsFrozen() && !ambientOcclusion) |
---|
11041 | 11105 | { |
---|
11042 | | - DrawSkyBox(gl); |
---|
| 11106 | + DrawSkyBox(gl, (float)ratio); |
---|
11043 | 11107 | } |
---|
11044 | 11108 | |
---|
11045 | 11109 | //if (selection_view == -1) |
---|
.. | .. |
---|
11325 | 11389 | |
---|
11326 | 11390 | // if (cam != lightCamera) |
---|
11327 | 11391 | //for (int count = parentcam.GetTransformCount(); --count>=0;) |
---|
11328 | | - LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013 |
---|
| 11392 | + LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013 |
---|
11329 | 11393 | } |
---|
11330 | 11394 | |
---|
11331 | 11395 | LA.xformDir(lightposition, cam.toScreen, lightposition); |
---|
.. | .. |
---|
12399 | 12463 | |
---|
12400 | 12464 | //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); |
---|
12401 | 12465 | |
---|
12402 | | - String program = |
---|
| 12466 | + String programmin = |
---|
| 12467 | + // Min shader |
---|
12403 | 12468 | "!!ARBfp1.0\n" + |
---|
| 12469 | + "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" + |
---|
| 12470 | + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + |
---|
| 12471 | + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + |
---|
| 12472 | + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + |
---|
| 12473 | + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + |
---|
| 12474 | + "PARAM light2cam0 = program.env[10];" + |
---|
| 12475 | + "PARAM light2cam1 = program.env[11];" + |
---|
| 12476 | + "PARAM light2cam2 = program.env[12];" + |
---|
| 12477 | + "TEMP temp;" + |
---|
| 12478 | + "TEMP light;" + |
---|
| 12479 | + "TEMP ndotl;" + |
---|
| 12480 | + "TEMP normal;" + |
---|
| 12481 | + "TEMP depth;" + |
---|
| 12482 | + "TEMP eye;" + |
---|
| 12483 | + "TEMP pos;" + |
---|
| 12484 | + |
---|
| 12485 | + "MAD normal, fragment.color, zero123.z, -zero123.y;" + |
---|
| 12486 | + Normalize("normal") + |
---|
| 12487 | + "MOV light, state.light[0].position;" + |
---|
| 12488 | + "DP3 ndotl.x, light, normal;" + |
---|
| 12489 | + |
---|
| 12490 | + // shadow |
---|
| 12491 | + "MOV pos, fragment.texcoord[1];" + |
---|
| 12492 | + "MOV temp, pos;" + |
---|
| 12493 | + ShadowTextureFetch("depth", "temp", "1") + |
---|
| 12494 | + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + |
---|
| 12495 | + "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" + |
---|
| 12496 | + |
---|
| 12497 | + // No shadow when out of frustum |
---|
| 12498 | + //"SGE temp.y, depth.z, zero123.y;" + |
---|
| 12499 | + //"LRP temp.x, temp.y, zero123.y, temp.x;" + |
---|
| 12500 | + |
---|
| 12501 | + "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow |
---|
| 12502 | + |
---|
| 12503 | + // Backlit |
---|
| 12504 | + "MOV pos.w, zero123.y;" + |
---|
| 12505 | + "DP4 eye.x, pos, light2cam0;" + |
---|
| 12506 | + "DP4 eye.y, pos, light2cam1;" + |
---|
| 12507 | + "DP4 eye.z, pos, light2cam2;" + |
---|
| 12508 | + Normalize("eye") + |
---|
| 12509 | + |
---|
| 12510 | + "DP3 ndotl.y, -eye, normal;" + |
---|
| 12511 | + //"MUL ndotl.y, ndotl.y, pow2.x;" + |
---|
| 12512 | + "POW ndotl.y, ndotl.y, pow2.z;" + // backlit |
---|
| 12513 | + "SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12514 | + //"SUB ndotl.y, zero123.y, ndotl.y;" + |
---|
| 12515 | + //"MUL ndotl.y, ndotl.y, pow2.z;" + |
---|
| 12516 | + |
---|
| 12517 | + //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient |
---|
| 12518 | + //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient |
---|
| 12519 | + |
---|
| 12520 | + // Pigment |
---|
| 12521 | + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + |
---|
| 12522 | + "LRP temp, zero123.w, temp, one;" + // texture proportion |
---|
| 12523 | + "MUL temp, temp, ndotl.x;" + |
---|
| 12524 | + |
---|
| 12525 | + "MUL temp, temp, zero123.z;" + |
---|
| 12526 | + |
---|
| 12527 | + //"MUL temp, temp, ndotl.y;" + |
---|
| 12528 | + |
---|
| 12529 | + "MOV temp.w, zero123.y;" + // reset alpha |
---|
| 12530 | + "MOV result.color, temp;" + |
---|
| 12531 | + "END"; |
---|
| 12532 | + |
---|
| 12533 | + String programmax = |
---|
| 12534 | + "!!ARBfp1.0\n" + |
---|
| 12535 | + |
---|
12404 | 12536 | //"OPTION ARB_fragment_program_shadow;" + |
---|
12405 | 12537 | "PARAM light2cam0 = program.env[10];" + |
---|
12406 | 12538 | "PARAM light2cam1 = program.env[11];" + |
---|
.. | .. |
---|
12515 | 12647 | "TEMP shininess;" + |
---|
12516 | 12648 | "\n" + |
---|
12517 | 12649 | "MOV texSamp, one;" + |
---|
12518 | | - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + |
---|
12519 | | - |
---|
| 12650 | + |
---|
12520 | 12651 | "MOV mapgrid.x, one2048th.x;" + |
---|
12521 | 12652 | "MOV temp, fragment.texcoord[1];" + |
---|
12522 | 12653 | /* |
---|
.. | .. |
---|
12537 | 12668 | "MUL temp, floor, mapgrid.x;" + |
---|
12538 | 12669 | //"TEX depth0, temp, texture[1], 2D;" + |
---|
12539 | 12670 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12540 | | - TextureFetch("depth0", "temp", "1") + |
---|
| 12671 | + ShadowTextureFetch("depth0", "temp", "1") + |
---|
12541 | 12672 | "") + |
---|
12542 | 12673 | "ADD temp.x, temp.x, mapgrid.x;" + |
---|
12543 | 12674 | //"TEX depth1, temp, texture[1], 2D;" + |
---|
12544 | 12675 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12545 | | - TextureFetch("depth1", "temp", "1") + |
---|
| 12676 | + ShadowTextureFetch("depth1", "temp", "1") + |
---|
12546 | 12677 | "") + |
---|
12547 | 12678 | "ADD temp.y, temp.y, mapgrid.x;" + |
---|
12548 | 12679 | //"TEX depth2, temp, texture[1], 2D;" + |
---|
12549 | | - TextureFetch("depth2", "temp", "1") + |
---|
| 12680 | + ShadowTextureFetch("depth2", "temp", "1") + |
---|
12550 | 12681 | "SUB temp.x, temp.x, mapgrid.x;" + |
---|
12551 | 12682 | //"TEX depth3, temp, texture[1], 2D;" + |
---|
12552 | 12683 | (((mode & FP_SOFTSHADOW) == 0) ? "" : |
---|
12553 | | - TextureFetch("depth3", "temp", "1") + |
---|
| 12684 | + ShadowTextureFetch("depth3", "temp", "1") + |
---|
12554 | 12685 | "") + |
---|
12555 | 12686 | //"MUL texSamp0, texSamp0, state.material.front.diffuse;" + |
---|
12556 | 12687 | //"MOV params, material;" + |
---|
.. | .. |
---|
12921 | 13052 | "MAD shadow.x, buffer.x, frac.y, shadow.x;" + |
---|
12922 | 13053 | "") + |
---|
12923 | 13054 | |
---|
12924 | | - // display shadow only (bump == 0) |
---|
| 13055 | + // display shadow only (fakedepth == 0) |
---|
12925 | 13056 | "SUB temp.x, half.x, shadow.x;" + |
---|
12926 | 13057 | "MOV temp.y, -params5.z;" + // params6.x;" + |
---|
12927 | | - "SLT temp.z, temp.y, -one2048th.x;" + |
---|
| 13058 | + "SLT temp.z, temp.y, -c256i.x;" + |
---|
12928 | 13059 | "SUB temp.y, one.x, temp.z;" + |
---|
12929 | 13060 | "MUL temp.x, temp.x, temp.y;" + |
---|
12930 | 13061 | "KIL temp.x;" + |
---|
.. | .. |
---|
13255 | 13386 | //once = true; |
---|
13256 | 13387 | } |
---|
13257 | 13388 | |
---|
| 13389 | + String program = programmax; |
---|
| 13390 | + |
---|
| 13391 | + if (Globals.MINSHADER) |
---|
| 13392 | + { |
---|
| 13393 | + program = programmin; |
---|
| 13394 | + } |
---|
| 13395 | + |
---|
13258 | 13396 | System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length()); |
---|
13259 | 13397 | System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : "")); |
---|
13260 | 13398 | loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program); |
---|
.. | .. |
---|
13348 | 13486 | return out; |
---|
13349 | 13487 | } |
---|
13350 | 13488 | |
---|
13351 | | - String TextureFetch(String dest, String src, String unit) |
---|
| 13489 | + // Also does frustum culling |
---|
| 13490 | + String ShadowTextureFetch(String dest, String src, String unit) |
---|
13352 | 13491 | { |
---|
13353 | 13492 | return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" + |
---|
13354 | 13493 | "SGE " + src + ".w, " + src + ".x, eps.x;" + |
---|
13355 | 13494 | "SGE " + src + ".z, " + src + ".y, eps.x;" + |
---|
| 13495 | + "SLT " + dest + ".x, " + src + ".x, one.x;" + |
---|
| 13496 | + "SLT " + dest + ".y, " + src + ".y, one.x;" + |
---|
13356 | 13497 | "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;" + |
---|
| 13498 | + "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" + |
---|
| 13499 | + "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" + |
---|
13361 | 13500 | //"SWZ buffer, temp, w,w,w,w;"; |
---|
13362 | | - "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
| 13501 | + //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" + |
---|
13363 | 13502 | "SUB " + src + ".z, " + "one.x, " + src + ".w;" + |
---|
13364 | 13503 | //"MUL " + src + ".z, " + src + ".z, infinity.x;" + |
---|
13365 | 13504 | //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;"; |
---|
13366 | | - "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
| 13505 | + //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13367 | 13506 | |
---|
13368 | | - //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
13369 | | - //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;"; |
---|
| 13507 | + //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;"; |
---|
| 13508 | + "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;"; |
---|
13370 | 13509 | } |
---|
13371 | 13510 | |
---|
13372 | 13511 | String Shadow(String depth, String shadow) |
---|
.. | .. |
---|
13413 | 13552 | "SLT temp.x, temp.x, zero.x;" + // shadoweps |
---|
13414 | 13553 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13415 | 13554 | |
---|
13416 | | - // No shadow when out of frustrum |
---|
| 13555 | + // No shadow when out of frustum |
---|
13417 | 13556 | "SGE temp.x, " + depth + ".z, one.z;" + |
---|
13418 | 13557 | "LRP " + shadow + ", temp.x, one, " + shadow + ";" + |
---|
13419 | 13558 | ""; |
---|
.. | .. |
---|
14211 | 14350 | drag = false; |
---|
14212 | 14351 | //System.out.println("Mouse DOWN"); |
---|
14213 | 14352 | 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); |
---|
| 14353 | + //ClickInfo info = new ClickInfo(); |
---|
| 14354 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14355 | + object.clickInfo.pane = this; |
---|
| 14356 | + object.clickInfo.camera = renderCamera; |
---|
| 14357 | + object.clickInfo.x = x; |
---|
| 14358 | + object.clickInfo.y = y; |
---|
| 14359 | + object.clickInfo.modifiers = modifiersex; |
---|
| 14360 | + editObj = object.doEditClick(//info, |
---|
| 14361 | + 0); |
---|
14222 | 14362 | if (!editObj) |
---|
14223 | 14363 | { |
---|
14224 | 14364 | hasMarquee = true; |
---|
.. | .. |
---|
14502 | 14642 | MODIFIERS |= COMMAND; |
---|
14503 | 14643 | /**/ |
---|
14504 | 14644 | if((mod&SHIFT) == SHIFT) |
---|
14505 | | - manipCamera.RotatePosition(0, -speed); |
---|
14506 | | - else |
---|
14507 | 14645 | manipCamera.BackForth(0, -speed*delta, 0); // getWidth()); |
---|
| 14646 | + else |
---|
| 14647 | + manipCamera.RotatePosition(0, -speed); |
---|
14508 | 14648 | /**/ |
---|
14509 | 14649 | if ((mod & SHIFT) == SHIFT) |
---|
14510 | 14650 | { |
---|
.. | .. |
---|
14523 | 14663 | MODIFIERS |= COMMAND; |
---|
14524 | 14664 | /**/ |
---|
14525 | 14665 | if((mod&SHIFT) == SHIFT) |
---|
14526 | | - manipCamera.RotatePosition(0, speed); |
---|
14527 | | - else |
---|
14528 | 14666 | manipCamera.BackForth(0, speed*delta, 0); // getWidth()); |
---|
| 14667 | + else |
---|
| 14668 | + manipCamera.RotatePosition(0, speed); |
---|
14529 | 14669 | /**/ |
---|
14530 | 14670 | if ((mod & SHIFT) == SHIFT) |
---|
14531 | 14671 | { |
---|
.. | .. |
---|
14618 | 14758 | if (editObj) |
---|
14619 | 14759 | { |
---|
14620 | 14760 | drag = true; |
---|
14621 | | - ClickInfo info = new ClickInfo(); |
---|
14622 | | - info.bounds.setBounds(0, 0, |
---|
| 14761 | + //ClickInfo info = new ClickInfo(); |
---|
| 14762 | + object.clickInfo.bounds.setBounds(0, 0, |
---|
14623 | 14763 | (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); |
---|
| 14764 | + object.clickInfo.pane = this; |
---|
| 14765 | + object.clickInfo.camera = renderCamera; |
---|
| 14766 | + object.clickInfo.x = x; |
---|
| 14767 | + object.clickInfo.y = y; |
---|
| 14768 | + object //.GetWindow().copy |
---|
| 14769 | + .doEditDrag(//info, |
---|
| 14770 | + (modifiers & MouseEvent.BUTTON3_MASK) != 0); |
---|
14630 | 14771 | } else |
---|
14631 | 14772 | { |
---|
14632 | 14773 | if (x < startX) |
---|
.. | .. |
---|
14775 | 14916 | } |
---|
14776 | 14917 | } |
---|
14777 | 14918 | |
---|
| 14919 | +// ClickInfo clickInfo = new ClickInfo(); |
---|
| 14920 | + |
---|
14778 | 14921 | public void mouseMoved(MouseEvent e) |
---|
14779 | 14922 | { |
---|
14780 | 14923 | //System.out.println("mouseMoved: " + e); |
---|
14781 | 14924 | if (isRenderer) |
---|
14782 | 14925 | return; |
---|
14783 | 14926 | |
---|
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; |
---|
| 14927 | + // Mouse cursor feedback |
---|
| 14928 | + object.clickInfo.x = e.getX(); |
---|
| 14929 | + object.clickInfo.y = e.getY(); |
---|
| 14930 | + object.clickInfo.modifiers = e.getModifiersEx(); |
---|
| 14931 | + object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom)); |
---|
| 14932 | + object.clickInfo.pane = this; |
---|
| 14933 | + object.clickInfo.camera = renderCamera; |
---|
14791 | 14934 | if (!isRenderer) |
---|
14792 | 14935 | { |
---|
14793 | 14936 | //ObjEditor editWindow = object.editWindow; |
---|
14794 | 14937 | //Object3D copy = editWindow.copy; |
---|
14795 | | - if (object.doEditClick(ci, 0)) |
---|
| 14938 | + if (object.doEditClick(//clickInfo, |
---|
| 14939 | + 0)) |
---|
14796 | 14940 | { |
---|
14797 | 14941 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); |
---|
14798 | 14942 | } else |
---|
.. | .. |
---|
15242 | 15386 | OCCLUSION_CULLING ^= true; |
---|
15243 | 15387 | System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING); |
---|
15244 | 15388 | break; |
---|
15245 | | - case '0': envyoff ^= true; repaint(); break; |
---|
| 15389 | + //case '0': envyoff ^= true; repaint(); break; |
---|
15246 | 15390 | case '1': |
---|
15247 | 15391 | case '2': |
---|
15248 | 15392 | case '3': |
---|
15249 | 15393 | case '4': |
---|
15250 | 15394 | case '5': |
---|
15251 | | - newenvy = Character.getNumericValue(key); |
---|
15252 | | - repaint(); |
---|
15253 | | - break; |
---|
15254 | 15395 | case '6': |
---|
15255 | 15396 | case '7': |
---|
15256 | 15397 | case '8': |
---|
15257 | 15398 | case '9': |
---|
15258 | | - BGcolor = (key - '6')/3.f; |
---|
| 15399 | + if (true) // envyoff) |
---|
| 15400 | + { |
---|
| 15401 | + BGcolor = (key - '1')/8.f; |
---|
| 15402 | + } |
---|
| 15403 | + else |
---|
| 15404 | + { |
---|
| 15405 | + //newenvy = Character.getNumericValue(key); |
---|
| 15406 | + } |
---|
15259 | 15407 | repaint(); |
---|
15260 | 15408 | break; |
---|
15261 | 15409 | case '!': |
---|
.. | .. |
---|
15818 | 15966 | |
---|
15819 | 15967 | int width = getBounds().width; |
---|
15820 | 15968 | int height = getBounds().height; |
---|
15821 | | - ClickInfo info = new ClickInfo(); |
---|
15822 | | - info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
15823 | 15969 | //Image img = CreateImage(width, height); |
---|
15824 | 15970 | //System.out.println("width = " + width + "; height = " + height + "\n"); |
---|
15825 | 15971 | |
---|
.. | .. |
---|
15896 | 16042 | } |
---|
15897 | 16043 | if (object != null && !hasMarquee) |
---|
15898 | 16044 | { |
---|
| 16045 | + if (object.clickInfo == null) |
---|
| 16046 | + object.clickInfo = new ClickInfo(); |
---|
| 16047 | + ClickInfo info = object.clickInfo; |
---|
| 16048 | + //ClickInfo info = new ClickInfo(); |
---|
| 16049 | + info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom)); |
---|
| 16050 | + |
---|
15899 | 16051 | if (isRenderer) |
---|
15900 | 16052 | { |
---|
15901 | | - info.flags++; |
---|
| 16053 | + object.clickInfo.flags++; |
---|
15902 | 16054 | double frameAspect = (double) width / (double) height; |
---|
15903 | 16055 | if (frameAspect > renderCamera.aspect) |
---|
15904 | 16056 | { |
---|
15905 | 16057 | int desired = (int) ((double) height * renderCamera.aspect); |
---|
15906 | | - info.bounds.width -= width - desired; |
---|
15907 | | - info.bounds.x += (width - desired) / 2; |
---|
| 16058 | + object.clickInfo.bounds.width -= width - desired; |
---|
| 16059 | + object.clickInfo.bounds.x += (width - desired) / 2; |
---|
15908 | 16060 | } else |
---|
15909 | 16061 | { |
---|
15910 | 16062 | int desired = (int) ((double) width / renderCamera.aspect); |
---|
15911 | | - info.bounds.height -= height - desired; |
---|
15912 | | - info.bounds.y += (height - desired) / 2; |
---|
| 16063 | + object.clickInfo.bounds.height -= height - desired; |
---|
| 16064 | + object.clickInfo.bounds.y += (height - desired) / 2; |
---|
15913 | 16065 | } |
---|
15914 | 16066 | } |
---|
15915 | 16067 | |
---|
15916 | | - info.g = gr; |
---|
15917 | | - info.camera = renderCamera; |
---|
| 16068 | + object.clickInfo.g = gr; |
---|
| 16069 | + object.clickInfo.camera = renderCamera; |
---|
15918 | 16070 | /* |
---|
15919 | 16071 | // Memory intensive (brep.verticescopy) |
---|
15920 | 16072 | if (!(object instanceof Composite)) |
---|
15921 | 16073 | object.draw(info, 0, false); // SLOW : |
---|
15922 | 16074 | */ |
---|
15923 | | - if (!isRenderer) |
---|
| 16075 | + if (!isRenderer) // && drag) |
---|
15924 | 16076 | { |
---|
15925 | 16077 | Grafreed.Assert(object != null); |
---|
15926 | 16078 | Grafreed.Assert(object.selection != null); |
---|
.. | .. |
---|
15928 | 16080 | { |
---|
15929 | 16081 | int hitSomething = object.selection.get(0).hitSomething; |
---|
15930 | 16082 | |
---|
15931 | | - info.DX = 0; |
---|
15932 | | - info.DY = 0; |
---|
15933 | | - info.W = 1; |
---|
| 16083 | + object.clickInfo.DX = 0; |
---|
| 16084 | + object.clickInfo.DY = 0; |
---|
| 16085 | + object.clickInfo.W = 1; |
---|
15934 | 16086 | if (hitSomething == Object3D.hitCenter) |
---|
15935 | 16087 | { |
---|
15936 | 16088 | info.DX = X; |
---|
.. | .. |
---|
15942 | 16094 | info.DY -= info.bounds.height/2; |
---|
15943 | 16095 | } |
---|
15944 | 16096 | |
---|
15945 | | - object.drawEditHandles(info, 0); |
---|
| 16097 | + object.drawEditHandles(//info, |
---|
| 16098 | + 0); |
---|
15946 | 16099 | |
---|
15947 | 16100 | if (drag && (X != 0 || Y != 0)) |
---|
15948 | 16101 | { |
---|
.. | .. |
---|
16441 | 16594 | private /*static*/ boolean firstime; |
---|
16442 | 16595 | private /*static*/ cVector newView = new cVector(); |
---|
16443 | 16596 | private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"}; |
---|
| 16597 | + private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"}; |
---|
| 16598 | + private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"}; |
---|
16444 | 16599 | private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, |
---|
16445 | 16600 | GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, |
---|
16446 | 16601 | GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, |
---|
.. | .. |
---|
16453 | 16608 | { |
---|
16454 | 16609 | com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP); |
---|
16455 | 16610 | |
---|
| 16611 | + int usedsuf = 0; |
---|
| 16612 | + |
---|
16456 | 16613 | for (int i = 0; i < suffixes.length; i++) |
---|
16457 | 16614 | { |
---|
16458 | | - String resourceName = basename + suffixes[i] + "." + suffix; |
---|
16459 | | - TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
16460 | | - mipmapped, |
---|
16461 | | - FileUtil.getFileSuffix(resourceName)); |
---|
16462 | | - if (data == null) |
---|
| 16615 | + String[] suffixe = suffixes; |
---|
| 16616 | + String[] fallback = suffixes2; |
---|
| 16617 | + String[] fallfallback = suffixes3; |
---|
| 16618 | + |
---|
| 16619 | + for (int c=usedsuf; --c>=0;) |
---|
16463 | 16620 | { |
---|
16464 | | - throw new IOException("Unable to load texture " + resourceName); |
---|
| 16621 | +// String[] temp = suffixe; |
---|
| 16622 | +// suffixe = fallback; |
---|
| 16623 | +// fallback = fallfallback; |
---|
| 16624 | +// fallfallback = temp; |
---|
16465 | 16625 | } |
---|
| 16626 | + |
---|
| 16627 | + String resourceName = basename + suffixe[i] + "." + suffix; |
---|
| 16628 | + TextureData data; |
---|
| 16629 | + |
---|
| 16630 | + try |
---|
| 16631 | + { |
---|
| 16632 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16633 | + mipmapped, |
---|
| 16634 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16635 | + } |
---|
| 16636 | + catch (Exception e) |
---|
| 16637 | + { |
---|
| 16638 | + try |
---|
| 16639 | + { |
---|
| 16640 | + resourceName = basename + fallback[i] + "." + suffix; |
---|
| 16641 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16642 | + mipmapped, |
---|
| 16643 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16644 | + } |
---|
| 16645 | + catch (Exception e2) |
---|
| 16646 | + { |
---|
| 16647 | + resourceName = basename + fallfallback[i] + "." + suffix; |
---|
| 16648 | + data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName), |
---|
| 16649 | + mipmapped, |
---|
| 16650 | + FileUtil.getFileSuffix(resourceName)); |
---|
| 16651 | + } |
---|
| 16652 | + } |
---|
| 16653 | + |
---|
16466 | 16654 | //System.out.println("Target = " + targets[i]); |
---|
16467 | 16655 | cubemap.updateImage(data, targets[i]); |
---|
16468 | 16656 | } |
---|
16469 | 16657 | |
---|
16470 | 16658 | return cubemap; |
---|
16471 | 16659 | } |
---|
| 16660 | + |
---|
16472 | 16661 | int bigsphere = -1; |
---|
16473 | 16662 | |
---|
16474 | 16663 | float BGcolor = 0.5f; |
---|
16475 | 16664 | |
---|
16476 | | - private void DrawSkyBox(GL gl) |
---|
| 16665 | + float ambientLight[] = {1f, 1f, 1f, 1.0f}; |
---|
| 16666 | + |
---|
| 16667 | + private void DrawSkyBox(GL gl, float ratio) |
---|
16477 | 16668 | { |
---|
16478 | | - if (envyoff || cubemap == null) |
---|
| 16669 | + if (//envyoff || |
---|
| 16670 | + WIREFRAME || |
---|
| 16671 | + cubemap == null) |
---|
16479 | 16672 | { |
---|
16480 | 16673 | gl.glClearColor(BGcolor, BGcolor, BGcolor, 1); |
---|
16481 | 16674 | gl.glClear(gl.GL_COLOR_BUFFER_BIT); |
---|
.. | .. |
---|
16490 | 16683 | // Compensates for ExaminerViewer's modification of modelview matrix |
---|
16491 | 16684 | gl.glMatrixMode(GL.GL_MODELVIEW); |
---|
16492 | 16685 | gl.glLoadIdentity(); |
---|
| 16686 | + gl.glScalef(1,ratio,1); |
---|
16493 | 16687 | |
---|
| 16688 | +// colorV[0] = 2; |
---|
| 16689 | +// colorV[1] = 2; |
---|
| 16690 | +// colorV[2] = 2; |
---|
| 16691 | +// colorV[3] = 1; |
---|
| 16692 | +// gl.glDisable(gl.GL_COLOR_MATERIAL); |
---|
| 16693 | +// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0); |
---|
| 16694 | +// |
---|
| 16695 | +// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0); |
---|
| 16696 | + |
---|
16494 | 16697 | //gl.glActiveTexture(GL.GL_TEXTURE1); |
---|
16495 | 16698 | //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP); |
---|
16496 | 16699 | |
---|
.. | .. |
---|
16522 | 16725 | { |
---|
16523 | 16726 | gl.glScalef(1.0f, -1.0f, 1.0f); |
---|
16524 | 16727 | } |
---|
| 16728 | + gl.glScalef(-1.0f, 1.0f, 1.0f); |
---|
16525 | 16729 | gl.glMultMatrixd(viewrot_1, 0); |
---|
16526 | 16730 | gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f); |
---|
16527 | 16731 | //viewer.updateInverseRotation(gl); |
---|
.. | .. |
---|
16780 | 16984 | //new Exception().printStackTrace(); |
---|
16781 | 16985 | System.out.println("select buffer init"); |
---|
16782 | 16986 | // Use debug pipeline |
---|
16783 | | - drawable.setGL(new DebugGL(drawable.getGL())); |
---|
| 16987 | + //drawable.setGL(new DebugGL(drawable.getGL())); |
---|
16784 | 16988 | |
---|
16785 | 16989 | GL gl = drawable.getGL(); |
---|
16786 | 16990 | |
---|