GUI: Box drawing
This commit is contained in:
39
assets/shaders/gui_box.frag
Normal file
39
assets/shaders/gui_box.frag
Normal file
@@ -0,0 +1,39 @@
|
||||
#version 460
|
||||
#extension GL_EXT_nonuniform_qualifier : require
|
||||
#extension GL_EXT_scalar_block_layout : require
|
||||
#extension GL_EXT_shader_16bit_storage : require
|
||||
|
||||
in Varyings {
|
||||
layout(location = 0) flat uint instance;
|
||||
layout(location = 1) vec2 positionSSPX;
|
||||
} var;
|
||||
|
||||
#include "includes/gui_box_common.glsl"
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
float boxSDF(vec2 p, vec2 center, vec2 halfExtents, float borderRadius) {
|
||||
vec2 q = abs(p - center) - halfExtents + borderRadius;
|
||||
return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - borderRadius;
|
||||
}
|
||||
|
||||
#define BOX _Boxes[var.instance]
|
||||
|
||||
void main() {
|
||||
vec2 halfExtentsPX = 0.5 * BOX.sizePX;
|
||||
vec2 centerSSPX = BOX.positionSSPX + halfExtentsPX;
|
||||
float borderHalfWidthPX = 0.5 * BOX.borderWidthPX;
|
||||
|
||||
float interiorSDF = boxSDF(var.positionSSPX, centerSSPX, halfExtentsPX, BOX.borderRadiusPX) + BOX.borderWidthPX;
|
||||
float borderSDF = abs(interiorSDF - borderHalfWidthPX) - borderHalfWidthPX;
|
||||
|
||||
float interiorCoverage = clamp(-interiorSDF + 0.5, 0.0, 1.0) * BOX.backgroundColor.a;
|
||||
float borderCoverage = clamp(-borderSDF + 0.5, 0.0, 1.0) * BOX.borderColor.a;
|
||||
float totalCoverage = interiorCoverage + borderCoverage;
|
||||
|
||||
fragColor = vec4(
|
||||
interiorCoverage * BOX.backgroundColor.rgb +
|
||||
borderCoverage * BOX.borderColor.rgb,
|
||||
totalCoverage
|
||||
);
|
||||
}
|
||||
30
assets/shaders/gui_box.vert
Normal file
30
assets/shaders/gui_box.vert
Normal file
@@ -0,0 +1,30 @@
|
||||
#version 460
|
||||
#extension GL_EXT_nonuniform_qualifier : require
|
||||
#extension GL_EXT_scalar_block_layout : require
|
||||
#extension GL_EXT_shader_16bit_storage : require
|
||||
|
||||
out Varyings {
|
||||
layout(location = 0) flat uint instance;
|
||||
layout(location = 1) vec2 positionSSPX;
|
||||
} var;
|
||||
|
||||
#include "includes/gui_box_common.glsl"
|
||||
|
||||
const vec2 VERTICES[4] = vec2[](
|
||||
vec2(0, 1),
|
||||
vec2(1, 1),
|
||||
vec2(0, 0),
|
||||
vec2(1, 0)
|
||||
);
|
||||
|
||||
#define BOX _Boxes[gl_InstanceIndex]
|
||||
#define VERTEX VERTICES[gl_VertexIndex]
|
||||
|
||||
void main() {
|
||||
vec2 positionSSPX = VERTEX * BOX.sizePX + BOX.positionSSPX;
|
||||
vec4 positionCS = vec4(_Global.matrixSSPXtoCS * vec3(positionSSPX, 1.0), 0.0, 1.0);
|
||||
|
||||
gl_Position = positionCS;
|
||||
var.instance = gl_InstanceIndex;
|
||||
var.positionSSPX = positionSSPX;
|
||||
}
|
||||
20
assets/shaders/gui_image.frag
Normal file
20
assets/shaders/gui_image.frag
Normal file
@@ -0,0 +1,20 @@
|
||||
#version 460
|
||||
#extension GL_EXT_nonuniform_qualifier : require
|
||||
#extension GL_EXT_scalar_block_layout : require
|
||||
#extension GL_EXT_shader_16bit_storage : require
|
||||
|
||||
in Varyings {
|
||||
layout(location = 0) flat uint instance;
|
||||
layout(location = 1) vec2 texCoord;
|
||||
} var;
|
||||
|
||||
#include "includes/gui_image_common.glsl"
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
#define IMAGE _Images[var.instance]
|
||||
|
||||
void main() {
|
||||
vec4 texel = texture(sampler2D(_Textures[uint(IMAGE.textureId)], _Sampler), var.texCoord);
|
||||
fragColor = texel * IMAGE.tint;
|
||||
}
|
||||
32
assets/shaders/gui_image.vert
Normal file
32
assets/shaders/gui_image.vert
Normal file
@@ -0,0 +1,32 @@
|
||||
#version 460
|
||||
#extension GL_EXT_nonuniform_qualifier : require
|
||||
#extension GL_EXT_scalar_block_layout : require
|
||||
#extension GL_EXT_shader_16bit_storage : require
|
||||
|
||||
out Varyings {
|
||||
layout(location = 0) flat uint instance;
|
||||
layout(location = 1) vec2 texCoord;
|
||||
} var;
|
||||
|
||||
#include "includes/gui_image_common.glsl"
|
||||
|
||||
const vec2 VERTICES[4] = vec2[](
|
||||
vec2(0, 1),
|
||||
vec2(1, 1),
|
||||
vec2(0, 0),
|
||||
vec2(1, 0)
|
||||
);
|
||||
|
||||
#define IMAGE _Images[gl_InstanceIndex]
|
||||
#define VERTEX VERTICES[gl_VertexIndex]
|
||||
|
||||
void main() {
|
||||
vec2 positionSSPX = VERTEX * IMAGE.sizePX + IMAGE.positionSSPX;
|
||||
vec4 positionCS = vec4(_Global.matrixSSPXtoCS * vec3(positionSSPX, 1.0), 0.0, 1.0);
|
||||
|
||||
vec2 texCoord = VERTEX * (IMAGE.uvMax - IMAGE.uvMin) + IMAGE.uvMin;
|
||||
|
||||
gl_Position = positionCS;
|
||||
var.instance = gl_InstanceIndex;
|
||||
var.texCoord = texCoord;
|
||||
}
|
||||
15
assets/shaders/gui_text.frag
Normal file
15
assets/shaders/gui_text.frag
Normal file
@@ -0,0 +1,15 @@
|
||||
#version 460
|
||||
#extension GL_EXT_nonuniform_qualifier : require
|
||||
#extension GL_EXT_scalar_block_layout : require
|
||||
#extension GL_EXT_shader_16bit_storage : require
|
||||
|
||||
uint calcRootCode(float y1, float y2, float y3) {
|
||||
uint i1 = floatBitsToUint(y1) >> 31U;
|
||||
uint i2 = floatBitsToUint(y2) >> 30U;
|
||||
uint i3 = floatBitsToUint(y3) >> 29U;
|
||||
|
||||
uint shift = (i2 & 2U) | (i1 & ~2U);
|
||||
shift = (i3 & 4U) | (shift & ~4U);
|
||||
|
||||
return ((0x2E74U >> shift) & 0x0101U);
|
||||
}
|
||||
10
assets/shaders/gui_text.vert
Normal file
10
assets/shaders/gui_text.vert
Normal file
@@ -0,0 +1,10 @@
|
||||
#version 460
|
||||
#extension GL_EXT_nonuniform_qualifier : require
|
||||
#extension GL_EXT_scalar_block_layout : require
|
||||
#extension GL_EXT_shader_16bit_storage : require
|
||||
|
||||
layout(location = 0) in vec4 positionOS_normalOS;
|
||||
layout(location = 1) in vec4 texCoordEM_band_flags;
|
||||
layout(location = 2) in vec4 jacobian;
|
||||
layout(location = 3) in vec4 scale_offset;
|
||||
layout(location = 4) in vec4 color;
|
||||
6
assets/shaders/includes/global_uniforms.glsl
Normal file
6
assets/shaders/includes/global_uniforms.glsl
Normal file
@@ -0,0 +1,6 @@
|
||||
layout(set = 0, binding = 0, scalar) uniform GlobalUniforms {
|
||||
mat4 matrixWStoVS;
|
||||
mat4 matrixVStoCS;
|
||||
mat3x2 matrixSSPXtoCS;
|
||||
vec3 ambientLight;
|
||||
} _Global;
|
||||
14
assets/shaders/includes/gui_box_common.glsl
Normal file
14
assets/shaders/includes/gui_box_common.glsl
Normal file
@@ -0,0 +1,14 @@
|
||||
struct Box {
|
||||
vec4 backgroundColor;
|
||||
vec4 borderColor;
|
||||
vec2 positionSSPX;
|
||||
vec2 sizePX;
|
||||
float borderWidthPX;
|
||||
float borderRadiusPX;
|
||||
};
|
||||
|
||||
#include "global_uniforms.glsl"
|
||||
|
||||
layout(set = 0, binding = 1, scalar) readonly buffer Boxes {
|
||||
Box _Boxes[];
|
||||
};
|
||||
17
assets/shaders/includes/gui_image_common.glsl
Normal file
17
assets/shaders/includes/gui_image_common.glsl
Normal file
@@ -0,0 +1,17 @@
|
||||
struct Image {
|
||||
vec4 tint;
|
||||
vec2 positionSSPX;
|
||||
vec2 sizePX;
|
||||
vec2 uvMin;
|
||||
vec2 uvMax;
|
||||
uint16_t textureId;
|
||||
};
|
||||
|
||||
#include "global_uniforms.glsl"
|
||||
|
||||
layout(set = 0, binding = 1, scalar) readonly buffer Images {
|
||||
Image _Images[];
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 2) uniform sampler _Sampler;
|
||||
layout(set = 0, binding = 3) uniform texture2D _Textures[];
|
||||
@@ -32,11 +32,7 @@ struct ObjectUniforms {
|
||||
uint16_t material;
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 0, scalar) uniform GlobalUniforms {
|
||||
mat4 matrixWStoVS;
|
||||
mat4 matrixVStoCS;
|
||||
vec3 ambientLight;
|
||||
} _Global;
|
||||
#include "global_uniforms.glsl"
|
||||
|
||||
layout(set = 0, binding = 1, scalar) readonly buffer PointLights {
|
||||
uint count;
|
||||
8
assets/shaders/includes/tone_mapping.glsl
Normal file
8
assets/shaders/includes/tone_mapping.glsl
Normal file
@@ -0,0 +1,8 @@
|
||||
vec3 toneMapAcesNarkowicz(vec3 color) {
|
||||
const float A = 2.51;
|
||||
const float B = 0.03;
|
||||
const float C = 2.43;
|
||||
const float D = 0.59;
|
||||
const float E = 0.14;
|
||||
return clamp((color * (A * color + B)) / (color * (C * color + D) + E), 0.0, 1.0);
|
||||
}
|
||||
@@ -12,7 +12,8 @@ in Varyings {
|
||||
layout(location = 5) vec3 bitangentVS;
|
||||
} var;
|
||||
|
||||
#include "main_common.glsl"
|
||||
#include "includes/main_common.glsl"
|
||||
#include "includes/tone_mapping.glsl"
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
@@ -39,15 +40,6 @@ float distributionGGX(float dotNH, float alpha) {
|
||||
return alphaSquared * INV_PI / (tmp * tmp);
|
||||
}
|
||||
|
||||
vec3 toneMapAcesNarkowicz(vec3 color) {
|
||||
const float A = 2.51;
|
||||
const float B = 0.03;
|
||||
const float C = 2.43;
|
||||
const float D = 0.59;
|
||||
const float E = 0.14;
|
||||
return clamp((color * (A * color + B)) / (color * (C * color + D) + E), 0.0, 1.0);
|
||||
}
|
||||
|
||||
vec3 lightOutgoingRadiance(
|
||||
vec3 viewDirectionVS, vec3 normalVS, float dotNV,
|
||||
vec3 baseColor, float alpha, float metallic, vec3 f0,
|
||||
|
||||
@@ -17,7 +17,7 @@ out Varyings {
|
||||
layout(location = 5) vec3 bitangentVS;
|
||||
} var;
|
||||
|
||||
#include "main_common.glsl"
|
||||
#include "includes/main_common.glsl"
|
||||
|
||||
#define OBJECT _Object[gl_InstanceIndex]
|
||||
|
||||
|
||||
@@ -9,14 +9,7 @@ layout(set = 0, binding = 2) uniform textureCube _Texture;
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
vec3 toneMapAcesNarkowicz(vec3 color) {
|
||||
const float A = 2.51;
|
||||
const float B = 0.03;
|
||||
const float C = 2.43;
|
||||
const float D = 0.59;
|
||||
const float E = 0.14;
|
||||
return clamp((color * (A * color + B)) / (color * (C * color + D) + E), 0.0, 1.0);
|
||||
}
|
||||
#include "includes/tone_mapping.glsl"
|
||||
|
||||
void main() {
|
||||
vec4 texel = texture(samplerCube(_Texture, _Sampler), var.texCoord);
|
||||
|
||||
@@ -7,11 +7,7 @@ out Varyings {
|
||||
layout(location = 0) vec3 texCoord;
|
||||
} var;
|
||||
|
||||
layout(set = 0, binding = 0, scalar) uniform GlobalUniforms {
|
||||
mat4 matrixWStoVS;
|
||||
mat4 matrixVStoCS;
|
||||
vec3 ambientLight;
|
||||
} _Global;
|
||||
#include "includes/global_uniforms.glsl"
|
||||
|
||||
void main() {
|
||||
vec3 directionVS = (_Global.matrixWStoVS * vec4(directionWS, 0.0)).xyz;
|
||||
|
||||
Reference in New Issue
Block a user