diff --git a/needed-shaders/text.frag b/needed-shaders/text.frag new file mode 100644 index 000000000..fe36a0eb4 --- /dev/null +++ b/needed-shaders/text.frag @@ -0,0 +1,12 @@ +#version 330 core +in vec2 TexCoords; +out vec4 color; + +uniform sampler2D text; +uniform vec4 uColor; + +void main() +{ + vec4 sampled = vec4(1.0, 1.0, 1.0, texture(text, TexCoords).r); + color = uColor * sampled; +} \ No newline at end of file diff --git a/needed-shaders/text.vert b/needed-shaders/text.vert new file mode 100644 index 000000000..ffb46f6d3 --- /dev/null +++ b/needed-shaders/text.vert @@ -0,0 +1,16 @@ +#version 330 core + +layout (location = 0) in vec2 aVertex; +layout (location = 1) in vec2 aUv; + +out vec2 TexCoords; + +uniform vec2 uResolution; +uniform mat4 uTransform; + +void main() +{ + TexCoords = aUv; + vec4 offset = vec4(1.0f, -1.0f, 0.f, 0.f); + gl_Position = uTransform * vec4(aVertex / uResolution, 0.0, 1.0) - offset; +} \ No newline at end of file diff --git a/needed-shaders/widget.frag b/needed-shaders/widget.frag new file mode 100644 index 000000000..a79f3c978 --- /dev/null +++ b/needed-shaders/widget.frag @@ -0,0 +1,87 @@ +#version 450 core + +out vec4 FragColor; + +in vec2 ioCv; +in vec2 ioTextRectSize; + +uniform sampler2D uTexture; +uniform float uGamma; +uniform float uBrightness; +uniform float uContrast; +uniform float uSaturation; +uniform vec4 uBorderColor; +uniform float uBorderWidth; +uniform bool uIsDrawBorder; +uniform bool uHasTexture; + +mat4 brightnessMatrix(float brightness) +{ + return mat4( + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + brightness, brightness, brightness, 1); +} + +mat4 contrastMatrix(float contrast) +{ + float t = (1.0 - contrast) / 2.0; + + return mat4( + contrast, 0, 0, 0, + 0, contrast, 0, 0, + 0, 0, contrast, 0, + t, t, t, 1); + +} + +mat4 saturationMatrix(float saturation) +{ + vec3 luminance = vec3(0.3086, 0.6094, 0.0820); + + float oneMinusSat = 1.0 - saturation; + + vec3 red = vec3(luminance.x * oneMinusSat); + red+= vec3(saturation, 0, 0); + + vec3 green = vec3(luminance.y * oneMinusSat); + green += vec3(0, saturation, 0); + + vec3 blue = vec3(luminance.z * oneMinusSat); + blue += vec3(0, 0, saturation); + + return mat4( + red, 0, + green, 0, + blue, 0, + 0, 0, 0, 1); +} + +bool canDrawBorder() +{ + return (ioCv.x <= uBorderWidth || ioCv.y <= uBorderWidth || 1.f - ioCv.x <= uBorderWidth || 1.f - ioCv.y <= uBorderWidth); +} + +void main() +{ + if (uIsDrawBorder && canDrawBorder()) + { + FragColor = uBorderColor; + } + else + { + vec2 cv = ioCv + vec2(ioTextRectSize); + vec4 textureColor = texture(uTexture, cv); + vec3 diffuseColor = pow(texture(uTexture, cv).rgb, vec3(uGamma)); + vec4 midColor = vec4(diffuseColor, textureColor.a); + vec4 outColor = brightnessMatrix(uBrightness) * contrastMatrix(uContrast) * saturationMatrix(uSaturation) * midColor; + + if (!uHasTexture) + { + outColor.a = 0.f; + } + + FragColor = outColor; + } +} \ No newline at end of file diff --git a/needed-shaders/widget.vert b/needed-shaders/widget.vert new file mode 100644 index 000000000..be22178e9 --- /dev/null +++ b/needed-shaders/widget.vert @@ -0,0 +1,22 @@ +#version 450 core + +layout (location = 0) in vec2 aVertex; +layout (location = 1) in vec2 aCv; +layout (location = 2) in vec2 aTextRectSize; + +out vec2 ioCv; +out vec2 ioTextRectSize; + +uniform mat4 uCameraMatrix; +uniform mat4 uTransform; +uniform vec2 uAtlasSize; +uniform vec2 uResolution; + +void main() +{ + ioCv = aCv / uAtlasSize; + ioTextRectSize = aTextRectSize / uAtlasSize; + + vec4 offset = vec4(1.0f, -1.0f, 0.f, 0.f); + gl_Position = uCameraMatrix * uTransform * vec4(aVertex / uResolution, 0.0, 1.0) - offset; +} \ No newline at end of file