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; }
/** * 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; }
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())); }
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; }