c/shaders: Tidy and codestyle

This commit is contained in:
Jakob Bornecrantz 2021-09-22 16:31:38 +01:00
parent 0b9bf9c772
commit 08135b6365
11 changed files with 147 additions and 130 deletions

View file

@ -4,6 +4,7 @@
#version 460
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
layout(set = 0, binding = 2) uniform writeonly restrict image2D target;
@ -15,6 +16,7 @@ layout(set = 0, binding = 3) uniform restrict Config
mat4 transform[2];
} data;
void main()
{
uint ix = gl_GlobalInvocationID.x;

View file

@ -7,6 +7,7 @@
#include "srgb.inc.glsl"
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
layout(set = 0, binding = 0) uniform sampler2D source[2];

View file

@ -7,6 +7,7 @@
#include "srgb.inc.glsl"
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
layout(set = 0, binding = 0) uniform sampler2D source[2];

View file

@ -4,45 +4,48 @@
#version 460
layout (location = 0) in vec2 uv;
layout (set = 0, binding = 0, std140) uniform Transformation {
mat4 mvp;
ivec2 offset;
ivec2 extent;
bool flip_y;
layout (set = 0, binding = 0, std140) uniform Transformation
{
mat4 mvp;
ivec2 offset;
ivec2 extent;
bool flip_y;
} ubo;
layout (set = 0, binding = 1) uniform sampler2D image;
layout (set = 1, binding = 0, std140) uniform Equirect {
vec2 scale;
vec2 bias;
float radius;
layout (set = 1, binding = 0, std140) uniform Equirect
{
vec2 scale;
vec2 bias;
float radius;
} equirect;
layout (location = 0) in vec2 uv;
layout (location = 0) out vec4 out_color;
const float PI = 3.1416;
void main ()
{
vec2 uv_sub = vec2(ubo.offset) + uv * vec2(ubo.extent);
uv_sub /= textureSize(image, 0);
vec2 uv_sub = vec2(ubo.offset) + uv * vec2(ubo.extent);
uv_sub /= textureSize(image, 0);
vec2 frag_coord = vec2(uv_sub) * 2 - 1;
vec2 frag_coord = vec2(uv_sub) * 2 - 1;
vec4 view_dir = normalize(ubo.mvp * vec4(frag_coord.x, -frag_coord.y, 1, 1));
vec4 view_dir = normalize(ubo.mvp * vec4(frag_coord.x, -frag_coord.y, 1, 1));
float lat = atan(view_dir.x, -view_dir.z) / (2 * PI);
float lon = acos(view_dir.y) / PI;
float lat = atan(view_dir.x, -view_dir.z) / (2 * PI);
float lon = acos(view_dir.y) / PI;
lat *= equirect.scale.x;
lon *= equirect.scale.y;
lat *= equirect.scale.x;
lon *= equirect.scale.y;
lat += equirect.bias.x;
lon += equirect.bias.y;
lat += equirect.bias.x;
lon += equirect.bias.y;
out_color = texture(image, vec2(lat, lon));
out_color = texture(image, vec2(lat, lon));
}

View file

@ -5,35 +5,34 @@
#version 460
layout (binding = 0, std140) uniform Transformation {
mat4 mvp;
ivec2 offset;
ivec2 extent;
bool flip_y;
mat4 mvp;
ivec2 offset;
ivec2 extent;
bool flip_y;
} transformation;
layout (location = 0) in vec3 position;
layout (location = 1) in vec2 uv;
layout (location = 0) in vec3 position;
layout (location = 1) in vec2 uv;
layout (location = 0) out vec2 out_uv;
out gl_PerVertex {
vec4 gl_Position;
vec4 gl_Position;
};
const mat4 mvp = mat4(
2, 0, 0, 0,
0, 2, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
2, 0, 0, 0,
0, 2, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
);
void main() {
gl_Position = mvp * vec4 (position, 1.0f);
gl_Position.y = -gl_Position.y;
out_uv = uv;
void main()
{
gl_Position = mvp * vec4 (position, 1.0f);
gl_Position.y = -gl_Position.y;
out_uv = uv;
if (transformation.flip_y) {
out_uv.y = 1.0 - out_uv.y;
}
if (transformation.flip_y) {
out_uv.y = 1.0 - out_uv.y;
}
}

View file

@ -4,73 +4,76 @@
#version 460
layout (location = 0) in vec2 uv;
layout (set = 0, binding = 0, std140) uniform Transformation {
mat4 mvp;
ivec2 offset;
ivec2 extent;
bool flip_y;
mat4 mvp;
ivec2 offset;
ivec2 extent;
bool flip_y;
} ubo;
layout (set = 0, binding = 1) uniform sampler2D image;
layout (set = 1, binding = 0, std140) uniform Equirect {
float radius;
float central_horizontal_angle;
float upper_vertical_angle;
float lower_vertical_angle;
float radius;
float central_horizontal_angle;
float upper_vertical_angle;
float lower_vertical_angle;
} equirect;
layout (location = 0) in vec2 uv;
layout (location = 0) out vec4 out_color;
const float PI = 3.1416;
// #define DEBUG 1
void main ()
{
vec2 uv_sub = vec2(ubo.offset) + uv * vec2(ubo.extent);
uv_sub /= textureSize(image, 0);
vec2 uv_sub = vec2(ubo.offset) + uv * vec2(ubo.extent);
uv_sub /= textureSize(image, 0);
vec2 frag_coord = vec2(uv_sub) * 2 - 1;
vec2 frag_coord = vec2(uv_sub) * 2 - 1;
vec4 view_dir = normalize(ubo.mvp * vec4(frag_coord.x, -frag_coord.y, 1, 1));
vec4 view_dir = normalize(ubo.mvp * vec4(frag_coord.x, -frag_coord.y, 1, 1));
float lat = atan(view_dir.x, -view_dir.z) / (2 * PI);
float lon = acos(view_dir.y) / PI;
float lat = atan(view_dir.x, -view_dir.z) / (2 * PI);
float lon = acos(view_dir.y) / PI;
#undef DEBUG
#ifdef DEBUG
int lat_int = int(lat * 1000.0);
int lon_int = int(lon * 1000.0);
int lat_int = int(lat * 1000.0);
int lon_int = int(lon * 1000.0);
if (lat < 0.001 && lat > -0.001)
out_color = vec4(1, 0, 0, 1);
else if (lat_int % 50 == 0)
out_color = vec4(1, 1, 1, 1);
else if (lon_int % 50 == 0)
out_color = vec4(1, 1, 1, 1);
else
out_color = vec4(lat, lon, 0, 1);
if (lat < 0.001 && lat > -0.001) {
out_color = vec4(1, 0, 0, 1);
} else if (lat_int % 50 == 0) {
out_color = vec4(1, 1, 1, 1);
} else if (lon_int % 50 == 0) {
out_color = vec4(1, 1, 1, 1);
} else {
out_color = vec4(lat, lon, 0, 1);
}
#endif
float chan = equirect.central_horizontal_angle / (PI * 2.0f);
float chan = equirect.central_horizontal_angle / (PI * 2.0f);
// Normalize [0, 2π] to [0, 1]
float uhan = chan / 2.0f;
float lhan = -chan / 2.0f;
// Normalize [0, 2π] to [0, 1]
float uhan = chan / 2.0f;
float lhan = -chan / 2.0f;
// Normalize [-π/2, π/2] to [0, 1]
float uvan = equirect.upper_vertical_angle / PI + 0.5f;
float lvan = equirect.lower_vertical_angle / PI + 0.5f;
// Normalize [-π/2, π/2] to [0, 1]
float uvan = equirect.upper_vertical_angle / PI + 0.5f;
float lvan = equirect.lower_vertical_angle / PI + 0.5f;
if (lon < uvan && lon > lvan && lat < uhan && lat > lhan) {
if (lon < uvan && lon > lvan && lat < uhan && lat > lhan)
#ifdef DEBUG
out_color += texture(image, vec2(lat, lon)) / 2.0;
out_color += texture(image, vec2(lat, lon)) / 2.0;
#else
out_color = texture(image, vec2(lat, lon));
else
out_color = vec4(0, 0, 0, 0);
out_color = texture(image, vec2(lat, lon));
} else {
out_color = vec4(0, 0, 0, 0);
}
#endif
}

View file

@ -4,36 +4,38 @@
#version 460
layout (binding = 0, std140) uniform Transformation {
mat4 mvp;
ivec2 offset;
ivec2 extent;
bool flip_y;
layout (binding = 0, std140) uniform Transformation
{
mat4 mvp;
ivec2 offset;
ivec2 extent;
bool flip_y;
} transformation;
layout (location = 0) in vec3 position;
layout (location = 1) in vec2 uv;
layout (location = 0) in vec3 position;
layout (location = 1) in vec2 uv;
layout (location = 0) out vec2 out_uv;
out gl_PerVertex {
vec4 gl_Position;
out gl_PerVertex
{
vec4 gl_Position;
};
const mat4 mvp = mat4(
2, 0, 0, 0,
0, 2, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
2, 0, 0, 0,
0, 2, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
);
void main() {
gl_Position = mvp * vec4 (position, 1.0f);
gl_Position.y = -gl_Position.y;
out_uv = uv;
if (transformation.flip_y) {
out_uv.y = 1.0 - out_uv.y;
}
void main() {
gl_Position = mvp * vec4 (position, 1.0f);
gl_Position.y = -gl_Position.y;
out_uv = uv;
if (transformation.flip_y) {
out_uv.y = 1.0 - out_uv.y;
}
}

View file

@ -4,22 +4,24 @@
#version 460
layout (location = 0) in vec2 uv;
layout (binding = 0, std140) uniform Transformation {
mat4 mvp;
ivec2 offset;
ivec2 extent;
bool flip_y;
layout (binding = 0, std140) uniform Transformation
{
mat4 mvp;
ivec2 offset;
ivec2 extent;
bool flip_y;
} ubo;
layout (binding = 1) uniform sampler2D image;
layout (location = 0) in vec2 uv;
layout (location = 0) out vec4 out_color;
void main ()
{
vec2 uv_sub = vec2(ubo.offset) + uv * vec2(ubo.extent);
uv_sub /= textureSize(image, 0);
out_color = texture(image, uv_sub);
vec2 uv_sub = vec2(ubo.offset) + uv * vec2(ubo.extent);
uv_sub /= textureSize(image, 0);
out_color = texture(image, uv_sub);
}

View file

@ -4,29 +4,31 @@
#version 460
layout (binding = 0, std140) uniform Transformation {
mat4 mvp;
ivec2 offset;
ivec2 extent;
bool flip_y;
layout (binding = 0, std140) uniform Transformation
{
mat4 mvp;
ivec2 offset;
ivec2 extent;
bool flip_y;
} transformation;
layout (location = 0) in vec3 position;
layout (location = 1) in vec2 uv;
layout (location = 0) in vec3 position;
layout (location = 1) in vec2 uv;
layout (location = 0) out vec2 out_uv;
out gl_PerVertex {
vec4 gl_Position;
out gl_PerVertex
{
vec4 gl_Position;
};
void main() {
gl_Position = transformation.mvp * vec4 (position, 1.0f);
gl_Position.y = -gl_Position.y;
out_uv = uv;
if (transformation.flip_y) {
out_uv.y = 1.0 - out_uv.y;
}
void main() {
gl_Position = transformation.mvp * vec4 (position, 1.0f);
gl_Position.y = -gl_Position.y;
out_uv = uv;
if (transformation.flip_y) {
out_uv.y = 1.0 - out_uv.y;
}
}

View file

@ -9,6 +9,7 @@
#version 450
layout (binding = 0) uniform sampler2D tex_sampler;
layout (location = 0) in vec2 in_ruv;
@ -23,5 +24,5 @@ void main()
float g = texture(tex_sampler, in_guv).y;
float b = texture(tex_sampler, in_buv).z;
out_color = vec4(r, g, b, 1.0);
out_color = vec4(r, g, b, 1.0);
}

View file

@ -6,6 +6,7 @@
#version 450
layout (binding = 1, std140) uniform ubo
{
vec4 vertex_rot;