-/************************************************************/
-/* Custom refraction effect shader******************************/
-/************************************************************/
-
-class RefractionEffect : public ShaderEffect
-{
-public:
-
- /**
- * Create an empty RefractionEffect handle.
- */
- RefractionEffect()
- {
- }
-
- /**
- * Virtual destructor
- */
- virtual ~RefractionEffect()
- {
- }
-
- /**
- * Create a RefractionEffect object.
- * @return A handle to a newly allocated RefractionEffect
- */
- static RefractionEffect New()
- {
- std::string vertexShader = MAKE_SHADER(
- precision mediump float;\n
- varying mediump vec2 vTextureOffset;\n
- void main()\n
- {\n
- gl_Position = uMvpMatrix * vec4( aPosition.xy, 0.0, 1.0 );\n
- vTexCoord = aTexCoord.xy;\n
-
- vNormal = aNormal;\n
- vVertex = vec4( aPosition, 1.0 );\n
- float length = max(0.01, length(aNormal.xy)) * 40.0;\n
- vTextureOffset = aNormal.xy / length;\n
- }\n
- );
-
- std::string fragmentShader = MAKE_SHADER(
- precision mediump float;\n
- uniform mediump float uEffectStrength;\n
- uniform mediump vec3 uLightPosition;\n
- uniform mediump vec2 uLightXYOffset;\n
- uniform mediump vec2 uLightSpinOffset;\n
- uniform mediump float uLightIntensity;\n
- varying mediump vec2 vTextureOffset;\n
-
- vec3 rgb2hsl(vec3 rgb)\n
- {\n
- float epsilon = 1.0e-10;\n
- vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n
- vec4 P = mix(vec4(rgb.bg, K.wz), vec4(rgb.gb, K.xy), step(rgb.b, rgb.g));\n
- vec4 Q = mix(vec4(P.xyw, rgb.r), vec4(rgb.r, P.yzx), step(P.x, rgb.r));\n
- \n
- // RGB -> HCV
- float value = Q.x;\n
- float chroma = Q.x - min(Q.w, Q.y);\n
- float hue = abs(Q.z + (Q.w-Q.y) / (6.0*chroma+epsilon));\n
- // HCV -> HSL
- float lightness = value - chroma*0.5;\n
- return vec3( hue, chroma/max( 1.0-abs(lightness*2.0-1.0), 1.0e-1 ), lightness );\n
- }\n
-
- vec3 hsl2rgb( vec3 hsl )
- {
- // pure hue->RGB
- vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n
- vec3 p = abs(fract(hsl.xxx + K.xyz) * 6.0 - K.www);\n
- vec3 RGB = clamp(p - K.xxx, 0.0, 1.0);\n
- \n
- float chroma = ( 1.0 - abs( hsl.z*2.0-1.0 ) ) * hsl.y;\n
- return ( RGB - 0.5 ) * chroma + hsl.z;
- }
-
- void main()\n
- {\n
- vec3 normal = normalize( vNormal);\n
-
- vec3 lightPosition = uLightPosition + vec3(uLightXYOffset+uLightSpinOffset, 0.0);\n
- mediump vec3 vecToLight = normalize( (lightPosition - vVertex.xyz) * 0.01 );\n
- mediump float spotEffect = pow( max(0.05, vecToLight.z ) - 0.05, 8.0);\n
-
- spotEffect = spotEffect * uEffectStrength;\n
- mediump float lightDiffuse = ( ( dot( vecToLight, normal )-0.75 ) *uLightIntensity ) * spotEffect;\n
-
- lowp vec4 color = texture2D( sTexture, vTexCoord + vTextureOffset * spotEffect );\n
- vec3 lightedColor = hsl2rgb( rgb2hsl(color.rgb) + vec3(0.0,0.0,lightDiffuse) );\n
-
- gl_FragColor = vec4( lightedColor, color.a ) * uColor;\n
- }\n
- );
-
- ShaderEffect shaderEffect = ShaderEffect::New( vertexShader, fragmentShader,
- GeometryType( GEOMETRY_TYPE_TEXTURED_MESH),
- ShaderEffect::GeometryHints( ShaderEffect::HINT_BLENDING ) );
- RefractionEffect handle( shaderEffect );
-
- Vector2 stageSize = Stage::GetCurrent().GetSize();
- handle.SetLightPosition( Vector2(stageSize.x, 0.f) );
- handle.SetUniform( "uLightXYOffset", Vector2::ZERO );
- handle.SetUniform( "uLightSpinOffset", Vector2::ZERO );
- handle.SetUniform( "uEffectStrength", 0.f );
- handle.SetUniform( "uLightIntensity", 2.5f );
-
- Dali::Property::Index index = handle.RegisterProperty( "uSpinAngle", 0.f );
- Constraint constraint = Constraint::New<Vector2>( handle, handle.GetPropertyIndex("uLightSpinOffset"), LightOffsetConstraint(stageSize.x*0.1f) );
- constraint.AddSource( LocalSource(index) );
- constraint.Apply();
-
- return handle;
- }
-
- void SetLightPosition( const Vector2& position )
- {
- Vector2 stageHalfSize = Stage::GetCurrent().GetSize() * 0.5f;
- SetUniform( "uLightPosition", Vector3( position.x - stageHalfSize.x, position.y - stageHalfSize.y, stageHalfSize.x ) );
- }
-
- void SetLightXYOffset( const Vector2& offset )
- {
- SetUniform( "uLightXYOffset", offset );
- }
-
- void SetEffectStrength( float strength )
- {
- SetUniform( "uEffectStrength", strength );
- }
+/************************************************************************************************
+ *** The shader source is used when the MeshActor is not touched***
+ ************************************************************************************************/
+const char* VERTEX_SHADER_FLAT = DALI_COMPOSE_SHADER(
+attribute mediump vec3 aPosition;\n
+attribute mediump vec3 aNormal;\n
+attribute highp vec2 aTexCoord;\n
+uniform mediump mat4 uMvpMatrix;\n
+varying mediump vec2 vTexCoord;\n
+void main()\n
+{\n
+ gl_Position = uMvpMatrix * vec4( aPosition.xy, 0.0, 1.0 );\n
+ vTexCoord = aTexCoord.xy;\n
+}\n
+);
+
+const char* FRAGMENT_SHADER_FLAT = DALI_COMPOSE_SHADER(
+uniform lowp vec4 uColor;\n
+uniform sampler2D sTexture;\n
+varying mediump vec2 vTexCoord;\n
+void main()\n
+{\n
+ gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
+}\n
+);
+
+/************************************************************
+ ** Custom refraction effect shader***************************
+ ************************************************************/
+const char* VERTEX_SHADER_REFRACTION = DALI_COMPOSE_SHADER(
+attribute mediump vec3 aPosition;\n
+attribute mediump vec3 aNormal;\n
+attribute highp vec2 aTexCoord;\n
+uniform mediump mat4 uMvpMatrix;\n
+varying mediump vec4 vVertex;\n
+varying mediump vec3 vNormal;\n
+varying mediump vec2 vTexCoord;\n
+varying mediump vec2 vTextureOffset;\n
+void main()\n
+{\n
+ gl_Position = uMvpMatrix * vec4( aPosition.xy, 0.0, 1.0 );\n
+ vTexCoord = aTexCoord.xy;\n
+
+ vNormal = aNormal;\n
+ vVertex = vec4( aPosition, 1.0 );\n
+ float length = max(0.01, length(aNormal.xy)) * 40.0;\n
+ vTextureOffset = aNormal.xy / length;\n
+}\n
+);
+
+const char* FRAGMENT_SHADER_REFRACTION = DALI_COMPOSE_SHADER(
+precision mediump float;\n
+uniform mediump float uEffectStrength;\n
+uniform mediump vec3 uLightPosition;\n
+uniform mediump vec2 uLightXYOffset;\n
+uniform mediump vec2 uLightSpinOffset;\n
+uniform mediump float uLightIntensity;\n
+uniform lowp vec4 uColor;\n
+uniform sampler2D sTexture;\n
+varying mediump vec4 vVertex;\n
+varying mediump vec3 vNormal;\n
+varying mediump vec2 vTexCoord;\n
+varying mediump vec2 vTextureOffset;\n
+
+vec3 rgb2hsl(vec3 rgb)\n
+{\n
+ float epsilon = 1.0e-10;\n
+ vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n
+ vec4 P = mix(vec4(rgb.bg, K.wz), vec4(rgb.gb, K.xy), step(rgb.b, rgb.g));\n
+ vec4 Q = mix(vec4(P.xyw, rgb.r), vec4(rgb.r, P.yzx), step(P.x, rgb.r));\n
+ \n
+ // RGB -> HCV
+ float value = Q.x;\n
+ float chroma = Q.x - min(Q.w, Q.y);\n
+ float hue = abs(Q.z + (Q.w-Q.y) / (6.0*chroma+epsilon));\n
+ // HCV -> HSL
+ float lightness = value - chroma*0.5;\n
+ return vec3( hue, chroma/max( 1.0-abs(lightness*2.0-1.0), 1.0e-1 ), lightness );\n
+}\n
+
+vec3 hsl2rgb( vec3 hsl )\n
+{\n
+ // pure hue->RGB
+ vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n
+ vec3 p = abs(fract(hsl.xxx + K.xyz) * 6.0 - K.www);\n
+ vec3 RGB = clamp(p - K.xxx, 0.0, 1.0);\n
+ \n
+ float chroma = ( 1.0 - abs( hsl.z*2.0-1.0 ) ) * hsl.y;\n
+ return ( RGB - 0.5 ) * chroma + hsl.z;\n
+}\n
+
+void main()\n
+{\n
+ vec3 normal = normalize( vNormal);\n
+
+ vec3 lightPosition = uLightPosition + vec3(uLightXYOffset+uLightSpinOffset, 0.0);\n
+ mediump vec3 vecToLight = normalize( (lightPosition - vVertex.xyz) * 0.01 );\n
+ mediump float spotEffect = pow( max(0.05, vecToLight.z ) - 0.05, 8.0);\n
+
+ spotEffect = spotEffect * uEffectStrength;\n
+ mediump float lightDiffuse = ( ( dot( vecToLight, normal )-0.75 ) *uLightIntensity ) * spotEffect;\n
+
+ lowp vec4 color = texture2D( sTexture, vTexCoord + vTextureOffset * spotEffect );\n
+ vec3 lightedColor = hsl2rgb( rgb2hsl(color.rgb) + vec3(0.0,0.0,lightDiffuse) );\n
+
+ gl_FragColor = vec4( lightedColor, color.a ) * uColor;\n
+}\n
+);