pathfinder/demo2/cover.vs.glsl

44 lines
1.3 KiB
Plaintext
Raw Normal View History

2018-11-14 16:56:45 -05:00
#version 300 es
// pathfinder/demo2/cover.vs.glsl
//
// Copyright © 2018 The Pathfinder Project Developers.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
precision highp float;
uniform vec2 uFramebufferSize;
uniform vec2 uTileSize;
2018-11-15 17:37:32 -05:00
uniform vec2 uStencilTextureSize;
2018-12-21 17:10:26 -05:00
uniform vec2 uViewBoxOrigin;
2018-11-14 16:56:45 -05:00
in vec2 aTessCoord;
in vec2 aTileOrigin;
2018-12-18 17:00:46 -05:00
in float aBackdrop;
2018-11-15 21:06:19 -05:00
in vec4 aColor;
2018-11-15 17:37:32 -05:00
out vec2 vTexCoord;
2018-12-18 17:00:46 -05:00
out float vBackdrop;
2018-11-15 21:06:19 -05:00
out vec4 vColor;
2018-11-15 17:37:32 -05:00
vec2 computeTileOffset(uint tileIndex, float stencilTextureWidth) {
uint tilesPerRow = uint(stencilTextureWidth / uTileSize.x);
2018-12-19 20:05:01 -05:00
uvec2 tileOffset = uvec2(tileIndex % tilesPerRow, tileIndex / tilesPerRow);
2018-11-15 17:37:32 -05:00
return vec2(tileOffset) * uTileSize;
}
2018-11-14 16:56:45 -05:00
void main() {
2018-12-19 20:05:01 -05:00
uint tileIndex = uint(gl_InstanceID);
2018-12-21 17:10:26 -05:00
vec2 position = (aTileOrigin + aTessCoord) * uTileSize + uViewBoxOrigin;
2018-12-19 20:05:01 -05:00
vec2 texCoord = computeTileOffset(tileIndex, uStencilTextureSize.x) + aTessCoord * uTileSize;
2018-11-15 17:37:32 -05:00
vTexCoord = texCoord / uStencilTextureSize;
2018-12-18 17:00:46 -05:00
vBackdrop = aBackdrop;
2018-11-15 21:06:19 -05:00
vColor = aColor;
2018-11-15 17:37:32 -05:00
gl_Position = vec4((position / uFramebufferSize * 2.0 - 1.0) * vec2(1.0, -1.0), 0.0, 1.0);
2018-11-14 16:56:45 -05:00
}