Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

Commit

Permalink
added needed shaders for a game
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeriiKoniushenko committed Oct 16, 2023
1 parent 2b4b821 commit 76eb276
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 0 deletions.
12 changes: 12 additions & 0 deletions needed-shaders/text.frag
Original file line number Diff line number Diff line change
@@ -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;
}
16 changes: 16 additions & 0 deletions needed-shaders/text.vert
Original file line number Diff line number Diff line change
@@ -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;
}
87 changes: 87 additions & 0 deletions needed-shaders/widget.frag
Original file line number Diff line number Diff line change
@@ -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;
}
}
22 changes: 22 additions & 0 deletions needed-shaders/widget.vert
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 76eb276

Please sign in to comment.