Use Window instead of Stage
[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 // Shader for basic, per-vertex lighting (vertex):
32 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
33   attribute mediump vec3  aPosition;
34   attribute highp   vec3  aNormal;
35   attribute highp   vec2  aTexCoord;
36
37   varying   mediump vec2  vTexCoord;
38   uniform   mediump mat4  uMvpMatrix;
39   uniform   mediump vec3  uSize;
40   uniform   mediump vec3  uObjectDimensions;
41   varying   mediump vec3  vIllumination;
42   uniform   mediump mat4  uModelView;
43   uniform   mediump mat4  uViewMatrix;
44   uniform   mediump mat3  uNormalMatrix;
45   uniform   mediump vec3  uLightPosition;
46
47   void main()
48   {
49     mediump vec4 vertexPosition = vec4( aPosition * uObjectDimensions, 1.0 );
50     vertexPosition = uMvpMatrix * vertexPosition;
51
52     vec4 mvVertexPosition = uModelView * vertexPosition;
53
54     vec3 vectorToLight = normalize( mat3( uViewMatrix ) * uLightPosition - mvVertexPosition.xyz );
55
56     vec3 normal = uNormalMatrix * aNormal;
57     float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );
58     vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );
59
60     gl_Position = vertexPosition;
61   }
62 );
63
64 // Fragment shader.
65 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
66   varying mediump vec2  vTexCoord;
67   varying mediump vec3  vIllumination;
68   uniform lowp    vec4  uColor;
69   uniform sampler2D     sTexture;
70
71   void main()
72   {
73     gl_FragColor = vec4( vIllumination.rgb * uColor.rgb, uColor.a );
74   }
75 );
76
77 // Shader for basic, per-vertex lighting with texture (vertex):
78 const char* VERTEX_SHADER_TEXTURED = DALI_COMPOSE_SHADER(
79   attribute mediump vec3  aPosition;
80   attribute highp   vec3  aNormal;
81   attribute highp   vec2  aTexCoord;
82
83   varying   mediump vec2  vTexCoord;
84   uniform   mediump mat4  uMvpMatrix;
85   uniform   mediump vec3  uSize;
86   uniform   mediump vec3  uObjectDimensions;
87   varying   mediump vec3  vIllumination;
88   uniform   mediump mat4  uModelView;
89   uniform   mediump mat4  uViewMatrix;
90   uniform   mediump mat3  uNormalMatrix;
91   uniform   mediump vec3  uLightPosition;
92
93   void main()
94   {
95     mediump vec4 vertexPosition = vec4( aPosition * uObjectDimensions, 1.0 );
96     vertexPosition = uMvpMatrix * vertexPosition;
97
98     vec4 mvVertexPosition = uModelView * vertexPosition;
99
100     vec3 vectorToLight = normalize( mat3( uViewMatrix ) * uLightPosition - mvVertexPosition.xyz );
101
102     vec3 normal = uNormalMatrix * aNormal;
103     float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );
104     vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );
105
106     vTexCoord = aTexCoord;
107     gl_Position = vertexPosition;
108   }
109 );
110
111 // Fragment shader.
112 const char* FRAGMENT_SHADER_TEXTURED = DALI_COMPOSE_SHADER(
113   varying mediump vec2  vTexCoord;
114   varying mediump vec3  vIllumination;
115   uniform lowp    vec4  uColor;
116   uniform sampler2D     sTexture;
117
118   void main()
119   {
120     gl_FragColor = vec4( texture2D( sTexture, vTexCoord ).rgb * vIllumination.rgb * uColor.rgb, uColor.a );
121   }
122 );
123
124 #endif // DALI_DEMO_RENDERER_STENCIL_SHADERS_H