1 #ifndef DALI_DEMO_RENDERER_STENCIL_SHADERS_H
2 #define DALI_DEMO_RENDERER_STENCIL_SHADERS_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/rendering/shader.h>
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");
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;
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;
51 mediump vec4 vertexPosition = vec4( aPosition * uObjectDimensions, 1.0 );
52 vertexPosition = uMvpMatrix * vertexPosition;
54 vec4 mvVertexPosition = uModelView * vertexPosition;
56 vec3 vectorToLight = normalize( mat3( uViewMatrix ) * uLightPosition - mvVertexPosition.xyz );
58 vec3 normal = uNormalMatrix * aNormal;
59 float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );
60 vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );
62 gl_Position = vertexPosition;
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;
75 gl_FragColor = vec4( vIllumination.rgb * uColor.rgb, uColor.a );
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;
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;
97 mediump vec4 vertexPosition = vec4( aPosition * uObjectDimensions, 1.0 );
98 vertexPosition = uMvpMatrix * vertexPosition;
100 vec4 mvVertexPosition = uModelView * vertexPosition;
102 vec3 vectorToLight = normalize( mat3( uViewMatrix ) * uLightPosition - mvVertexPosition.xyz );
104 vec3 normal = uNormalMatrix * aNormal;
105 float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );
106 vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );
108 vTexCoord = aTexCoord;
109 gl_Position = vertexPosition;
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;
122 gl_FragColor = vec4( texture2D( sTexture, vTexCoord ).rgb * vIllumination.rgb * uColor.rgb, uColor.a );
128 #endif // DALI_DEMO_RENDERER_STENCIL_SHADERS_H