4
4
NSString *const kGPUSolidColorFragmentShaderString = SHADER_STRING
5
5
(
6
6
precision lowp float ;
7
-
7
+
8
8
varying highp vec2 textureCoordinate;
9
-
10
9
uniform sampler2D inputImageTexture;
11
10
uniform vec4 color;
12
-
11
+ uniform float useExistingAlpha;
12
+
13
13
void main ()
14
14
{
15
- gl_FragColor = color;
15
+ lowp vec4 textureColor = texture2D (inputImageTexture, textureCoordinate);
16
+ gl_FragColor = vec4 (color.rgb , max (textureColor.a , 1.0 - useExistingAlpha));
16
17
}
17
- );
18
+ );
18
19
#else
19
20
NSString *const kGPUSolidColorFragmentShaderString = SHADER_STRING
20
21
(
21
22
varying vec2 textureCoordinate;
22
-
23
23
uniform sampler2D inputImageTexture;
24
24
uniform vec4 color;
25
-
25
+ uniform float useExistingAlpha;
26
+
26
27
void main ()
27
28
{
28
- gl_FragColor = color;
29
+ vec4 textureColor = texture2D (inputImageTexture, textureCoordinate);
30
+ gl_FragColor = vec4 (color.rgb , max (textureColor.a , 1.0 - useExistingAlpha));
29
31
}
30
- );
32
+ );
31
33
#endif
32
34
33
35
@implementation GPUImageSolidColorGenerator
@@ -42,8 +44,10 @@ - (id)init;
42
44
}
43
45
44
46
colorUniform = [filterProgram uniformIndex: @" color" ];
47
+ useExistingAlphaUniform = [filterProgram uniformIndex: @" useExistingAlpha" ];
45
48
46
49
self.color = (GPUVector4){0 .0f , 0 .0f , 0 .5f , 1 .0f };
50
+ self.useExistingAlpha = NO ;
47
51
48
52
return self;
49
53
}
@@ -65,7 +69,7 @@ - (void)forceProcessingAtSize:(CGSize)frameSize;
65
69
- (void )addTarget : (id <GPUImageInput>)newTarget atTextureLocation : (NSInteger )textureLocation ;
66
70
{
67
71
[super addTarget: newTarget atTextureLocation: textureLocation];
68
-
72
+
69
73
if (!CGSizeEqualToSize (inputTextureSize, CGSizeZero))
70
74
{
71
75
[newTarget setInputSize: inputTextureSize atIndex: textureLocation];
@@ -86,11 +90,13 @@ - (void)setColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GL
86
90
_color.four = alphaComponent;
87
91
88
92
[self setVec4: _color forUniform: colorUniform program: filterProgram];
89
-
90
- if (!CGSizeEqualToSize (inputTextureSize, CGSizeZero))
91
- {
92
- [self newFrameReadyAtTime: kCMTimeIndefinite atIndex: 0 ];
93
- }
93
+ }
94
+
95
+ - (void )setUseExistingAlpha : (BOOL )useExistingAlpha ;
96
+ {
97
+ _useExistingAlpha = useExistingAlpha;
98
+
99
+ [self setInteger: (useExistingAlpha ? 1 : 0 ) forUniform: useExistingAlphaUniform program: filterProgram];
94
100
}
95
101
96
102
@end
0 commit comments