From: <ha...@us...> - 2013-02-14 13:17:41
|
Revision: 17928 http://jmol.svn.sourceforge.net/jmol/?rev=17928&view=rev Author: hansonr Date: 2013-02-14 13:17:27 +0000 (Thu, 14 Feb 2013) Log Message: ----------- ___JmolVersion="13.1.13_dev" code: shader functions removed from Colix; Shader class made nonstatic FEATURE CHANGE: multiple applets will not share the same lighting space Modified Paths: -------------- trunk/Jmol/src/org/jmol/export/_PovrayExporter.java trunk/Jmol/src/org/jmol/export/_TachyonExporter.java trunk/Jmol/src/org/jmol/export/___Exporter.java trunk/Jmol/src/org/jmol/exportjs/Exporter.java trunk/Jmol/src/org/jmol/g3d/CylinderRenderer.java trunk/Jmol/src/org/jmol/g3d/Graphics3D.java trunk/Jmol/src/org/jmol/g3d/LineRenderer.java trunk/Jmol/src/org/jmol/g3d/SphereRenderer.java trunk/Jmol/src/org/jmol/script/Token.java trunk/Jmol/src/org/jmol/util/Colix.java trunk/Jmol/src/org/jmol/util/GData.java trunk/Jmol/src/org/jmol/util/Shader.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties trunk/Jmol/src/org/jmol/viewer/StateCreator.java trunk/Jmol/src/org/jmol/viewer/Viewer.java Modified: trunk/Jmol/src/org/jmol/export/_PovrayExporter.java =================================================================== --- trunk/Jmol/src/org/jmol/export/_PovrayExporter.java 2013-02-14 11:34:00 UTC (rev 17927) +++ trunk/Jmol/src/org/jmol/export/_PovrayExporter.java 2013-02-14 13:17:27 UTC (rev 17928) @@ -31,7 +31,6 @@ import org.jmol.util.BitSet; -import org.jmol.util.GData; import org.jmol.util.Measure; import org.jmol.util.Point3f; import org.jmol.util.Point4f; @@ -122,9 +121,9 @@ private void writeMacros() { output("#default { finish {\n" + " ambient " - + GData.getAmbientPercent() / 100f + "\n" + " diffuse " - + GData.getDiffusePercent() / 100f + "\n" + " specular " - + GData.getSpecularPercent() / 100f + "\n" + + g3d.getAmbientPercent() / 100f + "\n" + " diffuse " + + g3d.getDiffusePercent() / 100f + "\n" + " specular " + + g3d.getSpecularPercent() / 100f + "\n" + " roughness .00001\n metallic\n phong 0.9\n phong_size 120\n}}" + "\n\n"); @@ -191,9 +190,9 @@ + " #declare shineFactor = 0;\n" + " #end\n" + " finish {\n" + " ambient " - + GData.getAmbientPercent() / 100f + "\n" + " diffuse " - + GData.getDiffusePercent() / 100f + "\n" + " specular " - + GData.getSpecularPercent() / 100f + "\n" + + g3d.getAmbientPercent() / 100f + "\n" + " diffuse " + + g3d.getDiffusePercent() / 100f + "\n" + " specular " + + g3d.getSpecularPercent() / 100f + "\n" + " roughness .00001\n" + " metallic shineFactor\n" + " phong 0.9*shineFactor\n" Modified: trunk/Jmol/src/org/jmol/export/_TachyonExporter.java =================================================================== --- trunk/Jmol/src/org/jmol/export/_TachyonExporter.java 2013-02-14 11:34:00 UTC (rev 17927) +++ trunk/Jmol/src/org/jmol/export/_TachyonExporter.java 2013-02-14 13:17:27 UTC (rev 17928) @@ -66,10 +66,10 @@ } private void getLightingInfo() { - lighting = " AMBIENT " + round(GData.getAmbientPercent() / 100f) - + " DIFFUSE " + round(GData.getDiffusePercent()/100f) - + " SPECULAR " + round(GData.getSpecularPercent() / 100f); - phong = " Phong Plastic 0.5 Phong_size " + GData.getSpecularExponent(); + lighting = " AMBIENT " + round(g3d.getAmbientPercent() / 100f) + + " DIFFUSE " + round(g3d.getDiffusePercent()/100f) + + " SPECULAR " + round(g3d.getSpecularPercent() / 100f); + phong = " Phong Plastic 0.5 Phong_size " + g3d.getSpecularExponent(); } /* Modified: trunk/Jmol/src/org/jmol/export/___Exporter.java =================================================================== --- trunk/Jmol/src/org/jmol/export/___Exporter.java 2013-02-14 11:34:00 UTC (rev 17927) +++ trunk/Jmol/src/org/jmol/export/___Exporter.java 2013-02-14 13:17:27 UTC (rev 17928) @@ -164,7 +164,7 @@ protected int screenHeight; protected int slabZ; protected int depthZ; - protected Point3f lightSource = GData.getLightSource(); + protected Vector3f lightSource; protected Point3f fixedRotationCenter; protected Point3f referenceCenter; protected Point3f cameraPosition; @@ -218,6 +218,7 @@ } slabZ = g3d.getSlab(); depthZ = g3d.getDepth(); + lightSource = g3d.getLightSource(); Point3f[] cameraFactors = viewer.getCameraFactors(); referenceCenter = cameraFactors[0]; cameraPosition = cameraFactors[1]; Modified: trunk/Jmol/src/org/jmol/exportjs/Exporter.java =================================================================== --- trunk/Jmol/src/org/jmol/exportjs/Exporter.java 2013-02-14 11:34:00 UTC (rev 17927) +++ trunk/Jmol/src/org/jmol/exportjs/Exporter.java 2013-02-14 13:17:27 UTC (rev 17928) @@ -154,7 +154,6 @@ protected int screenHeight; protected int slabZ; protected int depthZ; - protected Point3f lightSource = GData.getLightSource(); protected Point3f fixedRotationCenter; protected Point3f referenceCenter; protected Point3f cameraPosition; Modified: trunk/Jmol/src/org/jmol/g3d/CylinderRenderer.java =================================================================== --- trunk/Jmol/src/org/jmol/g3d/CylinderRenderer.java 2013-02-14 11:34:00 UTC (rev 17927) +++ trunk/Jmol/src/org/jmol/g3d/CylinderRenderer.java 2013-02-14 13:17:27 UTC (rev 17928) @@ -42,10 +42,12 @@ private final Graphics3D g3d; private final LineRenderer line3d; + private final Shader shader; CylinderRenderer(Graphics3D g3d) { this.g3d = g3d; line3d = g3d.line3d; + shader = g3d.shader; } private short colixA, colixB; @@ -241,7 +243,7 @@ colixA = colix; this.isScreenedA = isScreened; shadesA = g3d.getShades(colix); - int shadeIndexTip = Shader.getShadeIndex(dxB, dyB, -dzB); + int shadeIndexTip = shader.getShadeIndex(dxB, dyB, -dzB); g3d.plotPixelClippedScreened(shadesA[shadeIndexTip], isScreenedA, (int) xTip, (int) yTip, (int) zTip); @@ -363,7 +365,7 @@ yRaster[i] = (int) (yR); zRaster[i] = (int) (zR + 0.5); } - fp8ShadeIndexUp[i] = Shader.getFp8ShadeIndex((float) xR, (float) yR, + fp8ShadeIndexUp[i] = shader.getFp8ShadeIndex((float) xR, (float) yR, (float) zR); } @@ -637,12 +639,12 @@ float dxf = (isFloat ? dxBf : (float) dxB); float dyf = (isFloat ? dyBf : (float) dyB); if (dzf >= 0 || !tCylinder) { - endcapShadeIndex = Shader.getShadeIndex(-dxf, -dyf, dzf); + endcapShadeIndex = shader.getShadeIndex(-dxf, -dyf, dzf); colixEndcap = colixA; shadesEndcap = shadesA; //Logger.debug("endcap is A"); } else { - endcapShadeIndex = Shader.getShadeIndex(dxf, dyf, -dzf); + endcapShadeIndex = shader.getShadeIndex(dxf, dyf, -dzf); colixEndcap = colixB; shadesEndcap = shadesB; xEndcap += dxB; Modified: trunk/Jmol/src/org/jmol/g3d/Graphics3D.java =================================================================== --- trunk/Jmol/src/org/jmol/g3d/Graphics3D.java 2013-02-14 11:34:00 UTC (rev 17927) +++ trunk/Jmol/src/org/jmol/g3d/Graphics3D.java 2013-02-14 13:17:27 UTC (rev 17928) @@ -619,8 +619,7 @@ if (argbCurrent == 0) argbCurrent = 0xFFFFFFFF; lastRawColor = argbCurrent; - Colix.allocateColix(argbCurrent); - Colix.getShadesArgb(argbCurrent, inGreyscaleMode); + shader.getShadesLast(argbCurrent, inGreyscaleMode); } } shadesCurrent = getShades(colix); @@ -702,13 +701,13 @@ public void volumeRender(boolean TF) { if (TF) { - saveAmbient = Shader.ambientPercent; - saveDiffuse = Shader.diffusePercent; - GData.setAmbientPercent(100); - GData.setDiffusePercent(0); + saveAmbient = shader.ambientPercent; + saveDiffuse = shader.diffusePercent; + setAmbientPercent(100); + setDiffusePercent(0); } else { - GData.setAmbientPercent(saveAmbient); - GData.setDiffusePercent(saveDiffuse); + setAmbientPercent(saveAmbient); + setDiffusePercent(saveDiffuse); } } /** @@ -1747,13 +1746,13 @@ - screenA.z); int shadeIndex; if (screenC == null) { - shadeIndex = Shader.getShadeIndex(-vectorAB.x, -vectorAB.y, vectorAB.z); + shadeIndex = shader.getShadeIndex(-vectorAB.x, -vectorAB.y, vectorAB.z); } else { vectorAC.set(screenC.x - screenA.x, screenC.y - screenA.y, screenC.z - screenA.z); vectorAB.cross(vectorAB, vectorAC); - shadeIndex = vectorAB.z >= 0 ? Shader.getShadeIndex(-vectorAB.x, - -vectorAB.y, vectorAB.z) : Shader.getShadeIndex(vectorAB.x, + shadeIndex = vectorAB.z >= 0 ? shader.getShadeIndex(-vectorAB.x, + -vectorAB.y, vectorAB.z) : shader.getShadeIndex(vectorAB.x, vectorAB.y, -vectorAB.z); } if (shadeIndex > Shader.shadeIndexNoisyLimit) @@ -1769,9 +1768,9 @@ vectorNormal.cross(vectorAB, vectorAC); return (vectorNormal.z >= 0 - ? Shader.getShadeIndex(-vectorNormal.x, -vectorNormal.y, + ? shader.getShadeIndex(-vectorNormal.x, -vectorNormal.y, vectorNormal.z) - : Shader.getShadeIndex(vectorNormal.x, vectorNormal.y, + : shader.getShadeIndex(vectorNormal.x, vectorNormal.y, -vectorNormal.z)); } @@ -1866,9 +1865,9 @@ for (int i = normixCount; --i >= 0; ) { Vector3f tv = transformedVectors[i]; rotationMatrix.transform2(vertexVectors[i], tv); - shadeIndexes[i] = Shader.getShadeIndexNormalized(tv.x, -tv.y, tv.z); + shadeIndexes[i] = shader.getShadeIndexNormalized(tv.x, -tv.y, tv.z); shadeIndexes2Sided[i] = (tv.z >= 0 ? shadeIndexes[i] - : Shader.getShadeIndexNormalized(-tv.x, tv.y, -tv.z)); + : shader.getShadeIndexNormalized(-tv.x, tv.y, -tv.z)); } } Modified: trunk/Jmol/src/org/jmol/g3d/LineRenderer.java =================================================================== --- trunk/Jmol/src/org/jmol/g3d/LineRenderer.java 2013-02-14 11:34:00 UTC (rev 17927) +++ trunk/Jmol/src/org/jmol/g3d/LineRenderer.java 2013-02-14 13:17:27 UTC (rev 17928) @@ -53,10 +53,12 @@ final class LineRenderer { - private Graphics3D g3d; + private final Graphics3D g3d; + private final Shader shader; LineRenderer(Graphics3D g3d) { this.g3d = g3d; + shader = g3d.shader; } private BitSet lineBits; @@ -533,7 +535,7 @@ && runIndex < rise && (!tScreened || (flipflop = !flipflop))) { int zCurrent = zCurrentScaled >> 10; if (zCurrent < zbuf[offset]) { - int rand8 = Shader.nextRandom8Bit(); + int rand8 = shader.nextRandom8Bit(); g3d.addPixel(offset, zCurrent, rand8 < 85 ? argbDn : (rand8 > 170 ? argbUp : argb)); } } @@ -576,7 +578,7 @@ && runIndex < rise && (!tScreened || (flipflop = !flipflop))) { int zCurrent = zCurrentScaled >> 10; if (zCurrent < zbuf[offset]) { - int rand8 = Shader.nextRandom8Bit(); + int rand8 = g3d.shader.nextRandom8Bit(); g3d.addPixel(offset, zCurrent, rand8 < 85 ? argbDn : (rand8 > 170 ? argbUp : argb)); } } @@ -671,7 +673,7 @@ if (argb != 0 && isInWindow && offset >= 0 && offset < offsetMax && runIndex < rise && (!tScreened || (flipflop = !flipflop))) { if (zFloat < zbuf[offset]) { - int rand8 = Shader.nextRandom8Bit(); + int rand8 = shader.nextRandom8Bit(); g3d.addPixel(offset, (int) zFloat, rand8 < 85 ? argbDn : (rand8 > 170 ? argbUp : argb)); } } Modified: trunk/Jmol/src/org/jmol/g3d/SphereRenderer.java =================================================================== --- trunk/Jmol/src/org/jmol/g3d/SphereRenderer.java 2013-02-14 11:34:00 UTC (rev 17927) +++ trunk/Jmol/src/org/jmol/g3d/SphereRenderer.java 2013-02-14 13:17:27 UTC (rev 17928) @@ -57,10 +57,12 @@ */ public class SphereRenderer { - Graphics3D g3d; + private final Graphics3D g3d; + private final Shader shader; SphereRenderer(Graphics3D g3d) { this.g3d = g3d; + shader = g3d.shader; } private int minX, maxX, minY, maxY, minZ, maxZ; @@ -109,7 +111,7 @@ if (maxZ < slab || minZ > depth) return; - Shader.nOut = Shader.nIn = 0; + shader.nOut = shader.nIn = 0; zbuf = g3d.zbuf; this.addAllPixels = addAllPixels; offsetPbufBeginLine = width * y + x; @@ -147,12 +149,12 @@ //System.out.println("sphere3d " + nIn + " " + nOut + " " + (1.0 * nIn / (nIn + nOut))); } - private static int[] getSphereShape(int diameter) { + private int[] getSphereShape(int diameter) { int[] ss; - return ((ss = Shader.sphereShapeCache[diameter - 1]) == null ? createSphereShape(diameter): ss); + return ((ss = shader.sphereShapeCache[diameter - 1]) == null ? createSphereShape(diameter): ss); } - private synchronized static int[] createSphereShape(int diameter) { + private int[] createSphereShape(int diameter) { int countSE = 0; boolean oddDiameter = (diameter & 1) != 0; float radiusF = diameter / 2.0f; @@ -184,10 +186,10 @@ if (z2 >= 0) { float z = (float)Math.sqrt(z2); int height = (int)z; - int shadeIndexSE = Shader.getDitheredNoisyShadeIndex( x, y, z, radiusF); - int shadeIndexSW = Shader.getDitheredNoisyShadeIndex(-x, y, z, radiusF); - int shadeIndexNE = Shader.getDitheredNoisyShadeIndex( x, -y, z, radiusF); - int shadeIndexNW = Shader.getDitheredNoisyShadeIndex(-x, -y, z, radiusF); + int shadeIndexSE = shader.getDitheredNoisyShadeIndex( x, y, z, radiusF); + int shadeIndexSW = shader.getDitheredNoisyShadeIndex(-x, y, z, radiusF); + int shadeIndexNE = shader.getDitheredNoisyShadeIndex( x, -y, z, radiusF); + int shadeIndexNW = shader.getDitheredNoisyShadeIndex(-x, -y, z, radiusF); int packed = (height | (shadeIndexSE << 7) | (shadeIndexSW << 13) | @@ -198,7 +200,7 @@ } sphereShape[offset - 1] |= 0x80000000; } - return Shader.sphereShapeCache[diameter - 1] = sphereShape; + return shader.sphereShapeCache[diameter - 1] = sphereShape; } private void renderShapeUnclipped(int[] sphereShape) { @@ -377,12 +379,12 @@ private void renderLarge() { if (mat != null) { - if (Shader.ellipsoidShades == null) - Shader.createEllipsoidShades(); + if (shader.ellipsoidShades == null) + shader.createEllipsoidShades(); if (octantPoints != null) setPlaneDerivatives(); - } else if (!Shader.sphereShadingCalculated) - Shader.calcSphereShading(); + } else if (!shader.sphereShadingCalculated) + shader.calcSphereShading(); renderQuadrant(-1, -1); renderQuadrant(-1, 1); renderQuadrant(1, -1); @@ -438,7 +440,7 @@ if (zbuf[offset] <= z0) continue; int x8 = ((j * xSign + radius) << 8) / dDivisor; - g3d.addPixel(offset,z0, shades[Shader.sphereShadeIndexes[((y8 << 8) + x8)]]); + g3d.addPixel(offset,z0, shades[shader.sphereShadeIndexes[((y8 << 8) + x8)]]); } } } @@ -552,14 +554,14 @@ mode = 1; break; case 2: //ellipsoid - iShade = Shader.getEllipsoidShade(xCurrent, yCurrent, (float) zroot[iRoot], radius, mDeriv); + iShade = shader.getEllipsoidShade(xCurrent, yCurrent, (float) zroot[iRoot], radius, mDeriv); break; case 3: //ellipsoid fill g3d.clearPixel(offset, z0); break; default: //sphere int x8 = ((j * xSign + radius) << 8) / dDivisor; - iShade = Shader.sphereShadeIndexes[(y8 << 8) + x8]; + iShade = shader.sphereShadeIndexes[(y8 << 8) + x8]; break; } g3d.addPixel(offset, zPixel, shades[iShade]); @@ -582,7 +584,7 @@ float dx = dxyz[i][0] = octantPoints[i].x - x; float dy = dxyz[i][1] = octantPoints[i].y - y; float dz = dxyz[i][2] = octantPoints[i].z - z; - planeShades[i] = Shader.getShadeIndex(dx, dy, -dz); + planeShades[i] = shader.getShadeIndex(dx, dy, -dz); if (dx == 0 && dy == 0) { planeShade = planeShades[i]; return; Modified: trunk/Jmol/src/org/jmol/script/Token.java =================================================================== --- trunk/Jmol/src/org/jmol/script/Token.java 2013-02-14 11:34:00 UTC (rev 17927) +++ trunk/Jmol/src/org/jmol/script/Token.java 2013-02-14 13:17:27 UTC (rev 17928) @@ -779,7 +779,7 @@ // handled specially in ScriptEvaluator public final static int backgroundmodel = setparam | 2; - public final static int celShading = setparam | 3; + public final static int celshading = setparam | 3; public final static int debug = setparam | 4; public final static int defaultlattice = setparam | 6; public final static int highlight = setparam | 8;// 12.0.RC14 @@ -2139,7 +2139,7 @@ // set params "backgroundModel", new Token(backgroundmodel), - "celShading", new Token(celShading), + "celShading", new Token(celshading), "debug", new Token(debug), "defaultLattice", new Token(defaultlattice), "measurements", new Token(measurements), Modified: trunk/Jmol/src/org/jmol/util/Colix.java =================================================================== --- trunk/Jmol/src/org/jmol/util/Colix.java 2013-02-14 11:34:00 UTC (rev 17927) +++ trunk/Jmol/src/org/jmol/util/Colix.java 2013-02-14 13:17:27 UTC (rev 17928) @@ -116,11 +116,12 @@ public final static short RAW_RGB = 3; public final static short SPECIAL_COLIX_MAX = 4; - private static int colixMax = SPECIAL_COLIX_MAX; - private static int[] argbs = new int[128]; + static int colixMax = SPECIAL_COLIX_MAX; + + static int[] argbs = new int[128]; + private static int[] argbsGreyscale; - private static int[][] ashades = ArrayUtil.newInt2(128); - private static int[][] ashadesGreyscale; + private static final Int2IntHash colixHash = new Int2IntHash(256); private static final int RAW_RGB_INT = RAW_RGB; public final static short UNMASK_CHANGEABLE_TRANSLUCENT = 0x07FF; @@ -154,7 +155,7 @@ public final static short YELLOW = 21; public final static short HOTPINK = 22; public final static short GOLD = 23; - + public Colix() { } @@ -195,9 +196,6 @@ if (argbsGreyscale != null) argbsGreyscale = ArrayUtil.arrayCopyI(argbsGreyscale, newSize); - ashades = ArrayUtil.arrayCopyII(ashades, newSize); - if (ashadesGreyscale != null) - ashadesGreyscale = ArrayUtil.arrayCopyII(ashadesGreyscale, newSize); } argbs[colixMax] = argb; if (argbsGreyscale != null) @@ -206,7 +204,12 @@ return (colixMax < LAST_AVAILABLE_COLIX ? colixMax++ : colixMax); } - private synchronized static void calcArgbsGreyscale() { + static void setLastGrey(int argb) { + calcArgbsGreyscale(); + argbsGreyscale[LAST_AVAILABLE_COLIX] = ColorUtil.calcGreyscaleRgbFromRgb(argb); + } + + synchronized static void calcArgbsGreyscale() { if (argbsGreyscale != null) return; int[] a = new int[argbs.length]; @@ -221,40 +224,6 @@ return argbsGreyscale[colix & OPAQUE_MASK]; } - public final static int[] getShadesArgb(int argb, boolean asGrey) { - if (asGrey) { - if (argbsGreyscale == null) - calcArgbsGreyscale(); - argbsGreyscale[LAST_AVAILABLE_COLIX] = ColorUtil.calcGreyscaleRgbFromRgb(argb); - } - return ashades[LAST_AVAILABLE_COLIX] = Shader.getShades(argb, false); - } - - public final static int[] getShades(short colix) { - colix &= OPAQUE_MASK; - int[] shades = ashades[colix]; - if (shades == null) - shades = ashades[colix] = Shader.getShades(argbs[colix], false); - return shades; - } - - public final static int[] getShadesGreyscale(short colix) { - colix &= OPAQUE_MASK; - if (ashadesGreyscale == null) - ashadesGreyscale = ArrayUtil.newInt2(ashades.length); - int[] shadesGreyscale = ashadesGreyscale[colix]; - if (shadesGreyscale == null) - shadesGreyscale = ashadesGreyscale[colix] = - Shader.getShades(argbs[colix], true); - return shadesGreyscale; - } - - public final synchronized static void flushShades() { - for (int i = colixMax; --i >= 0; ) - ashades[i] = null; - Shader.sphereShadingCalculated = false; - } - /* Int2IntHash hashMix2 = new Int2IntHash(32); Modified: trunk/Jmol/src/org/jmol/util/GData.java =================================================================== --- trunk/Jmol/src/org/jmol/util/GData.java 2013-02-14 11:34:00 UTC (rev 17927) +++ trunk/Jmol/src/org/jmol/util/GData.java 2013-02-14 13:17:27 UTC (rev 17928) @@ -39,6 +39,8 @@ public int bufferSize; + public Shader shader; + public final static byte ENDCAPS_NONE = 0; public final static byte ENDCAPS_OPEN = 1; public final static byte ENDCAPS_FLAT = 2; @@ -46,7 +48,7 @@ public final static byte ENDCAPS_OPENEND = 4; public GData() { - + shader = new Shader(); } public void initialize(ApiPlatform apiPlatform) { @@ -208,7 +210,7 @@ public int[] getShades(short colix) { if (colix < 0) colix = changeableColixMap[colix & Colix.UNMASK_CHANGEABLE_TRANSLUCENT]; - return (inGreyscaleMode ? Colix.getShadesGreyscale(colix) : Colix + return (inGreyscaleMode ? shader.getShadesGreyscale(colix) : shader .getShades(colix)); } @@ -222,8 +224,8 @@ this.inGreyscaleMode = greyscaleMode; } - public static int getSpecularPower() { - return Shader.specularPower; + public int getSpecularPower() { + return shader.specularPower; } /** @@ -231,20 +233,20 @@ * * @param val */ - public synchronized static void setSpecularPower(int val) { + public synchronized void setSpecularPower(int val) { if (val < 0) { setSpecularExponent(-val); return; } - if (Shader.specularPower == val) + if (shader.specularPower == val) return; - Shader.specularPower = val; - Shader.intenseFraction = val / 100f; + shader.specularPower = val; + shader.intenseFraction = val / 100f; flushCaches(); } - public static int getSpecularPercent() { - return Shader.specularPercent; + public int getSpecularPercent() { + return shader.specularPercent; } /** @@ -253,16 +255,16 @@ * * @param val */ - public synchronized static void setSpecularPercent(int val) { - if (Shader.specularPercent == val) + public synchronized void setSpecularPercent(int val) { + if (shader.specularPercent == val) return; - Shader.specularPercent = val; - Shader.specularFactor = val / 100f; + shader.specularPercent = val; + shader.specularFactor = val / 100f; flushCaches(); } - public static int getSpecularExponent() { - return Shader.specularExponent; + public int getSpecularExponent() { + return shader.specularExponent; } /** @@ -271,17 +273,17 @@ * * @param val */ - public synchronized static void setSpecularExponent(int val) { - if (Shader.specularExponent == val) + public synchronized void setSpecularExponent(int val) { + if (shader.specularExponent == val) return; - Shader.specularExponent = val; - Shader.phongExponent = (int) Math.pow(2, val); - Shader.usePhongExponent = false; + shader.specularExponent = val; + shader.phongExponent = (int) Math.pow(2, val); + shader.usePhongExponent = false; flushCaches(); } - public static int getPhongExponent() { - return Shader.phongExponent; + public int getPhongExponent() { + return shader.phongExponent; } /** @@ -289,19 +291,19 @@ * * @param val */ - public synchronized static void setPhongExponent(int val) { - if (Shader.phongExponent == val && Shader.usePhongExponent) + public synchronized void setPhongExponent(int val) { + if (shader.phongExponent == val && shader.usePhongExponent) return; - Shader.phongExponent = val; + shader.phongExponent = val; float x = (float) (Math.log(val) / Math.log(2)); - Shader.usePhongExponent = (x != (int) x); - if (!Shader.usePhongExponent) - Shader.specularExponent = (int) x; + shader.usePhongExponent = (x != (int) x); + if (!shader.usePhongExponent) + shader.specularExponent = (int) x; flushCaches(); } - public static int getDiffusePercent() { - return Shader.diffusePercent; + public int getDiffusePercent() { + return shader.diffusePercent; } /** @@ -309,16 +311,16 @@ * * @param val */ - public synchronized static void setDiffusePercent(int val) { - if (Shader.diffusePercent == val) + public synchronized void setDiffusePercent(int val) { + if (shader.diffusePercent == val) return; - Shader.diffusePercent = val; - Shader.diffuseFactor = val / 100f; + shader.diffusePercent = val; + shader.diffuseFactor = val / 100f; flushCaches(); } - public static int getAmbientPercent() { - return Shader.ambientPercent; + public int getAmbientPercent() { + return shader.ambientPercent; } /** @@ -326,43 +328,43 @@ * * @param val */ - public synchronized static void setAmbientPercent(int val) { - if (Shader.ambientPercent == val) + public synchronized void setAmbientPercent(int val) { + if (shader.ambientPercent == val) return; - Shader.ambientPercent = val; - Shader.ambientFraction = val / 100f; + shader.ambientPercent = val; + shader.ambientFraction = val / 100f; flushCaches(); } - public static boolean getSpecular() { - return Shader.specularOn; + public boolean getSpecular() { + return shader.specularOn; } - public synchronized static void setSpecular(boolean val) { - if (Shader.specularOn == val) + public synchronized void setSpecular(boolean val) { + if (shader.specularOn == val) return; - Shader.specularOn = val; + shader.specularOn = val; flushCaches(); } - public synchronized static void setCel(boolean val) { - if (Shader.celOn == val) + public synchronized void setCel(boolean val) { + if (shader.celOn == val) return; - Shader.celOn = val; + shader.celOn = val; flushCaches(); } - public static boolean getCel() { - return Shader.celOn; + public boolean getCel() { + return shader.celOn; } - private static void flushCaches() { - Colix.flushShades(); - Shader.flushSphereCache(); + private void flushCaches() { + shader.flushShades(); + shader.flushSphereCache(); } - public static Point3f getLightSource() { - return Point3f.new3(Shader.xLight, Shader.yLight, Shader.zLight); + public Vector3f getLightSource() { + return shader.lightSource; } public boolean isClipped3(int x, int y, int z) { Modified: trunk/Jmol/src/org/jmol/util/Shader.java =================================================================== --- trunk/Jmol/src/org/jmol/util/Shader.java 2013-02-14 11:34:00 UTC (rev 17927) +++ trunk/Jmol/src/org/jmol/util/Shader.java 2013-02-14 13:17:27 UTC (rev 17928) @@ -25,12 +25,9 @@ package org.jmol.util; - - - /** *<p> - * All static functions. + * All functions. * Implements the shading of RGB values to support shadow and lighting * highlights. *</p> @@ -40,63 +37,115 @@ *</p> * * @author Miguel, mi...@jm... + * @author Bob Hanson, ha...@st... + * */ -public final class Shader { +public class Shader { // there are 64 shades of a given color // 0 = ambient // 52 = normal // 56 = max for // 63 = specular - public static final int shadeIndexMax = 64; - public static final int shadeIndexLast = shadeIndexMax - 1; - public static final byte shadeIndexNormal = 52; - public final static byte shadeIndexNoisyLimit = 56; + private static int shadeIndexMax = 64; + public static int shadeIndexLast = shadeIndexMax - 1; + public static byte shadeIndexNormal = 52; + public static byte shadeIndexNoisyLimit = 56; // the viewer vector is always {0 0 1} - // the light source vector -- up and to the left - private static final float xLightsource = -1; - private static final float yLightsource = -1; - private static final float zLightsource = 2.5f; - - private static final float magnitudeLight = - (float)Math.sqrt(xLightsource * xLightsource + - yLightsource * yLightsource + - zLightsource * zLightsource); // the light source vector normalized - public static final float xLight = xLightsource / magnitudeLight; - public static final float yLight = yLightsource / magnitudeLight; - public static final float zLight = zLightsource / magnitudeLight; + private float xLight, yLight, zLight; - public static boolean specularOn = true; - public static boolean usePhongExponent = false; + public Shader() { + setLightSource(-1f, -1f, 2.5f); + } + Vector3f lightSource = new Vector3f(); + + private void setLightSource(float x, float y, float z) { + lightSource.set(x, y, z); + lightSource.normalize(); + xLight = lightSource.x; + yLight = lightSource.y; + zLight = lightSource.z; + } + + public boolean specularOn = true; + public boolean usePhongExponent = false; + //fractional distance from black for ambient color - public static int ambientPercent = 45; + public int ambientPercent = 45; // df in I = df * (N dot L) + sf * (R dot V)^p - public static int diffusePercent = 84; + public int diffusePercent = 84; // log_2(p) in I = df * (N dot L) + sf * (R dot V)^p // for faster calculation of shades - public static int specularExponent = 6; + public int specularExponent = 6; // sf in I = df * (N dot L) + sf * (R dot V)^p // not a percent of anything, really - public static int specularPercent = 22; + public int specularPercent = 22; // fractional distance to white for specular dot - public static int specularPower = 40; + public int specularPower = 40; // p in I = df * (N dot L) + sf * (R dot V)^p - public static int phongExponent = 64; + public int phongExponent = 64; - public static float ambientFraction = ambientPercent / 100f; - public static float diffuseFactor = diffusePercent / 100f; - public static float intenseFraction = specularPower / 100f; - public static float specularFactor = specularPercent / 100f; + public float ambientFraction = ambientPercent / 100f; + public float diffuseFactor = diffusePercent / 100f; + public float intenseFraction = specularPower / 100f; + public float specularFactor = specularPercent / 100f; + private int[][] ashades = ArrayUtil.newInt2(128); + private int[][] ashadesGreyscale; + + public int[] getShadesLast(int argb, boolean asGrey) { + Colix.allocateColix(argb); + checkShades(); + if (asGrey) + Colix.setLastGrey(argb); + return ashades[Colix.LAST_AVAILABLE_COLIX] = getShades2(argb, false); + } + + public int[] getShades(short colix) { + checkShades(); + colix &= Colix.OPAQUE_MASK; + int[] shades = ashades[colix]; + if (shades == null) + shades = ashades[colix] = getShades2(Colix.argbs[colix], false); + return shades; + } + + public int[] getShadesGreyscale(short colix) { + checkShades(); + colix &= Colix.OPAQUE_MASK; + if (ashadesGreyscale == null) + ashadesGreyscale = ArrayUtil.newInt2(ashades.length); + int[] shadesGreyscale = ashadesGreyscale[colix]; + if (shadesGreyscale == null) + shadesGreyscale = ashadesGreyscale[colix] = + getShades2(Colix.argbs[colix], true); + return shadesGreyscale; + } + + private void checkShades() { + if (ashades != null && ashades.length == Colix.colixMax) + return; + ashades = ArrayUtil.arrayCopyII(ashades, Colix.colixMax); + if (ashadesGreyscale != null) + ashadesGreyscale = ArrayUtil.arrayCopyII(ashadesGreyscale, Colix.colixMax); + } + + public void flushShades() { + checkShades(); + for (int i = Colix.colixMax; --i >= 0; ) + ashades[i] = null; + sphereShadingCalculated = false; + } + /* * intensity calculation: * @@ -110,7 +159,7 @@ * black <---ambient%--x---specular power----> white */ - public static int[] getShades(int rgb, boolean greyScale) { + public int[] getShades2(int rgb, boolean greyScale) { int[] shades = new int[shadeIndexMax]; if (rgb == 0) return shades; @@ -178,7 +227,7 @@ return shades; } - public static int getShadeIndex(float x, float y, float z) { + public int getShadeIndex(float x, float y, float z) { // from Cylinder3D.calcArgbEndcap and renderCone // from GData.getShadeIndex and getShadeIndex double magnitude = Math.sqrt(x*x + y*y + z*z); @@ -188,13 +237,13 @@ * shadeIndexLast); } - public static byte getShadeIndexNormalized(float x, float y, float z) { + public byte getShadeIndexNormalized(float x, float y, float z) { //from Normix3D.setRotationMatrix return (byte) Math.round (getFloatShadeIndexNormalized(x, y, z) * shadeIndexLast); } - public static int getFp8ShadeIndex(float x, float y, float z) { + public int getFp8ShadeIndex(float x, float y, float z) { //from calcDitheredNoisyShadeIndex (not utilized) //and Cylinder.calcRotatedPoint double magnitude = Math.sqrt(x*x + y*y + z*z); @@ -204,7 +253,7 @@ * shadeIndexLast * (1 << 8)); } - private static float getFloatShadeIndexNormalized(float x, float y, float z) { + private float getFloatShadeIndexNormalized(float x, float y, float z) { float NdotL = x * xLight + y * yLight + z * zLight; if (NdotL <= 0) return 0; @@ -252,7 +301,7 @@ } /* - static byte getDitheredShadeIndex(float x, float y, float z) { + byte getDitheredShadeIndex(float x, float y, float z) { //not utilized // add some randomness to prevent banding int fp8ShadeIndex = getFp8ShadeIndex(x, y, z); @@ -271,7 +320,7 @@ } */ - public static byte getDitheredNoisyShadeIndex(float x, float y, float z, float r) { + public byte getDitheredNoisyShadeIndex(float x, float y, float z, float r) { // from Sphere3D only // add some randomness to prevent banding int fp8ShadeIndex = (int) Math.floor(getFloatShadeIndexNormalized(x / r, y / r, z / r) @@ -296,8 +345,8 @@ The Art of Computer Programming, Volume 2: Seminumerical Algorithms, section 3.2.1. - static long seed = 1; - static int nextRandom8Bit() { + long seed = 1; + int nextRandom8Bit() { seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1); // return (int)(seed >>> (48 - bits)); return (int)(seed >>> 40); @@ -309,10 +358,10 @@ // Sphere shading cache for Large spheres //////////////////////////////////////////////////////////////// - public static boolean sphereShadingCalculated = false; - public final static byte[] sphereShadeIndexes = new byte[256 * 256]; + public boolean sphereShadingCalculated = false; + public byte[] sphereShadeIndexes = new byte[256 * 256]; - public synchronized static void calcSphereShading() { + public synchronized void calcSphereShading() { //if (!sphereShadingCalculated) { //unnecessary -- but be careful! float xF = -127.5f; for (int i = 0; i < 256; ++xF, ++i) { @@ -331,7 +380,7 @@ } /* - static byte getSphereshadeIndex(int x, int y, int r) { + byte getSphereshadeIndex(int x, int y, int r) { int d = 2*r + 1; x += r; if (x < 0) @@ -351,7 +400,7 @@ // this doesn't really need to be synchronized // no serious harm done if two threads write seed at the same time - private static int seed = 0x12345679; // turn lo bit on + private int seed = 0x12345679; // turn lo bit on /** *<p> * Implements RANDU algorithm for random noise in lighting/shading. @@ -363,7 +412,7 @@ * * @return Next random */ - public static int nextRandom8Bit() { + public int nextRandom8Bit() { int t = seed; seed = t = ((t << 16) + (t << 1) + t) & 0x7FFFFFFF; return t >> 23; @@ -372,13 +421,13 @@ private final static int SLIM = 20; private final static int SDIM = SLIM * 2; public final static int maxSphereCache = 128; - public final static int[][] sphereShapeCache = ArrayUtil.newInt2(maxSphereCache); - public static byte[][][] ellipsoidShades; - public static int nOut; - public static int nIn; - public static boolean celOn; + public int[][] sphereShapeCache = ArrayUtil.newInt2(maxSphereCache); + public byte[][][] ellipsoidShades; + public int nOut; + public int nIn; + public boolean celOn; - public static int getEllipsoidShade(float x, float y, float z, int radius, + public int getEllipsoidShade(float x, float y, float z, int radius, Matrix4f mDeriv) { float tx = mDeriv.m00 * x + mDeriv.m01 * y + mDeriv.m02 * z + mDeriv.m03; float ty = mDeriv.m10 * x + mDeriv.m11 * y + mDeriv.m12 * z + mDeriv.m13; @@ -410,7 +459,7 @@ : ellipsoidShades[i + SLIM][j + SLIM][k]); } - public static void createEllipsoidShades() { + public void createEllipsoidShades() { // we don't need to cache rear-directed normals (kk < 0) @@ -422,7 +471,7 @@ - SLIM, kk); } - public static synchronized void flushSphereCache() { + public synchronized void flushSphereCache() { for (int i = maxSphereCache; --i >= 0;) sphereShapeCache[i] = null; ellipsoidShades = null; Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2013-02-14 11:34:00 UTC (rev 17927) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2013-02-14 13:17:27 UTC (rev 17928) @@ -11,6 +11,10 @@ ___JmolVersion="13.1.13_dev" +code: shader functions removed from Colix; Shader class made nonstatic + +FEATURE CHANGE: multiple applets will not share the same lighting space + bug fix: set picking IDENT when picking is already ident can cancel a pending measurement bug fix: applet does not refresh when mouse exits with pending measurement Modified: trunk/Jmol/src/org/jmol/viewer/StateCreator.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/StateCreator.java 2013-02-14 11:34:00 UTC (rev 17927) +++ trunk/Jmol/src/org/jmol/viewer/StateCreator.java 2013-02-14 13:17:27 UTC (rev 17928) @@ -418,14 +418,15 @@ public String getSpecularState() { StringXBuilder str = new StringXBuilder(); - appendCmd(str, "set ambientPercent " + GData.getAmbientPercent()); - appendCmd(str, "set diffusePercent " + GData.getDiffusePercent()); - appendCmd(str, "set specular " + GData.getSpecular()); - appendCmd(str, "set specularPercent " + GData.getSpecularPercent()); - appendCmd(str, "set specularPower " + GData.getSpecularPower()); - appendCmd(str, "set celShading " + GData.getCel()); - int se = GData.getSpecularExponent(); - int pe = GData.getPhongExponent(); + GData g = viewer.gdata; + appendCmd(str, "set ambientPercent " + g.getAmbientPercent()); + appendCmd(str, "set diffusePercent " + g.getDiffusePercent()); + appendCmd(str, "set specular " + g.getSpecular()); + appendCmd(str, "set specularPercent " + g.getSpecularPercent()); + appendCmd(str, "set specularPower " + g.getSpecularPower()); + appendCmd(str, "set celShading " + g.getCel()); + int se = g.getSpecularExponent(); + int pe = g.getPhongExponent(); if (Math.pow(2, se) == pe) appendCmd(str, "set specularExponent " + se); else Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2013-02-14 11:34:00 UTC (rev 17927) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2013-02-14 13:17:27 UTC (rev 17928) @@ -747,14 +747,14 @@ // transfer default global settings to managers and g3d - GData.setAmbientPercent(global.ambientPercent); - GData.setDiffusePercent(global.diffusePercent); - GData.setSpecular(global.specular); - GData.setCel(global.celShading); - GData.setSpecularPercent(global.specularPercent); - GData.setSpecularPower(-global.specularExponent); - GData.setPhongExponent(global.phongExponent); - GData.setSpecularPower(global.specularPower); + gdata.setAmbientPercent(global.ambientPercent); + gdata.setDiffusePercent(global.diffusePercent); + gdata.setSpecular(global.specular); + gdata.setCel(global.celShading); + gdata.setSpecularPercent(global.specularPercent); + gdata.setSpecularPower(-global.specularExponent); + gdata.setPhongExponent(global.phongExponent); + gdata.setSpecularPower(global.specularPower); if (modelSet != null) animationManager.setAnimationOn(false); animationManager.setAnimationFps(global.animationFps); @@ -6127,7 +6127,7 @@ case Token.phongexponent: // 11.9.13 value = checkIntRange(value, 0, 1000); - GData.setPhongExponent(value); + gdata.setPhongExponent(value); break; case Token.helixstep: // 11.8.RC3 @@ -6189,11 +6189,11 @@ value = checkIntRange(value, -10, -1); else value = checkIntRange(value, 0, 100); - GData.setSpecularPower(value); + gdata.setSpecularPower(value); break; case Token.specularexponent: value = checkIntRange(-value, -10, -1); - GData.setSpecularPower(value); + gdata.setSpecularPower(value); break; case Token.bondradiusmilliangstroms: setMarBond((short) value); @@ -6204,15 +6204,15 @@ return; case Token.specularpercent: value = checkIntRange(value, 0, 100); - GData.setSpecularPercent(value); + gdata.setSpecularPercent(value); break; case Token.diffusepercent: value = checkIntRange(value, 0, 100); - GData.setDiffusePercent(value); + gdata.setDiffusePercent(value); break; case Token.ambientpercent: value = checkIntRange(value, 0, 100); - GData.setAmbientPercent(value); + gdata.setAmbientPercent(value); break; case Token.zdepth: transformManager.zDepthToPercent(value); @@ -6295,6 +6295,11 @@ private void setBooleanPropertyTok(String key, int tok, boolean value) { boolean doRepaint = true; switch (tok) { + case Token.celshading: + // 13.1.13 + global.celShading = value; + gdata.setCel(value); + break; case Token.cartoonfancy: // 12.3.7 global.cartoonFancy = value; @@ -6608,7 +6613,7 @@ global.hbondsSolid = value; break; case Token.specular: - GData.setSpecular(value); + gdata.setSpecular(value); break; case Token.slabenabled: // Eval.slab This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |