init
This commit is contained in:
35
data/shader/pipeline.frag
Executable file
35
data/shader/pipeline.frag
Executable file
@ -0,0 +1,35 @@
|
||||
#ifdef TW_TEXTURED
|
||||
#ifdef TW_3D_TEXTURED
|
||||
uniform sampler3D gTextureSampler;
|
||||
#else
|
||||
uniform sampler2DArray gTextureSampler;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef TW_MODERN_GL
|
||||
#ifdef TW_TEXTURED
|
||||
noperspective in vec3 oTexCoord;
|
||||
#endif
|
||||
noperspective in vec4 oVertColor;
|
||||
out vec4 FragClr;
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
#ifdef TW_MODERN_GL
|
||||
#ifdef TW_TEXTURED
|
||||
vec4 TexColor = texture(gTextureSampler, oTexCoord.xyz).rgba;
|
||||
FragClr = TexColor.rgba * oVertColor.rgba;
|
||||
#else
|
||||
FragClr = oVertColor.rgba;
|
||||
#endif
|
||||
#else
|
||||
#ifdef TW_TEXTURED
|
||||
vec4 TexColor = texture(gTextureSampler, gl_TexCoord[0].xyz).rgba;
|
||||
gl_FragColor = TexColor.rgba * gl_Color.rgba;
|
||||
#else
|
||||
gl_FragColor = gl_Color.rgba;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
32
data/shader/pipeline.vert
Executable file
32
data/shader/pipeline.vert
Executable file
@ -0,0 +1,32 @@
|
||||
#ifdef TW_MODERN_GL
|
||||
layout (location = 0) in vec2 inVertex;
|
||||
layout (location = 1) in vec4 inVertexColor;
|
||||
layout (location = 2) in vec3 inVertexTexCoord;
|
||||
#endif
|
||||
|
||||
uniform mat4x2 gPos;
|
||||
|
||||
#ifdef TW_MODERN_GL
|
||||
#ifdef TW_TEXTURED
|
||||
noperspective out vec3 oTexCoord;
|
||||
#endif
|
||||
noperspective out vec4 oVertColor;
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
#ifdef TW_MODERN_GL
|
||||
gl_Position = vec4(gPos * vec4(inVertex, 0.0, 1.0), 0.0, 1.0);
|
||||
#ifdef TW_TEXTURED
|
||||
oTexCoord = inVertexTexCoord;
|
||||
#endif
|
||||
oVertColor = inVertexColor;
|
||||
#else
|
||||
gl_Position = vec4(gPos * vec4(gl_Vertex.xy, 0.0, 1.0), 0.0, 1.0);
|
||||
#ifdef TW_TEXTURED
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
#endif
|
||||
gl_FrontColor = gl_Color.rgba;
|
||||
gl_BackColor = gl_Color.rgba;
|
||||
#endif
|
||||
}
|
15
data/shader/prim.frag
Executable file
15
data/shader/prim.frag
Executable file
@ -0,0 +1,15 @@
|
||||
uniform sampler2D gTextureSampler;
|
||||
|
||||
noperspective in vec2 texCoord;
|
||||
noperspective in vec4 vertColor;
|
||||
|
||||
out vec4 FragClr;
|
||||
void main()
|
||||
{
|
||||
#ifdef TW_TEXTURED
|
||||
vec4 tex = texture(gTextureSampler, texCoord);
|
||||
FragClr = tex * vertColor;
|
||||
#else
|
||||
FragClr = vertColor;
|
||||
#endif
|
||||
}
|
15
data/shader/prim.vert
Executable file
15
data/shader/prim.vert
Executable file
@ -0,0 +1,15 @@
|
||||
layout (location = 0) in vec2 inVertex;
|
||||
layout (location = 1) in vec2 inVertexTexCoord;
|
||||
layout (location = 2) in vec4 inVertexColor;
|
||||
|
||||
uniform mat4x2 gPos;
|
||||
|
||||
noperspective out vec2 texCoord;
|
||||
noperspective out vec4 vertColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(gPos * vec4(inVertex, 0.0, 1.0), 0.0, 1.0);
|
||||
texCoord = inVertexTexCoord;
|
||||
vertColor = inVertexColor;
|
||||
}
|
19
data/shader/primex.frag
Executable file
19
data/shader/primex.frag
Executable file
@ -0,0 +1,19 @@
|
||||
#ifdef TW_TEXTURED
|
||||
uniform sampler2D gTextureSampler;
|
||||
#endif
|
||||
|
||||
uniform vec4 gVerticesColor;
|
||||
|
||||
noperspective in vec2 texCoord;
|
||||
noperspective in vec4 vertColor;
|
||||
|
||||
out vec4 FragClr;
|
||||
void main()
|
||||
{
|
||||
#ifdef TW_TEXTURED
|
||||
vec4 tex = texture(gTextureSampler, texCoord);
|
||||
FragClr = tex * vertColor * gVerticesColor;
|
||||
#else
|
||||
FragClr = vertColor * gVerticesColor;
|
||||
#endif
|
||||
}
|
29
data/shader/primex.vert
Executable file
29
data/shader/primex.vert
Executable file
@ -0,0 +1,29 @@
|
||||
layout (location = 0) in vec2 inVertex;
|
||||
layout (location = 1) in vec2 inVertexTexCoord;
|
||||
layout (location = 2) in vec4 inVertexColor;
|
||||
|
||||
uniform mat4x2 gPos;
|
||||
|
||||
#ifndef TW_ROTATIONLESS
|
||||
uniform float gRotation;
|
||||
#endif
|
||||
uniform vec2 gCenter;
|
||||
|
||||
noperspective out vec2 texCoord;
|
||||
noperspective out vec4 vertColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 FinalPos = vec2(inVertex.xy);
|
||||
#ifndef TW_ROTATIONLESS
|
||||
float X = FinalPos.x - gCenter.x;
|
||||
float Y = FinalPos.y - gCenter.y;
|
||||
|
||||
FinalPos.x = X * cos(gRotation) - Y * sin(gRotation) + gCenter.x;
|
||||
FinalPos.y = X * sin(gRotation) + Y * cos(gRotation) + gCenter.y;
|
||||
#endif
|
||||
|
||||
gl_Position = vec4(gPos * vec4(FinalPos, 0.0, 1.0), 0.0, 1.0);
|
||||
texCoord = inVertexTexCoord;
|
||||
vertColor = inVertexColor;
|
||||
}
|
22
data/shader/quad.frag
Executable file
22
data/shader/quad.frag
Executable file
@ -0,0 +1,22 @@
|
||||
#ifdef TW_QUAD_TEXTURED
|
||||
uniform sampler2D gTextureSampler;
|
||||
#endif
|
||||
|
||||
uniform vec4 gVertColors[TW_MAX_QUADS];
|
||||
|
||||
noperspective in vec4 QuadColor;
|
||||
flat in int QuadIndex;
|
||||
#ifdef TW_QUAD_TEXTURED
|
||||
noperspective in vec2 TexCoord;
|
||||
#endif
|
||||
|
||||
out vec4 FragClr;
|
||||
void main()
|
||||
{
|
||||
#ifdef TW_QUAD_TEXTURED
|
||||
vec4 TexColor = texture(gTextureSampler, TexCoord);
|
||||
FragClr = TexColor * QuadColor * gVertColors[QuadIndex];
|
||||
#else
|
||||
FragClr = QuadColor * gVertColors[QuadIndex];
|
||||
#endif
|
||||
}
|
44
data/shader/quad.vert
Executable file
44
data/shader/quad.vert
Executable file
@ -0,0 +1,44 @@
|
||||
layout (location = 0) in vec4 inVertex;
|
||||
layout (location = 1) in vec4 inColor;
|
||||
#ifdef TW_QUAD_TEXTURED
|
||||
layout (location = 2) in vec2 inVertexTexCoord;
|
||||
#endif
|
||||
|
||||
uniform mat4x2 gPos;
|
||||
|
||||
uniform vec2 gOffsets[TW_MAX_QUADS];
|
||||
uniform float gRotations[TW_MAX_QUADS];
|
||||
|
||||
uniform int gQuadOffset;
|
||||
|
||||
noperspective out vec4 QuadColor;
|
||||
flat out int QuadIndex;
|
||||
#ifdef TW_QUAD_TEXTURED
|
||||
noperspective out vec2 TexCoord;
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 FinalPos = vec2(inVertex.xy);
|
||||
|
||||
int TmpQuadIndex = int(gl_VertexID / 4) - gQuadOffset;
|
||||
|
||||
if(gRotations[TmpQuadIndex] != 0.0)
|
||||
{
|
||||
float X = FinalPos.x - inVertex.z;
|
||||
float Y = FinalPos.y - inVertex.w;
|
||||
|
||||
FinalPos.x = X * cos(gRotations[TmpQuadIndex]) - Y * sin(gRotations[TmpQuadIndex]) + inVertex.z;
|
||||
FinalPos.y = X * sin(gRotations[TmpQuadIndex]) + Y * cos(gRotations[TmpQuadIndex]) + inVertex.w;
|
||||
}
|
||||
|
||||
FinalPos.x = FinalPos.x / 1024.0 + gOffsets[TmpQuadIndex].x;
|
||||
FinalPos.y = FinalPos.y / 1024.0 + gOffsets[TmpQuadIndex].y;
|
||||
|
||||
gl_Position = vec4(gPos * vec4(FinalPos, 0.0, 1.0), 0.0, 1.0);
|
||||
QuadColor = inColor;
|
||||
QuadIndex = TmpQuadIndex;
|
||||
#ifdef TW_QUAD_TEXTURED
|
||||
TexCoord = inVertexTexCoord;
|
||||
#endif
|
||||
}
|
13
data/shader/spritemulti.frag
Executable file
13
data/shader/spritemulti.frag
Executable file
@ -0,0 +1,13 @@
|
||||
uniform sampler2D gTextureSampler;
|
||||
|
||||
uniform vec4 gVerticesColor;
|
||||
|
||||
noperspective in vec2 texCoord;
|
||||
noperspective in vec4 vertColor;
|
||||
|
||||
out vec4 FragClr;
|
||||
void main()
|
||||
{
|
||||
vec4 tex = texture(gTextureSampler, texCoord);
|
||||
FragClr = tex * vertColor * gVerticesColor;
|
||||
}
|
34
data/shader/spritemulti.vert
Executable file
34
data/shader/spritemulti.vert
Executable file
@ -0,0 +1,34 @@
|
||||
layout (location = 0) in vec2 inVertex;
|
||||
layout (location = 1) in vec2 inVertexTexCoord;
|
||||
layout (location = 2) in vec4 inVertexColor;
|
||||
|
||||
uniform mat4x2 gPos;
|
||||
|
||||
uniform vec4 gRSP[228];
|
||||
uniform vec2 gCenter;
|
||||
|
||||
noperspective out vec2 texCoord;
|
||||
noperspective out vec4 vertColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 FinalPos = vec2(inVertex.xy);
|
||||
if(gRSP[gl_InstanceID].w != 0.0)
|
||||
{
|
||||
float X = FinalPos.x - gCenter.x;
|
||||
float Y = FinalPos.y - gCenter.y;
|
||||
|
||||
FinalPos.x = X * cos(gRSP[gl_InstanceID].w) - Y * sin(gRSP[gl_InstanceID].w) + gCenter.x;
|
||||
FinalPos.y = X * sin(gRSP[gl_InstanceID].w) + Y * cos(gRSP[gl_InstanceID].w) + gCenter.y;
|
||||
}
|
||||
|
||||
FinalPos.x *= gRSP[gl_InstanceID].z;
|
||||
FinalPos.y *= gRSP[gl_InstanceID].z;
|
||||
|
||||
FinalPos.x += gRSP[gl_InstanceID].x;
|
||||
FinalPos.y += gRSP[gl_InstanceID].y;
|
||||
|
||||
gl_Position = vec4(gPos * vec4(FinalPos, 0.0, 1.0), 0.0, 1.0);
|
||||
texCoord = inVertexTexCoord;
|
||||
vertColor = inVertexColor;
|
||||
}
|
37
data/shader/text.frag
Executable file
37
data/shader/text.frag
Executable file
@ -0,0 +1,37 @@
|
||||
uniform sampler2D gTextSampler;
|
||||
uniform sampler2D gTextOutlineSampler;
|
||||
|
||||
uniform vec4 gVertColor;
|
||||
uniform vec4 gVertOutlineColor;
|
||||
|
||||
noperspective in vec2 texCoord;
|
||||
noperspective in vec4 outVertColor;
|
||||
|
||||
out vec4 FragClr;
|
||||
void main()
|
||||
{
|
||||
vec4 textColor = gVertColor * outVertColor * vec4(1.0, 1.0, 1.0, texture(gTextSampler, texCoord).r);
|
||||
vec4 textOutlineTex = gVertOutlineColor * vec4(1.0, 1.0, 1.0, texture(gTextOutlineSampler, texCoord).r);
|
||||
|
||||
// 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 losing 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);
|
||||
|
||||
// simply add the color we will loose through blending
|
||||
if(RealAlpha > 0.0)
|
||||
FragClr = vec4(finalFragColor / RealAlpha, RealAlpha);
|
||||
else
|
||||
FragClr = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
17
data/shader/text.vert
Executable file
17
data/shader/text.vert
Executable file
@ -0,0 +1,17 @@
|
||||
layout (location = 0) in vec2 inVertex;
|
||||
layout (location = 1) in vec2 inVertexTexCoord;
|
||||
layout (location = 2) in vec4 inVertexColor;
|
||||
|
||||
uniform mat4x2 gPos;
|
||||
uniform float gTextureSize;
|
||||
|
||||
noperspective out vec2 texCoord;
|
||||
noperspective out vec4 outVertColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(gPos * vec4(inVertex, 0.0, 1.0), 0.0, 1.0);
|
||||
|
||||
texCoord = vec2(inVertexTexCoord.x / gTextureSize, inVertexTexCoord.y / gTextureSize);
|
||||
outVertColor = inVertexColor;
|
||||
}
|
24
data/shader/tile.frag
Executable file
24
data/shader/tile.frag
Executable file
@ -0,0 +1,24 @@
|
||||
#ifdef TW_TILE_TEXTURED
|
||||
#ifdef TW_TILE_3D_TEXTURED
|
||||
uniform sampler3D gTextureSampler;
|
||||
#else
|
||||
uniform sampler2DArray gTextureSampler;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
uniform vec4 gVertColor;
|
||||
|
||||
#ifdef TW_TILE_TEXTURED
|
||||
noperspective in vec3 TexCoord;
|
||||
#endif
|
||||
|
||||
out vec4 FragClr;
|
||||
void main()
|
||||
{
|
||||
#ifdef TW_TILE_TEXTURED
|
||||
vec4 TexColor = texture(gTextureSampler, TexCoord.xyz);
|
||||
FragClr = TexColor * gVertColor;
|
||||
#else
|
||||
FragClr = gVertColor;
|
||||
#endif
|
||||
}
|
44
data/shader/tile.vert
Executable file
44
data/shader/tile.vert
Executable file
@ -0,0 +1,44 @@
|
||||
layout (location = 0) in vec2 inVertex;
|
||||
#ifdef TW_TILE_TEXTURED
|
||||
layout (location = 1) in vec3 inVertexTexCoord;
|
||||
#endif
|
||||
|
||||
uniform mat4x2 gPos;
|
||||
|
||||
#if defined(TW_TILE_BORDER) || defined(TW_TILE_BORDER_LINE)
|
||||
uniform vec2 gDir;
|
||||
uniform vec2 gOffset;
|
||||
#endif
|
||||
|
||||
#if defined(TW_TILE_BORDER)
|
||||
uniform int gJumpIndex;
|
||||
#endif
|
||||
|
||||
#ifdef TW_TILE_TEXTURED
|
||||
noperspective out vec3 TexCoord;
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
#if defined(TW_TILE_BORDER)
|
||||
vec4 VertPos = vec4(inVertex, 0.0, 1.0);
|
||||
int XCount = gl_InstanceID - (int(gl_InstanceID/gJumpIndex) * gJumpIndex);
|
||||
int YCount = (int(gl_InstanceID/gJumpIndex));
|
||||
VertPos.x += gOffset.x + gDir.x * float(XCount);
|
||||
VertPos.y += gOffset.y + gDir.y * float(YCount);
|
||||
|
||||
gl_Position = vec4(gPos * VertPos, 0.0, 1.0);
|
||||
#elif defined(TW_TILE_BORDER_LINE)
|
||||
vec4 VertPos = vec4(inVertex.x + gOffset.x, inVertex.y + gOffset.y, 0.0, 1.0);
|
||||
VertPos.x += gDir.x * float(gl_InstanceID);
|
||||
VertPos.y += gDir.y * float(gl_InstanceID);
|
||||
|
||||
gl_Position = vec4(gPos * VertPos, 0.0, 1.0);
|
||||
#else
|
||||
gl_Position = vec4(gPos * vec4(inVertex, 0.0, 1.0), 0.0, 1.0);
|
||||
#endif
|
||||
|
||||
#ifdef TW_TILE_TEXTURED
|
||||
TexCoord = inVertexTexCoord;
|
||||
#endif
|
||||
}
|
20
data/shader/vulkan/prim.frag
Executable file
20
data/shader/vulkan/prim.frag
Executable file
@ -0,0 +1,20 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
#ifdef TW_TEXTURED
|
||||
layout(binding = 0) uniform sampler2D gTextureSampler;
|
||||
#endif
|
||||
|
||||
layout(location = 0) noperspective in vec2 texCoord;
|
||||
layout(location = 1) noperspective in vec4 vertColor;
|
||||
|
||||
layout(location = 0) out vec4 FragClr;
|
||||
void main()
|
||||
{
|
||||
#ifdef TW_TEXTURED
|
||||
vec4 tex = texture(gTextureSampler, texCoord);
|
||||
FragClr = tex * vertColor;
|
||||
#else
|
||||
FragClr = vertColor;
|
||||
#endif
|
||||
}
|
20
data/shader/vulkan/prim.vert
Executable file
20
data/shader/vulkan/prim.vert
Executable file
@ -0,0 +1,20 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout (location = 0) in vec2 inVertex;
|
||||
layout (location = 1) in vec2 inVertexTexCoord;
|
||||
layout (location = 2) in vec4 inVertexColor;
|
||||
|
||||
layout(push_constant) uniform SPosBO {
|
||||
layout(offset = 0) mat4x2 gPos;
|
||||
} gPosBO;
|
||||
|
||||
layout (location = 0) noperspective out vec2 texCoord;
|
||||
layout (location = 1) noperspective out vec4 vertColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(gPosBO.gPos * vec4(inVertex, 0.0, 1.0), 0.0, 1.0);
|
||||
texCoord = inVertexTexCoord;
|
||||
vertColor = vec4(inVertexColor);
|
||||
}
|
24
data/shader/vulkan/prim3d.frag
Executable file
24
data/shader/vulkan/prim3d.frag
Executable file
@ -0,0 +1,24 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
#ifdef TW_TEXTURED
|
||||
layout (binding = 0) uniform sampler2DArray gTextureSampler;
|
||||
#endif
|
||||
|
||||
layout (location = 0) noperspective in vec4 oVertColor;
|
||||
#ifdef TW_TEXTURED
|
||||
layout (location = 1) noperspective in vec3 oTexCoord;
|
||||
#endif
|
||||
|
||||
layout (location = 0) out vec4 FragClr;
|
||||
|
||||
void main()
|
||||
{
|
||||
#ifdef TW_TEXTURED
|
||||
vec4 TexColor = texture(gTextureSampler, oTexCoord.xyz).rgba;
|
||||
FragClr = TexColor.rgba * oVertColor.rgba;
|
||||
#else
|
||||
FragClr = oVertColor.rgba;
|
||||
#endif
|
||||
}
|
||||
|
24
data/shader/vulkan/prim3d.vert
Executable file
24
data/shader/vulkan/prim3d.vert
Executable file
@ -0,0 +1,24 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout (location = 0) in vec2 inVertex;
|
||||
layout (location = 1) in vec4 inVertexColor;
|
||||
layout (location = 2) in vec3 inVertexTexCoord;
|
||||
|
||||
layout(push_constant) uniform SPosBO {
|
||||
layout(offset = 0) mat4x2 gPos;
|
||||
} gPosBO;
|
||||
|
||||
layout (location = 0) noperspective out vec4 oVertColor;
|
||||
#ifdef TW_TEXTURED
|
||||
layout (location = 1) noperspective out vec3 oTexCoord;
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(gPosBO.gPos * vec4(inVertex, 0.0, 1.0), 0.0, 1.0);
|
||||
#ifdef TW_TEXTURED
|
||||
oTexCoord = inVertexTexCoord;
|
||||
#endif
|
||||
oVertColor = inVertexColor;
|
||||
}
|
24
data/shader/vulkan/primex.frag
Executable file
24
data/shader/vulkan/primex.frag
Executable file
@ -0,0 +1,24 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
#ifdef TW_TEXTURED
|
||||
layout(binding = 0) uniform sampler2D gTextureSampler;
|
||||
#endif
|
||||
|
||||
layout(push_constant) uniform SVertexColorBO {
|
||||
layout(offset = 48) vec4 gVerticesColor;
|
||||
} gColorBO;
|
||||
|
||||
layout (location = 0) noperspective in vec2 texCoord;
|
||||
layout (location = 1) noperspective in vec4 vertColor;
|
||||
|
||||
layout (location = 0) out vec4 FragClr;
|
||||
void main()
|
||||
{
|
||||
#ifdef TW_TEXTURED
|
||||
vec4 tex = texture(gTextureSampler, texCoord);
|
||||
FragClr = tex * vertColor * gColorBO.gVerticesColor;
|
||||
#else
|
||||
FragClr = vertColor * gColorBO.gVerticesColor;
|
||||
#endif
|
||||
}
|
33
data/shader/vulkan/primex.vert
Executable file
33
data/shader/vulkan/primex.vert
Executable file
@ -0,0 +1,33 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout (location = 0) in vec2 inVertex;
|
||||
layout (location = 1) in vec2 inVertexTexCoord;
|
||||
layout (location = 2) in vec4 inVertexColor;
|
||||
|
||||
layout(push_constant) uniform SPosBO {
|
||||
layout(offset = 0) mat4x2 gPos;
|
||||
#ifndef TW_ROTATIONLESS
|
||||
layout(offset = 32) vec2 gCenter;
|
||||
layout(offset = 40) float gRotation;
|
||||
#endif
|
||||
} gPosBO;
|
||||
|
||||
layout (location = 0) noperspective out vec2 texCoord;
|
||||
layout (location = 1) noperspective out vec4 vertColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 FinalPos = vec2(inVertex.xy);
|
||||
#ifndef TW_ROTATIONLESS
|
||||
float X = FinalPos.x - gPosBO.gCenter.x;
|
||||
float Y = FinalPos.y - gPosBO.gCenter.y;
|
||||
|
||||
FinalPos.x = X * cos(gPosBO.gRotation) - Y * sin(gPosBO.gRotation) + gPosBO.gCenter.x;
|
||||
FinalPos.y = X * sin(gPosBO.gRotation) + Y * cos(gPosBO.gRotation) + gPosBO.gCenter.y;
|
||||
#endif
|
||||
|
||||
gl_Position = vec4(gPosBO.gPos * vec4(FinalPos, 0.0, 1.0), 0.0, 1.0);
|
||||
texCoord = inVertexTexCoord;
|
||||
vertColor = inVertexColor;
|
||||
}
|
62
data/shader/vulkan/quad.frag
Executable file
62
data/shader/vulkan/quad.frag
Executable file
@ -0,0 +1,62 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
#ifdef TW_QUAD_TEXTURED
|
||||
layout (set = 0, binding = 0) uniform sampler2D gTextureSampler;
|
||||
#endif
|
||||
|
||||
#ifdef TW_QUAD_TEXTURED
|
||||
#define UBOSetIndex 1
|
||||
#else
|
||||
#define UBOSetIndex 0
|
||||
#endif
|
||||
|
||||
struct SQuadUniformEl {
|
||||
vec4 gVertColor;
|
||||
vec2 gOffset;
|
||||
float gRotation;
|
||||
};
|
||||
|
||||
#ifndef TW_PUSH_CONST
|
||||
#define TW_MAX_QUADS 256
|
||||
|
||||
layout (std140, set = UBOSetIndex, binding = 1) uniform SOffBO {
|
||||
uniform SQuadUniformEl gUniEls[TW_MAX_QUADS];
|
||||
} gQuadBO;
|
||||
#else
|
||||
#define gQuadBO gPosBO
|
||||
#define QuadIndex 0
|
||||
#endif
|
||||
|
||||
layout(push_constant) uniform SPosBO {
|
||||
layout(offset = 0) uniform mat4x2 gPos;
|
||||
#ifdef TW_PUSH_CONST
|
||||
layout(offset = 32) uniform SQuadUniformEl gUniEls[1];
|
||||
layout(offset = 64) uniform int gQuadOffset;
|
||||
#else
|
||||
layout(offset = 32) uniform int gQuadOffset;
|
||||
#endif
|
||||
} gPosBO;
|
||||
|
||||
layout (location = 0) noperspective in vec4 QuadColor;
|
||||
#ifndef TW_PUSH_CONST
|
||||
layout (location = 1) flat in int QuadIndex;
|
||||
#endif
|
||||
#ifdef TW_QUAD_TEXTURED
|
||||
#ifndef TW_PUSH_CONST
|
||||
layout (location = 2) noperspective in vec2 TexCoord;
|
||||
#else
|
||||
layout (location = 1) noperspective in vec2 TexCoord;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
layout (location = 0) out vec4 FragClr;
|
||||
void main()
|
||||
{
|
||||
#ifdef TW_QUAD_TEXTURED
|
||||
vec4 TexColor = texture(gTextureSampler, TexCoord);
|
||||
FragClr = TexColor * QuadColor * gQuadBO.gUniEls[QuadIndex].gVertColor;
|
||||
#else
|
||||
FragClr = QuadColor * gQuadBO.gUniEls[QuadIndex].gVertColor;
|
||||
#endif
|
||||
}
|
83
data/shader/vulkan/quad.vert
Executable file
83
data/shader/vulkan/quad.vert
Executable file
@ -0,0 +1,83 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout (location = 0) in vec4 inVertex;
|
||||
layout (location = 1) in vec4 inColor;
|
||||
#ifdef TW_QUAD_TEXTURED
|
||||
layout (location = 2) in vec2 inVertexTexCoord;
|
||||
#endif
|
||||
|
||||
#ifdef TW_QUAD_TEXTURED
|
||||
#define UBOSetIndex 1
|
||||
#else
|
||||
#define UBOSetIndex 0
|
||||
#endif
|
||||
|
||||
struct SQuadUniformEl {
|
||||
vec4 gVertColor;
|
||||
vec2 gOffset;
|
||||
float gRotation;
|
||||
};
|
||||
|
||||
#ifndef TW_PUSH_CONST
|
||||
#define TW_MAX_QUADS 256
|
||||
|
||||
layout (std140, set = UBOSetIndex, binding = 1) uniform SOffBO {
|
||||
uniform SQuadUniformEl gUniEls[TW_MAX_QUADS];
|
||||
} gQuadBO;
|
||||
#else
|
||||
#define gQuadBO gPosBO
|
||||
#define TmpQuadIndex 0
|
||||
#endif
|
||||
|
||||
layout(push_constant) uniform SPosBO {
|
||||
layout(offset = 0) uniform mat4x2 gPos;
|
||||
#ifdef TW_PUSH_CONST
|
||||
layout(offset = 32) uniform SQuadUniformEl gUniEls[1];
|
||||
layout(offset = 64) uniform int gQuadOffset;
|
||||
#else
|
||||
layout(offset = 32) uniform int gQuadOffset;
|
||||
#endif
|
||||
} gPosBO;
|
||||
|
||||
layout (location = 0) noperspective out vec4 QuadColor;
|
||||
#ifndef TW_PUSH_CONST
|
||||
layout (location = 1) flat out int QuadIndex;
|
||||
#endif
|
||||
#ifdef TW_QUAD_TEXTURED
|
||||
#ifndef TW_PUSH_CONST
|
||||
layout (location = 2) noperspective out vec2 TexCoord;
|
||||
#else
|
||||
layout (location = 1) noperspective out vec2 TexCoord;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 FinalPos = vec2(inVertex.xy);
|
||||
|
||||
#ifndef TW_PUSH_CONST
|
||||
int TmpQuadIndex = int(gl_VertexIndex / 4) - gPosBO.gQuadOffset;
|
||||
#endif
|
||||
|
||||
if(gQuadBO.gUniEls[TmpQuadIndex].gRotation != 0.0)
|
||||
{
|
||||
float X = FinalPos.x - inVertex.z;
|
||||
float Y = FinalPos.y - inVertex.w;
|
||||
|
||||
FinalPos.x = X * cos(gQuadBO.gUniEls[TmpQuadIndex].gRotation) - Y * sin(gQuadBO.gUniEls[TmpQuadIndex].gRotation) + inVertex.z;
|
||||
FinalPos.y = X * sin(gQuadBO.gUniEls[TmpQuadIndex].gRotation) + Y * cos(gQuadBO.gUniEls[TmpQuadIndex].gRotation) + inVertex.w;
|
||||
}
|
||||
|
||||
FinalPos.x = FinalPos.x / 1024.0 + gQuadBO.gUniEls[TmpQuadIndex].gOffset.x;
|
||||
FinalPos.y = FinalPos.y / 1024.0 + gQuadBO.gUniEls[TmpQuadIndex].gOffset.y;
|
||||
|
||||
gl_Position = vec4(gPosBO.gPos * vec4(FinalPos, 0.0, 1.0), 0.0, 1.0);
|
||||
QuadColor = inColor;
|
||||
#ifndef TW_PUSH_CONST
|
||||
QuadIndex = TmpQuadIndex;
|
||||
#endif
|
||||
#ifdef TW_QUAD_TEXTURED
|
||||
TexCoord = inVertexTexCoord;
|
||||
#endif
|
||||
}
|
13
data/shader/vulkan/quadbo.vertfrag
Executable file
13
data/shader/vulkan/quadbo.vertfrag
Executable file
@ -0,0 +1,13 @@
|
||||
|
||||
struct SQuadUniformEl {
|
||||
vec4 gVertColor;
|
||||
vec2 gOffset;
|
||||
float gRotation;
|
||||
};
|
||||
|
||||
#define TW_MAX_QUADS 256
|
||||
|
||||
layout (std140, set = 2, binding = 2) uniform SOffBO {
|
||||
uniform SQuadUniformEl gUniEls[TW_MAX_QUADS];
|
||||
} gQuadBO;
|
||||
|
23
data/shader/vulkan/spritemulti.frag
Executable file
23
data/shader/vulkan/spritemulti.frag
Executable file
@ -0,0 +1,23 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout (set = 0, binding = 0) uniform sampler2D gTextureSampler;
|
||||
|
||||
layout(push_constant) uniform SVertexColorBO {
|
||||
#ifdef TW_PUSH_CONST
|
||||
layout(offset = 64) vec4 gVerticesColor;
|
||||
#else
|
||||
layout(offset = 48) vec4 gVerticesColor;
|
||||
#endif
|
||||
} gColorBO;
|
||||
|
||||
layout (location = 0) noperspective in vec2 texCoord;
|
||||
layout (location = 1) noperspective in vec4 vertColor;
|
||||
|
||||
layout (location = 0) out vec4 FragClr;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 tex = texture(gTextureSampler, texCoord);
|
||||
FragClr = tex * vertColor * gColorBO.gVerticesColor;
|
||||
}
|
50
data/shader/vulkan/spritemulti.vert
Executable file
50
data/shader/vulkan/spritemulti.vert
Executable file
@ -0,0 +1,50 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout (location = 0) in vec2 inVertex;
|
||||
layout (location = 1) in vec2 inVertexTexCoord;
|
||||
layout (location = 2) in vec4 inVertexColor;
|
||||
|
||||
layout(push_constant) uniform SPosBO {
|
||||
layout(offset = 0) uniform mat4x2 gPos;
|
||||
layout(offset = 32) uniform vec2 gCenter;
|
||||
#ifdef TW_PUSH_CONST
|
||||
layout(offset = 48) uniform vec4 gRSP[1];
|
||||
#endif
|
||||
} gPosBO;
|
||||
|
||||
#ifndef TW_PUSH_CONST
|
||||
layout (std140, set = 1, binding = 1) uniform SRSPBO {
|
||||
vec4 gRSP[512];
|
||||
} gRSPBO;
|
||||
#define RSPIndex gl_InstanceIndex
|
||||
#else
|
||||
#define gRSPBO gPosBO
|
||||
#define RSPIndex 0
|
||||
#endif
|
||||
|
||||
layout (location = 0) noperspective out vec2 texCoord;
|
||||
layout (location = 1) noperspective out vec4 vertColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 FinalPos = vec2(inVertex.xy);
|
||||
if(gRSPBO.gRSP[RSPIndex].w != 0.0)
|
||||
{
|
||||
float X = FinalPos.x - gPosBO.gCenter.x;
|
||||
float Y = FinalPos.y - gPosBO.gCenter.y;
|
||||
|
||||
FinalPos.x = X * cos(gRSPBO.gRSP[RSPIndex].w) - Y * sin(gRSPBO.gRSP[RSPIndex].w) + gPosBO.gCenter.x;
|
||||
FinalPos.y = X * sin(gRSPBO.gRSP[RSPIndex].w) + Y * cos(gRSPBO.gRSP[RSPIndex].w) + gPosBO.gCenter.y;
|
||||
}
|
||||
|
||||
FinalPos.x *= gRSPBO.gRSP[RSPIndex].z;
|
||||
FinalPos.y *= gRSPBO.gRSP[RSPIndex].z;
|
||||
|
||||
FinalPos.x += gRSPBO.gRSP[RSPIndex].x;
|
||||
FinalPos.y += gRSPBO.gRSP[RSPIndex].y;
|
||||
|
||||
gl_Position = vec4(gPosBO.gPos * vec4(FinalPos, 0.0, 1.0), 0.0, 1.0);
|
||||
texCoord = inVertexTexCoord;
|
||||
vertColor = inVertexColor;
|
||||
}
|
43
data/shader/vulkan/text.frag
Executable file
43
data/shader/vulkan/text.frag
Executable file
@ -0,0 +1,43 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout(binding = 0) uniform sampler2D gTextSampler;
|
||||
layout(binding = 1) uniform sampler2D gTextOutlineSampler;
|
||||
|
||||
layout(push_constant) uniform SFragConstBO {
|
||||
layout(offset = 48) uniform vec4 gVertColor;
|
||||
layout(offset = 64) uniform vec4 gVertOutlineColor;
|
||||
} gFragConst;
|
||||
|
||||
layout (location = 0) noperspective in vec2 texCoord;
|
||||
layout (location = 1) noperspective in vec4 outVertColor;
|
||||
|
||||
layout(location = 0) out vec4 FragClr;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 textColor = gFragConst.gVertColor * outVertColor * vec4(1.0, 1.0, 1.0, texture(gTextSampler, texCoord).r);
|
||||
vec4 textOutlineTex = gFragConst.gVertOutlineColor * vec4(1.0, 1.0, 1.0, texture(gTextOutlineSampler, texCoord).r);
|
||||
|
||||
// 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 losing 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);
|
||||
|
||||
// simply add the color we will loose through blending
|
||||
if(RealAlpha > 0.0)
|
||||
FragClr = vec4(finalFragColor / RealAlpha, RealAlpha);
|
||||
else
|
||||
FragClr = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
22
data/shader/vulkan/text.vert
Executable file
22
data/shader/vulkan/text.vert
Executable file
@ -0,0 +1,22 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout (location = 0) in vec2 inVertex;
|
||||
layout (location = 1) in vec2 inVertexTexCoord;
|
||||
layout (location = 2) in vec4 inVertexColor;
|
||||
|
||||
layout(push_constant) uniform SPosBO {
|
||||
layout(offset = 0) mat4x2 gPos;
|
||||
layout(offset = 32) float gTextureSize;
|
||||
} gPosBO;
|
||||
|
||||
layout (location = 0) noperspective out vec2 texCoord;
|
||||
layout (location = 1) noperspective out vec4 outVertColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(gPosBO.gPos * vec4(inVertex, 0.0, 1.0), 0.0, 1.0);
|
||||
|
||||
texCoord = vec2(inVertexTexCoord.x / gPosBO.gTextureSize, inVertexTexCoord.y / gPosBO.gTextureSize);
|
||||
outVertColor = inVertexColor;
|
||||
}
|
25
data/shader/vulkan/tile.frag
Executable file
25
data/shader/vulkan/tile.frag
Executable file
@ -0,0 +1,25 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
#ifdef TW_TILE_TEXTURED
|
||||
layout(binding = 0) uniform sampler2DArray gTextureSampler;
|
||||
#endif
|
||||
|
||||
layout(push_constant) uniform SVertexColorBO {
|
||||
layout(offset = 64) uniform vec4 gVertColor;
|
||||
} gColorBO;
|
||||
|
||||
#ifdef TW_TILE_TEXTURED
|
||||
layout (location = 0) noperspective in vec3 TexCoord;
|
||||
#endif
|
||||
|
||||
layout (location = 0) out vec4 FragClr;
|
||||
void main()
|
||||
{
|
||||
#ifdef TW_TILE_TEXTURED
|
||||
vec4 TexColor = texture(gTextureSampler, TexCoord.xyz);
|
||||
FragClr = TexColor * gColorBO.gVertColor;
|
||||
#else
|
||||
FragClr = gColorBO.gVertColor;
|
||||
#endif
|
||||
}
|
49
data/shader/vulkan/tile.vert
Executable file
49
data/shader/vulkan/tile.vert
Executable file
@ -0,0 +1,49 @@
|
||||
#version 450
|
||||
#extension GL_ARB_separate_shader_objects : enable
|
||||
|
||||
layout (location = 0) in vec2 inVertex;
|
||||
#ifdef TW_TILE_TEXTURED
|
||||
layout (location = 1) in vec3 inVertexTexCoord;
|
||||
#endif
|
||||
|
||||
layout(push_constant) uniform SPosBO {
|
||||
layout(offset = 0) uniform mat4x2 gPos;
|
||||
|
||||
#if defined(TW_TILE_BORDER) || defined(TW_TILE_BORDER_LINE)
|
||||
layout(offset = 32) uniform vec2 gDir;
|
||||
layout(offset = 40) uniform vec2 gOffset;
|
||||
#endif
|
||||
|
||||
#if defined(TW_TILE_BORDER)
|
||||
layout(offset = 48) uniform int gJumpIndex;
|
||||
#endif
|
||||
} gPosBO;
|
||||
|
||||
#ifdef TW_TILE_TEXTURED
|
||||
layout (location = 0) noperspective out vec3 TexCoord;
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
#if defined(TW_TILE_BORDER)
|
||||
vec4 VertPos = vec4(inVertex, 0.0, 1.0);
|
||||
int XCount = gl_InstanceIndex - (int(gl_InstanceIndex/gPosBO.gJumpIndex) * gPosBO.gJumpIndex);
|
||||
int YCount = (int(gl_InstanceIndex/gPosBO.gJumpIndex));
|
||||
VertPos.x += gPosBO.gOffset.x + gPosBO.gDir.x * float(XCount);
|
||||
VertPos.y += gPosBO.gOffset.y + gPosBO.gDir.y * float(YCount);
|
||||
|
||||
gl_Position = vec4(gPosBO.gPos * VertPos, 0.0, 1.0);
|
||||
#elif defined(TW_TILE_BORDER_LINE)
|
||||
vec4 VertPos = vec4(inVertex.x + gPosBO.gOffset.x, inVertex.y + gPosBO.gOffset.y, 0.0, 1.0);
|
||||
VertPos.x += gPosBO.gDir.x * float(gl_InstanceIndex);
|
||||
VertPos.y += gPosBO.gDir.y * float(gl_InstanceIndex);
|
||||
|
||||
gl_Position = vec4(gPosBO.gPos * VertPos, 0.0, 1.0);
|
||||
#else
|
||||
gl_Position = vec4(gPosBO.gPos * vec4(inVertex, 0.0, 1.0), 0.0, 1.0);
|
||||
#endif
|
||||
|
||||
#ifdef TW_TILE_TEXTURED
|
||||
TexCoord = inVertexTexCoord;
|
||||
#endif
|
||||
}
|
Reference in New Issue
Block a user