All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jsl-decora.LinearConvolveShadow.jsl Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

<<
private LinearConvolveKernel getKernel() {
    return (LinearConvolveKernel) AccessHelper.getState(getEffect());
}

public int getPow2ScaleX(LinearConvolveKernel kernel) {
    return kernel.getPow2ScaleX();
}

public int getPow2ScaleY(LinearConvolveKernel kernel) {
    return kernel.getPow2ScaleY();
}

public Rectangle getResultBounds(com.sun.javafx.geom.transform.BaseTransform transform,
                                 com.sun.javafx.geom.Rectangle outputClip,
                                 com.sun.scenario.effect.ImageData... inputDatas)
{
    return getKernel().getScaledResultBounds(inputDatas[0].getTransformedBounds(outputClip), getPass());
}

private int getCount() {
    return (getKernel().getScaledKernelSize(getPass()) + 3) / 4;
}

private float[] getOffset() {
    return getKernel().getVector(getInputNativeBounds(0), getInputTransform(0), getPass());
}

private FloatBuffer getWeights() {
    return getKernel().getWeights(getPass());
}

private int getWeightsArrayLength() {
    return getKernel().getWeightsArrayLength(getPass());
}

private float[] getShadowColor() {
    return getKernel().getShadowColorComponents(getPass());
}
>>

param sampler img;
param int count;
// offset.x = dx offset between adjacent weighted convolution samples
// offset.y = dy offset between adjacent weighted convolution samples
// offset.z = dx offset to first weighted convolution sample
// offset.w = dy offset to first weighted convolution sample
param float4 offset;
param float4 shadowColor;
// value for each location in the offsets array:
//   weights[i].x = weight for pos0 + offset + i*direction*4+0
//   weights[i].y = weight for pos0 + offset + i*direction*4+1
//   weights[i].z = weight for pos0 + offset + i*direction*4+2
//   weights[i].w = weight for pos0 + offset + i*direction*4+3
param float4 weights[%d];

void main()
{
    int i;
    float sum = 0.0;
    float2 loc = pos0 + offset.zw;
    unroll (%d, 0) for (i = 0; i < count; i++) {
        sum += weights[i].x * sample(img, loc).a;
        loc += offset.xy;
        sum += weights[i].y * sample(img, loc).a;
        loc += offset.xy;
        sum += weights[i].z * sample(img, loc).a;
        loc += offset.xy;
        sum += weights[i].w * sample(img, loc).a;
        loc += offset.xy;
    }
    sum = clamp(sum, 0.0, 1.0);
    color = sum * shadowColor;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy