关于shader的问题,求大佬解答

我想让精灵可以设置 色相 饱和度 亮度(HSL),但我还想在这同时实现对透明度色设置。不知道能不能实现。注:色相 饱和度 亮度 我通过粘贴复制实现了 但是精灵无法设置透明度了
#ifdef GL_ES
precision mediump float;
#endif
varying vec2 v_texCoord;
uniform float u_dH;
uniform float u_dS;
uniform float u_dL;
void main() {
vec4 texColor = texture2D(CC_Texture0, v_texCoord);
float r = texColor.r;
float g = texColor.g;
float b = texColor.b;
float a = texColor.a;
//convert rgb to hsl
float h;
float s;
float l;
{
float max = max(max(r, g), b);
float min = min(min(r, g), b);
//----h
if (max == min){
h = 0.0;
}
else if (max == r&&g >= b){
h = 60.0*(g - b) / (max - min) + 0.0;
}
else if (max == r&&g < b){
h = 60.0*(g - b) / (max - min) + 360.0;
}
else if (max == g){
h = 60.0*(b - r) / (max - min) + 120.0;
}
else if (max == b){
h = 60.0*(r - g) / (max - min) + 240.0;
}
//----l
l = 0.5*(max + min);
//----s
if (l == 0.0 || max == min){
s = 0.0;
}
else if (0.0 <= l&&l <= 0.5){
s = (max - min) / (2.0l);
}
else if (l > 0.5){
s = (max - min) / (2.0 - 2.0
l);
}
}
//(h,s,l)+(dH,dS,dL) -> (h,s,l)
h = h + u_dH;
s = min(1.0, max(0.0, s + u_dS));
l = l + u_dL;
//convert (h,s,l) to rgb and got final color
vec4 finalColor;
{
float q;
if (l < 0.5){
q = l*(1.0 + s);
}
else if (l >= 0.5){
q = l + s - ls;
}
float p = 2.0
l - q;
float hk = h / 360.0;

            float t[3]; 
            t[0] = hk + 1.0 / 3.0; 
            t[1] = hk; 
            t[2] = hk - 1.0 / 3.0;  
            
            float c[3]; 
            for (int i = 0; i < 3; i++){ 
                if (t[i] < 0.0)t[i] += 1.0; 
                if (t[i] > 1.0)t[i] -= 1.0; 
                
                if (t[i] < 1.0 / 6.0){ 
                    c[i] = p + ((q - p)*6.0*t[i]); 
                } 
                else if (1.0 / 6.0 <= t[i] && t[i] < 0.5){ 
                    c[i] = q; 
                } 
                else if (0.5 <= t[i] && t[i] < 2.0 / 3.0){ 
                    c[i] = p + ((q - p)*6.0*(2.0 / 3.0 - t[i])); 
                } 
                else{ 
                    c[i] = p; 
                }
            } 
            finalColor = vec4(c[0], c[1], c[2], a); 
        } 
        finalColor += vec4(u_dL, u_dL, u_dL, 0.0); 
        gl_FragColor = finalColor; 
    }

HSL的过程:
rgb -> HSL +加入自己设置的值 ->rgb
过程中,没有对a进行操作。

怎么对a进行设置呢 我试了设置a的值 透明显示不正常 :joy:不知道能不能实现同时对透明度的设置

我设置了透明度(a的值)(0-1) ,能透明了 但图片原来透明的地方变了黑色了。这个这么处理呢?
finalColor = vec4(c[0], c[1], c[2], a);//a的范围0-1 可以设置透明度
上传中…
上传中…

finalColor = vec4( (texColor.r==0&&texColor.g==0&&texColor.b==0&&texColor.a!=0)?255:c[0], c[1], c[2], (texColor.r==0&&texColor.g==0&&texColor.b==0)?0:0.5);
:joy:我这么写居然被我瞎猫碰上死耗子成功了

finalColor = vec4( c[0],c[1], c[2], (texColor.r==0&&texColor.g==0&&texColor.b==0&&texColor.a==0)?0:0.5); 完美

finalColor = vec4( c[0],c[1], c[2], (a<100)?a:0.5); 真.完美

finalColor = vec4( c[0],c[1], c[2], (texColor.a<0.8)?a:0.5); 真真.完美版:joy:

没看懂你想干嘛