NOTE : As you know, GPU doesn't like if-else statement.
But if we can skip operations for most adjacent pixels,
if-else statemnet is somtimes more efficient.
Change-Id: Ibb09a84e383e4769c3e7ead39f48073455d6e650
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
void main()
{
- mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;
OUT_COLOR = vec4(mixColor, 1.0) * uColor;
- OUT_COLOR.a *= 1.0 - smoothstep( -1.0, 1.0, dist );
-}
\ No newline at end of file
+ mediump vec2 diff = abs( vPosition ) - vRectSize;
+ mediump float dist = length( max( diff, vec2( 0.0 ) ) ) - vCornerRadius;
+ if( dist > 1.0 )
+ {
+ OUT_COLOR.a = 0.0;
+ }
+ else if( dist > -1.0 )
+ {
+ if( min( diff.x, diff.y ) < 0.0)
+ {
+ dist += min( diff.x, diff.y ) / vCornerRadius;
+ }
+ OUT_COLOR.a *= 1.0 - smoothstep( -1.0, 1.0, dist );
+ }
+}
vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);
vCornerRadius = min( vCornerRadius, minSize * 0.5 );
vRectSize = visualSize / 2.0 - vCornerRadius;
+ vCornerRadius = max( vCornerRadius, 1.0 );
vPosition = aPosition* visualSize;
return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
}
void main()
{
gl_Position = uMvpMatrix * ComputeVertexPosition();
-}
\ No newline at end of file
+}
vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);
vCornerRadius = min( vCornerRadius, minSize * 0.5 );
vRectSize = visualSize * 0.5 - vCornerRadius;
+ vCornerRadius = max( vCornerRadius, 1.0 );
vPosition = aPosition * visualSize;
return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
}
void main()
{
- mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;
gl_FragColor = texture2D( sTexture, vec2( vTexCoord.y, 0.5 ) ) * vec4(mixColor, 1.0) * uColor;
- gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist );
+ mediump vec2 diff = abs( vPosition ) - vRectSize;
+ mediump float dist = length( max( diff, vec2( 0.0 ) ) ) - vCornerRadius;
+ if( dist > 1.0 )
+ {
+ gl_FragColor = vec4( 0.0 );
+ }
+ else if( dist > -1.0 )
+ {
+ if( min( diff.x, diff.y ) < 0.0 )
+ {
+ dist += min( diff.x, diff.y ) / vCornerRadius;
+ }
+ gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist );
+ }
}
void main()
{
- mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;
gl_FragColor = texture2D( sTexture, vec2( length(vTexCoord), 0.5 ) ) * vec4(mixColor, 1.0) * uColor;
- gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist );
+ mediump vec2 diff = abs( vPosition ) - vRectSize;
+ mediump float dist = length( max( diff, vec2( 0.0 ) ) ) - vCornerRadius;
+ if( dist > 1.0 )
+ {
+ gl_FragColor = vec4( 0.0 );
+ }
+ else if( dist > -1.0 )
+ {
+ if( min( diff.x, diff.y ) < 0.0)
+ {
+ dist += min( diff.x, diff.y ) / vCornerRadius;
+ }
+ gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist );
+ }
}
vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);
vCornerRadius = min( vCornerRadius, minSize * 0.5 );
vRectSize = visualSize * 0.5 - vCornerRadius;
+ vCornerRadius = max( vCornerRadius, 1.0 );
vPosition = aPosition * visualSize;
return vec4( (aPosition + anchorPoint)*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
}
void main()
{
- mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;
- mediump float opacity = 1.0 - smoothstep( -1.0, 1.0, dist );
+ mediump vec2 diff = abs( vPosition ) - vRectSize;
+ mediump float dist = length( max( diff, vec2( 0.0 ) ) ) - vCornerRadius;
+ mediump float opacity = 1.0;
+ if( dist > 1.0 )
+ {
+ opacity = 0.0;
+ }
+ else if( dist > -1.0 )
+ {
+ if( min( diff.x, diff.y ) < 0.0 )
+ {
+ dist += min( diff.x, diff.y ) / vCornerRadius;
+ }
+ opacity = 1.0 - smoothstep( -1.0, 1.0, dist );
+ }
OUT_COLOR = TEXTURE( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );
OUT_COLOR.a *= opacity;
OUT_COLOR.rgb *= mix( 1.0, opacity, preMultipliedAlpha );
-}
\ No newline at end of file
+}
vCornerRadius = mix( cornerRadius * minSize, cornerRadius, cornerRadiusPolicy);
vCornerRadius = min( vCornerRadius, minSize * 0.5 );
vRectSize = visualSize * 0.5 - vCornerRadius;
+ vCornerRadius = max( vCornerRadius, 1.0 );
vPosition = aPosition* visualSize;
return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );
}
{
gl_Position = uMvpMatrix * ComputeVertexPosition();
vTexCoord = pixelArea.xy+pixelArea.zw*(aPosition + vec2(0.5) );
-}
\ No newline at end of file
+}