Exemple #1
0
 public final int toRGB() {
   int ir = (int) (r * 255 + 0.5);
   int ig = (int) (g * 255 + 0.5);
   int ib = (int) (b * 255 + 0.5);
   ir = MathUtils.clamp(ir, 0, 255);
   ig = MathUtils.clamp(ig, 0, 255);
   ib = MathUtils.clamp(ib, 0, 255);
   return (ir << 16) | (ig << 8) | ib;
 }
Exemple #2
0
 /**
  * Quantize the specified colors to 8-bit RGB format. The returned array contains 3 bytes for each
  * color in the original array.
  *
  * @param color array of colors to quantize
  * @return array of quantized RGB values
  */
 public static final byte[] quantizeRGB8(Color[] color) {
   byte[] output = new byte[color.length * 3];
   for (int i = 0, index = 0; i < color.length; i++, index += 3) {
     float[] rgb = color[i].getRGB();
     output[index + 0] = (byte) MathUtils.clamp((int) (rgb[0] * 255 + 0.5f), 0, 255);
     output[index + 1] = (byte) MathUtils.clamp((int) (rgb[1] * 255 + 0.5f), 0, 255);
     output[index + 2] = (byte) MathUtils.clamp((int) (rgb[2] * 255 + 0.5f), 0, 255);
   }
   return output;
 }
Exemple #3
0
 public float getPrimitiveBound(int primID, int i) {
   int quad = 4 * primID;
   int a = 3 * quads[quad + 0];
   int b = 3 * quads[quad + 1];
   int c = 3 * quads[quad + 2];
   int d = 3 * quads[quad + 3];
   int axis = i >>> 1;
   if ((i & 1) == 0)
     return MathUtils.min(points[a + axis], points[b + axis], points[c + axis], points[d + axis]);
   else
     return MathUtils.max(points[a + axis], points[b + axis], points[c + axis], points[d + axis]);
 }
Exemple #4
0
  public final int toRGBE() {
    // encode the color into 32bits while preserving HDR using Ward's RGBE
    // technique
    float v = MathUtils.max(r, g, b);
    if (v < 1e-32f) return 0;

    // get mantissa and exponent
    float m = v;
    int e = 0;
    if (v > 1.0f) {
      while (m > 1.0f) {
        m *= 0.5f;
        e++;
      }
    } else if (v <= 0.5f) {
      while (m <= 0.5f) {
        m *= 2.0f;
        e--;
      }
    }
    v = (m * 255.0f) / v;
    int c = (e + 128);
    c |= ((int) (r * v) << 24);
    c |= ((int) (g * v) << 16);
    c |= ((int) (b * v) << 8);
    return c;
  }
Exemple #5
0
 public final Color constrainRGB() {
   // clamp the RGB value to a representable value
   float w = -MathUtils.min(0, r, g, b);
   if (w > 0) {
     r += w;
     g += w;
     b += w;
   }
   return this;
 }
Exemple #6
0
 public void prepareShadingState(ShadingState state) {
   state.init();
   state.getRay().getPoint(state.getPoint());
   Instance parent = state.getInstance();
   Point3 p = parent.transformWorldToObject(state.getPoint());
   float deriv = p.x * p.x + p.y * p.y + p.z * p.z - ri2 - ro2;
   state.getNormal().set(p.x * deriv, p.y * deriv, p.z * deriv + 2 * ro2 * p.z);
   state.getNormal().normalize();
   double phi = Math.asin(MathUtils.clamp(p.z / ri, -1, 1));
   double theta = Math.atan2(p.y, p.x);
   if (theta < 0) theta += 2 * Math.PI;
   state.getUV().x = (float) (theta / (2 * Math.PI));
   state.getUV().y = (float) ((phi + Math.PI / 2) / Math.PI);
   state.setShader(parent.getShader(0));
   state.setModifier(parent.getModifier(0));
   Vector3 worldNormal = parent.transformNormalObjectToWorld(state.getNormal());
   state.getNormal().set(worldNormal);
   state.getNormal().normalize();
   state.getGeoNormal().set(state.getNormal());
   state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
 }
Exemple #7
0
 public final Color clamp(float min, float max) {
   r = MathUtils.clamp(r, min, max);
   g = MathUtils.clamp(r, min, max);
   b = MathUtils.clamp(r, min, max);
   return this;
 }
Exemple #8
0
 public final float getMax() {
   return MathUtils.max(r, g, b);
 }
Exemple #9
0
 public final float getMin() {
   return MathUtils.min(r, g, b);
 }