/ chmod777_includes / shaders / html.fs.glsl
html.fs.glsl
  1  #version 420
  2  #extension GL_ARB_uniform_buffer_object : require
  3  #extension GL_ARB_shading_language_420pack: require
  4  
  5  // file: html.vs.glsl
  6  
  7  /*
  8  Copyright (C) 2024 chmod777
  9  
 10  This program is free software: you can redistribute it and/or modify it under
 11  the terms of the GNU Affero General Public License version 3 as published by the
 12  Free Software Foundation.
 13  
 14  This program is distributed in the hope that it will be useful, but WITHOUT ANY
 15  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 16  PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
 17  
 18  You should have received a copy of the GNU Affero General Public License along
 19  with this program. If not, see <https://www.gnu.org/licenses/>. 
 20  */
 21  
 22  layout (binding = 0) uniform sampler2D tex0;
 23  layout (binding = 1) uniform sampler2D tex1;
 24  layout (binding = 2) uniform sampler2D tex2;
 25  layout (binding = 3) uniform sampler2D tex3;
 26  layout (binding = 4) uniform sampler2D tex4;
 27  layout (binding = 5) uniform sampler2D tex5;
 28  layout (binding = 6) uniform sampler2D tex6;
 29  layout (binding = 7) uniform sampler2D tex7;
 30  
 31  in DataVS {
 32  	vec2 uv;
 33  	vec4 flags;
 34  	vec2 position;
 35  	vec2 size;
 36  	vec4 background_color;
 37  	vec4 background_images;
 38  	vec4 border_widths;
 39  	vec4 border_color;
 40  	vec4 image0_size_offset;
 41  	vec2 image0_uv;
 42  } vs_in;
 43  
 44  out vec4 fragColor;
 45  
 46  vec4 image_color(int image_flag, vec2 image_uv) {
 47  	vec4 color;
 48  	if (image_flag == 1) { color = texture(tex0, image_uv); }
 49  	if (image_flag == 2) { color = texture(tex1, image_uv); }
 50  	if (image_flag == 3) { color = texture(tex2, image_uv); }
 51  	if (image_flag == 4) { color = texture(tex3, image_uv); }
 52  	if (image_flag == 5) { color = texture(tex4, image_uv); }
 53  	if (image_flag == 6) { color = texture(tex5, image_uv); }
 54  	if (image_flag == 7) { color = texture(tex6, image_uv); }
 55  	if (image_flag == 8) { color = texture(tex7, image_uv); }
 56  	return color;
 57  }
 58  vec4 image_on_top(vec4 base, vec4 image, bool is_active) {
 59  	return mix(base, image, image.a * float(is_active));
 60  }
 61  vec4 image_color_or_one(vec4 color, bool is_active) {
 62  	return fma(color, vec4(float(is_active)), vec4(float(!is_active)));
 63  }
 64  
 65  float radius = 5.0;
 66  vec4 border_width = vec4(5.0, 5.0, 5.0, 5.0);
 67  vec4 border_color = vec4(1.0, 0.0, 0.0, 1.0);
 68  
 69  void main() {
 70  	vec2 uv = vs_in.uv;
 71  	vec4 flags = vs_in.flags;
 72  	vec4 background_color = vs_in.background_color;
 73  	vec4 background_images = vs_in.background_images;
 74  
 75  	ivec3 active_image_flags = ivec3(floor(background_images.xyz + vec3(0.1)));
 76  	int background_blend_mode = int(floor(background_images.w+0.1));
 77  
 78  	bool image0_active = bool(active_image_flags[0]);
 79  	bool image1_active = bool(active_image_flags[1]);
 80  	bool image2_active = bool(active_image_flags[2]);
 81  	int active_image_count = int(image0_active) + int(image1_active) + int(image2_active);
 82  
 83  	vec4 image0_color = image_color(active_image_flags[0], vs_in.image0_uv);
 84  	vec4 image1_color = image_color(active_image_flags[1], uv);
 85  	vec4 image2_color = image_color(active_image_flags[2], uv);
 86  
 87  	vec4 color;
 88  	// background_blend_mode = 1;
 89  	if (background_blend_mode == 0) { // "normal"
 90  		color = background_color;
 91  		color = image_on_top(color, image2_color, image2_active);
 92  		color = image_on_top(color, image1_color, image1_active);
 93  		color = image_on_top(color, image0_color, image0_active);
 94  	}
 95  	if (background_blend_mode == 1) { // "multiply"
 96  		vec4 a = image_color_or_one(image2_color, image2_active);
 97  		vec4 b = image_color_or_one(image1_color, image1_active);
 98  		vec4 c = image_color_or_one(image0_color, image0_active);
 99  		color = a * b * c * background_color;
100  	}
101  	if (background_blend_mode == 2) { // "darken"
102  	}
103  	if (background_blend_mode == 3) { // "screen"
104  	}
105  	if (background_blend_mode == 4) { // "lighten"
106  	}
107  	if (background_blend_mode == 5) { // "overlay"
108  	}
109  	if (background_blend_mode == 6) { // "color-dodge"
110  	}
111  	if (background_blend_mode == 7) { // "color-burn"
112  	}
113  	if (background_blend_mode == 8) { // "hard-light"
114  	}
115  	if (background_blend_mode == 8) { // "soft-light"
116  	}
117  	if (background_blend_mode == 8) { // "difference"
118  	}
119  	if (background_blend_mode == 8) { // "exclusion"
120  	}
121  	if (background_blend_mode == 8) { // "hue"
122  	}
123  	if (background_blend_mode == 8) { // "saturation"
124  	}
125  	if (background_blend_mode == 8) { // "color"
126  	}
127  	if (background_blend_mode == 8) { // "luminosity"
128  	}
129  	if (background_blend_mode == 8) { // "plus-darker"
130  	}
131  	if (background_blend_mode == 8) { // "plus-lighter"
132  	}
133  
134  	fragColor = clamp(color, vec4(0.0), vec4(1.0));
135  }