public int getPixel(int x, int y, int[] inPixels, int width, int height) { float nx = m00 * x + m01 * y; float ny = m10 * x + m11 * y; nx /= scale; ny /= scale * stretch; nx += 1000; ny += 1000; // Reduce artifacts around 0,0 float f = evaluate(nx, ny); float f1 = results[0].distance; float f2 = results[1].distance; int srcx = ImageMath.clamp((int) ((results[0].x - 1000) * scale), 0, width - 1); int srcy = ImageMath.clamp((int) ((results[0].y - 1000) * scale), 0, height - 1); int v = inPixels[srcy * width + srcx]; f = (f2 - f1) / edgeThickness; f = ImageMath.smoothStep(0, edgeThickness, f); if (fadeEdges) { srcx = ImageMath.clamp((int) ((results[1].x - 1000) * scale), 0, width - 1); srcy = ImageMath.clamp((int) ((results[1].y - 1000) * scale), 0, height - 1); int v2 = inPixels[srcy * width + srcx]; v2 = ImageMath.mixColors(0.5f, v2, v); v = ImageMath.mixColors(f, v2, v); } else v = ImageMath.mixColors(f, edgeColor, v); return v; }
public int getPixel(int x, int y, int[] inPixels, int width, int height) { float nx = m00 * x + m01 * y; float ny = m10 * x + m11 * y; nx /= scale; ny /= scale * stretch; nx += 1000; ny += 1000; // Reduce artifacts around 0,0 float f = turbulence == 1.0f ? evaluate(nx, ny) : turbulence2(nx, ny, turbulence); // Normalize to 0..1 // f = (f-min)/(max-min); f *= 2; f *= amount; int a = 0xff000000; int v; if (colormap != null) { v = colormap.getColor(f); if (useColor) { int srcx = ImageMath.clamp((int) ((results[0].x - 1000) * scale), 0, width - 1); int srcy = ImageMath.clamp((int) ((results[0].y - 1000) * scale), 0, height - 1); v = inPixels[srcy * width + srcx]; f = (results[1].distance - results[0].distance) / (results[1].distance + results[0].distance); f = ImageMath.smoothStep(coefficients[1], coefficients[0], f); v = ImageMath.mixColors(f, 0xff000000, v); } return v; } else { v = PixelUtils.clamp((int) (f * 255)); int r = v << 16; int g = v << 8; int b = v; return a | r | g | b; } }
private int getEnvironmentMap(Vector3f normal, int[] inPixels, int width, int height) { if (environmentMap != null) { float angle = (float) Math.acos(-normal.y); float x, y; y = angle / ImageMath.PI; if (y == 0.0f || y == 1.0f) x = 0.0f; else { float f = normal.x / (float) Math.sin(angle); if (f > 1.0f) f = 1.0f; else if (f < -1.0f) f = -1.0f; x = (float) Math.acos(f) / ImageMath.PI; } // A bit of empirical scaling.... x = ImageMath.clamp(x * envWidth, 0, envWidth - 1); y = ImageMath.clamp(y * envHeight, 0, envHeight - 1); int ix = (int) x; int iy = (int) y; float xWeight = x - ix; float yWeight = y - iy; int i = envWidth * iy + ix; int dx = ix == envWidth - 1 ? 0 : 1; int dy = iy == envHeight - 1 ? 0 : envWidth; return ImageMath.bilinearInterpolate( xWeight, yWeight, envPixels[i], envPixels[i + dx], envPixels[i + dy], envPixels[i + dx + dy]); } return 0; }
public int filterRGB(int x, int y, int rgb) { float dx = x - centreX; float dy = y - centreY; float distance = dx * dx + dy * dy; float angle = (float) Math.atan2(dy, dx); float d = (angle + ImageMath.PI) / (ImageMath.TWO_PI) * rays; int i = (int) d; float f = d - i; if (radius != 0) { float length = ImageMath.lerp(f, rayLengths[i % rays], rayLengths[(i + 1) % rays]); float g = length * length / (distance + 0.0001f); g = (float) Math.pow(g, (100 - amount) / 50.0); f -= 0.5f; // f *= amount/50.0f; f = 1 - f * f; f *= g; } f = ImageMath.clamp(f, 0, 1); return ImageMath.mixColors(f, rgb, color); }