Updated demos to use DALi clang-format
[platform/core/uifw/dali-demo.git] / examples / renderer-stencil / renderer-stencil-shaders.h
1 #ifndef DALI_DEMO_RENDERER_STENCIL_SHADERS_H
2 #define DALI_DEMO_RENDERER_STENCIL_SHADERS_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/rendering/shader.h>
22
23 // Shader uniforms:
24 const char* const COLOR_UNIFORM_NAME("uColor");
25 const char* const OBJECT_DIMENSIONS_UNIFORM_NAME("uObjectDimensions");
26 const char* const LIGHT_POSITION_UNIFORM_NAME = "uLightPosition";
27 const char* const POSITION("aPosition");
28 const char* const NORMAL("aNormal");
29 const char* const TEXTURE("aTexCoord");
30
31 // clang-format off
32
33 // Shader for basic, per-vertex lighting (vertex):
34 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
35   attribute mediump vec3  aPosition;
36   attribute highp   vec3  aNormal;
37   attribute highp   vec2  aTexCoord;
38
39   varying   mediump vec2  vTexCoord;
40   uniform   mediump mat4  uMvpMatrix;
41   uniform   mediump vec3  uSize;
42   uniform   mediump vec3  uObjectDimensions;
43   varying   mediump vec3  vIllumination;
44   uniform   mediump mat4  uModelView;
45   uniform   mediump mat4  uViewMatrix;
46   uniform   mediump mat3  uNormalMatrix;
47   uniform   mediump vec3  uLightPosition;
48
49   void main()
50   {
51     mediump vec4 vertexPosition = vec4( aPosition * uObjectDimensions, 1.0 );
52     vertexPosition = uMvpMatrix * vertexPosition;
53
54     vec4 mvVertexPosition = uModelView * vertexPosition;
55
56     vec3 vectorToLight = normalize( mat3( uViewMatrix ) * uLightPosition - mvVertexPosition.xyz );
57
58     vec3 normal = uNormalMatrix * aNormal;
59     float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );
60     vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );
61
62     gl_Position = vertexPosition;
63   }
64 );
65
66 // Fragment shader.
67 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
68   varying mediump vec2  vTexCoord;
69   varying mediump vec3  vIllumination;
70   uniform lowp    vec4  uColor;
71   uniform sampler2D     sTexture;
72
73   void main()
74   {
75     gl_FragColor = vec4( vIllumination.rgb * uColor.rgb, uColor.a );
76   }
77 );
78
79 // Shader for basic, per-vertex lighting with texture (vertex):
80 const char* VERTEX_SHADER_TEXTURED = DALI_COMPOSE_SHADER(
81   attribute mediump vec3  aPosition;
82   attribute highp   vec3  aNormal;
83   attribute highp   vec2  aTexCoord;
84
85   varying   mediump vec2  vTexCoord;
86   uniform   mediump mat4  uMvpMatrix;
87   uniform   mediump vec3  uSize;
88   uniform   mediump vec3  uObjectDimensions;
89   varying   mediump vec3  vIllumination;
90   uniform   mediump mat4  uModelView;
91   uniform   mediump mat4  uViewMatrix;
92   uniform   mediump mat3  uNormalMatrix;
93   uniform   mediump vec3  uLightPosition;
94
95   void main()
96   {
97     mediump vec4 vertexPosition = vec4( aPosition * uObjectDimensions, 1.0 );
98     vertexPosition = uMvpMatrix * vertexPosition;
99
100     vec4 mvVertexPosition = uModelView * vertexPosition;
101
102     vec3 vectorToLight = normalize( mat3( uViewMatrix ) * uLightPosition - mvVertexPosition.xyz );
103
104     vec3 normal = uNormalMatrix * aNormal;
105     float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );
106     vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );
107
108     vTexCoord = aTexCoord;
109     gl_Position = vertexPosition;
110   }
111 );
112
113 // Fragment shader.
114 const char* FRAGMENT_SHADER_TEXTURED = DALI_COMPOSE_SHADER(
115   varying mediump vec2  vTexCoord;
116   varying mediump vec3  vIllumination;
117   uniform lowp    vec4  uColor;
118   uniform sampler2D     sTexture;
119
120   void main()
121   {
122     gl_FragColor = vec4( texture2D( sTexture, vTexCoord ).rgb * vIllumination.rgb * uColor.rgb, uColor.a );
123   }
124 );
125
126 // clang-format on
127
128 #endif // DALI_DEMO_RENDERER_STENCIL_SHADERS_H