Shader
Date: 2019-10-22

org.jmol.util

## Class Shader

- java.lang.Object
- - org.jmol.util.Shader

-     public class Shader
      extends java.lang.Object

  All functions. Implements the shading of RGB values to support shadow and lighting highlights.

  Each RGB value has 64 shades. shade[0] represents ambient lighting. shade[63] is white ... a full specular highlight.

  Author:
    Miguel, miguel@jmol.org, Bob Hanson, hansonr@stolaf.edu, N David Brown -- cel shading

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `(package private) float` | `ambientFraction`
    `(package private) int` | `ambientPercent`
    `private int[][]` | `ashades`
    `private int[][]` | `ashadesGreyscale`
    `(package private) boolean` | `celOn`
    `(package private) int` | `celPower`
    `private int` | `celRGB`
    `private float` | `celZ`
    `(package private) float` | `diffuseFactor`
    `(package private) int` | `diffusePercent`
    `byte[][][]` | `ellipsoidShades`
    `(package private) float` | `intenseFraction`
    `(package private) javajs.util.V3` | `lightSource`
    `static int` | `maxSphereCache`
    `int` | `nIn`
    `int` | `nOut`
    `(package private) int` | `phongExponent`
    `private static int` | `SDIM`
    `private int` | `seed`
    `static int` | `SHADE_INDEX_LAST`
    `private static int` | `SHADE_INDEX_MAX`
    `static byte` | `SHADE_INDEX_NOISY_LIMIT`
    `static byte` | `SHADE_INDEX_NORMAL`
    `private static int` | `SLIM`
    `(package private) int` | `specularExponent`
    `(package private) float` | `specularFactor`
    `(package private) boolean` | `specularOn`
    `(package private) int` | `specularPercent`
    `(package private) int` | `specularPower`
    `byte[]` | `sphereShadeIndexes`
    `int[][]` | `sphereShapeCache`
    `private boolean` | `useLight`
    `(package private) boolean` | `usePhongExponent`
    `private float` | `xLight`
    `private float` | `yLight`
    `private float` | `zLight`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Shader()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `private void` | `calcSphereShading()`
    `private void` | `checkShades(int n)`
    `void` | `createEllipsoidShades()`
    `(package private) void` | `flushCaches()`
    `int` | `getEllipsoidShade(float x, float y, float z, int radius, javajs.util.M4 mDeriv)`
    `byte` | `getShadeB(float x, float y, float z)`
    `private float` | `getShadeF(float x, float y, float z)`
    `int` | `getShadeFp8(float x, float y, float z)`
    `int` | `getShadeIndex(float x, float y, float z)`
    `byte` | `getShadeN(float x, float y, float z, float r)`
    `(package private) int[]` | `getShades(short colix)`
    `private int[]` | `getShades2(int rgb, boolean greyScale)`
    `(package private) int[]` | `getShadesG(short colix)`
    `int` | `nextRandom8Bit()` Implements RANDU algorithm for random noise in lighting/shading.
    `(package private) void` | `setCel(boolean celShading, int celShadingPower, int argb)`
    `void` | `setLastColix(int argb, boolean asGrey)`
    `private void` | `setLightSource(float x, float y, float z)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### SHADE_INDEX_MAX

          private static final int SHADE_INDEX_MAX

      See Also:
        Constant Field Values

    - #### SHADE_INDEX_LAST

          public static final int SHADE_INDEX_LAST

      See Also:
        Constant Field Values

    - #### SHADE_INDEX_NORMAL

          public static final byte SHADE_INDEX_NORMAL

      See Also:
        Constant Field Values

    - #### SHADE_INDEX_NOISY_LIMIT

          public static final byte SHADE_INDEX_NOISY_LIMIT

      See Also:
        Constant Field Values

    - #### xLight

          private float xLight

    - #### yLight

          private float yLight

    - #### zLight

          private float zLight

    - #### lightSource

          javajs.util.V3 lightSource

    - #### specularOn

          boolean specularOn

    - #### usePhongExponent

          boolean usePhongExponent

    - #### ambientPercent

          int ambientPercent

    - #### diffusePercent

          int diffusePercent

    - #### specularExponent

          int specularExponent

    - #### specularPercent

          int specularPercent

    - #### specularPower

          int specularPower

    - #### phongExponent

          int phongExponent

    - #### ambientFraction

          float ambientFraction

    - #### diffuseFactor

          float diffuseFactor

    - #### intenseFraction

          float intenseFraction

    - #### specularFactor

          float specularFactor

    - #### ashades

          private int[][] ashades

    - #### ashadesGreyscale

          private int[][] ashadesGreyscale

    - #### celOn

          boolean celOn

    - #### celPower

          int celPower

    - #### celRGB

          private int celRGB

    - #### celZ

          private float celZ

    - #### useLight

          private boolean useLight

    - #### sphereShadeIndexes

          public byte[] sphereShadeIndexes

    - #### seed

          private int seed

    - #### SLIM

          private static final int SLIM

      See Also:
        Constant Field Values

    - #### SDIM

          private static final int SDIM

      See Also:
        Constant Field Values

    - #### maxSphereCache

          public static final int maxSphereCache

      See Also:
        Constant Field Values

    - #### sphereShapeCache

          public int[][] sphereShapeCache

    - #### ellipsoidShades

          public byte[][][] ellipsoidShades

    - #### nOut

          public int nOut

    - #### nIn

          public int nIn

  - ### Constructor Detail

    - #### Shader

          public Shader()

  - ### Method Detail

    - #### setLightSource

          private void setLightSource(float x,
                                      float y,
                                      float z)

    - #### setCel

          void setCel(boolean celShading,
                      int celShadingPower,
                      int argb)

    - #### flushCaches

          void flushCaches()

    - #### setLastColix

          public void setLastColix(int argb,
                                   boolean asGrey)

    - #### getShades

          int[] getShades(short colix)

    - #### getShadesG

          int[] getShadesG(short colix)

    - #### checkShades

          private void checkShades(int n)

    - #### getShades2

          private int[] getShades2(int rgb,
                                   boolean greyScale)

    - #### getShadeIndex

          public int getShadeIndex(float x,
                                   float y,
                                   float z)

    - #### getShadeB

          public byte getShadeB(float x,
                                float y,
                                float z)

    - #### getShadeFp8

          public int getShadeFp8(float x,
                                 float y,
                                 float z)

    - #### getShadeF

          private float getShadeF(float x,
                                  float y,
                                  float z)

    - #### getShadeN

          public byte getShadeN(float x,
                                float y,
                                float z,
                                float r)

    - #### calcSphereShading

          private void calcSphereShading()

    - #### nextRandom8Bit

          public int nextRandom8Bit()

      Implements RANDU algorithm for random noise in lighting/shading.

      RANDU is the classic example of a poor random number generator. But it is very cheap to calculate and is good enough for our purposes.

      Returns:
        Next random

    - #### getEllipsoidShade

          public int getEllipsoidShade(float x,
                                       float y,
                                       float z,
                                       int radius,
                                       javajs.util.M4 mDeriv)

    - #### createEllipsoidShades

          public void createEllipsoidShades()