" \"vertexPrefix\": \"\",\n"
" \"vertex\": \"void main(void)\\n{\\n gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
" \"fragmentPrefix\": \"\",\n"
- " \"fragment\": \"precision mediump float;\\nuniform float uAmplitude; // 0.02; (< 1)\\nuniform float uTime;\\nvoid main()\\n{\\n highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\\n highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\\n highp float len = length(pos);\\n highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \\n gl_FragColor = texture2D(sTexture, texCoord) * uColor;\\n}\\n\\n\\n\",\n"
+ " \"fragment\": \"precision mediump float;\\nuniform float uAmplitude; // 0.02; (< 1)\\nuniform float uTime;\\nvoid main()\\n{\\n highp vec2 textureSize = uTextureRect.zw - uTextureRect.xy;\\n highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\\n highp float len = length(pos);\\n highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \\n gl_FragColor = texture2D(sTexture, texCoord) * uColor;\\n}\\n\\n\\n\",\n"
" \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
" },\n"
" \"geometryHints\": \"HINT_NONE\",\n"
" \"vertexPrefix\": \"\",\n"
" \"vertex\": \"void main(void)\\n{\\n gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
" \"fragmentPrefix\": \"\",\n"
- " \"fragment\": \"precision mediump float;\\nuniform float uAmplitude; // 0.02; (< 1)\\nuniform float uTime;\\nvoid main()\\n{\\n highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\\n highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\\n highp float len = length(pos);\\n highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \\n gl_FragColor = texture2D(sTexture, texCoord) * uColor;\\n}\\n\\n\\n\",\n"
+ " \"fragment\": \"precision mediump float;\\nuniform float uAmplitude; // 0.02; (< 1)\\nuniform float uTime;\\nvoid main()\\n{\\n highp vec2 textureSize = uTextureRect.zw - uTextureRect.xy;\\n highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\\n highp float len = length(pos);\\n highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \\n gl_FragColor = texture2D(sTexture, texCoord) * uColor;\\n}\\n\\n\\n\",\n"
" \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
" },\n"
" \"geometryHints\": \"HINT_NONE\",\n"
" \"vertexPrefix\": \"\",\n"
" \"vertex\": \"void main(void)\\n{\\n gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
" \"fragmentPrefix\": \"\",\n"
- " \"fragment\": \"precision mediump float;\\nuniform float uAmplitude; // 0.02; (< 1)\\nuniform float uTime;\\nvoid main()\\n{\\n highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\\n highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\\n highp float len = length(pos);\\n highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \\n gl_FragColor = texture2D(sTexture, texCoord) * uColor;\\n}\\n\\n\\n\",\n"
+ " \"fragment\": \"precision mediump float;\\nuniform float uAmplitude; // 0.02; (< 1)\\nuniform float uTime;\\nvoid main()\\n{\\n highp vec2 textureSize = uTextureRect.zw - uTextureRect.xy;\\n highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\\n highp float len = length(pos);\\n highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \\n gl_FragColor = texture2D(sTexture, texCoord) * uColor;\\n}\\n\\n\\n\",\n"
" \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
" },\n"
" \"geometryHints\": \"HINT_NONE\",\n"
" \"vertexPrefix\": \"\",\n"
" \"vertex\": \"void main(void)\\n{\\n gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\\n vTexCoord = aTexCoord;\\n}\\n\\n\",\n"
" \"fragmentPrefix\": \"\",\n"
- " \"fragment\": \"precision mediump float;\\nuniform float uAmplitude; // 0.02; (< 1)\\nuniform float uTime;\\nvoid main()\\n{\\n highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\\n highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\\n highp float len = length(pos);\\n highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \\n gl_FragColor = texture2D(sTexture, texCoord) * uColor;\\n}\\n\\n\\n\",\n"
+ " \"fragment\": \"precision mediump float;\\nuniform float uAmplitude; // 0.02; (< 1)\\nuniform float uTime;\\nvoid main()\\n{\\n highp vec2 textureSize = uTextureRect.zw - uTextureRect.xy;\\n highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\\n highp float len = length(pos);\\n highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude; \\n gl_FragColor = texture2D(sTexture, texCoord) * uColor;\\n}\\n\\n\\n\",\n"
" \"geometryType\": \"GEOMETRY_TYPE_IMAGE\"\n"
" },\n"
" \"geometryHints\": \"HINT_NONE\",\n"
"void main()\n"
"{\n"
" mediump float lighting = 0.25;\n"
- " mediump vec4 position = uModelView * vec4(aPosition,1.0);\n"
+ " mediump vec4 position = uModelView * vec4(aPosition*uSize.xy, 0.0, 1.0);\n"
"\n"
" mediump vec2 d = position.xy - uCenter;\n"
" mediump float dist = max( 0.0, dot(d,uDirection) );\n"
"\n"
"vShade = 1.0 - abs(sn) * lighting;\n"
"\n"
- "vTexCoord = aTexCoord;\n"
+ "vTexCoord = mix( uTextureRect.xy, uTextureRect.zw, aPosition + vec2(0.5) );\n;\n"
"}" );
std::string fragmentShader(
"\n"
"void main()\n"
"{\n"
- " mediump vec4 world = uModelView * vec4(aPosition,1.0);\n"
+ " mediump vec4 world = uModelView * vec4(aPosition*uSize.xy, 0.0, 1.0);\n"
" mediump vec2 d = (world.xy - uCenter) * uAnglePerUnit;\n"
" mediump float a = length(d);\n"
" mediump float cs = cos(radians(a));\n"
" world.z -= cs * uRadius;\n"
" gl_Position = uProjection * world;\n"
" \n"
- " vTexCoord = aTexCoord;\n"
+ " vTexCoord = mix( uTextureRect.xy, uTextureRect.zw, aPosition + vec2(0.5) );\n;\n"
"}\n");
ShaderEffect shaderEffect = ShaderEffect::New(
"varying float vPercentage;\n"
"void main()\n"
"{\n"
- " vec4 position = uModelView * vec4( aPosition, 1.0 );\n"
+ " vec4 position = uModelView * vec4( aPosition*uSize.xy, 0.0, 1.0 );\n"
" float percentage = 0.0;\n"
" for( int i=0; i<NUMBER_OF_DIMPLE; ++i )\n"
" {\n"
" }\n"
" vPercentage = clamp( percentage, 0.0, 1.0 );\n"
" gl_Position = uProjection * position;\n"
- " vTexCoord = aTexCoord;\n"
+ " vTexCoord = mix( uTextureRect.xy, uTextureRect.zw, aPosition + vec2(0.5) );\n;\n"
"}\n");
vertexShaderStringStream << vertexShader;
" position.xyz *= uSize;\n"
" gl_Position = uMvpMatrix * position;\n"
// The line below is doing the same as the following commented lines:
- //" vec2 imageSize = sTextureRect.zw - sTextureRect.xy;\n"
- //" vec2 topLeft = sTextureRect.xy + uTopLeft * imageSize;\n"
- //" vec2 bottomRight = sTextureRect.xy + uBottomRight * imageSize;\n"
- //" vec2 texCoord = (aTexCoord - sTextureRect.xy) / imageSize;\n"
+ //" vec2 imageSize = uTextureRect.zw - uTextureRect.xy;\n"
+ //" vec2 topLeft = uTextureRect.xy + uTopLeft * imageSize;\n"
+ //" vec2 bottomRight = uTextureRect.xy + uBottomRight * imageSize;\n"
+ //" vec2 texCoord = (aTexCoord - uTextureRect.xy) / imageSize;\n"
//" vTexCoord = topLeft + texCoord * ( bottomRight - topLeft );\n"
" vec2 texCoord = aPosition + vec2(0.5);\n"
"\n"
"void main()\n"
"{\n"
- " mediump vec4 world = uModelView * vec4(aPosition,1.0);\n"
+ " mediump vec4 world = uModelView * vec4(aPosition*uSize.xy, 0.0, 1.0);\n"
" gl_Position = uProjection * world;\n"
" \n"
- " vTexCoord = aTexCoord;\n"
- " vRelativePosition = aTexCoord - uCenter;\n"
+ " vTexCoord = mix( uTextureRect.xy, uTextureRect.zw, aPosition + vec2(0.5) );;\n"
+ " vRelativePosition = vTexCoord - uCenter;\n"
"}\n");
std::string fragmentShader(
std::string vertexShader(
"void main() \n"
"{ \n"
- " mediump vec3 pos = aPosition; \n"
+ " mediump vec3 pos = vec3(aPosition, 0.0)*uSize; \n"
" pos.y = pos.y * 3.0; \n"
" mediump vec4 world = uModelView * vec4(pos,1.0); \n"
" gl_Position = uProjection * world; \n"
- " vTexCoord = aTexCoord; \n"
+ " vTexCoord = mix( uTextureRect.xy, uTextureRect.zw, aPosition + vec2(0.5) ); \n"
"} \n" );
std::string fragmentShader(
"{\n"
"float lighting = uAmplitude * 0.02;\n"
"float waveLength = uAmplitude * 0.0016;\n"
- "vec4 world = uModelView * vec4(aPosition,1.0);\n"
+ "vec4 world = uModelView * vec4(aPosition*uSize.xy, 0.0, 1.0);\n"
"vec2 d = vec2(world.x - uCenter.x, world.y - uCenter.y);\n"
"float dist = length(d);\n"
"float amplitude = cos(uTime - dist*waveLength);\n"
"}\n"
"vShade = 1.0 - (dot * slope);\n"
"vLight = max(0.0, dot * -slope);\n"
- "vTexCoord = aTexCoord;\n"
+ "vTexCoord = mix( uTextureRect.xy, uTextureRect.zw, aPosition + vec2(0.5) );\n;\n"
"}" );
// append the default version
"uniform float uTime;\n"
"void main()\n"
"{\n"
- " highp vec2 textureSize = sTextureRect.zw - sTextureRect.xy;\n"
+ " highp vec2 textureSize = uTextureRect.zw - uTextureRect.xy;\n"
" highp vec2 pos = -1.0 + 2.0 * vTexCoord.st/textureSize;\n"
" highp float len = length(pos);\n"
" highp vec2 texCoord = vTexCoord.st/textureSize + pos/len * sin( len * 12.0 - uTime * 4.0 ) * uAmplitude;\n"
"\n"
"void main()\n"
"{\n"
- "mediump vec4 world = uModelView * vec4(aPosition,1.0);\n"
+ "mediump vec4 world = uModelView * vec4(aPosition*uSize.xy, 0.0, 1.0);\n"
"\n"
"world.x = world.x + tan(radians(uAngleXAxis)) * (world.y - uCenter.y * world.w);\n"
"world.y = world.y + tan(radians(uAngleYAxis)) * (world.x - uCenter.x * world.w);\n"
"\n"
"gl_Position = uProjection * world;\n"
"\n"
- "vTexCoord = aTexCoord;\n"
+ "vTexCoord = mix( uTextureRect.xy, uTextureRect.zw, aPosition + vec2(0.5) );\n;\n"
"}" );
// Create the implementation, temporarily owned on stack,
"void main()\n"
"{\n"
- " vTexCoord = aTexCoord;\n"
+ " vTexCoord = mix( uTextureRect.xy, uTextureRect.zw, aPosition + vec2(0.5) );\n;\n"
// Get the rect coords of the effect region in -1..1 range, i.e. circle centred around the center of the rect
// Done in the vertex shader itself to make use of gl interpolation for varying.
" vCentredCoord = vec2( ( (vTexCoord.x - uEffectRegion.x)/(uEffectRegion.z - uEffectRegion.x) * 2.0 - 1.0 ), ( (vTexCoord.y - uEffectRegion.y)/(uEffectRegion.w - uEffectRegion.y) * 2.0 - 1.0 ) );\n"
- " gl_Position = uMvpMatrix * vec4(aPosition, 1.0);\n"
+ " gl_Position = uMvpMatrix * vec4(aPosition*uSize.xy, 0.0, 1.0);\n"
"}\n";
std::string fragmentSourceFixed;
"\n"
"void main()\n"
"{\n"
- " mediump vec4 world = vec4(aPosition, 1.0);\n"
+ " mediump vec4 world = vec4(aPosition*uSize.xy, 0.0, 1.0);\n"
" \n"
" mediump vec2 d = vec2(world.xy - uCenter);\n"
" mediump float dist = length(d);\n"
" vRange = max(0.1, range);\n"
" \n"
" gl_Position = uMvpMatrix * world;\n"
- " vTexCoord = aTexCoord;\n"
+ " vTexCoord = mix( uTextureRect.xy, uTextureRect.zw, aPosition + vec2(0.5) );\n;\n"
"}");
std::string fragmentShader(
"uniform mediump vec2 uCenter;\n"
"void main()\n"
"{\n"
- " highp vec2 textureCenter = (sTextureRect.xy + sTextureRect.zw) * 0.5;\n"
+ " highp vec2 textureCenter = (uTextureRect.xy + uTextureRect.zw) * 0.5;\n"
" textureCenter = vTexCoord.st - textureCenter;\n"
" highp float distance = length(textureCenter);\n"
" if (distance >= uRadius)\n"
**/
inline ShaderEffect CreatePageTurnBookSpineEffect()
{
- std::string vertexSource = DALI_COMPOSE_SHADER(
- precision mediump float;\n
- void main()\n
- {\n
- gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\n
- vTexCoord = aTexCoord;\n
- }\n);
-
// the simplified version of the fragment shader of page turn effect
std::string fragmentSource = DALI_COMPOSE_SHADER(
precision mediump float;\n
{\n
// flip the image horizontally by changing the x component of the texture coordinate
if( uIsBackImageVisible == 1.0 )\n
- gl_FragColor = texture2D( sTexture, vec2( sTextureRect.p+sTextureRect.s-vTexCoord.x, vTexCoord.y ) ) * uColor; \n
+ gl_FragColor = texture2D( sTexture, vec2( uTextureRect.p+uTextureRect.s-vTexCoord.x, vTexCoord.y ) ) * uColor; \n
else\n
gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
// display book spine, a stripe of shadowed texture
- float pixelPos = (vTexCoord.x-sTextureRect.s)*uPageWidth; \n
+ float pixelPos = (vTexCoord.x-uTextureRect.s)*uPageWidth; \n
if(pixelPos < uSpineShadowParameter.x) \n
{\n
float x = pixelPos - uSpineShadowParameter.x;\n
const Vector2 DEFAULT_SPINE_SHADOW_PARAMETER(50.0f, 20.0f);
- ShaderEffect shaderEffect = ShaderEffect::New( vertexSource, fragmentSource );
+ ShaderEffect shaderEffect = ShaderEffect::New( "", fragmentSource );
shaderEffect.SetUniform( "uIsBackImageVisible", -1.f );
shaderEffect.SetUniform( "uSpineShadowParameter", DEFAULT_SPINE_SHADOW_PARAMETER );
\n
void main()\n
{\n
- vec4 position = vec4( aPosition.xy, 0.0, 1.0);\n
+ vec4 position = vec4( aPosition*uSize.xy, 0.0, 1.0);\n
vec2 currentCenter = vec2( uCommonParameters[1][2], uCommonParameters[1][3]);\n
vec2 originalCenter = vec2( uCommonParameters[0][2], uCommonParameters[0][3]);\n
vec3 normal = vec3(0.0,0.0,1.0);\n
// change the coordinate origin from the top-left of the page to its center
position.xy -= uPageSize * 0.5; \n
}\n
- position.z += aPosition.z;\n
gl_Position = uMvpMatrix * position;\n
// varying parameters for fragment shader
- vTexCoord = aTexCoord;
+ vTexCoord = mix( uTextureRect.xy, uTextureRect.zw, aPosition + vec2(0.5) );\n;
vNormal = uNormalMatrix*normal;\n
vPosition = uModelView * position;\n
}\n
float spineShadowCoef = 1.0; \n
// display page content
// display back image of the page, flip the texture
- if( dot(vPosition.xyz, normal) > 0.0 ) texel = texture2D( sTexture, vec2( sTextureRect.p+sTextureRect.s-vTexCoord.x, vTexCoord.y ) );\n
+ if( dot(vPosition.xyz, normal) > 0.0 ) texel = texture2D( sTexture, vec2( uTextureRect.p+uTextureRect.s-vTexCoord.x, vTexCoord.y ) );\n
// display front image of the page
else texel = texture2D( sTexture, vTexCoord );\n
// display book spine, a stripe of shadowed texture
- float pixelPos = (vTexCoord.x-sTextureRect.s)*uPageSize.x; \n
+ float pixelPos = (vTexCoord.x-uTextureRect.s)*uPageSize.x; \n
if(pixelPos < uSpineShadowParameter.x) \n
{\n
float x = pixelPos - uSpineShadowParameter.x;\n