@@ -53,11 +53,14 @@ const char* gVS_Header_Uniforms_IsPoint =
5353 " uniform mediump float pointSize;\n " ;
5454const char * gVS_Header_Uniforms_HasGradient [3 ] = {
5555 // Linear
56- " uniform mat4 screenSpace;\n " ,
56+ " uniform mat4 screenSpace;\n "
57+ " uniform float ditherSize;\n " ,
5758 // Circular
58- " uniform mat4 screenSpace;\n " ,
59+ " uniform mat4 screenSpace;\n "
60+ " uniform float ditherSize;\n " ,
5961 // Sweep
6062 " uniform mat4 screenSpace;\n "
63+ " uniform float ditherSize;\n "
6164};
6265const char * gVS_Header_Uniforms_HasBitmap =
6366 " uniform mat4 textureTransform;\n "
@@ -75,16 +78,22 @@ const char* gVS_Header_Varyings_PointHasBitmap =
7578 " varying highp vec2 outPointBitmapTexCoords;\n " ;
7679const char * gVS_Header_Varyings_HasGradient [6 ] = {
7780 // Linear
78- " varying highp vec2 linear;\n " ,
79- " varying float linear;\n " ,
81+ " varying highp vec2 linear;\n "
82+ " varying vec2 ditherTexCoords;\n " ,
83+ " varying float linear;\n "
84+ " varying vec2 ditherTexCoords;\n " ,
8085
8186 // Circular
82- " varying highp vec2 circular;\n " ,
83- " varying highp vec2 circular;\n " ,
87+ " varying highp vec2 circular;\n "
88+ " varying vec2 ditherTexCoords;\n " ,
89+ " varying highp vec2 circular;\n "
90+ " varying vec2 ditherTexCoords;\n " ,
8491
8592 // Sweep
86- " varying highp vec2 sweep;\n " ,
87- " varying highp vec2 sweep;\n " ,
93+ " varying highp vec2 sweep;\n "
94+ " varying vec2 ditherTexCoords;\n " ,
95+ " varying highp vec2 sweep;\n "
96+ " varying vec2 ditherTexCoords;\n " ,
8897};
8998const char * gVS_Main =
9099 " \n void main(void) {\n " ;
@@ -94,16 +103,22 @@ const char* gVS_Main_OutTransformedTexCoords =
94103 " outTexCoords = (mainTextureTransform * vec4(texCoords, 0.0, 1.0)).xy;\n " ;
95104const char * gVS_Main_OutGradient [6 ] = {
96105 // Linear
97- " linear = vec2((screenSpace * position).x, 0.5);\n " ,
98- " linear = (screenSpace * position).x;\n " ,
106+ " linear = vec2((screenSpace * position).x, 0.5);\n "
107+ " ditherTexCoords = (gl_Position * ditherSize).xy;\n " ,
108+ " linear = (screenSpace * position).x;\n "
109+ " ditherTexCoords = (gl_Position * ditherSize).xy;\n " ,
99110
100111 // Circular
101- " circular = (screenSpace * position).xy;\n " ,
102- " circular = (screenSpace * position).xy;\n " ,
112+ " circular = (screenSpace * position).xy;\n "
113+ " ditherTexCoords = (gl_Position * ditherSize).xy;\n " ,
114+ " circular = (screenSpace * position).xy;\n "
115+ " ditherTexCoords = (gl_Position * ditherSize).xy;\n " ,
103116
104117 // Sweep
105- " sweep = (screenSpace * position).xy;\n " ,
106- " sweep = (screenSpace * position).xy;\n " ,
118+ " sweep = (screenSpace * position).xy;\n "
119+ " ditherTexCoords = (gl_Position * ditherSize).xy;\n " ,
120+ " sweep = (screenSpace * position).xy;\n "
121+ " ditherTexCoords = (gl_Position * ditherSize).xy;\n " ,
107122};
108123const char * gVS_Main_OutBitmapTexCoords =
109124 " outBitmapTexCoords = (textureTransform * position).xy * textureDimension;\n " ;
@@ -144,7 +159,7 @@ const char* gFS_Uniforms_TextureSampler =
144159const char * gFS_Uniforms_ExternalTextureSampler =
145160 " uniform samplerExternalOES baseSampler;\n " ;
146161#define FS_UNIFORMS_DITHER \
147- " uniform float ditherSize ;\n " \
162+ " uniform float ditherSizeSquared ;\n " \
148163 " uniform sampler2D ditherSampler;\n "
149164#define FS_UNIFORMS_GRADIENT \
150165 " uniform vec4 startColor;\n " \
@@ -188,7 +203,7 @@ const char* gFS_Main_PointBitmapTexCoords =
188203 " ((gl_PointCoord - vec2(0.5, 0.5)) * textureDimension * vec2(pointSize, pointSize));\n " ;
189204
190205#define FS_MAIN_DITHER \
191- " texture2D(ditherSampler, gl_FragCoord.xy * ditherSize ).a * ditherSize * ditherSize "
206+ " texture2D(ditherSampler, ditherTexCoords ).a * ditherSizeSquared "
192207const char * gFS_Main_AddDitherToGradient =
193208 " gradientColor += " FS_MAIN_DITHER " ;\n " ;
194209
@@ -511,9 +526,6 @@ String8 ProgramCache::generateVertexShader(const ProgramDescription& description
511526 shader.append (gVS_Main_AALine );
512527 }
513528 }
514- if (description.hasGradient ) {
515- shader.append (gVS_Main_OutGradient [gradientIndex (description)]);
516- }
517529 if (description.hasBitmap ) {
518530 shader.append (description.isPoint ?
519531 gVS_Main_OutPointBitmapTexCoords :
@@ -524,6 +536,9 @@ String8 ProgramCache::generateVertexShader(const ProgramDescription& description
524536 }
525537 // Output transformed position
526538 shader.append (gVS_Main_Position );
539+ if (description.hasGradient ) {
540+ shader.append (gVS_Main_OutGradient [gradientIndex (description)]);
541+ }
527542 }
528543 // End the shader
529544 shader.append (gVS_Footer );
0 commit comments