Basic GUI
This commit is contained in:
+30
-5
@@ -21,6 +21,8 @@
|
||||
|
||||
#define NB_TEXCOORDS 2
|
||||
|
||||
#define DITHERING
|
||||
|
||||
layout(set = 0, binding = 0) uniform scene_ubo
|
||||
{
|
||||
mat4 view;
|
||||
@@ -99,16 +101,25 @@ void main()
|
||||
|
||||
gl_Position = mesh.modelviewproj * vec4(in_position, 1.0);
|
||||
frag_pos = vec3(mesh.modelview * vec4(in_position, 1.0));
|
||||
// light_pos = mesh.modelview * scene.light_position;
|
||||
light_pos = scene.view * scene.light_position;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef FRAG_SHADER
|
||||
|
||||
#ifdef DITHERING
|
||||
const float dither_pattern[4][4] = {
|
||||
{ 0.0f, 0.5f, 0.125f, 0.625f},
|
||||
{ 0.75f, 0.22f, 0.875f, 0.375f},
|
||||
{ 0.1875f, 0.6875f, 0.0625f, 0.5625},
|
||||
{ 0.9375f, 0.4375f, 0.8125f, 0.3125}
|
||||
};
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
// vec3 light_dir = normalize(light_pos.xyz - frag_pos * light_pos.w);
|
||||
vec3 light_dir = normalize(scene.light_position.xyz - frag_pos * scene.light_position.w);
|
||||
vec3 light_dir = normalize(light_pos.xyz - frag_pos * light_pos.w);
|
||||
vec3 view_dir = normalize(frag_pos);
|
||||
vec3 normal_unit = normalize(normal);
|
||||
vec3 reflect_dir = reflect(-light_dir, normal_unit);
|
||||
@@ -125,8 +136,22 @@ void main()
|
||||
// vec3 specular = pow(spec_angle, instance.specular_power) * instance.specular_strength * instance.light_color;
|
||||
|
||||
vec3 light = ambient + diffuse /*+ specular*/;
|
||||
out_color = texture(base_color, texcoord[0]) * vec4(light, 1.0);
|
||||
|
||||
// out_color = texture(base_color, texcoord[0]);
|
||||
vec4 c = texture(base_color, texcoord[0]);
|
||||
|
||||
if (c.a <= 0.5)
|
||||
discard;
|
||||
|
||||
#ifdef DITHERING
|
||||
ivec2 tmp = ivec2(gl_FragCoord.xy) % 4;
|
||||
float dither_thd = dither_pattern[tmp.x][tmp.y];
|
||||
|
||||
vec4 color = c * vec4(light, 1.0) * 255.0f;
|
||||
|
||||
bvec4 tmp2 = greaterThan(fract(color), vec4(dither_thd, dither_thd, dither_thd, dither_thd));
|
||||
out_color = (ceil(color) + vec4(tmp2)) / 255.0;
|
||||
#else
|
||||
out_color = c * vec4(light, 1.0);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
+65
-23
@@ -19,44 +19,86 @@
|
||||
|
||||
#version 450
|
||||
|
||||
#define NB_TEXCOORDS 2
|
||||
|
||||
layout(set = 0, binding = 0) uniform scene_ubo
|
||||
{
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
vec4 light_position;
|
||||
vec4 ambient_color;
|
||||
vec4 light_color;
|
||||
} scene;
|
||||
|
||||
layout(set = 0, binding = 1) uniform mesh_ubo
|
||||
{
|
||||
mat4 model;
|
||||
mat4 modelview;
|
||||
mat4 modelviewproj;
|
||||
} mesh;
|
||||
|
||||
#ifdef FRAG_SHADER
|
||||
layout(set = 1, binding = 0) uniform sampler2D base_color;
|
||||
layout(set = 1, binding = 1) uniform sampler2D metallic_roughness;
|
||||
layout(set = 1, binding = 2) uniform sampler2D occlusion;
|
||||
layout(set = 1, binding = 3) uniform sampler2D emissive;
|
||||
layout(set = 1, binding = 4) uniform sampler2D normal_map;
|
||||
layout(set = 1, binding = 5) uniform material_ubo
|
||||
{
|
||||
vec4 base_color_factor;
|
||||
vec4 base_emissive_factor;
|
||||
float metallic_factor;
|
||||
float roughness_factor;
|
||||
float occlusion_strength;
|
||||
float normal_scale;
|
||||
|
||||
int base_color_texcoord;
|
||||
int metallic_roughness_texcoord;
|
||||
int occlusion_texcoord;
|
||||
int emissive_texcoord;
|
||||
int normal_texcoord;
|
||||
} material;
|
||||
#endif
|
||||
|
||||
// Vertex input
|
||||
#ifdef VERT_SHADER
|
||||
layout(location = 0) in vec3 in_position;
|
||||
layout(location = 1) in vec3 in_normal;
|
||||
layout(location = 2) in vec2 in_texcoord0;
|
||||
layout(location = 2) in vec3 in_tangent;
|
||||
layout(location = 3) in vec2 in_texcoord[NB_TEXCOORDS];
|
||||
layout(location = 3+NB_TEXCOORDS) in vec4 in_color;
|
||||
layout(location = 4+NB_TEXCOORDS) in vec4 in_joints;
|
||||
layout(location = 5+NB_TEXCOORDS) in vec4 in_weights;
|
||||
#endif
|
||||
|
||||
layout(set = 1, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 model_view;
|
||||
mat4 projection;
|
||||
}
|
||||
instance;
|
||||
// Vertex-to-fragment
|
||||
#ifdef VERT_SHADER
|
||||
#define VERT_TO_FRAG out
|
||||
#else
|
||||
#define VERT_TO_FRAG in
|
||||
#endif
|
||||
|
||||
layout(location = 0) out vec4 normal;
|
||||
layout(location = 1) out vec2 texcoord0;
|
||||
layout(location = 0) VERT_TO_FRAG vec2 texcoord;
|
||||
|
||||
// Fragment output
|
||||
#ifdef FRAG_SHADER
|
||||
layout(location = 0) out vec4 out_color;
|
||||
#endif
|
||||
|
||||
// Shader code
|
||||
#ifdef VERT_SHADER
|
||||
void main()
|
||||
{
|
||||
normal = instance.model_view * vec4(in_normal, 0.0);
|
||||
texcoord0 = texcoord0;
|
||||
gl_Position = instance.projection * instance.model_view * vec4(in_position, 1.0);
|
||||
texcoord = in_texcoord[0];
|
||||
gl_Position = mesh.modelviewproj * vec4(in_position, 1.0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef FRAG_SHADER
|
||||
layout(set = 0, binding = 0) uniform sampler2D base_color;
|
||||
|
||||
layout(set = 1, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 model_view;
|
||||
mat4 projection;
|
||||
}
|
||||
instance;
|
||||
|
||||
layout(location = 0) in vec4 normal;
|
||||
layout(location = 1) in vec2 texcoord0;
|
||||
|
||||
void main()
|
||||
{
|
||||
out_color = texture(base_color, texcoord);
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user