Copy as Markdown

Other Tools

#define SWGL 1
#define __VERSION__ 150
#define WR_MAX_VERTEX_TEXTURE_WIDTH 1024U
#define WR_FEATURE_DEBUG_OVERDRAW
#define WR_FEATURE_DUAL_SOURCE_BLENDING
#define WR_FEATURE_TEXTURE_2D
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifdef WR_FEATURE_TEXTURE_EXTERNAL
// for this extension.
#endif
#ifdef WR_FEATURE_TEXTURE_EXTERNAL_ESSL1
// Some GLES 3 devices do not support GL_OES_EGL_image_external_essl3, so we
// must use GL_OES_EGL_image_external instead and make the shader ESSL1
// compatible.
#endif
#ifdef WR_FEATURE_TEXTURE_EXTERNAL_BT709
#endif
#ifdef WR_FEATURE_ADVANCED_BLEND
#endif
#ifdef WR_FEATURE_DUAL_SOURCE_BLENDING
#ifdef GL_ES
#else
#endif
#endif
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#if defined(GL_ES)
#if GL_ES == 1
// Sampler default precision is lowp on mobile GPUs.
// This causes RGBA32F texture data to be clamped to 16 bit floats on some GPUs (e.g. Mali-T880).
// Define highp precision macro to allow lossless FLOAT texture sampling.
#define HIGHP_SAMPLER_FLOAT highp
// Default int precision in GLES 3 is highp (32 bits) in vertex shaders
// and mediump (16 bits) in fragment shaders. If an int is being used as
// a texel address in a fragment shader it, and therefore requires > 16
// bits, it must be qualified with this.
#define HIGHP_FS_ADDRESS highp
// texelFetchOffset is buggy on some Android GPUs (see issue #1694).
// Fallback to texelFetch on mobile GPUs.
#define TEXEL_FETCH(sampler, position, lod, offset) texelFetch(sampler, position + offset, lod)
#else
#define HIGHP_SAMPLER_FLOAT
#define HIGHP_FS_ADDRESS
#define TEXEL_FETCH(sampler, position, lod, offset) texelFetchOffset(sampler, position, lod, offset)
#endif
#else
#define HIGHP_SAMPLER_FLOAT
#define HIGHP_FS_ADDRESS
#if defined(PLATFORM_MACOS) && !defined(SWGL)
// texelFetchOffset introduces a variety of shader compilation bugs on macOS Intel so avoid it.
#define TEXEL_FETCH(sampler, position, lod, offset) texelFetch(sampler, position + offset, lod)
#else
#define TEXEL_FETCH(sampler, position, lod, offset) texelFetchOffset(sampler, position, lod, offset)
#endif
#endif
#ifdef SWGL
#define SWGL_DRAW_SPAN
#define SWGL_CLIP_MASK
#define SWGL_ANTIALIAS
#define SWGL_BLEND
#define SWGL_CLIP_DIST
#endif
#ifdef WR_VERTEX_SHADER
#ifdef SWGL
// Annotate a vertex attribute as being flat per each drawn primitive instance.
// SWGL can use this information to avoid redundantly loading the attribute in all SIMD lanes.
#define PER_INSTANCE flat
#else
#define PER_INSTANCE
#endif
#if __VERSION__ != 100
#define varying out
#define attribute in
#endif
#endif
#ifdef WR_FRAGMENT_SHADER
precision highp float;
#if __VERSION__ != 100
#define varying in
#endif
#endif
// Flat interpolation is not supported on ESSL 1
#if __VERSION__ == 100
#define flat
#endif
#if defined(WR_FEATURE_TEXTURE_EXTERNAL_ESSL1)
#define TEX_SAMPLE(sampler, tex_coord) texture2D(sampler, tex_coord.xy)
#elif defined(WR_FEATURE_TEXTURE_EXTERNAL_BT709)
// Force conversion from yuv to rgb using BT709 colorspace
#define TEX_SAMPLE(sampler, tex_coord) vec4(yuv_2_rgb(texture(sampler, tex_coord.xy).xyz, itu_709), 1.0)
#else
#define TEX_SAMPLE(sampler, tex_coord) texture(sampler, tex_coord.xy)
#endif
#if defined(WR_FEATURE_TEXTURE_EXTERNAL) && defined(PLATFORM_ANDROID)
// On some Mali GPUs we have encountered crashes in glDrawElements when using
// textureSize(samplerExternalOES) in a vertex shader without potentially
// sampling from the texture. This tricks the driver in to thinking the texture
// may be sampled from, avoiding the crash. See bug 1692848.
uniform bool u_mali_workaround_dummy;
#define TEX_SIZE(sampler) (u_mali_workaround_dummy ? ivec2(texture(sampler, vec2(0.0, 0.0)).rr) : textureSize(sampler, 0))
#else
#define TEX_SIZE(sampler) textureSize(sampler, 0)
#endif
//======================================================================================
// Vertex shader attributes and uniforms
//======================================================================================
#ifdef WR_VERTEX_SHADER
// Uniform inputs
uniform mat4 uTransform; // Orthographic projection
// Attribute inputs
attribute vec2 aPosition;
// get_fetch_uv is a macro to work around a macOS Intel driver parsing bug.
// TODO: convert back to a function once the driver issues are resolved, if ever.
// Do the division with unsigned ints because that's more efficient with D3D
#define get_fetch_uv(i, vpi) ivec2(int(vpi * (uint(i) % (WR_MAX_VERTEX_TEXTURE_WIDTH/vpi))), int(uint(i) / (WR_MAX_VERTEX_TEXTURE_WIDTH/vpi)))
#endif
//======================================================================================
// Fragment shader attributes and uniforms
//======================================================================================
#ifdef WR_FRAGMENT_SHADER
// Uniform inputs
// Fragment shader outputs
#ifdef WR_FEATURE_ADVANCED_BLEND
layout(blend_support_all_equations) out;
#endif
#if __VERSION__ == 100
#define oFragColor gl_FragColor
#elif defined(WR_FEATURE_DUAL_SOURCE_BLENDING)
layout(location = 0, index = 0) out vec4 oFragColor;
layout(location = 0, index = 1) out vec4 oFragBlend;
#else
out vec4 oFragColor;
#endif
// Write an output color in normal shaders.
void write_output(vec4 color) {
oFragColor = color;
}
#define EPSILON 0.0001
// "Show Overdraw" color. Premultiplied.
#define WR_DEBUG_OVERDRAW_COLOR vec4(0.110, 0.077, 0.027, 0.125)
float distance_to_line(vec2 p0, vec2 perp_dir, vec2 p) {
vec2 dir_to_p0 = p0 - p;
return dot(normalize(perp_dir), dir_to_p0);
}
// fwidth is not defined in ESSL 1, but that's okay because we don't need
// it for any ESSL 1 shader variants.
#if __VERSION__ != 100
/// Find the appropriate half range to apply the AA approximation over.
/// This range represents a coefficient to go from one CSS pixel to half a device pixel.
vec2 compute_aa_range_xy(vec2 position) {
return fwidth(position);
}
float compute_aa_range(vec2 position) {
// The constant factor is chosen to compensate for the fact that length(fw) is equal
// to sqrt(2) times the device pixel ratio in the typical case.
//
// This coefficient is chosen to ensure that any sample 0.5 pixels or more inside of
// the shape has no anti-aliasing applied to it (since pixels are sampled at their center,
// such a pixel (axis aligned) is fully inside the border). We need this so that antialiased
// curves properly connect with non-antialiased vertical or horizontal lines, among other things.
//
// Lines over a half-pixel away from the pixel center *can* intersect with the pixel square;
// indeed, unless they are horizontal or vertical, they are guaranteed to. However, choosing
// a nonzero area for such pixels causes noticeable artifacts at the junction between an anti-
// aliased corner and a straight edge.
//
// We may want to adjust this constant in specific scenarios (for example keep the principled
// value for straight edges where we want pixel-perfect equivalence with non antialiased lines
// when axis aligned, while selecting a larger and smoother aa range on curves).
//
// As a further optimization, we compute the reciprocal of this range, such that we
// can then use the cheaper inversesqrt() instead of length(). This also elides a
// division that would otherwise be necessary inside distance_aa.
#ifdef SWGL
// SWGL uses an approximation for fwidth() such that it returns equal x and y.
// Thus, sqrt(2)/length(w) = sqrt(2)/sqrt(x*x + x*x) = recip(x).
return recip(fwidth(position).x);
#else
// sqrt(2)/length(w) = inversesqrt(0.5 * dot(w, w))
vec2 w = fwidth(position);
return inversesqrt(0.5 * dot(w, w));
#endif
}
#endif
/// Return the blending coefficient for distance antialiasing.
///
/// 0.0 means inside the shape, 1.0 means outside.
///
/// This makes the simplifying assumption that the area of a 1x1 pixel square
/// under a line is reasonably similar to just the signed Euclidian distance
/// from the center of the square to that line. This diverges slightly from
/// better approximations of the exact area, but the difference between the
/// methods is not perceptibly noticeable, while this approximation is much
/// faster to compute.
///
/// See the comments in `compute_aa_range()` for more information on the
/// cutoff values of -0.5 and 0.5.
float distance_aa_xy(vec2 aa_range, vec2 signed_distance) {
// The aa_range is the raw per-axis filter width, so we need to divide
// the local signed distance by the filter width to get an approximation
// of screen distance.
#ifdef SWGL
// The SWGL fwidth() approximation returns uniform X and Y ranges.
vec2 dist = signed_distance * recip(aa_range.x);
#else
vec2 dist = signed_distance / aa_range;
#endif
// Choose whichever axis is further outside the rectangle for AA.
return clamp(0.5 - max(dist.x, dist.y), 0.0, 1.0);
}
float distance_aa(float aa_range, float signed_distance) {
// The aa_range is already stored as a reciprocal with uniform scale,
// so just multiply it, then use that for AA.
float dist = signed_distance * aa_range;
return clamp(0.5 - dist, 0.0, 1.0);
}
/// Component-wise selection.
///
/// The idea of using this is to ensure both potential branches are executed before
/// selecting the result, to avoid observable timing differences based on the condition.
///
/// Example usage: color = if_then_else(LessThanEqual(color, vec3(0.5)), vec3(0.0), vec3(1.0));
///
/// The above example sets each component to 0.0 or 1.0 independently depending on whether
/// their values are below or above 0.5.
///
/// This is written as a macro in order to work with vectors of any dimension.
///
/// Note: Some older android devices don't support mix with bvec. If we ever run into them
/// the only option we have is to polyfill it with a branch per component.
#define if_then_else(cond, then_branch, else_branch) mix(else_branch, then_branch, cond)
#endif
//======================================================================================
// Shared shader uniforms
//======================================================================================
#ifdef WR_FEATURE_TEXTURE_2D
uniform sampler2D sColor0;
uniform sampler2D sColor1;
uniform sampler2D sColor2;
#elif defined WR_FEATURE_TEXTURE_RECT
uniform sampler2DRect sColor0;
uniform sampler2DRect sColor1;
uniform sampler2DRect sColor2;
#elif defined(WR_FEATURE_TEXTURE_EXTERNAL) || defined(WR_FEATURE_TEXTURE_EXTERNAL_ESSL1)
uniform samplerExternalOES sColor0;
uniform samplerExternalOES sColor1;
uniform samplerExternalOES sColor2;
#elif defined(WR_FEATURE_TEXTURE_EXTERNAL_BT709)
uniform __samplerExternal2DY2YEXT sColor0;
uniform __samplerExternal2DY2YEXT sColor1;
uniform __samplerExternal2DY2YEXT sColor2;
#endif
#ifdef WR_FEATURE_DITHERING
uniform sampler2D sDither;
#endif
//======================================================================================
// Interpolator definitions
//======================================================================================
//======================================================================================
// VS only types and UBOs
//======================================================================================
//======================================================================================
// VS only functions
//======================================================================================
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
struct RectWithSize {
vec2 p0;
vec2 size;
};
struct RectWithEndpoint {
vec2 p0;
vec2 p1;
};
float point_inside_rect(vec2 p, vec2 p0, vec2 p1) {
vec2 s = step(p0, p) - step(p1, p);
return s.x * s.y;
}
vec2 signed_distance_rect_xy(vec2 pos, vec2 p0, vec2 p1) {
// Instead of using a true signed distance to rect here, we just use the
// simpler approximation of the maximum distance on either axis from the
// outside of the rectangle. This avoids expensive use of length() and only
// causes mostly imperceptible differences at corner pixels.
return max(p0 - pos, pos - p1);
}
float signed_distance_rect(vec2 pos, vec2 p0, vec2 p1) {
// Collapse the per-axis distances to edges to a single approximate value.
vec2 d = signed_distance_rect_xy(pos, p0, p1);
return max(d.x, d.y);
}
vec2 rect_clamp(RectWithEndpoint rect, vec2 pt) {
return clamp(pt, rect.p0, rect.p1);
}
vec2 rect_size(RectWithEndpoint rect) {
return rect.p1 - rect.p0;
}
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifdef WR_VERTEX_SHADER
#define VECS_PER_RENDER_TASK 2U
uniform HIGHP_SAMPLER_FLOAT sampler2D sRenderTasks;
struct RenderTaskData {
RectWithEndpoint task_rect;
vec4 user_data;
};
// See RenderTaskData in render_task.rs
RenderTaskData fetch_render_task_data(int index) {
ivec2 uv = get_fetch_uv(index, VECS_PER_RENDER_TASK);
vec4 texel0 = TEXEL_FETCH(sRenderTasks, uv, 0, ivec2(0, 0));
vec4 texel1 = TEXEL_FETCH(sRenderTasks, uv, 0, ivec2(1, 0));
RectWithEndpoint task_rect = RectWithEndpoint(
texel0.xy,
texel0.zw
);
RenderTaskData data = RenderTaskData(
task_rect,
texel1
);
return data;
}
RectWithEndpoint fetch_render_task_rect(int index) {
ivec2 uv = get_fetch_uv(index, VECS_PER_RENDER_TASK);
vec4 texel0 = TEXEL_FETCH(sRenderTasks, uv, 0, ivec2(0, 0));
vec4 texel1 = TEXEL_FETCH(sRenderTasks, uv, 0, ivec2(1, 0));
RectWithEndpoint task_rect = RectWithEndpoint(
texel0.xy,
texel0.zw
);
return task_rect;
}
#define PIC_TYPE_IMAGE 1
#define PIC_TYPE_TEXT_SHADOW 2
/*
The dynamic picture that this brush exists on. Right now, it
contains minimal information. In the future, it will describe
the transform mode of primitives on this picture, among other things.
*/
struct PictureTask {
RectWithEndpoint task_rect;
float device_pixel_scale;
vec2 content_origin;
};
PictureTask fetch_picture_task(int address) {
RenderTaskData task_data = fetch_render_task_data(address);
PictureTask task = PictureTask(
task_data.task_rect,
task_data.user_data.x,
task_data.user_data.yz
);
return task;
}
#define CLIP_TASK_EMPTY 0x7FFFFFFF
struct ClipArea {
RectWithEndpoint task_rect;
float device_pixel_scale;
vec2 screen_origin;
};
ClipArea fetch_clip_area(int index) {
RenderTaskData task_data;
if (index >= CLIP_TASK_EMPTY) {
// We deliberately create a dummy RenderTaskData here then convert to a
// ClipArea after this if-else statement, rather than initialize the
// ClipArea in separate branches, to avoid a miscompile in some Adreno
// drivers. See bug 1884791. Unfortunately the specific details of the bug
// are unknown, so please take extra care not to regress this when
// refactoring.
task_data = RenderTaskData(RectWithEndpoint(vec2(0.0), vec2(0.0)),
vec4(0.0));
} else {
task_data = fetch_render_task_data(index);
}
return ClipArea(task_data.task_rect, task_data.user_data.x,
task_data.user_data.yz);
}
#endif //WR_VERTEX_SHADER
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
uniform HIGHP_SAMPLER_FLOAT sampler2D sGpuCache;
#define VECS_PER_IMAGE_RESOURCE 2
// TODO(gw): This is here temporarily while we have
// both GPU store and cache. When the GPU
// store code is removed, we can change the
// PrimitiveInstance instance structure to
// use 2x unsigned shorts as vertex attributes
// instead of an int, and encode the UV directly
// in the vertices.
ivec2 get_gpu_cache_uv(HIGHP_FS_ADDRESS int address) {
return ivec2(uint(address) % WR_MAX_VERTEX_TEXTURE_WIDTH,
uint(address) / WR_MAX_VERTEX_TEXTURE_WIDTH);
}
vec4[2] fetch_from_gpu_cache_2_direct(ivec2 address) {
return vec4[2](
TEXEL_FETCH(sGpuCache, address, 0, ivec2(0, 0)),
TEXEL_FETCH(sGpuCache, address, 0, ivec2(1, 0))
);
}
vec4[2] fetch_from_gpu_cache_2(HIGHP_FS_ADDRESS int address) {
ivec2 uv = get_gpu_cache_uv(address);
return vec4[2](
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(0, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(1, 0))
);
}
vec4 fetch_from_gpu_cache_1_direct(ivec2 address) {
return texelFetch(sGpuCache, address, 0);
}
vec4 fetch_from_gpu_cache_1(HIGHP_FS_ADDRESS int address) {
ivec2 uv = get_gpu_cache_uv(address);
return texelFetch(sGpuCache, uv, 0);
}
#ifdef WR_VERTEX_SHADER
vec4[8] fetch_from_gpu_cache_8(int address) {
ivec2 uv = get_gpu_cache_uv(address);
return vec4[8](
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(0, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(1, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(2, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(3, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(4, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(5, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(6, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(7, 0))
);
}
vec4[3] fetch_from_gpu_cache_3(int address) {
ivec2 uv = get_gpu_cache_uv(address);
return vec4[3](
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(0, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(1, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(2, 0))
);
}
vec4[3] fetch_from_gpu_cache_3_direct(ivec2 address) {
return vec4[3](
TEXEL_FETCH(sGpuCache, address, 0, ivec2(0, 0)),
TEXEL_FETCH(sGpuCache, address, 0, ivec2(1, 0)),
TEXEL_FETCH(sGpuCache, address, 0, ivec2(2, 0))
);
}
vec4[4] fetch_from_gpu_cache_4_direct(ivec2 address) {
return vec4[4](
TEXEL_FETCH(sGpuCache, address, 0, ivec2(0, 0)),
TEXEL_FETCH(sGpuCache, address, 0, ivec2(1, 0)),
TEXEL_FETCH(sGpuCache, address, 0, ivec2(2, 0)),
TEXEL_FETCH(sGpuCache, address, 0, ivec2(3, 0))
);
}
vec4[4] fetch_from_gpu_cache_4(int address) {
ivec2 uv = get_gpu_cache_uv(address);
return vec4[4](
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(0, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(1, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(2, 0)),
TEXEL_FETCH(sGpuCache, uv, 0, ivec2(3, 0))
);
}
//TODO: image resource is too specific for this module
struct ImageSource {
RectWithEndpoint uv_rect;
vec4 user_data;
};
ImageSource fetch_image_source(int address) {
//Note: number of blocks has to match `renderer::BLOCKS_PER_UV_RECT`
vec4 data[2] = fetch_from_gpu_cache_2(address);
RectWithEndpoint uv_rect = RectWithEndpoint(data[0].xy, data[0].zw);
return ImageSource(uv_rect, data[1]);
}
ImageSource fetch_image_source_direct(ivec2 address) {
vec4 data[2] = fetch_from_gpu_cache_2_direct(address);
RectWithEndpoint uv_rect = RectWithEndpoint(data[0].xy, data[0].zw);
return ImageSource(uv_rect, data[1]);
}
// Fetch optional extra data for a texture cache resource. This can contain
// a polygon defining a UV rect within the texture cache resource.
// Note: the polygon coordinates are in homogeneous space.
struct ImageSourceExtra {
vec4 st_tl;
vec4 st_tr;
vec4 st_bl;
vec4 st_br;
};
ImageSourceExtra fetch_image_source_extra(int address) {
vec4 data[4] = fetch_from_gpu_cache_4(address + VECS_PER_IMAGE_RESOURCE);
return ImageSourceExtra(
data[0],
data[1],
data[2],
data[3]
);
}
#endif //WR_VERTEX_SHADER
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
flat varying highp vec4 vTransformBounds;
#ifdef WR_VERTEX_SHADER
#define VECS_PER_TRANSFORM 8U
uniform HIGHP_SAMPLER_FLOAT sampler2D sTransformPalette;
void init_transform_vs(vec4 local_bounds) {
vTransformBounds = local_bounds;
}
struct Transform {
mat4 m;
mat4 inv_m;
bool is_axis_aligned;
};
Transform fetch_transform(int id) {
Transform transform;
transform.is_axis_aligned = (id >> 23) == 0;
int index = id & 0x007fffff;
// Create a UV base coord for each 8 texels.
// This is required because trying to use an offset
// of more than 8 texels doesn't work on some versions
// of macOS.
ivec2 uv = get_fetch_uv(index, VECS_PER_TRANSFORM);
ivec2 uv0 = ivec2(uv.x + 0, uv.y);
transform.m[0] = TEXEL_FETCH(sTransformPalette, uv0, 0, ivec2(0, 0));
transform.m[1] = TEXEL_FETCH(sTransformPalette, uv0, 0, ivec2(1, 0));
transform.m[2] = TEXEL_FETCH(sTransformPalette, uv0, 0, ivec2(2, 0));
transform.m[3] = TEXEL_FETCH(sTransformPalette, uv0, 0, ivec2(3, 0));
transform.inv_m[0] = TEXEL_FETCH(sTransformPalette, uv0, 0, ivec2(4, 0));
transform.inv_m[1] = TEXEL_FETCH(sTransformPalette, uv0, 0, ivec2(5, 0));
transform.inv_m[2] = TEXEL_FETCH(sTransformPalette, uv0, 0, ivec2(6, 0));
transform.inv_m[3] = TEXEL_FETCH(sTransformPalette, uv0, 0, ivec2(7, 0));
return transform;
}
// Return the intersection of the plane (set up by "normal" and "point")
// with the ray (set up by "ray_origin" and "ray_dir"),
// writing the resulting scaler into "t".
bool ray_plane(vec3 normal, vec3 pt, vec3 ray_origin, vec3 ray_dir, out float t)
{
float denom = dot(normal, ray_dir);
if (abs(denom) > 1e-6) {
vec3 d = pt - ray_origin;
t = dot(d, normal) / denom;
return t >= 0.0;
}
return false;
}
// Apply the inverse transform "inv_transform"
// to the reference point "ref" in CSS space,
// producing a local point on a Transform plane,
// set by a base point "a" and a normal "n".
vec4 untransform(vec2 ref, vec3 n, vec3 a, mat4 inv_transform) {
vec3 p = vec3(ref, -10000.0);
vec3 d = vec3(0, 0, 1.0);
float t = 0.0;
// get an intersection of the Transform plane with Z axis vector,
// originated from the "ref" point
ray_plane(n, a, p, d, t);
float z = p.z + d.z * t; // Z of the visible point on the Transform
vec4 r = inv_transform * vec4(ref, z, 1.0);
return r;
}
// Given a CSS space position, transform it back into the Transform space.
vec4 get_node_pos(vec2 pos, Transform transform) {
// get a point on the scroll node plane
vec4 ah = transform.m * vec4(0.0, 0.0, 0.0, 1.0);
vec3 a = ah.xyz / ah.w;
// get the normal to the scroll node plane
vec3 n = transpose(mat3(transform.inv_m)) * vec3(0.0, 0.0, 1.0);
return untransform(pos, n, a, transform.inv_m);
}
#endif //WR_VERTEX_SHADER
#ifdef WR_FRAGMENT_SHADER
// Assume transform bounds are set to a large scale to signal they are invalid.
bool has_valid_transform_bounds() {
return vTransformBounds.w < 1.0e15;
}
float init_transform_fs(vec2 local_pos) {
// Ideally we want to track distances in screen space after transformation
// as signed distance calculations lose context about the direction vector
// to exit the geometry, merely remembering the minimum distance to the
// exit. However, we can't always sanely track distances in screen space
// due to perspective transforms, clipping, and other concerns, so we do
// this in local space. However, this causes problems tracking distances
// in local space when attempting to scale by a uniform AA range later in
// the presence of a transform which actually has non-uniform scaling.
//
// To work around this, we independently track the distances on the local
// space X and Y axes and then scale them by the independent AA ranges (as
// computed from fwidth derivatives) for the X and Y axes. This can break
// down at certain angles (45 degrees or close to it), but still gives a
// better approximation of screen-space distances in the presence of non-
// uniform scaling for other rotations.
//
// Get signed distance from local rect bounds.
vec2 d = signed_distance_rect_xy(
local_pos,
vTransformBounds.xy,
vTransformBounds.zw
);
// Find the appropriate distance to apply the AA smoothstep over.
vec2 aa_range = compute_aa_range_xy(local_pos);
// Only apply AA to fragments outside the signed distance field.
return distance_aa_xy(aa_range, d);
}
float init_transform_rough_fs(vec2 local_pos) {
return point_inside_rect(
local_pos,
vTransformBounds.xy,
vTransformBounds.zw
);
}
#endif //WR_FRAGMENT_SHADER
#define EXTEND_MODE_CLAMP 0
#define EXTEND_MODE_REPEAT 1
#define SUBPX_DIR_NONE 0
#define SUBPX_DIR_HORIZONTAL 1
#define SUBPX_DIR_VERTICAL 2
#define SUBPX_DIR_MIXED 3
#define RASTER_LOCAL 0
#define RASTER_SCREEN 1
uniform sampler2D sClipMask;
#ifndef SWGL_CLIP_MASK
// TODO: convert back to RectWithEndpoint if driver issues are resolved, if ever.
flat varying mediump vec4 vClipMaskUvBounds;
varying highp vec2 vClipMaskUv;
#endif
#ifdef WR_VERTEX_SHADER
#define COLOR_MODE_ALPHA 0
#define COLOR_MODE_SUBPX_DUAL_SOURCE 1
#define COLOR_MODE_BITMAP_SHADOW 2
#define COLOR_MODE_COLOR_BITMAP 3
#define COLOR_MODE_IMAGE 4
#define COLOR_MODE_MULTIPLY_DUAL_SOURCE 5
uniform HIGHP_SAMPLER_FLOAT sampler2D sPrimitiveHeadersF;
uniform HIGHP_SAMPLER_FLOAT isampler2D sPrimitiveHeadersI;
// Instanced attributes
PER_INSTANCE in ivec4 aData;
#define VECS_PER_PRIM_HEADER_F 2U
#define VECS_PER_PRIM_HEADER_I 2U
struct Instance
{
int prim_header_address;
int clip_address;
int segment_index;
int flags;
int resource_address;
int brush_kind;
};
Instance decode_instance_attributes() {
Instance instance;
instance.prim_header_address = aData.x;
instance.clip_address = aData.y;
instance.segment_index = aData.z & 0xffff;
instance.flags = aData.z >> 16;
instance.resource_address = aData.w & 0xffffff;
instance.brush_kind = aData.w >> 24;
return instance;
}
struct PrimitiveHeader {
RectWithEndpoint local_rect;
RectWithEndpoint local_clip_rect;
float z;
int specific_prim_address;
int transform_id;
int picture_task_address;
ivec4 user_data;
};
PrimitiveHeader fetch_prim_header(int index) {
PrimitiveHeader ph;
ivec2 uv_f = get_fetch_uv(index, VECS_PER_PRIM_HEADER_F);
vec4 local_rect = TEXEL_FETCH(sPrimitiveHeadersF, uv_f, 0, ivec2(0, 0));
vec4 local_clip_rect = TEXEL_FETCH(sPrimitiveHeadersF, uv_f, 0, ivec2(1, 0));
ph.local_rect = RectWithEndpoint(local_rect.xy, local_rect.zw);
ph.local_clip_rect = RectWithEndpoint(local_clip_rect.xy, local_clip_rect.zw);
ivec2 uv_i = get_fetch_uv(index, VECS_PER_PRIM_HEADER_I);
ivec4 data0 = TEXEL_FETCH(sPrimitiveHeadersI, uv_i, 0, ivec2(0, 0));
ivec4 data1 = TEXEL_FETCH(sPrimitiveHeadersI, uv_i, 0, ivec2(1, 0));
ph.z = float(data0.x);
ph.specific_prim_address = data0.y;
ph.transform_id = data0.z;
ph.picture_task_address = data0.w;
ph.user_data = data1;
return ph;
}
struct VertexInfo {
vec2 local_pos;
vec4 world_pos;
};
VertexInfo write_vertex(vec2 local_pos,
RectWithEndpoint local_clip_rect,
float z,
Transform transform,
PictureTask task) {
// Clamp to the two local clip rects.
vec2 clamped_local_pos = rect_clamp(local_clip_rect, local_pos);
// Transform the current vertex to world space.
vec4 world_pos = transform.m * vec4(clamped_local_pos, 0.0, 1.0);
// Convert the world positions to device pixel space.
vec2 device_pos = world_pos.xy * task.device_pixel_scale;
// Apply offsets for the render task to get correct screen location.
vec2 final_offset = -task.content_origin + task.task_rect.p0;
gl_Position = uTransform * vec4(device_pos + final_offset * world_pos.w, z * world_pos.w, world_pos.w);
VertexInfo vi = VertexInfo(
clamped_local_pos,
world_pos
);
return vi;
}
RectWithEndpoint clip_and_init_antialiasing(RectWithEndpoint segment_rect,
RectWithEndpoint prim_rect,
RectWithEndpoint clip_rect,
int edge_flags,
float z,
Transform transform,
PictureTask task) {
#ifdef SWGL_ANTIALIAS
// Check if the bounds are smaller than the unmodified segment rect. If so,
// it is safe to enable AA on those edges.
bvec4 clipped = bvec4(greaterThan(clip_rect.p0, segment_rect.p0),
lessThan(clip_rect.p1, segment_rect.p1));
swgl_antiAlias(edge_flags | (clipped.x ? 1 : 0) | (clipped.y ? 2 : 0) |
(clipped.z ? 4 : 0) | (clipped.w ? 8 : 0));
#endif
segment_rect.p0 = clamp(segment_rect.p0, clip_rect.p0, clip_rect.p1);
segment_rect.p1 = clamp(segment_rect.p1, clip_rect.p0, clip_rect.p1);
#ifndef SWGL_ANTIALIAS
prim_rect.p0 = clamp(prim_rect.p0, clip_rect.p0, clip_rect.p1);
prim_rect.p1 = clamp(prim_rect.p1, clip_rect.p0, clip_rect.p1);
// Select between the segment and prim edges based on edge mask.
// We must perform the bitwise-and for each component individually, as a
// vector bitwise-and followed by conversion to bvec4 causes shader
// compilation crashes on some Adreno devices. See bug 1715746.
bvec4 clip_edge_mask = bvec4(bool(edge_flags & 1), bool(edge_flags & 2), bool(edge_flags & 4), bool(edge_flags & 8));
init_transform_vs(mix(
vec4(vec2(-1e16), vec2(1e16)),
vec4(segment_rect.p0, segment_rect.p1),
clip_edge_mask
));
// As this is a transform shader, extrude by 2 (local space) pixels
// in each direction. This gives enough space around the edge to
// apply distance anti-aliasing. Technically, it:
// (a) slightly over-estimates the number of required pixels in the simple case.
// (b) might not provide enough edge in edge case perspective projections.
// However, it's fast and simple. If / when we ever run into issues, we
// can do some math on the projection matrix to work out a variable
// amount to extrude.
// Only extrude along edges where we are going to apply AA.
float extrude_amount = 2.0;
vec4 extrude_distance = mix(vec4(0.0), vec4(extrude_amount), clip_edge_mask);
segment_rect.p0 -= extrude_distance.xy;
segment_rect.p1 += extrude_distance.zw;
#endif
return segment_rect;
}
void write_clip(vec4 world_pos, ClipArea area, PictureTask task) {
#ifdef SWGL_CLIP_MASK
swgl_clipMask(
sClipMask,
(task.task_rect.p0 - task.content_origin) - (area.task_rect.p0 - area.screen_origin),
area.task_rect.p0,
rect_size(area.task_rect)
);
#else
vec2 uv = world_pos.xy * area.device_pixel_scale +
world_pos.w * (area.task_rect.p0 - area.screen_origin);
vClipMaskUvBounds = vec4(
area.task_rect.p0,
area.task_rect.p1
);
vClipMaskUv = uv;
#endif
}
// Read the exta image data containing the homogeneous screen space coordinates
// of the corners, interpolate between them, and return real screen space UV.
vec2 get_image_quad_uv(int address, vec2 f) {
ImageSourceExtra extra_data = fetch_image_source_extra(address);
vec4 x = mix(extra_data.st_tl, extra_data.st_tr, f.x);
vec4 y = mix(extra_data.st_bl, extra_data.st_br, f.x);
vec4 z = mix(x, y, f.y);
return z.xy / z.w;
}
#endif //WR_VERTEX_SHADER
#ifdef WR_FRAGMENT_SHADER
struct Fragment {
vec4 color;
#ifdef WR_FEATURE_DUAL_SOURCE_BLENDING
vec4 blend;
#endif
};
float do_clip() {
#ifdef SWGL_CLIP_MASK
// SWGL relies on builtin clip-mask support to do this more efficiently,
// so no clipping is required here.
return 1.0;
#else
// check for the dummy bounds, which are given to the opaque objects
if (vClipMaskUvBounds.xy == vClipMaskUvBounds.zw) {
return 1.0;
}
// anything outside of the mask is considered transparent
//Note: we assume gl_FragCoord.w == interpolated(1 / vClipMaskUv.w)
vec2 mask_uv = vClipMaskUv * gl_FragCoord.w;
bvec2 left = lessThanEqual(vClipMaskUvBounds.xy, mask_uv); // inclusive
bvec2 right = greaterThan(vClipMaskUvBounds.zw, mask_uv); // non-inclusive
// bail out if the pixel is outside the valid bounds
if (!all(bvec4(left, right))) {
return 0.0;
}
// finally, the slow path - fetch the mask value from an image
return texelFetch(sClipMask, ivec2(mask_uv), 0).r;
#endif
}
#endif //WR_FRAGMENT_SHADER
flat varying mediump vec4 v_color;
flat varying mediump vec3 v_mask_swizzle;
// Normalized bounds of the source image in the texture.
flat varying highp vec4 v_uv_bounds;
// Interpolated UV coordinates to sample.
varying highp vec2 v_uv;
#if defined(WR_FEATURE_GLYPH_TRANSFORM) && !defined(SWGL_CLIP_DIST)
varying highp vec4 v_uv_clip;
#endif
#ifdef WR_VERTEX_SHADER
#define VECS_PER_TEXT_RUN 1
#define GLYPHS_PER_GPU_BLOCK 2U
#ifdef WR_FEATURE_GLYPH_TRANSFORM
RectWithEndpoint transform_rect(RectWithEndpoint rect, mat2 transform) {
vec2 size = rect_size(rect);
vec2 center = transform * (rect.p0 + size * 0.5);
vec2 radius = mat2(abs(transform[0]), abs(transform[1])) * (size * 0.5);
return RectWithEndpoint(center - radius, center + radius);
}
bool rect_inside_rect(RectWithEndpoint little, RectWithEndpoint big) {
return all(lessThanEqual(vec4(big.p0, little.p1), vec4(little.p0, big.p1)));
}
#endif //WR_FEATURE_GLYPH_TRANSFORM
struct Glyph {
vec2 offset;
};
Glyph fetch_glyph(int specific_prim_address,
int glyph_index) {
// Two glyphs are packed in each texel in the GPU cache.
int glyph_address = specific_prim_address +
VECS_PER_TEXT_RUN +
int(uint(glyph_index) / GLYPHS_PER_GPU_BLOCK);
vec4 data = fetch_from_gpu_cache_1(glyph_address);
// Select XY or ZW based on glyph index.
vec2 glyph = mix(data.xy, data.zw,
bvec2(uint(glyph_index) % GLYPHS_PER_GPU_BLOCK == 1U));
return Glyph(glyph);
}
struct GlyphResource {
vec4 uv_rect;
vec2 offset;
float scale;
};
GlyphResource fetch_glyph_resource(int address) {
vec4 data[2] = fetch_from_gpu_cache_2(address);
return GlyphResource(data[0], data[1].xy, data[1].z);
}
struct TextRun {
vec4 color;
};
TextRun fetch_text_run(int address) {
vec4 data = fetch_from_gpu_cache_1(address);
return TextRun(data);
}
vec2 get_snap_bias(int subpx_dir) {
// In subpixel mode, the subpixel offset has already been
// accounted for while rasterizing the glyph. However, we
// must still round with a subpixel bias rather than rounding
// to the nearest whole pixel, depending on subpixel direciton.
switch (subpx_dir) {
case SUBPX_DIR_NONE:
default:
return vec2(0.5);
case SUBPX_DIR_HORIZONTAL:
// Glyphs positioned [-0.125, 0.125] get a
// subpx position of zero. So include that
// offset in the glyph position to ensure
// we round to the correct whole position.
return vec2(0.125, 0.5);
case SUBPX_DIR_VERTICAL:
return vec2(0.5, 0.125);
case SUBPX_DIR_MIXED:
return vec2(0.125);
}
}
void main() {
Instance instance = decode_instance_attributes();
PrimitiveHeader ph = fetch_prim_header(instance.prim_header_address);
Transform transform = fetch_transform(ph.transform_id);
ClipArea clip_area = fetch_clip_area(instance.clip_address);
PictureTask task = fetch_picture_task(ph.picture_task_address);
int glyph_index = instance.segment_index;
int subpx_dir = (instance.flags >> 8) & 0xff;
int color_mode = instance.flags & 0xff;
// Note that the reference frame relative offset is stored in the prim local
// rect size during batching, instead of the actual size of the primitive.
TextRun text = fetch_text_run(ph.specific_prim_address);
vec2 text_offset = ph.local_rect.p1;
// Note that the unsnapped reference frame relative offset has already
// been subtracted from the prim local rect origin during batching.
// It was done this way to avoid pushing both the snapped and the
// unsnapped offsets to the shader.
Glyph glyph = fetch_glyph(ph.specific_prim_address, glyph_index);
glyph.offset += ph.local_rect.p0;
GlyphResource res = fetch_glyph_resource(instance.resource_address);
vec2 snap_bias = get_snap_bias(subpx_dir);
// Glyph space refers to the pixel space used by glyph rasterization during frame
// building. If a non-identity transform was used, WR_FEATURE_GLYPH_TRANSFORM will
// be set. Otherwise, regardless of whether the raster space is LOCAL or SCREEN,
// we ignored the transform during glyph rasterization, and need to snap just using
// the device pixel scale and the raster scale.
#ifdef WR_FEATURE_GLYPH_TRANSFORM
// Transform from local space to glyph space.
mat2 glyph_transform = mat2(transform.m) * task.device_pixel_scale;
vec2 glyph_translation = transform.m[3].xy * task.device_pixel_scale;
// Transform from glyph space back to local space.
mat2 glyph_transform_inv = inverse(glyph_transform);
// Glyph raster pixels include the impact of the transform. This path can only be
// entered for 3d transforms that can be coerced into a 2d transform; they have no
// perspective, and have a 2d inverse. This is a looser condition than axis aligned
// transforms because it also allows 2d rotations.
vec2 raster_glyph_offset = floor(glyph_transform * glyph.offset + snap_bias);
// We want to eliminate any subpixel translation in device space to ensure glyph
// snapping is stable for equivalent glyph subpixel positions. Note that we must take
// into account the translation from the transform for snapping purposes.
vec2 raster_text_offset = floor(glyph_transform * text_offset + glyph_translation + 0.5) - glyph_translation;
vec2 glyph_origin = res.offset + raster_glyph_offset + raster_text_offset;
// Compute the glyph rect in glyph space.
RectWithEndpoint glyph_rect = RectWithEndpoint(
glyph_origin,
glyph_origin + res.uv_rect.zw - res.uv_rect.xy
);
// The glyph rect is in glyph space, so transform it back to local space.
RectWithEndpoint local_rect = transform_rect(glyph_rect, glyph_transform_inv);
// Select the corner of the glyph's local space rect that we are processing.
vec2 local_pos = mix(local_rect.p0, local_rect.p1, aPosition.xy);
// If the glyph's local rect would fit inside the local clip rect, then select a corner from
// the device space glyph rect to reduce overdraw of clipped pixels in the fragment shader.
// Otherwise, fall back to clamping the glyph's local rect to the local clip rect.
if (rect_inside_rect(local_rect, ph.local_clip_rect)) {
local_pos = glyph_transform_inv * mix(glyph_rect.p0, glyph_rect.p1, aPosition.xy);
}
#else
float raster_scale = float(ph.user_data.x) / 65535.0;
// Scale in which the glyph is snapped when rasterized.
float glyph_raster_scale = raster_scale * task.device_pixel_scale;
// Scale from glyph space to local space.
float glyph_scale_inv = res.scale / glyph_raster_scale;
// Glyph raster pixels do not include the impact of the transform. Instead it was
// replaced with an identity transform during glyph rasterization. As such only the
// impact of the raster scale (if in local space) and the device pixel scale (for both
// local and screen space) are included.
//
// This implies one or more of the following conditions:
// - The transform is an identity. In that case, setting WR_FEATURE_GLYPH_TRANSFORM
// should have the same output result as not. We just distingush which path to use
// based on the transform used during glyph rasterization. (Screen space).
// - The transform contains an animation. We will imply local raster space in such
// cases to avoid constantly rerasterizing the glyphs.
// - The transform has perspective or does not have a 2d inverse (Screen or local space).
// - The transform's scale will result in result in very large rasterized glyphs and
// we clamped the size. This will imply local raster space.
vec2 raster_glyph_offset = floor(glyph.offset * glyph_raster_scale + snap_bias) / res.scale;
// Compute the glyph rect in local space.
//
// The transform may be animated, so we don't want to do any snapping here for the
// text offset to avoid glyphs wiggling. The text offset should have been snapped
// already for axis aligned transforms excluding any animations during frame building.
vec2 glyph_origin = glyph_scale_inv * (res.offset + raster_glyph_offset) + text_offset;
RectWithEndpoint glyph_rect = RectWithEndpoint(
glyph_origin,
glyph_origin + glyph_scale_inv * (res.uv_rect.zw - res.uv_rect.xy)
);
// Select the corner of the glyph rect that we are processing.
vec2 local_pos = mix(glyph_rect.p0, glyph_rect.p1, aPosition.xy);
#endif
VertexInfo vi = write_vertex(
local_pos,
ph.local_clip_rect,
ph.z,
transform,
task
);
#ifdef WR_FEATURE_GLYPH_TRANSFORM
vec2 f = (glyph_transform * vi.local_pos - glyph_rect.p0) / rect_size(glyph_rect);
#ifdef SWGL_CLIP_DIST
gl_ClipDistance[0] = f.x;
gl_ClipDistance[1] = f.y;
gl_ClipDistance[2] = 1.0 - f.x;
gl_ClipDistance[3] = 1.0 - f.y;
#else
v_uv_clip = vec4(f, 1.0 - f);
#endif
#else
vec2 f = (vi.local_pos - glyph_rect.p0) / rect_size(glyph_rect);
#endif
write_clip(vi.world_pos, clip_area, task);
switch (color_mode) {
case COLOR_MODE_ALPHA:
v_mask_swizzle = vec3(0.0, 1.0, 1.0);
v_color = text.color;
break;
case COLOR_MODE_BITMAP_SHADOW:
#ifdef SWGL_BLEND
swgl_blendDropShadow(text.color);
v_mask_swizzle = vec3(1.0, 0.0, 0.0);
v_color = vec4(1.0);
#else
v_mask_swizzle = vec3(0.0, 1.0, 0.0);
v_color = text.color;
#endif
break;
case COLOR_MODE_COLOR_BITMAP:
v_mask_swizzle = vec3(1.0, 0.0, 0.0);
v_color = vec4(text.color.a);
break;
case COLOR_MODE_SUBPX_DUAL_SOURCE:
#ifdef SWGL_BLEND
swgl_blendSubpixelText(text.color);
v_mask_swizzle = vec3(1.0, 0.0, 0.0);
v_color = vec4(1.0);
#else
v_mask_swizzle = vec3(text.color.a, 0.0, 0.0);
v_color = text.color;
#endif
break;
default:
v_mask_swizzle = vec3(0.0, 0.0, 0.0);
v_color = vec4(1.0);
}
vec2 texture_size = vec2(TEX_SIZE(sColor0));
vec2 st0 = res.uv_rect.xy / texture_size;
vec2 st1 = res.uv_rect.zw / texture_size;
v_uv = mix(st0, st1, f);
v_uv_bounds = (res.uv_rect + vec4(0.5, 0.5, -0.5, -0.5)) / texture_size.xyxy;
}
#endif // WR_VERTEX_SHADER
#ifdef WR_FRAGMENT_SHADER
Fragment text_fs(void) {
Fragment frag;
vec2 tc = clamp(v_uv, v_uv_bounds.xy, v_uv_bounds.zw);
vec4 mask = texture(sColor0, tc);
// v_mask_swizzle.z != 0 means we are using an R8 texture as alpha,
// and therefore must swizzle from the r channel to all channels.
mask = mix(mask, mask.rrrr, bvec4(v_mask_swizzle.z != 0.0));
#ifndef WR_FEATURE_DUAL_SOURCE_BLENDING
mask.rgb = mask.rgb * v_mask_swizzle.x + mask.aaa * v_mask_swizzle.y;
#endif
#if defined(WR_FEATURE_GLYPH_TRANSFORM) && !defined(SWGL_CLIP_DIST)
mask *= float(all(greaterThanEqual(v_uv_clip, vec4(0.0))));
#endif
frag.color = v_color * mask;
#if defined(WR_FEATURE_DUAL_SOURCE_BLENDING) && !defined(SWGL_BLEND)
frag.blend = mask * v_mask_swizzle.x + mask.aaaa * v_mask_swizzle.y;
#endif
return frag;
}
void main() {
Fragment frag = text_fs();
float clip_mask = do_clip();
frag.color *= clip_mask;
#if defined(WR_FEATURE_DEBUG_OVERDRAW)
oFragColor = WR_DEBUG_OVERDRAW_COLOR;
#elif defined(WR_FEATURE_DUAL_SOURCE_BLENDING) && !defined(SWGL_BLEND)
oFragColor = frag.color;
oFragBlend = frag.blend * clip_mask;
#else
write_output(frag.color);
#endif
}
#if defined(SWGL_DRAW_SPAN) && defined(SWGL_BLEND) && defined(SWGL_CLIP_DIST)
void swgl_drawSpanRGBA8() {
// Only support simple swizzles for now. More complex swizzles must either
// be handled by blend overrides or the slow path.
if (v_mask_swizzle.x != 0.0 && v_mask_swizzle.x != 1.0) {
return;
}
#ifdef WR_FEATURE_DUAL_SOURCE_BLENDING
swgl_commitTextureLinearRGBA8(sColor0, v_uv, v_uv_bounds);
#else
if (swgl_isTextureR8(sColor0)) {
swgl_commitTextureLinearColorR8ToRGBA8(sColor0, v_uv, v_uv_bounds, v_color);
} else {
swgl_commitTextureLinearColorRGBA8(sColor0, v_uv, v_uv_bounds, v_color);
}
#endif
}
#endif
#endif // WR_FRAGMENT_SHADER