[Vulkan] Builtin shaders and shaders offline compilation script
[platform/core/uifw/dali-core.git] / dali / graphics / vulkan / shaders / npatch-visual-shader.vert
1 #version 430
2
3 layout(location=0) in vec2 aPosition;
4 layout(location=0) out vec2 vTexCoord;
5
6 // using specialization constants
7 layout(constant_id = 0) const int FACTOR_SIZE_X = 4;
8 layout(constant_id = 1) const int FACTOR_SIZE_Y = 4;
9
10 layout(set=0, binding=0, std140) uniform VertData
11 {
12     mat4 uMvpMatrix;
13     vec3 uSize;
14     vec2 uNinePatchFactorsX[ FACTOR_SIZE_X ];
15     vec2 uNinePatchFactorsY[ FACTOR_SIZE_Y ];
16
17     //Visual size and offset
18     vec2 offset;
19     vec2 size;
20     vec4 offsetSizeMode;
21     vec2 origin;
22     vec2 anchorPoint;
23 };
24
25 void main()
26 {
27     vec2 fixedFactor  = vec2( uNinePatchFactorsX[ int( ( aPosition.x + 1.0 ) * 0.5 ) ].x, uNinePatchFactorsY[ int( ( aPosition.y + 1.0 ) * 0.5 ) ].x );
28     vec2 stretch      = vec2( uNinePatchFactorsX[ int( ( aPosition.x       ) * 0.5 ) ].y, uNinePatchFactorsY[ int( ( aPosition.y       ) * 0.5 ) ].y );
29
30     vec2 fixedTotal   = vec2( uNinePatchFactorsX[ FACTOR_SIZE_X - 1 ].x, uNinePatchFactorsY[ FACTOR_SIZE_Y - 1 ].x );
31     vec2 stretchTotal = vec2( uNinePatchFactorsX[ FACTOR_SIZE_X - 1 ].y, uNinePatchFactorsY[ FACTOR_SIZE_Y - 1 ].y );
32
33
34     vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
35     vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);
36
37     vec4 vertexPosition = vec4( ( fixedFactor + ( visualSize.xy - fixedTotal ) * stretch / stretchTotal ) +  anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
38     vertexPosition.xy -= visualSize.xy * vec2( 0.5, 0.5 );
39
40     vertexPosition = uMvpMatrix * vertexPosition;
41
42     vTexCoord = ( fixedFactor + stretch ) / ( fixedTotal + stretchTotal );
43
44     gl_Position = vertexPosition;
45 }