You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-12-02 16:48:55 +00:00
Refactor GLSL shader compilation
-Used a more consistent set of keywords for the shader -Remove all harcoded entry points -Re-wrote the GLSL shader parser, new system is more flexible. Allows any entry point organization. -Entry point for sky shaders is now sky(). -Entry point for particle shaders is now process().
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
#define BLOCK_SIZE 8
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
#ifdef USE_ATTRIBUTES
|
||||
layout(location = 0) in vec2 vertex_attrib;
|
||||
@@ -26,17 +26,15 @@ layout(location = 3) out vec2 pixel_size_interp;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef USE_MATERIAL_UNIFORMS
|
||||
#ifdef MATERIAL_UNIFORMS_USED
|
||||
layout(set = 1, binding = 0, std140) uniform MaterialUniforms{
|
||||
/* clang-format off */
|
||||
MATERIAL_UNIFORMS
|
||||
/* clang-format on */
|
||||
|
||||
#MATERIAL_UNIFORMS
|
||||
|
||||
} material;
|
||||
#endif
|
||||
|
||||
/* clang-format off */
|
||||
VERTEX_SHADER_GLOBALS
|
||||
/* clang-format on */
|
||||
#GLOBALS
|
||||
|
||||
void main() {
|
||||
vec4 instance_custom = vec4(0.0);
|
||||
@@ -132,9 +130,7 @@ void main() {
|
||||
float point_size = 1.0;
|
||||
#endif
|
||||
{
|
||||
/* clang-format off */
|
||||
VERTEX_SHADER_CODE
|
||||
/* clang-format on */
|
||||
#CODE : VERTEX
|
||||
}
|
||||
|
||||
#ifdef USE_NINEPATCH
|
||||
@@ -212,7 +208,7 @@ VERTEX_SHADER_CODE
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
#include "canvas_uniforms_inc.glsl"
|
||||
|
||||
@@ -228,11 +224,11 @@ layout(location = 3) in vec2 pixel_size_interp;
|
||||
|
||||
layout(location = 0) out vec4 frag_color;
|
||||
|
||||
#ifdef USE_MATERIAL_UNIFORMS
|
||||
#ifdef MATERIAL_UNIFORMS_USED
|
||||
layout(set = 1, binding = 0, std140) uniform MaterialUniforms{
|
||||
/* clang-format off */
|
||||
MATERIAL_UNIFORMS
|
||||
/* clang-format on */
|
||||
|
||||
#MATERIAL_UNIFORMS
|
||||
|
||||
} material;
|
||||
#endif
|
||||
|
||||
@@ -260,11 +256,9 @@ vec2 sdf_to_screen_uv(vec2 p_sdf) {
|
||||
return p_sdf * canvas_data.sdf_to_screen;
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
FRAGMENT_SHADER_GLOBALS
|
||||
/* clang-format on */
|
||||
#GLOBALS
|
||||
|
||||
#ifdef LIGHT_SHADER_CODE_USED
|
||||
#ifdef LIGHT_CODE_USED
|
||||
|
||||
vec4 light_compute(
|
||||
vec3 light_vertex,
|
||||
@@ -278,9 +272,9 @@ vec4 light_compute(
|
||||
vec2 uv,
|
||||
vec4 color, bool is_directional) {
|
||||
vec4 light = vec4(0.0);
|
||||
/* clang-format off */
|
||||
LIGHT_SHADER_CODE
|
||||
/* clang-format on */
|
||||
|
||||
#CODE : LIGHT
|
||||
|
||||
return light;
|
||||
}
|
||||
|
||||
@@ -356,7 +350,7 @@ vec3 light_normal_compute(vec3 light_vec, vec3 normal, vec3 base_color, vec3 lig
|
||||
|
||||
//float distance = length(shadow_pos);
|
||||
vec4 light_shadow_compute(uint light_base, vec4 light_color, vec4 shadow_uv
|
||||
#ifdef LIGHT_SHADER_CODE_USED
|
||||
#ifdef LIGHT_CODE_USED
|
||||
,
|
||||
vec3 shadow_modulate
|
||||
#endif
|
||||
@@ -395,7 +389,7 @@ vec4 light_shadow_compute(uint light_base, vec4 light_color, vec4 shadow_uv
|
||||
}
|
||||
|
||||
vec4 shadow_color = unpackUnorm4x8(light_array.data[light_base].shadow_color);
|
||||
#ifdef LIGHT_SHADER_CODE_USED
|
||||
#ifdef LIGHT_CODE_USED
|
||||
shadow_color.rgb *= shadow_modulate;
|
||||
#endif
|
||||
|
||||
@@ -504,11 +498,7 @@ void main() {
|
||||
normal_used = true;
|
||||
#endif
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
FRAGMENT_SHADER_CODE
|
||||
|
||||
/* clang-format on */
|
||||
#CODE : FRAGMENT
|
||||
|
||||
#if defined(NORMAL_MAP_USED)
|
||||
normal = mix(vec3(0.0, 0.0, 1.0), normal_map * vec3(2.0, -2.0, 1.0) - vec3(1.0, -1.0, 0.0), normal_map_depth);
|
||||
@@ -543,7 +533,7 @@ FRAGMENT_SHADER_CODE
|
||||
vec2 direction = light_array.data[light_base].position;
|
||||
vec4 light_color = light_array.data[light_base].color;
|
||||
|
||||
#ifdef LIGHT_SHADER_CODE_USED
|
||||
#ifdef LIGHT_CODE_USED
|
||||
|
||||
vec4 shadow_modulate = vec4(1.0);
|
||||
light_color = light_compute(light_vertex, vec3(direction, light_array.data[light_base].height), normal, light_color, light_color.a, specular_shininess, shadow_modulate, screen_uv, uv, color, true);
|
||||
@@ -561,7 +551,7 @@ FRAGMENT_SHADER_CODE
|
||||
vec4 shadow_uv = vec4(shadow_pos.x, light_array.data[light_base].shadow_y_ofs, shadow_pos.y * light_array.data[light_base].shadow_zfar_inv, 1.0);
|
||||
|
||||
light_color = light_shadow_compute(light_base, light_color, shadow_uv
|
||||
#ifdef LIGHT_SHADER_CODE_USED
|
||||
#ifdef LIGHT_CODE_USED
|
||||
,
|
||||
shadow_modulate.rgb
|
||||
#endif
|
||||
@@ -599,7 +589,7 @@ FRAGMENT_SHADER_CODE
|
||||
vec4 light_color = textureLod(sampler2D(atlas_texture, texture_sampler), tex_uv_atlas, 0.0);
|
||||
vec4 light_base_color = light_array.data[light_base].color;
|
||||
|
||||
#ifdef LIGHT_SHADER_CODE_USED
|
||||
#ifdef LIGHT_CODE_USED
|
||||
|
||||
vec4 shadow_modulate = vec4(1.0);
|
||||
vec3 light_position = vec3(light_array.data[light_base].position, light_array.data[light_base].height);
|
||||
@@ -657,7 +647,7 @@ FRAGMENT_SHADER_CODE
|
||||
vec4 shadow_uv = vec4(tex_ofs, light_array.data[light_base].shadow_y_ofs, distance, 1.0);
|
||||
|
||||
light_color = light_shadow_compute(light_base, light_color, shadow_uv
|
||||
#ifdef LIGHT_SHADER_CODE_USED
|
||||
#ifdef LIGHT_CODE_USED
|
||||
,
|
||||
shadow_modulate.rgb
|
||||
#endif
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(location = 0) in highp vec3 vertex;
|
||||
|
||||
@@ -32,7 +32,7 @@ void main() {
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(push_constant, binding = 0, std430) uniform Constants {
|
||||
mat4 projection;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(location = 0) in vec3 vertex_attrib;
|
||||
|
||||
@@ -63,7 +63,7 @@ void main() {
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
#if defined(has_GL_KHR_shader_subgroup_ballot) && defined(has_GL_KHR_shader_subgroup_arithmetic) && defined(has_GL_KHR_shader_subgroup_vote)
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(location = 0) out vec2 uv_interp;
|
||||
|
||||
@@ -37,7 +37,7 @@ void main() {
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(push_constant, binding = 1, std430) uniform Params {
|
||||
vec4 section;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(push_constant, binding = 1, std430) uniform Params {
|
||||
float z_far;
|
||||
@@ -26,7 +26,7 @@ void main() {
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(location = 0) in vec2 uv_interp;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
#define BLOCK_SIZE 8
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
#define GROUP_SIZE 64
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
#define GROUP_SIZE 8
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
#ifdef MODE_DYNAMIC
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
struct CellData {
|
||||
uint position; // xyz 10 bits
|
||||
@@ -172,7 +172,7 @@ void main() {
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(location = 0) in vec4 color_interp;
|
||||
layout(location = 0) out vec4 frag_color;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 4, local_size_y = 4, local_size_z = 4) in;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
#define BLOCK_SIZE 8
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
|
||||
|
||||
@@ -146,11 +146,11 @@ layout(set = 2, binding = 1) uniform texture2D height_field_texture;
|
||||
|
||||
/* SET 3: MATERIAL */
|
||||
|
||||
#ifdef USE_MATERIAL_UNIFORMS
|
||||
#ifdef MATERIAL_UNIFORMS_USED
|
||||
layout(set = 3, binding = 0, std140) uniform MaterialUniforms{
|
||||
/* clang-format off */
|
||||
MATERIAL_UNIFORMS
|
||||
/* clang-format on */
|
||||
|
||||
#MATERIAL_UNIFORMS
|
||||
|
||||
} material;
|
||||
#endif
|
||||
|
||||
@@ -196,11 +196,7 @@ bool emit_subparticle(mat4 p_xform, vec3 p_velocity, vec4 p_color, vec4 p_custom
|
||||
return true;
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
COMPUTE_SHADER_GLOBALS
|
||||
|
||||
/* clang-format on */
|
||||
#GLOBALS
|
||||
|
||||
void main() {
|
||||
uint particle = gl_GlobalInvocationID.x;
|
||||
@@ -540,10 +536,6 @@ void main() {
|
||||
}
|
||||
|
||||
if (PARTICLE.is_active) {
|
||||
/* clang-format off */
|
||||
|
||||
COMPUTE_SHADER_CODE
|
||||
|
||||
/* clang-format on */
|
||||
#CODE : PROCESS
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
#include "scene_forward_clustered_inc.glsl"
|
||||
|
||||
@@ -81,11 +81,11 @@ layout(location = 5) out vec3 tangent_interp;
|
||||
layout(location = 6) out vec3 binormal_interp;
|
||||
#endif
|
||||
|
||||
#ifdef USE_MATERIAL_UNIFORMS
|
||||
#ifdef MATERIAL_UNIFORMS_USED
|
||||
layout(set = MATERIAL_UNIFORM_SET, binding = 0, std140) uniform MaterialUniforms{
|
||||
/* clang-format off */
|
||||
MATERIAL_UNIFORMS
|
||||
/* clang-format on */
|
||||
|
||||
#MATERIAL_UNIFORMS
|
||||
|
||||
} material;
|
||||
#endif
|
||||
|
||||
@@ -99,11 +99,7 @@ layout(location = 8) out float dp_clip;
|
||||
|
||||
layout(location = 9) out flat uint instance_index;
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
VERTEX_SHADER_GLOBALS
|
||||
|
||||
/* clang-format on */
|
||||
#GLOBALS
|
||||
|
||||
void main() {
|
||||
vec4 instance_custom = vec4(0.0);
|
||||
@@ -230,11 +226,7 @@ void main() {
|
||||
mat3 modelview_normal = mat3(scene_data.inv_camera_matrix) * world_normal_matrix;
|
||||
|
||||
{
|
||||
/* clang-format off */
|
||||
|
||||
VERTEX_SHADER_CODE
|
||||
|
||||
/* clang-format on */
|
||||
#CODE : VERTEX
|
||||
}
|
||||
|
||||
// using local coordinates (default)
|
||||
@@ -325,7 +317,7 @@ VERTEX_SHADER_CODE
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
#include "scene_forward_clustered_inc.glsl"
|
||||
|
||||
@@ -372,19 +364,15 @@ layout(location = 9) in flat uint instance_index;
|
||||
#define LIGHT_TRANSMITTANCE_USED
|
||||
#endif
|
||||
|
||||
#ifdef USE_MATERIAL_UNIFORMS
|
||||
#ifdef MATERIAL_UNIFORMS_USED
|
||||
layout(set = MATERIAL_UNIFORM_SET, binding = 0, std140) uniform MaterialUniforms{
|
||||
/* clang-format off */
|
||||
MATERIAL_UNIFORMS
|
||||
/* clang-format on */
|
||||
|
||||
#MATERIAL_UNIFORMS
|
||||
|
||||
} material;
|
||||
#endif
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
FRAGMENT_SHADER_GLOBALS
|
||||
|
||||
/* clang-format on */
|
||||
#GLOBALS
|
||||
|
||||
#ifdef MODE_RENDER_DEPTH
|
||||
|
||||
@@ -581,18 +569,14 @@ void light_compute(vec3 N, vec3 L, vec3 V, vec3 light_color, float attenuation,
|
||||
#endif
|
||||
inout vec3 diffuse_light, inout vec3 specular_light) {
|
||||
|
||||
#if defined(USE_LIGHT_SHADER_CODE)
|
||||
#if defined(LIGHT_CODE_USED)
|
||||
// light is written by the light shader
|
||||
|
||||
vec3 normal = N;
|
||||
vec3 light = L;
|
||||
vec3 view = V;
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
LIGHT_SHADER_CODE
|
||||
|
||||
/* clang-format on */
|
||||
#CODE : LIGHT
|
||||
|
||||
#else
|
||||
|
||||
@@ -794,7 +778,7 @@ LIGHT_SHADER_CODE
|
||||
alpha = min(alpha, clamp(1.0 - attenuation), 0.0, 1.0));
|
||||
#endif
|
||||
|
||||
#endif //defined(USE_LIGHT_SHADER_CODE)
|
||||
#endif //defined(LIGHT_CODE_USED)
|
||||
}
|
||||
|
||||
#ifndef USE_NO_SHADOWS
|
||||
@@ -1925,11 +1909,7 @@ void main() {
|
||||
#endif // ALPHA_ANTIALIASING_EDGE_USED
|
||||
|
||||
{
|
||||
/* clang-format off */
|
||||
|
||||
FRAGMENT_SHADER_CODE
|
||||
|
||||
/* clang-format on */
|
||||
#CODE : FRAGMENT
|
||||
}
|
||||
|
||||
#ifdef LIGHT_TRANSMITTANCE_USED
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
#define MAX_CASCADES 8
|
||||
|
||||
@@ -153,7 +153,7 @@ void main() {
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(location = 0) out vec4 frag_color;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -1,182 +0,0 @@
|
||||
/* clang-format off */
|
||||
[compute]
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = OCT_RES, local_size_y = OCT_RES, local_size_z = 1) in;
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
#define MAX_CASCADES 8
|
||||
|
||||
layout(rgba16f, set = 0, binding = 1) uniform restrict image2DArray irradiance_texture;
|
||||
layout(rg16f, set = 0, binding = 2) uniform restrict image2DArray depth_texture;
|
||||
|
||||
layout(rgba32ui, set = 0, binding = 3) uniform restrict uimage2DArray irradiance_history_texture;
|
||||
layout(rg32ui, set = 0, binding = 4) uniform restrict uimage2DArray depth_history_texture;
|
||||
|
||||
struct CascadeData {
|
||||
vec3 offset; //offset of (0,0,0) in world coordinates
|
||||
float to_cell; // 1/bounds * grid_size
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 5, std140) uniform Cascades {
|
||||
CascadeData data[MAX_CASCADES];
|
||||
}
|
||||
cascades;
|
||||
|
||||
#define DEPTH_HISTORY_BITS 24
|
||||
#define IRRADIANCE_HISTORY_BITS 16
|
||||
|
||||
layout(push_constant, binding = 0, std430) uniform Params {
|
||||
vec3 grid_size;
|
||||
uint max_cascades;
|
||||
|
||||
uint probe_axis_size;
|
||||
uint cascade;
|
||||
uint history_size;
|
||||
uint pad0;
|
||||
|
||||
ivec3 scroll; //scroll in probes
|
||||
uint pad1;
|
||||
}
|
||||
params;
|
||||
|
||||
void main() {
|
||||
ivec2 local = ivec2(gl_LocalInvocationID.xy);
|
||||
ivec2 probe = ivec2(gl_WorkGroupID.xy);
|
||||
|
||||
ivec3 probe_cell;
|
||||
probe_cell.x = probe.x % int(params.probe_axis_size);
|
||||
probe_cell.y = probe.y;
|
||||
probe_cell.z = probe.x / int(params.probe_axis_size);
|
||||
|
||||
#ifdef MODE_SCROLL_BEGIN
|
||||
|
||||
ivec3 read_cell = probe_cell - params.scroll;
|
||||
|
||||
uint src_layer = (params.history_size + 1) * params.cascade;
|
||||
uint dst_layer = (params.history_size + 1) * params.max_cascades;
|
||||
|
||||
for (uint i = 0; i <= params.history_size; i++) {
|
||||
ivec3 write_pos = ivec3(probe * OCT_RES + local, int(i));
|
||||
|
||||
if (any(lessThan(read_pos, ivec3(0))) || any(greaterThanEqual(read_pos, ivec3(params.probe_axis_size)))) {
|
||||
// nowhere to read from for scrolling, try finding the value from upper probes
|
||||
|
||||
#ifdef MODE_IRRADIANCE
|
||||
imageStore(irradiance_history_texture, write_pos, uvec4(0));
|
||||
#endif
|
||||
#ifdef MODE_DEPTH
|
||||
imageStore(depth_history_texture, write_pos, uvec4(0));
|
||||
#endif
|
||||
} else {
|
||||
ivec3 read_pos;
|
||||
read_pos.xy = read_cell.xy;
|
||||
read_pos.x += read_cell.z * params.probe_axis_size;
|
||||
read_pos.xy = read_pos.xy * OCT_RES + local;
|
||||
read_pos.z = int(i);
|
||||
|
||||
#ifdef MODE_IRRADIANCE
|
||||
uvec4 value = imageLoad(irradiance_history_texture, read_pos);
|
||||
imageStore(irradiance_history_texture, write_pos, value);
|
||||
#endif
|
||||
#ifdef MODE_DEPTH
|
||||
uvec2 value = imageLoad(depth_history_texture, read_pos);
|
||||
imageStore(depth_history_texture, write_pos, value);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif // MODE_SCROLL_BEGIN
|
||||
|
||||
#ifdef MODE_SCROLL_END
|
||||
|
||||
uint src_layer = (params.history_size + 1) * params.max_cascades;
|
||||
uint dst_layer = (params.history_size + 1) * params.cascade;
|
||||
|
||||
for (uint i = 0; i <= params.history_size; i++) {
|
||||
ivec3 pos = ivec3(probe * OCT_RES + local, int(i));
|
||||
|
||||
#ifdef MODE_IRRADIANCE
|
||||
uvec4 value = imageLoad(irradiance_history_texture, read_pos);
|
||||
imageStore(irradiance_history_texture, write_pos, value);
|
||||
#endif
|
||||
#ifdef MODE_DEPTH
|
||||
uvec2 value = imageLoad(depth_history_texture, read_pos);
|
||||
imageStore(depth_history_texture, write_pos, value);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif //MODE_SCROLL_END
|
||||
|
||||
#ifdef MODE_STORE
|
||||
|
||||
uint src_layer = (params.history_size + 1) * params.cascade + params.history_size;
|
||||
ivec3 read_pos = ivec3(probe * OCT_RES + local, int(src_layer));
|
||||
|
||||
ivec3 write_pos = ivec3(probe * (OCT_RES + 2) + ivec2(1), int(params.cascade));
|
||||
|
||||
ivec3 copy_to[4] = ivec3[](write_pos, ivec3(-2, -2, -2), ivec3(-2, -2, -2), ivec3(-2, -2, -2));
|
||||
|
||||
#ifdef MODE_IRRADIANCE
|
||||
uvec4 average = imageLoad(irradiance_history_texture, read_pos);
|
||||
vec4 light_accum = vec4(average / params.history_size) / float(1 << IRRADIANCE_HISTORY_BITS);
|
||||
|
||||
#endif
|
||||
#ifdef MODE_DEPTH
|
||||
uvec2 value = imageLoad(depth_history_texture, read_pos);
|
||||
vec2 depth_accum = vec4(average / params.history_size) / float(1 << IRRADIANCE_HISTORY_BITS);
|
||||
|
||||
float probe_cell_size = float(params.grid_size / float(params.probe_axis_size - 1)) / cascades.data[params.cascade].to_cell;
|
||||
float max_depth = length(params.grid_size / cascades.data[params.max_cascades - 1].to_cell);
|
||||
max_depth /= probe_cell_size;
|
||||
|
||||
depth_value = (vec2(average / params.history_size) / float(1 << DEPTH_HISTORY_BITS)) * vec2(max_depth, max_depth * max_depth);
|
||||
|
||||
#endif
|
||||
|
||||
/* Fill the border if required */
|
||||
|
||||
if (local == ivec2(0, 0)) {
|
||||
copy_to[1] = texture_pos + ivec3(OCT_RES - 1, -1, 0);
|
||||
copy_to[2] = texture_pos + ivec3(-1, OCT_RES - 1, 0);
|
||||
copy_to[3] = texture_pos + ivec3(OCT_RES, OCT_RES, 0);
|
||||
} else if (local == ivec2(OCT_RES - 1, 0)) {
|
||||
copy_to[1] = texture_pos + ivec3(0, -1, 0);
|
||||
copy_to[2] = texture_pos + ivec3(OCT_RES, OCT_RES - 1, 0);
|
||||
copy_to[3] = texture_pos + ivec3(-1, OCT_RES, 0);
|
||||
} else if (local == ivec2(0, OCT_RES - 1)) {
|
||||
copy_to[1] = texture_pos + ivec3(-1, 0, 0);
|
||||
copy_to[2] = texture_pos + ivec3(OCT_RES - 1, OCT_RES, 0);
|
||||
copy_to[3] = texture_pos + ivec3(OCT_RES, -1, 0);
|
||||
} else if (local == ivec2(OCT_RES - 1, OCT_RES - 1)) {
|
||||
copy_to[1] = texture_pos + ivec3(0, OCT_RES, 0);
|
||||
copy_to[2] = texture_pos + ivec3(OCT_RES, 0, 0);
|
||||
copy_to[3] = texture_pos + ivec3(-1, -1, 0);
|
||||
} else if (local.y == 0) {
|
||||
copy_to[1] = texture_pos + ivec3(OCT_RES - local.x - 1, local.y - 1, 0);
|
||||
} else if (local.x == 0) {
|
||||
copy_to[1] = texture_pos + ivec3(local.x - 1, OCT_RES - local.y - 1, 0);
|
||||
} else if (local.y == OCT_RES - 1) {
|
||||
copy_to[1] = texture_pos + ivec3(OCT_RES - local.x - 1, local.y + 1, 0);
|
||||
} else if (local.x == OCT_RES - 1) {
|
||||
copy_to[1] = texture_pos + ivec3(local.x + 1, OCT_RES - local.y - 1, 0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (copy_to[i] == ivec3(-2, -2, -2)) {
|
||||
continue;
|
||||
}
|
||||
#ifdef MODE_IRRADIANCE
|
||||
imageStore(irradiance_texture, copy_to[i], light_accum);
|
||||
#endif
|
||||
#ifdef MODE_DEPTH
|
||||
imageStore(depth_texture, copy_to[i], vec4(depth_value, 0.0, 0.0));
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // MODE_STORE
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
#ifdef MODE_JUMPFLOOD_OPTIMIZED
|
||||
#define GROUP_SIZE 8
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(location = 0) out vec2 uv_interp;
|
||||
|
||||
@@ -24,7 +24,7 @@ void main() {
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
#define M_PI 3.14159265359
|
||||
|
||||
@@ -88,13 +88,9 @@ layout(set = 0, binding = 3, std140) uniform DirectionalLights {
|
||||
|
||||
directional_lights;
|
||||
|
||||
#ifdef USE_MATERIAL_UNIFORMS
|
||||
#ifdef MATERIAL_UNIFORMS_USED
|
||||
layout(set = 1, binding = 0, std140) uniform MaterialUniforms{
|
||||
/* clang-format off */
|
||||
|
||||
MATERIAL_UNIFORMS
|
||||
|
||||
/* clang-format on */
|
||||
#MATERIAL_UNIFORMS
|
||||
} material;
|
||||
#endif
|
||||
|
||||
@@ -127,11 +123,7 @@ layout(set = 3, binding = 0) uniform texture3D volumetric_fog_texture;
|
||||
#define AT_QUARTER_RES_PASS false
|
||||
#endif
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
FRAGMENT_SHADER_GLOBALS
|
||||
|
||||
/* clang-format on */
|
||||
#GLOBALS
|
||||
|
||||
layout(location = 0) out vec4 frag_color;
|
||||
|
||||
@@ -202,22 +194,10 @@ void main() {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// unused, just here to make our compiler happy, make sure we don't execute any light code the user adds in..
|
||||
#ifndef REALLYINCLUDETHIS
|
||||
{
|
||||
/* clang-format off */
|
||||
|
||||
LIGHT_SHADER_CODE
|
||||
#CODE : SKY
|
||||
|
||||
/* clang-format on */
|
||||
}
|
||||
#endif
|
||||
{
|
||||
/* clang-format off */
|
||||
|
||||
FRAGMENT_SHADER_CODE
|
||||
|
||||
/* clang-format on */
|
||||
}
|
||||
|
||||
frag_color.rgb = color * params.position_multiplier.w;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
// Original version here:
|
||||
// https://github.com/GPUOpen-LibrariesAndSDKs/GPUParticles11/blob/master/gpuparticles11/src/Shaders
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(location = 0) out vec2 uv_interp;
|
||||
|
||||
@@ -17,7 +17,7 @@ void main() {
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(location = 0) in vec2 uv_interp;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
#define SSAO_ADAPTIVE_TAP_BASE_COUNT 5
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(location = 0) out vec2 uv_interp;
|
||||
|
||||
@@ -16,7 +16,7 @@ void main() {
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
layout(location = 0) in vec2 uv_interp;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#version 450
|
||||
|
||||
VERSION_DEFINES
|
||||
#VERSION_DEFINES
|
||||
|
||||
/* Do not use subgroups here, seems there is not much advantage and causes glitches
|
||||
#if defined(has_GL_KHR_shader_subgroup_ballot) && defined(has_GL_KHR_shader_subgroup_arithmetic)
|
||||
|
||||
Reference in New Issue
Block a user