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