Skip to content

Commit

Permalink
update image shader.
Browse files Browse the repository at this point in the history
  • Loading branch information
JerryShih committed Mar 28, 2017
1 parent b3a3dfd commit 224cf99
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions webrender/res/ps_image.fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ void main(void) {

alpha = alpha * float(all(bvec2(step(position_in_tile, vStretchSize))));

#ifndef WR_FEATURE_TEXTURE_RECT
oFragColor = vec4(alpha) * textureLod(sColor0, st, 0.0);
#else
#ifdef WR_FEATURE_TEXTURE_RECT
// textureLod doesn't support sampler2DRect. Use texture() instead.
oFragColor = vec4(alpha) * texture(sColor0, st);
#else
oFragColor = vec4(alpha) * textureLod(sColor0, st, 0.0);
#endif
}
2 changes: 1 addition & 1 deletion webrender/res/ps_image.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// If this is in WR_FEATURE_TEXTURE_RECT mode, the rect and size use non-normalized
// texture coordinates. Otherwise, it's use normalized texture coordinates. Please
// texture coordinates. Otherwise, it uses normalized texture coordinates. Please
// check GL_TEXTURE_RECTANGLE.
flat varying vec2 vTextureOffset; // Offset of this image into the texture atlas.
flat varying vec2 vTextureSize; // Size of the image in the texture atlas.
Expand Down
30 changes: 15 additions & 15 deletions webrender/res/ps_image.vs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@ void main(void) {
vTileSpacing = image.stretch_size_and_tile_spacing.zw;
vStretchSize = image.stretch_size_and_tile_spacing.xy;

// We clamp the texture coordinates to the half-pixel offset from the borders
// in order to avoid sampling outside of the texture area.
// If this is in WR_FEATURE_TEXTURE_RECT mode, the rect and size use
// non-normalized texture coordinates.
#ifdef WR_FEATURE_TEXTURE_RECT
vec2 texture_size_normalization_factor = vec2(1, 1);
#else
vec2 texture_size_normalization_factor = vec2(textureSize(sColor0, 0));
#endif

// vUv will contain how many times this image has wrapped around the image size.
#ifndef WR_FEATURE_TEXTURE_RECT
vec2 texture_size = vec2(textureSize(sColor0, 0));
vec2 st0 = res.uv_rect.xy / texture_size;
vec2 st1 = res.uv_rect.zw / texture_size;
vec2 st0 = res.uv_rect.xy / texture_size_normalization_factor;
vec2 st1 = res.uv_rect.zw / texture_size_normalization_factor;

vTextureSize = st1 - st0;
vTextureOffset = st0;
vTileSpacing = image.stretch_size_and_tile_spacing.zw;
vStretchSize = image.stretch_size_and_tile_spacing.xy;

vec2 half_texel = vec2(0.5) / texture_size;
// We clamp the texture coordinates to the half-pixel offset from the borders
// in order to avoid sampling outside of the texture area.
vec2 half_texel = vec2(0.5) / texture_size_normalization_factor;
vStRect = vec4(min(st0, st1) + half_texel, max(st0, st1) - half_texel);
#else
vTextureSize = res.uv_rect.zw - res.uv_rect.xy;
vTextureOffset = res.uv_rect.xy;

vec2 half_texel = vec2(0.5);
vStRect = vec4(min(res.uv_rect.xy, res.uv_rect.zw) + half_texel,
max(res.uv_rect.xy, res.uv_rect.zw)) - half_texel;
#endif
}

0 comments on commit 224cf99

Please sign in to comment.