1 #ifndef DALI_DEMO_RENDERER_STENCIL_SHADERS_H
2 #define DALI_DEMO_RENDERER_STENCIL_SHADERS_H
5 * Copyright (c) 2016 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 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" );
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;
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;
50 mediump vec4 vertexPosition = vec4( aPosition * uObjectDimensions, 1.0 );
51 vertexPosition = uMvpMatrix * vertexPosition;
53 vec4 mvVertexPosition = uModelView * vertexPosition;
55 vec3 vectorToLight = normalize( mat3( uViewMatrix ) * uLightPosition - mvVertexPosition.xyz );
57 vec3 normal = uNormalMatrix * aNormal;
58 float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );
59 vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );
61 gl_Position = vertexPosition;
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;
74 gl_FragColor = vec4( vIllumination.rgb * uColor.rgb, uColor.a );
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;
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;
96 mediump vec4 vertexPosition = vec4( aPosition * uObjectDimensions, 1.0 );
97 vertexPosition = uMvpMatrix * vertexPosition;
99 vec4 mvVertexPosition = uModelView * vertexPosition;
101 vec3 vectorToLight = normalize( mat3( uViewMatrix ) * uLightPosition - mvVertexPosition.xyz );
103 vec3 normal = uNormalMatrix * aNormal;
104 float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );
105 vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );
107 vTexCoord = aTexCoord;
108 gl_Position = vertexPosition;
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;
121 gl_FragColor = vec4( texture2D( sTexture, vTexCoord ).rgb * vIllumination.rgb * uColor.rgb, uColor.a );
125 #endif // DALI_DEMO_RENDERER_STENCIL_SHADERS_H