mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
add new shaders for quads,text and sprites
This commit is contained in:
parent
b911ee9044
commit
91dcab6645
11
data/shader/quad.frag
Normal file
11
data/shader/quad.frag
Normal file
|
@ -0,0 +1,11 @@
|
|||
#version 330
|
||||
|
||||
uniform vec4 vertColor;
|
||||
|
||||
noperspective in vec4 quadColor;
|
||||
|
||||
out vec4 FragClr;
|
||||
void main()
|
||||
{
|
||||
FragClr = quadColor * vertColor;
|
||||
}
|
31
data/shader/quad.vert
Normal file
31
data/shader/quad.vert
Normal file
|
@ -0,0 +1,31 @@
|
|||
#version 330
|
||||
|
||||
layout (location = 0) in vec4 inVertex;
|
||||
layout (location = 1) in vec4 inColor;
|
||||
|
||||
uniform mat4x2 Pos;
|
||||
|
||||
uniform vec2 Offset;
|
||||
uniform float Rotation;
|
||||
|
||||
noperspective out vec4 quadColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 FinalPos = vec2(inVertex.xy);
|
||||
|
||||
if(Rotation != 0.0)
|
||||
{
|
||||
float X = FinalPos.x - inVertex.z;
|
||||
float Y = FinalPos.y - inVertex.w;
|
||||
|
||||
FinalPos.x = X * cos(Rotation) - Y * sin(Rotation) + inVertex.z;
|
||||
FinalPos.y = X * sin(Rotation) + Y * cos(Rotation) + inVertex.w;
|
||||
}
|
||||
|
||||
FinalPos.x = FinalPos.x / 1024.0 + Offset.x;
|
||||
FinalPos.y = FinalPos.y / 1024.0 + Offset.y;
|
||||
|
||||
gl_Position = vec4(Pos * vec4(FinalPos, 0.0, 1.0), 0.0, 1.0);
|
||||
quadColor = inColor;
|
||||
}
|
15
data/shader/quadtex.frag
Normal file
15
data/shader/quadtex.frag
Normal file
|
@ -0,0 +1,15 @@
|
|||
#version 330
|
||||
|
||||
uniform sampler2D textureSampler;
|
||||
|
||||
uniform vec4 vertColor;
|
||||
|
||||
noperspective in vec2 texCoord;
|
||||
noperspective in vec4 quadColor;
|
||||
|
||||
out vec4 FragClr;
|
||||
void main()
|
||||
{
|
||||
vec4 tex = texture(textureSampler, texCoord);
|
||||
FragClr = tex * quadColor * vertColor;
|
||||
}
|
34
data/shader/quadtex.vert
Normal file
34
data/shader/quadtex.vert
Normal file
|
@ -0,0 +1,34 @@
|
|||
#version 330
|
||||
|
||||
layout (location = 0) in vec4 inVertex;
|
||||
layout (location = 1) in vec2 inVertexTexCoord;
|
||||
layout (location = 2) in vec4 inColor;
|
||||
|
||||
uniform mat4x2 Pos;
|
||||
|
||||
uniform vec2 Offset;
|
||||
uniform float Rotation;
|
||||
|
||||
noperspective out vec2 texCoord;
|
||||
noperspective out vec4 quadColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 FinalPos = vec2(inVertex.xy);
|
||||
|
||||
if(Rotation != 0.0)
|
||||
{
|
||||
float X = FinalPos.x - inVertex.z;
|
||||
float Y = FinalPos.y - inVertex.w;
|
||||
|
||||
FinalPos.x = X * cos(Rotation) - Y * sin(Rotation) + inVertex.z;
|
||||
FinalPos.y = X * sin(Rotation) + Y * cos(Rotation) + inVertex.w;
|
||||
}
|
||||
|
||||
FinalPos.x = FinalPos.x / 1024.0 + Offset.x;
|
||||
FinalPos.y = FinalPos.y / 1024.0 + Offset.y;
|
||||
|
||||
gl_Position = vec4(Pos * vec4(FinalPos, 0.0, 1.0), 0.0, 1.0);
|
||||
texCoord = inVertexTexCoord;
|
||||
quadColor = inColor;
|
||||
}
|
15
data/shader/sprite.frag
Normal file
15
data/shader/sprite.frag
Normal file
|
@ -0,0 +1,15 @@
|
|||
#version 330
|
||||
|
||||
uniform sampler2D textureSampler;
|
||||
|
||||
uniform vec4 VerticesColor;
|
||||
|
||||
noperspective in vec2 texCoord;
|
||||
noperspective in vec4 vertColor;
|
||||
|
||||
out vec4 FragClr;
|
||||
void main()
|
||||
{
|
||||
vec4 tex = texture(textureSampler, texCoord);
|
||||
FragClr = tex * vertColor * VerticesColor;
|
||||
}
|
30
data/shader/sprite.vert
Normal file
30
data/shader/sprite.vert
Normal file
|
@ -0,0 +1,30 @@
|
|||
#version 330
|
||||
|
||||
layout (location = 0) in vec2 inVertex;
|
||||
layout (location = 1) in vec2 inVertexTexCoord;
|
||||
layout (location = 2) in vec4 inVertexColor;
|
||||
|
||||
uniform mat4x2 Pos;
|
||||
|
||||
uniform float Rotation;
|
||||
uniform vec2 Center;
|
||||
|
||||
noperspective out vec2 texCoord;
|
||||
noperspective out vec4 vertColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 FinalPos = vec2(inVertex.xy);
|
||||
if(Rotation != 0.0)
|
||||
{
|
||||
float X = FinalPos.x - Center.x;
|
||||
float Y = FinalPos.y - Center.y;
|
||||
|
||||
FinalPos.x = X * cos(Rotation) - Y * sin(Rotation) + Center.x;
|
||||
FinalPos.y = X * sin(Rotation) + Y * cos(Rotation) + Center.y;
|
||||
}
|
||||
|
||||
gl_Position = vec4(Pos * vec4(FinalPos, 0.0, 1.0), 0.0, 1.0);
|
||||
texCoord = inVertexTexCoord;
|
||||
vertColor = inVertexColor;
|
||||
}
|
15
data/shader/spritemulti.frag
Normal file
15
data/shader/spritemulti.frag
Normal file
|
@ -0,0 +1,15 @@
|
|||
#version 330
|
||||
|
||||
uniform sampler2D textureSampler;
|
||||
|
||||
uniform vec4 VerticesColor;
|
||||
|
||||
noperspective in vec2 texCoord;
|
||||
noperspective in vec4 vertColor;
|
||||
|
||||
out vec4 FragClr;
|
||||
void main()
|
||||
{
|
||||
vec4 tex = texture(textureSampler, texCoord);
|
||||
FragClr = tex * vertColor * VerticesColor;
|
||||
}
|
36
data/shader/spritemulti.vert
Normal file
36
data/shader/spritemulti.vert
Normal file
|
@ -0,0 +1,36 @@
|
|||
#version 330
|
||||
|
||||
layout (location = 0) in vec2 inVertex;
|
||||
layout (location = 1) in vec2 inVertexTexCoord;
|
||||
layout (location = 2) in vec4 inVertexColor;
|
||||
|
||||
uniform mat4x2 Pos;
|
||||
|
||||
uniform vec4 RSP[228];
|
||||
uniform vec2 Center;
|
||||
|
||||
noperspective out vec2 texCoord;
|
||||
noperspective out vec4 vertColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 FinalPos = vec2(inVertex.xy);
|
||||
if(RSP[gl_InstanceID].w != 0.0)
|
||||
{
|
||||
float X = FinalPos.x - Center.x;
|
||||
float Y = FinalPos.y - Center.y;
|
||||
|
||||
FinalPos.x = X * cos(RSP[gl_InstanceID].w) - Y * sin(RSP[gl_InstanceID].w) + Center.x;
|
||||
FinalPos.y = X * sin(RSP[gl_InstanceID].w) + Y * cos(RSP[gl_InstanceID].w) + Center.y;
|
||||
}
|
||||
|
||||
FinalPos.x *= RSP[gl_InstanceID].z;
|
||||
FinalPos.y *= RSP[gl_InstanceID].z;
|
||||
|
||||
FinalPos.x += RSP[gl_InstanceID].x;
|
||||
FinalPos.y += RSP[gl_InstanceID].y;
|
||||
|
||||
gl_Position = vec4(Pos * vec4(FinalPos, 0.0, 1.0), 0.0, 1.0);
|
||||
texCoord = inVertexTexCoord;
|
||||
vertColor = inVertexColor;
|
||||
}
|
40
data/shader/text.frag
Normal file
40
data/shader/text.frag
Normal file
|
@ -0,0 +1,40 @@
|
|||
#version 330
|
||||
|
||||
uniform sampler2D textSampler;
|
||||
uniform sampler2D textOutlineSampler;
|
||||
|
||||
uniform vec4 vertColor;
|
||||
uniform vec4 vertOutlineColor;
|
||||
|
||||
noperspective in vec2 texCoord;
|
||||
noperspective in vec4 outVertColor;
|
||||
|
||||
out vec4 FragClr;
|
||||
void main()
|
||||
{
|
||||
vec4 textColor = vertColor * outVertColor * texture(textSampler, texCoord);
|
||||
vec4 textOutlineTex = vertOutlineColor * texture(textOutlineSampler, texCoord);
|
||||
|
||||
// ratio between the two textures
|
||||
float OutlineBlend = (1.0 - textColor.a);
|
||||
|
||||
// since the outline is always black, or even if it has decent colors, it can be just added to the actual color
|
||||
// without loosing any or too much color
|
||||
|
||||
// lerp isn't commutative, so add the color the fragment looses by lerping
|
||||
// this reduces the chance of false color calculation if the text is transparent
|
||||
|
||||
// first get the right color
|
||||
vec4 textOutlineFrag = vec4(textOutlineTex.rgb * textOutlineTex.a, textOutlineTex.a) * OutlineBlend;
|
||||
vec3 textFrag = (textColor.rgb * textColor.a);
|
||||
vec3 finalFragColor = textOutlineFrag.rgb + textFrag;
|
||||
|
||||
float RealAlpha = (textOutlineFrag.a + textColor.a);
|
||||
|
||||
// discard transparent fragments
|
||||
if(RealAlpha == 0.0)
|
||||
discard;
|
||||
|
||||
// simply add the color we will loose through blending
|
||||
FragClr = vec4(finalFragColor / RealAlpha, RealAlpha);
|
||||
}
|
19
data/shader/text.vert
Normal file
19
data/shader/text.vert
Normal file
|
@ -0,0 +1,19 @@
|
|||
#version 330
|
||||
|
||||
layout (location = 0) in vec2 inVertex;
|
||||
layout (location = 1) in vec2 inVertexTexCoord;
|
||||
layout (location = 2) in vec4 inVertexColor;
|
||||
|
||||
uniform mat4x2 Pos;
|
||||
uniform float textureSize;
|
||||
|
||||
noperspective out vec2 texCoord;
|
||||
noperspective out vec4 outVertColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(Pos * vec4(inVertex, 0.0, 1.0), 0.0, 1.0);
|
||||
|
||||
texCoord = vec2(inVertexTexCoord.x / textureSize, inVertexTexCoord.y / textureSize);
|
||||
outVertColor = inVertexColor;
|
||||
}
|
Loading…
Reference in a new issue