[Vulkan] Builtin shaders and shaders offline compilation script
[platform/core/uifw/dali-core.git] / dali / graphics / vulkan / shaders / mesh-visual-simple-shader.vert
1 #version 430
2
3 layout(location=0) in vec3 aPosition;
4 layout(location=1) in vec3 aNormal;
5
6 layout(location=0) out vec3 vIllumination;
7
8 layout(set=0, binding=0, std140) uniform VertData
9 {
10     vec3 uSize;
11     mat4 uMvpMatrix;
12     mat4 uModelView;
13     mat4 uViewMatrix;
14     mat3 uNormalMatrix;
15     mat4 uObjectMatrix;
16     vec3 lightPosition;
17     vec2 uStageOffset;
18
19     //Visual size and offset
20     vec2 offset;
21     vec2 size;
22     vec4 offsetSizeMode;
23     vec2 origin;
24     vec2 anchorPoint;
25 };
26
27 vec4 ComputeVertexPosition()
28 {
29     vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw );
30     float scaleFactor = min( visualSize.x, visualSize.y );
31     vec3 originFlipY =  vec3(origin.x, -origin.y, 0.0);
32     vec3 anchorPointFlipY = vec3( anchorPoint.x, -anchorPoint.y, 0.0);
33     vec3 offset = vec3( ( offset / uSize.xy ) * offsetSizeMode.xy + offset * (1.0-offsetSizeMode.xy), 0.0) * vec3(1.0,-1.0,1.0);
34     return vec4( (aPosition + anchorPointFlipY)*scaleFactor + (offset + originFlipY)*uSize, 1.0 );
35 }
36
37 void main()
38 {
39     vec4 normalisedVertexPosition = ComputeVertexPosition();
40     vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;
41     vertexPosition = uMvpMatrix * vertexPosition;
42
43     //Illumination in Model-View space - Transform attributes and uniforms
44     vec4 mvVertexPosition = uModelView * normalisedVertexPosition;
45     vec3 normal = uNormalMatrix * mat3( uObjectMatrix ) * aNormal;
46
47     vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );
48     mvLightPosition = uViewMatrix * mvLightPosition;
49     vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );
50
51     float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );
52     vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );
53
54     gl_Position = vertexPosition;
55 }