jsl-prism.MaskDrawPgram.jsl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openjfx-78-backport-native Show documentation
Show all versions of openjfx-78-backport-native Show documentation
This contains the native files for the backport of OpenJFX 8 to run on Java 7.
The newest version!
/*
* Copyright (c) 2009, 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.
*/
/*
* This shader fills the space between an outer and inner parallelogram.
* It can be used to draw an outline by specifying both inner and outer
* values. It fills pixels by estimating what portion falls inside the
* outer shape, and subtracting an estimate of what portion falls inside
* the inner shape. Specifying both inner and outer values produces a
* standard "wide outline". Specifying an inner shape that falls far
* outside the outer shape allows the same shader to fill the outer
* shape entirely since pixels that fall within the outer shape are never
* inside the inner shape and so they are filled based solely on their
* coverage of the outer shape.
*
* The method for determining coverage values is explained in the
* MaskFillPgram.jsl file. This shader can use the same texture
* coordinates for both the inner and outer parallelograms, it just
* needs two sets of j,k constants - one that specifies the distances
* for the edges of the outer parallelogram and another pair that
* specifies the distances for the inner parallelogram.
*
* @param tco the X and Y texture coordinates that vary as in the
* diagram in the MaskFillPgram.jsl file
* @param odim the j and k constants for the outer parallelogram
* @param idim the j and k constants for the inner parallelogram
*/
param float2 idim;
float mask(float2 tco, float2 odim)
{
float2 ocov = clamp(odim + 0.5 - abs(tco), 0.0, 1.0);
float2 icov = clamp(idim + 0.5 - abs(tco), 0.0, 1.0);
// The dim values are essentially half the size of the parallelogram
// If the pgram is less than a pixel wide (in either direction), then
// that is the maximum coverage that any pixel can receive (in that
// particular direction), so we need to clip the pixel coverages
// against these dimensions (i.e. dim * 2).
// Technically these 2 steps could be eliminated if all wh are >= 1.0
ocov = min(ocov, odim * 2.0);
icov = min(icov, idim * 2.0);
return ocov.x * ocov.y - icov.x * icov.y;
}