if ( bumpSoftness != 0 ) {
int bumpWidth = width;
int bumpHeight = height;
int[] bumpPixels = inPixels;
if ( bumpSource == BUMPS_FROM_MAP && bumpFunction instanceof ImageFunction2D ) {
ImageFunction2D if2d = (ImageFunction2D)bumpFunction;
bumpWidth = if2d.getWidth();
bumpHeight = if2d.getHeight();
bumpPixels = if2d.getPixels();
}
int [] tmpPixels = new int[bumpWidth * bumpHeight];
int [] softPixels = new int[bumpWidth * bumpHeight];
/*
for (int i = 0; i < 3; i++ ) {
BoxBlurFilter.blur( bumpPixels, tmpPixels, bumpWidth, bumpHeight, (int)bumpSoftness );
BoxBlurFilter.blur( tmpPixels, softPixels, bumpHeight, bumpWidth, (int)bumpSoftness );
}
*/
Kernel kernel = GaussianFilter.makeKernel( bumpSoftness );
GaussianFilter.convolveAndTranspose( kernel, bumpPixels, tmpPixels, bumpWidth, bumpHeight, true, false, false, GaussianFilter.WRAP_EDGES );
GaussianFilter.convolveAndTranspose( kernel, tmpPixels, softPixels, bumpHeight, bumpWidth, true, false, false, GaussianFilter.WRAP_EDGES );
bump = new ImageFunction2D(softPixels, bumpWidth, bumpHeight, ImageFunction2D.CLAMP, bumpSource == BUMPS_FROM_IMAGE_ALPHA);
final Function2D bbump = bump;
if ( bumpShape != 0 ) {
bump = new Function2D() {
private Function2D original = bbump;
public float evaluate(float x, float y) {
float v = original.evaluate( x, y );
switch ( bumpShape ) {
case 1:
// v = v > 0.5f ? 0.5f : v;
v *= ImageMath.smoothStep( 0.45f, 0.55f, v );
break;
case 2:
v = v < 0.5f ? 0.5f : v;
break;
case 3:
v = ImageMath.triangle( v );
break;
case 4:
v = ImageMath.circleDown( v );
break;
case 5:
v = ImageMath.gain( v, 0.75f );
break;
}
return v;
}
};
}
} else if ( bumpSource != BUMPS_FROM_MAP )
bump = new ImageFunction2D(inPixels, width, height, ImageFunction2D.CLAMP, bumpSource == BUMPS_FROM_IMAGE_ALPHA);
}
float reflectivity = material.reflectivity;
float areflectivity = (1-reflectivity);
Vector3f v1 = new Vector3f();