3 layout(location=0) in vec2 aPosition;
4 layout(location=0) out vec2 vTexCoord;
5 layout(location=1) out vec2 vMaskTexCoord;
7 // using specialization constants
8 layout(constant_id = 0) const int FACTOR_SIZE_X = 4;
9 layout(constant_id = 1) const int FACTOR_SIZE_Y = 4;
11 layout(set=0, binding=0, std140) uniform VertData
15 vec2 uNinePatchFactorsX[ FACTOR_SIZE_X ];
16 vec2 uNinePatchFactorsY[ FACTOR_SIZE_Y ];
18 //Visual size and offset
28 vec2 fixedFactor = vec2( uNinePatchFactorsX[ int( ( aPosition.x + 1.0 ) * 0.5 ) ].x, uNinePatchFactorsY[ int( ( aPosition.y + 1.0 ) * 0.5 ) ].x );
29 vec2 stretch = vec2( uNinePatchFactorsX[ int( ( aPosition.x ) * 0.5 ) ].y, uNinePatchFactorsY[ int( ( aPosition.y ) * 0.5 ) ].y );
31 vec2 fixedTotal = vec2( uNinePatchFactorsX[ FACTOR_SIZE_X - 1 ].x, uNinePatchFactorsY[ FACTOR_SIZE_Y - 1 ].x );
32 vec2 stretchTotal = vec2( uNinePatchFactorsX[ FACTOR_SIZE_X - 1 ].y, uNinePatchFactorsY[ FACTOR_SIZE_Y - 1 ].y );
34 vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
35 vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
37 vec4 gridPosition = vec4( fixedFactor + ( visualSize.xy - fixedTotal ) * stretch / stretchTotal, 0.0, 1.0 );
38 vec4 vertexPosition = gridPosition;
39 vertexPosition.xy -= visualSize.xy * vec2( 0.5, 0.5 );
40 vertexPosition.xy += anchorPoint*visualSize + (visualOffset + origin)*uSize.xy;
41 vertexPosition = uMvpMatrix * vertexPosition;
43 vTexCoord = ( fixedFactor + stretch ) / ( fixedTotal + stretchTotal );
44 vMaskTexCoord = gridPosition.xy / visualSize;
45 gl_Position = vertexPosition;