From: <ha...@us...> - 2007-04-06 15:43:26
|
Revision: 7339 http://svn.sourceforge.net/jmol/?rev=7339&view=rev Author: hansonr Date: 2007-04-06 08:43:21 -0700 (Fri, 06 Apr 2007) Log Message: ----------- 11.1.28 making variable lighting parameters nonstatic Modified Paths: -------------- trunk/Jmol/src/org/jmol/g3d/Colix.java trunk/Jmol/src/org/jmol/g3d/Cylinder3D.java trunk/Jmol/src/org/jmol/g3d/Graphics3D.java trunk/Jmol/src/org/jmol/g3d/Normix3D.java trunk/Jmol/src/org/jmol/g3d/Shade3D.java trunk/Jmol/src/org/jmol/g3d/Sphere3D.java Modified: trunk/Jmol/src/org/jmol/g3d/Colix.java =================================================================== --- trunk/Jmol/src/org/jmol/g3d/Colix.java 2007-04-06 14:49:20 UTC (rev 7338) +++ trunk/Jmol/src/org/jmol/g3d/Colix.java 2007-04-06 15:43:21 UTC (rev 7339) @@ -139,22 +139,22 @@ return argbsGreyscale[colix & Graphics3D.OPAQUE_MASK]; } - final static int[] getShades(short colix) { + final static int[] getShades(short colix, float[] lighting) { colix &= Graphics3D.OPAQUE_MASK; int[] shades = ashades[colix]; if (shades == null) - shades = ashades[colix] = Shade3D.getShades(argbs[colix], false); + shades = ashades[colix] = Shade3D.getShades(argbs[colix], false, lighting); return shades; } - final static int[] getShadesGreyscale(short colix) { + final static int[] getShadesGreyscale(short colix, float[] lighting) { colix &= Graphics3D.OPAQUE_MASK; if (ashadesGreyscale == null) ashadesGreyscale = new int[ashades.length][]; int[] shadesGreyscale = ashadesGreyscale[colix]; if (shadesGreyscale == null) shadesGreyscale = ashadesGreyscale[colix] = - Shade3D.getShades(argbs[colix], true); + Shade3D.getShades(argbs[colix], true, lighting); return shadesGreyscale; } Modified: trunk/Jmol/src/org/jmol/g3d/Cylinder3D.java =================================================================== --- trunk/Jmol/src/org/jmol/g3d/Cylinder3D.java 2007-04-06 14:49:20 UTC (rev 7338) +++ trunk/Jmol/src/org/jmol/g3d/Cylinder3D.java 2007-04-06 15:43:21 UTC (rev 7339) @@ -38,10 +38,12 @@ final Graphics3D g3d; final Line3D line3d; + final float[] lighting; Cylinder3D(Graphics3D g3d) { this.g3d = g3d; - this.line3d = g3d.line3d; + line3d = g3d.line3d; + lighting = g3d.lighting; } private short colixA, colixB; @@ -234,7 +236,7 @@ colixA = colix; this.isScreenedA = isScreened; shadesA = g3d.getShades(colix); - int intensityTip = Shade3D.calcIntensity(dxB, dyB, -dzB); + int intensityTip = Shade3D.calcIntensity(dxB, dyB, -dzB, lighting); g3d.plotPixelClipped(shadesA[intensityTip], isScreenedA, (int) xTip, (int) yTip, (int) zTip); @@ -350,7 +352,7 @@ zRaster[i] = (int) (zR + 0.5); } fp8IntensityUp[i] = Shade3D.calcFp8Intensity((float) xR, (float) yR, - (float) zR); + (float) zR, lighting); } private void interpolate(int iLower, int iUpper) { @@ -605,12 +607,12 @@ zEndcap = zA; int[] shadesEndcap; if (dzB >= 0 || !tCylinder) { - intensityEndcap = Shade3D.calcIntensity(-dxB, -dyB, dzB); + intensityEndcap = Shade3D.calcIntensity(-dxB, -dyB, dzB, lighting); colixEndcap = colixA; shadesEndcap = shadesA; //Logger.debug("endcap is A"); } else { - intensityEndcap = Shade3D.calcIntensity(dxB, dyB, -dzB); + intensityEndcap = Shade3D.calcIntensity(dxB, dyB, -dzB, lighting); colixEndcap = colixB; shadesEndcap = shadesB; xEndcap += dxB; Modified: trunk/Jmol/src/org/jmol/g3d/Graphics3D.java =================================================================== --- trunk/Jmol/src/org/jmol/g3d/Graphics3D.java 2007-04-06 14:49:20 UTC (rev 7338) +++ trunk/Jmol/src/org/jmol/g3d/Graphics3D.java 2007-04-06 15:43:21 UTC (rev 7339) @@ -724,7 +724,7 @@ boolean twoPass) { if (currentlyRendering) endRendering(); - normix3d.setRotationMatrix(rotationMatrix); + normix3d.setRotationMatrix(rotationMatrix, lighting); antialiasThisFrame &= isFullSceneAntialiasingEnabled; this.antialiasThisFrame = antialiasThisFrame; currentlyRendering = true; @@ -1792,8 +1792,8 @@ if (colix < 0) colix = changeableColixMap[colix & UNMASK_CHANGEABLE_TRANSLUCENT]; if (! inGreyscaleMode) - return Colix.getShades(colix); - return Colix.getShadesGreyscale(colix); + return Colix.getShades(colix, lighting); + return Colix.getShadesGreyscale(colix, lighting); } public final static short getChangeableColixIndex(short colix) { @@ -1910,66 +1910,102 @@ public final static byte intensitySpecularSurfaceLimit = Shade3D.intensitySpecularSurfaceLimit; + /* + static boolean specularOn = true; + // set specular 0-100 + static float intensitySpecular = 0.22f; + // set specpower -6 + static int specularExponent = 6; + // set specpower 0-100 + static float intenseFraction = 0.4f; + // set diffuse 0-100 + static float intensityDiffuse = 0.84f; + // set ambient 0-100 + static float ambientFraction = 0.45f; + +*/ + + + final float[] lighting = new float[] {1f, 0.22f, 6f, 0.4f, 0.84f, 0.45f}; + public void setSpecular(boolean specular) { - Shade3D.setSpecular(specular); + lighting[Shade3D.SPECULAR_ON] = (specular ? 1f : 0f); } public boolean getSpecular() { - return Shade3D.getSpecular(); + return (lighting[Shade3D.SPECULAR_ON] != 0); } public void setSpecularPower(int specularPower) { - Shade3D.setSpecularPower(specularPower); + if (specularPower >= 0) + lighting[Shade3D.INTENSE_FRACTION] = specularPower / 100f; + else + lighting[Shade3D.SPECULAR_EXPONENT] = -specularPower; } public void setAmbientPercent(int ambientPercent) { - Shade3D.setAmbientPercent(ambientPercent); + lighting[Shade3D.AMBIENT_FRACTION] = ambientPercent / 100f; } public int getAmbientPercent() { - return Shade3D.getAmbientPercent(); + return (int) (lighting[Shade3D.AMBIENT_FRACTION] * 100); } - + public void setDiffusePercent(int diffusePercent) { - Shade3D.setDiffusePercent(diffusePercent); + lighting[Shade3D.INTENSITY_DIFFUSE]= diffusePercent / 100f; } public int getDiffusePercent() { - return Shade3D.getDiffusePercent(); + return (int) (lighting[Shade3D.INTENSITY_DIFFUSE] * 100); } + public void setSpecularPercent(int specularPercent) { - Shade3D.setSpecularPercent(specularPercent); + lighting[Shade3D.INTENSITY_SPECULAR] = specularPercent / 100f; } public int getSpecularPercent() { - return Shade3D.getSpecularPercent(); + return (int) (lighting[Shade3D.INTENSITY_SPECULAR] * 100); } +/* + static void dump() { + Logger.debug("\n ambientPercent=" + ambientFraction + + "\n diffusePercent=" + intensityDiffuse + + "\n specularOn=" + specularOn + + "\n specularPercent=" + intensitySpecular + + "\n specularPower=" + intenseFraction + + "\n lighting[Shade3D.SPECULAR_EXPONENT]=" + lighting[Shade3D.SPECULAR_EXPONENT] + + "\n zLightsource=" + zLightsource + + "\n shadeNormal=" + shadeNormal); + } +*/ + + /* public void setLightsourceZ(float dist) { Shade3D.setLightsourceZ(dist); } - + */ + private final Vector3f vectorAB = new Vector3f(); private final Vector3f vectorAC = new Vector3f(); private final Vector3f vectorNormal = new Vector3f(); // these points are in screen coordinates even though 3f - public void calcSurfaceShade(Point3i screenA, - Point3i screenB, Point3i screenC) { + public void calcSurfaceShade(Point3i screenA, Point3i screenB, Point3i screenC) { vectorAB.x = screenB.x - screenA.x; vectorAB.y = screenB.y - screenA.y; vectorAB.z = screenB.z - screenA.z; - + vectorAC.x = screenC.x - screenA.x; vectorAC.y = screenC.y - screenA.y; vectorAC.z = screenC.z - screenA.z; vectorNormal.cross(vectorAB, vectorAC); - int intensity = - vectorNormal.z >= 0 - ? calcIntensity(-vectorNormal.x, -vectorNormal.y, vectorNormal.z) - : calcIntensity(vectorNormal.x, vectorNormal.y, -vectorNormal.z); + int intensity = vectorNormal.z >= 0 ? Shade3D.calcIntensity( + -vectorNormal.x, -vectorNormal.y, vectorNormal.z, lighting) : Shade3D + .calcIntensity(vectorNormal.x, vectorNormal.y, -vectorNormal.z, + lighting); if (intensity > intensitySpecularSurfaceLimit) intensity = intensitySpecularSurfaceLimit; setColorNoisy(intensity); @@ -1984,16 +2020,11 @@ return (vectorNormal.z >= 0 ? Shade3D.calcIntensity(-vectorNormal.x, -vectorNormal.y, - vectorNormal.z) + vectorNormal.z, lighting) : Shade3D.calcIntensity(vectorNormal.x, vectorNormal.y, - -vectorNormal.z)); + -vectorNormal.z, lighting)); } - static public int calcIntensity(float x, float y, float z) { - // from calcSurfaceShade - return Shade3D.calcIntensity(x, y, z); - } - /* *************************************************************** * fontID stuff * a fontID is a byte that contains the size + the face + the style Modified: trunk/Jmol/src/org/jmol/g3d/Normix3D.java =================================================================== --- trunk/Jmol/src/org/jmol/g3d/Normix3D.java 2007-04-06 14:49:20 UTC (rev 7338) +++ trunk/Jmol/src/org/jmol/g3d/Normix3D.java 2007-04-06 15:43:21 UTC (rev 7339) @@ -257,7 +257,7 @@ return intensities[normix]; } - void setRotationMatrix(Matrix3f rotationMatrix) { + void setRotationMatrix(Matrix3f rotationMatrix, float[] lighting) { this.rotationMatrix.set(rotationMatrix); for (int i = normixCount; --i >= 0; ) { Vector3f tv = transformedVectors[i]; @@ -277,12 +277,12 @@ z = -z; } */ - byte intensity = Shade3D.calcIntensityNormalized(x, y, z); + byte intensity = Shade3D.calcIntensityNormalized(x, y, z, lighting); intensities[i] = intensity; if (z >= 0) intensities2Sided[i] = intensity; else - intensities2Sided[i] = Shade3D.calcIntensityNormalized(-x, -y, -z); + intensities2Sided[i] = Shade3D.calcIntensityNormalized(-x, -y, -z, lighting); } } Modified: trunk/Jmol/src/org/jmol/g3d/Shade3D.java =================================================================== --- trunk/Jmol/src/org/jmol/g3d/Shade3D.java 2007-04-06 14:49:20 UTC (rev 7338) +++ trunk/Jmol/src/org/jmol/g3d/Shade3D.java 2007-04-06 15:43:21 UTC (rev 7339) @@ -51,34 +51,29 @@ // the light source vector static final float xLightsource = -1; static final float yLightsource = -1; - static float zLightsource = 2.5f; - static float magnitudeLight = + static final float zLightsource = 2.5f; + static final float magnitudeLight = (float)Math.sqrt(xLightsource * xLightsource + yLightsource * yLightsource + zLightsource * zLightsource); // the light source vector normalized - static float xLight = xLightsource / magnitudeLight; - static float yLight = yLightsource / magnitudeLight; - static float zLight = zLightsource / magnitudeLight; + static final float xLight = xLightsource / magnitudeLight; + static final float yLight = yLightsource / magnitudeLight; + static final float zLight = zLightsource / magnitudeLight; // the viewer vector is always 0,0,1 - // the following six settings are actually set in StateManager + // the following six settings are set in StateManager + // and saved in g3d.lighting - // set specular on|off - static boolean specularOn = true; - // set specular 0-100 - static float intensitySpecular = 0.22f; - // set specpower -6 - static int specularExponent = 6; - // set specpower 0-100 - static float intenseFraction = 0.4f; - // set diffuse 0-100 - static float intensityDiffuse = 0.84f; - // set ambient 0-100 - static float ambientFraction = 0.45f; + static int SPECULAR_ON = 0; // set specular on|off + static int INTENSITY_SPECULAR = 1; + static int SPECULAR_EXPONENT = 2; + static int INTENSE_FRACTION = 3; + static int INTENSITY_DIFFUSE = 4; + static int AMBIENT_FRACTION = 5; - static int[] getShades(int rgb, boolean greyScale) { + static int[] getShades(int rgb, boolean greyScale, float[] lighting) { int[] shades = new int[shadeMax]; if (rgb == 0) return shades; @@ -86,9 +81,10 @@ int red = (rgb >> 16) & 0xFF; int grn = (rgb >> 8) & 0xFF; int blu = rgb & 0xFF; - + float ambientFraction = lighting[AMBIENT_FRACTION]; float ambientRange = 1 - ambientFraction; - + float intenseFraction = lighting[INTENSE_FRACTION]; + shades[shadeNormal] = rgb(red, grn, blu); for (int i = 0; i < shadeNormal; ++i) { float fraction = ambientFraction + ambientRange*i/shadeNormal; @@ -127,55 +123,56 @@ final static byte intensitySpecularSurfaceLimit = (byte)(shadeNormal + 4); - static byte calcIntensity(float x, float y, float z) { + static byte calcIntensity(float x, float y, float z, float[] lighting) { // from Cylinder3D.calcArgbEndcap and renderCone // from Graphics3D.calcIntensity and calcIntensityScreen double magnitude = Math.sqrt(x*x + y*y + z*z); return (byte)(calcFloatIntensityNormalized((float)(x/magnitude), (float)(y/magnitude), - (float)(z/magnitude)) + (float)(z/magnitude), lighting) * shadeLast + 0.5f); } - static byte calcIntensityNormalized(float x, float y, float z) { + static byte calcIntensityNormalized(float x, float y, float z, float[] lighting) { //from Normix3D.setRotationMatrix - return (byte)(calcFloatIntensityNormalized(x, y, z) + return (byte)(calcFloatIntensityNormalized(x, y, z, lighting) * shadeLast + 0.5f); } - static int calcFp8Intensity(float x, float y, float z) { + static int calcFp8Intensity(float x, float y, float z, float[] lighting) { //from calcDitheredNoisyIntensity (not utilized) //and Cylinder.calcRotatedPoint double magnitude = Math.sqrt(x*x + y*y + z*z); return (int)(calcFloatIntensityNormalized((float)(x/magnitude), (float)(y/magnitude), - (float)(z/magnitude)) + (float)(z/magnitude), lighting) * shadeLast * (1 << 8)); } - - static float calcFloatIntensity(float x, float y, float z) { +/* + static float calcFloatIntensity(float x, float y, float z, float[] lighting) { //not utilized double magnitude = Math.sqrt(x*x + y*y + z*z); return calcFloatIntensityNormalized((float)(x/magnitude), (float)(y/magnitude), - (float)(z/magnitude)); + (float)(z/magnitude), lighting); } - - static float calcFloatIntensityNormalized(float x, float y, float z) { +*/ + + private static float calcFloatIntensityNormalized(float x, float y, float z, float[] lighting) { float cosTheta = x*xLight + y*yLight + z*zLight; float intensity = 0; // ambient component if (cosTheta > 0) { - intensity += cosTheta * intensityDiffuse; // diffuse component + intensity += cosTheta * lighting[INTENSITY_DIFFUSE]; // diffuse component - if (specularOn) { + if (lighting[SPECULAR_ON] != 0) { // this is the dot product of the reflection and the viewer // but the viewer only has a z component float dotProduct = z * 2 * cosTheta - zLight; if (dotProduct > 0) { - for (int n = specularExponent; --n >= 0 && dotProduct > .0001f; ) + for (int n = (int)lighting[SPECULAR_EXPONENT]; --n >= 0 && dotProduct > .0001f; ) dotProduct *= dotProduct; // specular component - intensity += dotProduct * intensitySpecular; + intensity += dotProduct * lighting[INTENSITY_SPECULAR]; } } } @@ -184,29 +181,33 @@ return intensity; } - static byte calcDitheredNoisyIntensity(float x, float y, float z) { - //not utilized - // add some randomness to prevent banding - int fp8Intensity = calcFp8Intensity(x, y, z); - int intensity = fp8Intensity >> 8; - // this cannot overflow because the if the float intensity is 1.0 - // then intensity will be == shadeLast - // but there will be no fractional component, so the next test will fail - if ((fp8Intensity & 0xFF) > nextRandom8Bit()) - ++intensity; - int random16bit = seed & 0xFFFF; - if (random16bit < 65536 / 3 && intensity > 0) - --intensity; - else if (random16bit > 65536 * 2 / 3 && intensity < shadeLast) - ++intensity; - return (byte)intensity; - } + /* + static byte calcDitheredNoisyIntensity(float x, float y, float z, float[] lighting) { + //not utilized + // add some randomness to prevent banding + int fp8Intensity = calcFp8Intensity(x, y, z, lighting); + int intensity = fp8Intensity >> 8; + // this cannot overflow because the if the float intensity is 1.0 + // then intensity will be == shadeLast + // but there will be no fractional component, so the next test will fail + if ((fp8Intensity & 0xFF) > nextRandom8Bit()) + ++intensity; + int random16bit = seed & 0xFFFF; + if (random16bit < 65536 / 3 && intensity > 0) + --intensity; + else if (random16bit > 65536 * 2 / 3 && intensity < shadeLast) + ++intensity; + return (byte)intensity; + } + */ - static byte calcDitheredNoisyIntensity(float x, float y, float z, float r) { + static byte calcDitheredNoisyIntensity(float x, float y, float z, float r, + float[] lighting) { // from Sphere3D only // add some randomness to prevent banding - int fp8Intensity = (int)(calcFloatIntensityNormalized(x/r, y/r, z/r) - * shadeLast * (1 << 8)); + int fp8Intensity = (int) (calcFloatIntensityNormalized(x / r, y / r, z / r, + lighting) + * shadeLast * (1 << 8)); int intensity = fp8Intensity >> 8; // this cannot overflow because the if the float intensity is 1.0 // then intensity will be == shadeLast @@ -218,7 +219,7 @@ --intensity; else if (random16bit > 65536 * 2 / 3 && intensity < shadeLast) ++intensity; - return (byte)intensity; + return (byte) intensity; } /* @@ -255,15 +256,7 @@ return t >> 23; } - static void setSpecular(boolean specular) { - specularOn = specular; - //dump(); - } - - static boolean getSpecular() { - return specularOn; - } - + /* static void setLightsourceZ(float z) { zLightsource = z; magnitudeLight = @@ -272,52 +265,6 @@ zLightsource * zLightsource); //dump(); } - - static void setSpecularPower(int specularPower) { - if (specularPower >= 0) - intenseFraction = specularPower / 100f; - else - specularExponent = -specularPower; - //dump(); - } - - static void setAmbientPercent(int ambientPercent) { - ambientFraction = ambientPercent / 100f; - //dump(); - } - - static int getAmbientPercent() { - return (int) (ambientFraction * 100); - } - - - static void setDiffusePercent(int diffusePercent) { - intensityDiffuse = diffusePercent / 100f; - //dump(); - } - - static int getDiffusePercent() { - return (int) (intensityDiffuse * 100); - } - - static void setSpecularPercent(int specularPercent) { - intensitySpecular = specularPercent / 100f; - //dump(); - } - - static int getSpecularPercent() { - return (int) (intensitySpecular * 100); - } -/* - static void dump() { - Logger.debug("\n ambientPercent=" + ambientFraction + - "\n diffusePercent=" + intensityDiffuse + - "\n specularOn=" + specularOn + - "\n specularPercent=" + intensitySpecular + - "\n specularPower=" + intenseFraction + - "\n specularExponent=" + specularExponent + - "\n zLightsource=" + zLightsource + - "\n shadeNormal=" + shadeNormal); - } */ + } Modified: trunk/Jmol/src/org/jmol/g3d/Sphere3D.java =================================================================== --- trunk/Jmol/src/org/jmol/g3d/Sphere3D.java 2007-04-06 14:49:20 UTC (rev 7338) +++ trunk/Jmol/src/org/jmol/g3d/Sphere3D.java 2007-04-06 15:43:21 UTC (rev 7339) @@ -47,9 +47,11 @@ class Sphere3D { Graphics3D g3d; - + float[] lighting; + Sphere3D(Graphics3D g3d) { this.g3d = g3d; + lighting = g3d.lighting; } private final static int maxSphereCache = 128; @@ -323,10 +325,10 @@ if (z2 >= 0) { float z = (float)Math.sqrt(z2); int height = (int)z; - int intensitySE = Shade3D.calcDitheredNoisyIntensity( x, y, z, radiusF); - int intensitySW = Shade3D.calcDitheredNoisyIntensity(-x, y, z, radiusF); - int intensityNE = Shade3D.calcDitheredNoisyIntensity( x, -y, z, radiusF); - int intensityNW = Shade3D.calcDitheredNoisyIntensity(-x, -y, z, radiusF); + int intensitySE = Shade3D.calcDitheredNoisyIntensity( x, y, z, radiusF, lighting); + int intensitySW = Shade3D.calcDitheredNoisyIntensity(-x, y, z, radiusF, lighting); + int intensityNE = Shade3D.calcDitheredNoisyIntensity( x, -y, z, radiusF, lighting); + int intensityNW = Shade3D.calcDitheredNoisyIntensity(-x, -y, z, radiusF, lighting); int packed = (height | (intensitySE << 7) | (intensitySW << 13) | @@ -357,7 +359,7 @@ float z2 = 130*130 - xF*xF - yF*yF; if (z2 > 0) { float z = (float)Math.sqrt(z2); - intensity = Shade3D.calcDitheredNoisyIntensity(xF, yF, z, 130); + intensity = Shade3D.calcDitheredNoisyIntensity(xF, yF, z, 130, lighting); } sphereIntensities[(j << 8) + i] = intensity; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |