From 239ecc8d568902e170d1dfcbc009360a7555a25d Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Thu, 10 Mar 2022 10:21:09 -0500 Subject: [PATCH] Revert "Another big WebGPU compatibility patch" This reverts commit 3229c4fa2cbb294e6af18649ce826831cd85eada. --- engine/core/include/scene.hpp | 5 +- engine/gfx/webgpu/include/gfx_webgpu.hpp | 1 - engine/gfx/webgpu/src/gfx_webgpu.cpp | 87 ++++--------------- engine/gfx/webgpu/src/gfx_webgpu_pipeline.hpp | 2 - engine/gfx/webgpu/src/gfx_webgpu_texture.hpp | 1 + engine/renderer/include/materialcompiler.hpp | 12 +-- engine/renderer/include/renderer.hpp | 2 + engine/renderer/src/materialcompiler.cpp | 18 ++-- engine/renderer/src/renderer.cpp | 59 +++++++------ engine/shadercompiler/src/shadercompiler.cpp | 9 -- engine/shaders/dof.vert.glsl | 9 +- engine/shaders/filter.frag.glsl | 4 +- engine/shaders/mesh.vert.nocompile.glsl | 21 +++-- engine/shaders/omnishadow.frag.glsl | 4 +- .../shaders/scenecapture.vert.nocompile.glsl | 10 ++- engine/shaders/shadow.vert.nocompile.glsl | 4 +- engine/utility/include/render_constants.hpp | 6 -- 17 files changed, 103 insertions(+), 151 deletions(-) delete mode 100644 engine/utility/include/render_constants.hpp diff --git a/engine/core/include/scene.hpp b/engine/core/include/scene.hpp index ecef2b7..e9b05a7 100755 --- a/engine/core/include/scene.hpp +++ b/engine/core/include/scene.hpp @@ -7,7 +7,6 @@ #include "object.hpp" #include "components.hpp" #include "utility.hpp" -#include "render_constants.hpp" template using Pool = std::unordered_map; @@ -194,6 +193,10 @@ private: std::vector _objects; }; +const int max_spot_shadows = 4; +const int max_point_shadows = 4; +const int max_environment_probes = 4; + class GFXFramebuffer; class GFXTexture; diff --git a/engine/gfx/webgpu/include/gfx_webgpu.hpp b/engine/gfx/webgpu/include/gfx_webgpu.hpp index 50eace7..7a5a9ee 100755 --- a/engine/gfx/webgpu/include/gfx_webgpu.hpp +++ b/engine/gfx/webgpu/include/gfx_webgpu.hpp @@ -12,7 +12,6 @@ public: ShaderLanguage accepted_shader_language() override; const char* get_name() override; - bool supports_feature(GFXFeature feature) override; // buffer GFXBuffer* create_buffer(void* data, GFXSize size, bool is_dynamic, GFXBufferUsage usage) override; diff --git a/engine/gfx/webgpu/src/gfx_webgpu.cpp b/engine/gfx/webgpu/src/gfx_webgpu.cpp index 7a17226..f24d269 100755 --- a/engine/gfx/webgpu/src/gfx_webgpu.cpp +++ b/engine/gfx/webgpu/src/gfx_webgpu.cpp @@ -196,23 +196,10 @@ GFXBuffer* GFXWebGPU::create_buffer(void* data, const GFXSize size, const bool i buffer->size = size; WGPUBufferDescriptor desc = {}; + desc.usage = WGPUBufferUsage_CopyDst; desc.size = size; desc.mappedAtCreation = true; - switch(usage) { - case GFXBufferUsage::Vertex: - desc.usage = WGPUBufferUsage_Vertex; - break; - case GFXBufferUsage::Index: - desc.usage = WGPUBufferUsage_Index; - break; - case GFXBufferUsage::Storage: - desc.usage = WGPUBufferUsage_Storage; - break; - } - - desc.usage |= WGPUBufferUsage_Uniform; // TODO: not currently exposed in gfx api - buffer->handle = wgpuDeviceCreateBuffer(device, &desc); wgpuQueueWriteBuffer(queue, buffer->handle, 0, data, size); @@ -255,7 +242,6 @@ GFXTexture* GFXWebGPU::create_texture(const GFXTextureCreateInfo& info) { descriptor.mipLevelCount = info.mip_count; descriptor.usage = WGPUTextureUsage_None; - descriptor.sampleCount = 1; if((info.usage & GFXTextureUsage::Sampled) == GFXTextureUsage::Sampled) descriptor.usage |= WGPUTextureUsage_TextureBinding; @@ -274,17 +260,6 @@ GFXTexture* GFXWebGPU::create_texture(const GFXTextureCreateInfo& info) { texture->handle = wgpuDeviceCreateTexture(device, &descriptor); - WGPUTextureViewDescriptor view_descriptor = {}; - view_descriptor.label = info.label.data(); - view_descriptor.format = descriptor.format; - view_descriptor.mipLevelCount = descriptor.mipLevelCount; - view_descriptor.dimension = WGPUTextureViewDimension_2D; - view_descriptor.baseArrayLayer = 0; - view_descriptor.aspect = WGPUTextureAspect_All; - view_descriptor.arrayLayerCount = info.array_length; - - texture->view = wgpuTextureCreateView(texture->handle, &view_descriptor); - return texture; } @@ -303,10 +278,6 @@ void GFXWebGPU::copy_texture(GFXTexture* from, GFXBuffer* to) { GFXSampler* GFXWebGPU::create_sampler(const GFXSamplerCreateInfo& info) { auto sampler = new GFXWebGPUSampler(); - WGPUSamplerDescriptor sampler_descriptor = {}; - - sampler->handle = wgpuDeviceCreateSampler(device, &sampler_descriptor); - return sampler; } @@ -325,10 +296,8 @@ GFXRenderPass* GFXWebGPU::create_render_pass(const GFXRenderPassCreateInfo& info GFXPipeline* GFXWebGPU::create_graphics_pipeline(const GFXGraphicsPipelineCreateInfo& info) { auto pipeline = new GFXWebGPUPipeline(); - pipeline->label = info.label; - WGPURenderPipelineDescriptor descriptor = {}; - descriptor.label = pipeline->label.c_str(); + descriptor.label = info.label.c_str(); const bool has_vertex_stage = !info.shaders.vertex_src.empty(); if (has_vertex_stage) { @@ -340,7 +309,7 @@ GFXPipeline* GFXWebGPU::create_graphics_pipeline(const GFXGraphicsPipelineCreate descriptor.vertex.module = create_shader(vertex_shader_vector.data(), vertex_shader_vector.size() * sizeof(uint32_t), std::string(info.label + " vertex stage").c_str()); } else { - auto vertex_shader = prism::open_file(prism::internal_domain / (info.shaders.vertex_src.as_path().string() + ".wgsl"), true); + auto vertex_shader = prism::open_file(prism::internal_domain / (info.shaders.vertex_src.as_path().string() + ".wgsl.spv"), true); vertex_shader->read_all(); descriptor.vertex.module = create_shader(vertex_shader->cast_data(), vertex_shader->size(), info.shaders.vertex_src.as_path().string().c_str()); @@ -348,7 +317,6 @@ GFXPipeline* GFXWebGPU::create_graphics_pipeline(const GFXGraphicsPipelineCreate } WGPUFragmentState fragment = {}; - fragment.entryPoint = "main"; const bool has_fragment_stage = !info.shaders.fragment_src.empty(); if (has_fragment_stage) { @@ -362,15 +330,13 @@ GFXPipeline* GFXWebGPU::create_graphics_pipeline(const GFXGraphicsPipelineCreate fragment.module = create_shader(fragment_shader_vector.data(), fragment_shader_vector.size() * sizeof(uint32_t), std::string(info.label + " fragment stage").c_str()); } else { - auto fragment_shader = prism::open_file(prism::internal_domain / (info.shaders.fragment_src.as_path().string() + ".wgsl"), true); + auto fragment_shader = prism::open_file(prism::internal_domain / (info.shaders.fragment_src.as_path().string() + ".wgsl.spv"), true); fragment_shader->read_all(); fragment.module = create_shader(fragment_shader->cast_data(), fragment_shader->size(), info.shaders.fragment_src.as_path().string().c_str()); } } - descriptor.vertex.entryPoint = "main"; - prism::log("building pipeline {}", info.label); prism::log("--------"); @@ -434,6 +400,7 @@ GFXPipeline* GFXWebGPU::create_graphics_pipeline(const GFXGraphicsPipelineCreate break; } + descriptor.primitive.stripIndexFormat = WGPUIndexFormat_Uint16; descriptor.primitive.topology = WGPUPrimitiveTopology_TriangleList; // create bind group layout @@ -449,9 +416,9 @@ GFXPipeline* GFXWebGPU::create_graphics_pipeline(const GFXGraphicsPipelineCreate switch (binding.type) { case GFXBindingType::StorageBuffer: - { - entry.buffer.type = WGPUBufferBindingType_Uniform; - } + { + entry.buffer.type = WGPUBufferBindingType_Uniform; + } break; case GFXBindingType::StorageImage: { @@ -472,8 +439,6 @@ GFXPipeline* GFXWebGPU::create_graphics_pipeline(const GFXGraphicsPipelineCreate group_entries.push_back(entry); } - descriptor.multisample.count = 1; - WGPUBindGroupLayoutDescriptor bind_group_layout_descriptor = {}; bind_group_layout_descriptor.entryCount = group_entries.size(); bind_group_layout_descriptor.entries = group_entries.data(); @@ -500,20 +465,15 @@ GFXPipeline* GFXWebGPU::create_compute_pipeline(const GFXComputePipelineCreateIn descriptor.compute.module = create_shader(compute_shader_vector.data(), compute_shader_vector.size() * sizeof(uint32_t), info.label.c_str()); } else { - auto compute_shader = prism::open_file(prism::internal_domain / (info.compute_src.as_path().string() + ".wgsl"), true); + auto compute_shader = prism::open_file(prism::internal_domain / (info.compute_src.as_path().string() + ".wgsl.spv"), true); compute_shader->read_all(); descriptor.compute.module = create_shader(compute_shader->cast_data(), compute_shader->size(), info.compute_src.as_path().string().c_str()); } } - pipeline->compute_handle = wgpuDeviceCreateComputePipeline(device, &descriptor); - WGPUBindGroupLayoutDescriptor bind_group_layout_descriptor = {}; - - pipeline->bind_group_layout = wgpuDeviceCreateBindGroupLayout(device, &bind_group_layout_descriptor); - return pipeline; } @@ -619,18 +579,17 @@ void GFXWebGPU::submit(GFXCommandBuffer* command_buffer, const platform::window_ if(current_pipeline == nullptr) return false; - const uint64_t hash = get_bind_group_hash(current_pipeline); - if(last_bind_group_hash != hash) { - if(!current_pipeline->cached_bind_groups.count(hash)) + if(last_bind_group_hash != get_bind_group_hash(current_pipeline)) { + if(!current_pipeline->cached_bind_groups.count(get_bind_group_hash(current_pipeline))) cache_bind_group_state(current_pipeline, current_pipeline->bind_group_layout); - auto bind_group = current_pipeline->cached_bind_groups[hash]; + auto& bind_group = current_pipeline->cached_bind_groups[get_bind_group_hash(current_pipeline)]; if(bind_group == nullptr) return false; wgpuRenderPassEncoderSetBindGroup(render_encoder, 0, bind_group, 0, nullptr); - last_bind_group_hash = hash; + last_bind_group_hash = get_bind_group_hash(current_pipeline); } return true; @@ -872,18 +831,14 @@ uint64_t GFXWebGPU::get_bind_group_hash(GFXWebGPUPipeline *pipeline) { } void GFXWebGPU::cache_bind_group_state(GFXWebGPUPipeline* pipeline, WGPUBindGroupLayout group_layout) { - const uint64_t hash = get_bind_group_hash(pipeline); + uint64_t hash = get_bind_group_hash(pipeline); std::vector group_entries; - prism::log("creating bind group for {}", pipeline->label); - for (auto [i, buffer] : utility::enumerate(boundShaderBuffers)) { if (buffer.buffer != nullptr) { auto wgpu_buffer = (GFXWebGPUBuffer*)buffer.buffer; - prism::log("binding {} filled", i); - WGPUBindGroupEntry entry = {}; entry.buffer = wgpu_buffer->handle; entry.size = buffer.size; @@ -898,10 +853,9 @@ void GFXWebGPU::cache_bind_group_state(GFXWebGPUPipeline* pipeline, WGPUBindGrou if (texture != nullptr) { auto wgpu_texture = (GFXWebGPUTexture*) texture; - prism::log("binding {} filled", i); - WGPUBindGroupEntry entry = {}; entry.textureView = wgpu_texture->view; + entry.sampler = wgpu_texture->sampler; entry.binding = i; group_entries.push_back(entry); @@ -912,8 +866,6 @@ void GFXWebGPU::cache_bind_group_state(GFXWebGPUPipeline* pipeline, WGPUBindGrou if (sampler != nullptr) { auto wgpu_sampler = (GFXWebGPUSampler*) sampler; - prism::log("binding {} filled", i); - WGPUBindGroupEntry entry = {}; entry.sampler = wgpu_sampler->handle; entry.binding = i; @@ -922,15 +874,10 @@ void GFXWebGPU::cache_bind_group_state(GFXWebGPUPipeline* pipeline, WGPUBindGrou } } - prism::log("num entries: {}", group_entries.size()); - - prism::log("-----"); - WGPUBindGroupDescriptor group_descriptor = {}; group_descriptor.layout = group_layout; group_descriptor.entryCount = group_entries.size(); group_descriptor.entries = group_entries.data(); - group_descriptor.label = pipeline->label.c_str(); pipeline->cached_bind_groups[hash] = wgpuDeviceCreateBindGroup(device, &group_descriptor); } @@ -945,7 +892,3 @@ void GFXWebGPU::reset_bind_state() { for (auto& sampler : boundSamplers) sampler = nullptr; } - -bool GFXWebGPU::supports_feature(GFXFeature feature) { - return true; -} diff --git a/engine/gfx/webgpu/src/gfx_webgpu_pipeline.hpp b/engine/gfx/webgpu/src/gfx_webgpu_pipeline.hpp index 80d6c38..6519867 100644 --- a/engine/gfx/webgpu/src/gfx_webgpu_pipeline.hpp +++ b/engine/gfx/webgpu/src/gfx_webgpu_pipeline.hpp @@ -6,8 +6,6 @@ class GFXWebGPUPipeline : public GFXPipeline { public: - std::string label; - WGPURenderPipeline render_handle = nullptr; WGPUComputePipeline compute_handle = nullptr; diff --git a/engine/gfx/webgpu/src/gfx_webgpu_texture.hpp b/engine/gfx/webgpu/src/gfx_webgpu_texture.hpp index cd95c20..5c9dfc0 100644 --- a/engine/gfx/webgpu/src/gfx_webgpu_texture.hpp +++ b/engine/gfx/webgpu/src/gfx_webgpu_texture.hpp @@ -7,4 +7,5 @@ public: WGPUTexture handle = nullptr; WGPUTextureFormat format = WGPUTextureFormat_Undefined; WGPUTextureView view = nullptr; + WGPUSampler sampler = nullptr; }; diff --git a/engine/renderer/include/materialcompiler.hpp b/engine/renderer/include/materialcompiler.hpp index 2608a8a..af2c10b 100755 --- a/engine/renderer/include/materialcompiler.hpp +++ b/engine/renderer/include/materialcompiler.hpp @@ -6,12 +6,12 @@ class Material; -constexpr int position_buffer_index = 2; -constexpr int normal_buffer_index = 3; -constexpr int texcoord_buffer_index = 4; -constexpr int tangent_buffer_index = 5; -constexpr int bitangent_buffer_index = 6; -constexpr int bone_buffer_index = 7; +constexpr int position_buffer_index = 5; +constexpr int normal_buffer_index = 6; +constexpr int texcoord_buffer_index = 7; +constexpr int tangent_buffer_index = 8; +constexpr int bitangent_buffer_index = 9; +constexpr int bone_buffer_index = 10; class MaterialCompiler { public: diff --git a/engine/renderer/include/renderer.hpp b/engine/renderer/include/renderer.hpp index f781853..e83f51f 100755 --- a/engine/renderer/include/renderer.hpp +++ b/engine/renderer/include/renderer.hpp @@ -30,6 +30,8 @@ class DoFPass; class Scene; struct Camera; +constexpr int max_scene_materials = 25, max_scene_lights = 25; + struct render_screen_options { bool render_world = false; Matrix4x4 mvp; diff --git a/engine/renderer/src/materialcompiler.cpp b/engine/renderer/src/materialcompiler.cpp index c4a2953..0993ae7 100755 --- a/engine/renderer/src/materialcompiler.cpp +++ b/engine/renderer/src/materialcompiler.cpp @@ -125,7 +125,11 @@ std::tuple MaterialCompiler::create_pipeline_permuta } constexpr std::string_view struct_info = -R"(struct Material {{ +R"(layout (constant_id = 0) const int max_materials = 25; +layout (constant_id = 1) const int max_lights = 25; +layout (constant_id = 2) const int max_spot_lights = 4; +layout (constant_id = 3) const int max_probes = 4; +struct Material {{ vec4 color, info; }}; struct Light {{ @@ -141,10 +145,10 @@ layout(std430, binding = 1) buffer readonly SceneInformation {{ vec4 options; vec4 camPos; mat4 vp, lightSpace; - mat4 spotLightSpaces[MAX_SPOT_LIGHTS]; - Material materials[MAX_MATERIALS]; - Light lights[MAX_LIGHTS]; - Probe probes[MAX_PROBES]; + mat4 spotLightSpaces[max_spot_lights]; + Material materials[max_materials]; + Light lights[max_lights]; + Probe probes[max_probes]; int numLights; }} scene; layout (binding = 2) uniform sampler2D sun_shadow; @@ -199,7 +203,7 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo format_to(std::back_inserter(src), R"(layout(location = 4) in vec4 fragPosLightSpace; layout(location = 5) in mat3 in_tbn; - layout(location = 14) in vec4 fragPostSpotLightSpace[MAX_SPOT_LIGHTS]; + layout(location = 14) in vec4 fragPostSpotLightSpace[max_spot_lights]; layout(location = 13) in flat int inMaterialIndex; #include "common.glsl" #include "rendering.glsl" @@ -348,7 +352,7 @@ ShaderSource MaterialCompiler::compile_material_fragment(Material& material, boo format_to(std::back_inserter(src), R"(vec3 ambient = vec3(0.0); float sum = 0.0; - for(int i = 0; i < MAX_PROBES; i++) {{ + for(int i = 0; i < max_probes; i++) {{ if(scene.probes[i].position.w == 1) {{ const vec3 position = scene.probes[i].position.xyz; const vec3 probe_min = position - (scene.probes[i].size.xyz / 2.0); diff --git a/engine/renderer/src/renderer.cpp b/engine/renderer/src/renderer.cpp index 9ff7620..35da550 100755 --- a/engine/renderer/src/renderer.cpp +++ b/engine/renderer/src/renderer.cpp @@ -211,39 +211,38 @@ void renderer::render(GFXCommandBuffer* commandbuffer, Scene* scene, RenderTarge commandbuffer->end_render_pass(); // begin auto exposure - if(render_options.tonemapping == TonemapOperator::AutoExposure) { - commandbuffer->set_compute_pipeline(histogram_pipeline); + + commandbuffer->set_compute_pipeline(histogram_pipeline); + + commandbuffer->bind_texture(target.offscreenColorTexture, 0); + commandbuffer->bind_shader_buffer(histogram_buffer, 0, 1, sizeof(uint32_t) * 256); + + const float lum_range = render_options.max_luminance - render_options.min_luminance; - commandbuffer->bind_texture(target.offscreenColorTexture, 0); - commandbuffer->bind_shader_buffer(histogram_buffer, 0, 1, sizeof(uint32_t) * 256); + prism::float4 params = prism::float4(render_options.min_luminance, + 1.0f / lum_range, + static_cast(render_extent.width), + static_cast(render_extent.height)); + + commandbuffer->set_push_constant(¶ms, sizeof(prism::float4)); + + commandbuffer->dispatch(static_cast(std::ceil(static_cast(render_extent.width) / 16.0f)), + static_cast(std::ceil(static_cast(render_extent.height) / 16.0f)), 1); + + commandbuffer->set_compute_pipeline(histogram_average_pipeline); - const float lum_range = render_options.max_luminance - render_options.min_luminance; + commandbuffer->bind_shader_buffer(histogram_buffer, 0, 1, sizeof(uint32_t) * 256); - prism::float4 params = prism::float4(render_options.min_luminance, - 1.0f / lum_range, - static_cast(render_extent.width), - static_cast(render_extent.height)); - - commandbuffer->set_push_constant(¶ms, sizeof(prism::float4)); - - commandbuffer->dispatch(static_cast(std::ceil(static_cast(render_extent.width) / 16.0f)), - static_cast(std::ceil(static_cast(render_extent.height) / 16.0f)), 1); - - commandbuffer->set_compute_pipeline(histogram_average_pipeline); - - commandbuffer->bind_shader_buffer(histogram_buffer, 0, 1, sizeof(uint32_t) * 256); - - params = prism::float4(render_options.min_luminance, - lum_range, - std::clamp(1.0f - std::exp(-(1.0f / 60.0f) * 1.1f), 0.0f, 1.0f), - static_cast(render_extent.width * render_extent.height)); - - commandbuffer->set_push_constant(¶ms, sizeof(prism::float4)); - - commandbuffer->bind_texture(average_luminance_texture, 0); - - commandbuffer->dispatch(1, 1, 1); - } + params = prism::float4(render_options.min_luminance, + lum_range, + std::clamp(1.0f - std::exp(-(1.0f / 60.0f) * 1.1f), 0.0f, 1.0f), + static_cast(render_extent.width * render_extent.height)); + + commandbuffer->set_push_constant(¶ms, sizeof(prism::float4)); + + commandbuffer->bind_texture(average_luminance_texture, 0); + + commandbuffer->dispatch(1, 1, 1); // continue post processing beginInfo.framebuffer = nullptr; diff --git a/engine/shadercompiler/src/shadercompiler.cpp b/engine/shadercompiler/src/shadercompiler.cpp index 7cf69fe..0c5a6be 100755 --- a/engine/shadercompiler/src/shadercompiler.cpp +++ b/engine/shadercompiler/src/shadercompiler.cpp @@ -8,7 +8,6 @@ #include "includer.hpp" #include "defaultresources.hpp" #include "spirv_hlsl.hpp" -#include "render_constants.hpp" static inline std::vector include_path; @@ -107,14 +106,6 @@ std::optional ShaderCompiler::compile(const ShaderLanguage from_la options.enable_wgpu_compat = to_language == ShaderLanguage::WGSL; - options.definitions.emplace_back("FILTER_SIZE " + std::to_string(512)); - options.definitions.emplace_back("DOF_WIDTH " + std::to_string(15)); - options.definitions.emplace_back("DOF_HEIGHT " + std::to_string(15)); - options.definitions.emplace_back("MAX_LIGHTS " + std::to_string(max_scene_lights)); - options.definitions.emplace_back("MAX_MATERIALS " + std::to_string(max_scene_materials)); - options.definitions.emplace_back("MAX_PROBES " + std::to_string(15)); - options.definitions.emplace_back("MAX_SPOT_LIGHTS " + std::to_string(max_spot_shadows)); - auto spirv = compile_glsl_to_spv(shader_source.as_string(), lang, options); if(spirv.empty()) { prism::log("SPIRV generation failed!"); diff --git a/engine/shaders/dof.vert.glsl b/engine/shaders/dof.vert.glsl index f2ca263..93c1745 100644 --- a/engine/shaders/dof.vert.glsl +++ b/engine/shaders/dof.vert.glsl @@ -1,3 +1,6 @@ +layout(constant_id = 0) const int width = 25; +layout(constant_id = 1) const int height = 25; + layout(location = 0) out vec2 outUV; layout(location = 1) out flat ivec2 outPixel; layout(location = 2) out float outDepth; @@ -11,10 +14,10 @@ layout(push_constant) uniform readonly PushConstant{ void main() { outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2); - ivec2 pixel = ivec2(gl_InstanceIndex % DOF_WIDTH, gl_InstanceIndex / DOF_WIDTH); + ivec2 pixel = ivec2(gl_InstanceIndex % width, gl_InstanceIndex / width); outPixel = pixel; - const float depth = texture(depth_sampler, vec2(pixel) / vec2(DOF_WIDTH, DOF_HEIGHT)).r; + const float depth = texture(depth_sampler, vec2(pixel) / vec2(width, height)).r; outDepth = depth; vec2 pos = vec2(outUV * 2.0 + -1.0); @@ -25,7 +28,7 @@ void main() { } pos += vec2(pixel.x, pixel.y); - pos *= 2.0 / vec2(DOF_WIDTH, DOF_HEIGHT); + pos *= 2.0 / vec2(width, height); pos += vec2(-1, -1); gl_Position = vec4(pos.x, pos.y, 0.0, 1.0); diff --git a/engine/shaders/filter.frag.glsl b/engine/shaders/filter.frag.glsl index 86ed83a..8ad675f 100644 --- a/engine/shaders/filter.frag.glsl +++ b/engine/shaders/filter.frag.glsl @@ -1,5 +1,7 @@ #include "common.nocompile.glsl" +layout (constant_id = 0) const int texture_size = 512; + layout(location = 0) in vec3 inPos; layout(location = 0) out vec4 outColor; @@ -35,7 +37,7 @@ void main() { const float HdotV = max(dot(H, V), 0.0); const float pdf = D * NdotH / (4.0 * HdotV) + 0.0001; - const float saTexel = 4.0 * PI / (6.0 * FILTER_SIZE * FILTER_SIZE); + const float saTexel = 4.0 * PI / (6.0 * texture_size * texture_size); const float saSample = 1.0 / (float(SAMPLE_COUNT) * pdf + 0.0001); const float mipLevel = roughness == 0.0 ? 0.0 : 0.5 * log2(saSample / saTexel); diff --git a/engine/shaders/mesh.vert.nocompile.glsl b/engine/shaders/mesh.vert.nocompile.glsl index 9476f68..f0bbaf3 100644 --- a/engine/shaders/mesh.vert.nocompile.glsl +++ b/engine/shaders/mesh.vert.nocompile.glsl @@ -1,3 +1,8 @@ +layout (constant_id = 0) const int max_materials = 25; +layout (constant_id = 1) const int max_lights = 25; +layout (constant_id = 2) const int max_spot_lights = 4; +layout (constant_id = 3) const int max_probes = 4; + layout (location = 0) in vec3 inPosition; layout (location = 1) in vec3 inNormal; layout (location = 2) in vec2 inUV; @@ -14,7 +19,7 @@ layout (location = 1) out vec3 outNormal; layout (location = 2) out vec2 outUV; layout (location = 4) out vec4 fragPosLightSpace; layout (location = 5) out mat3 outTBN; -layout (location = 14) out vec4 fragPostSpotLightSpace[MAX_SPOT_LIGHTS]; +layout (location = 14) out vec4 fragPostSpotLightSpace[max_spot_lights]; layout (location = 13) out flat int outMaterialIndex; struct Material { @@ -35,10 +40,10 @@ layout(std430, binding = 1) buffer readonly SceneInformation { vec4 options; vec4 camPos; mat4 vp, lightSpace; - mat4 spotLightSpaces[MAX_SPOT_LIGHTS]; - Material materials[MAX_MATERIALS]; - Light lights[MAX_LIGHTS]; - Probe probes[MAX_PROBES]; + mat4 spotLightSpaces[max_spot_lights]; + Material materials[max_materials]; + Light lights[max_lights]; + Probe probes[max_probes]; int numLights; } scene; @@ -88,7 +93,7 @@ void main() { outUV = inUV; fragPosLightSpace = (biasMat * scene.lightSpace) * bPos; - for(int i = 0; i < MAX_SPOT_LIGHTS; i++) { + for(int i = 0; i < max_spot_lights; i++) { fragPostSpotLightSpace[i] = (biasMat * scene.spotLightSpaces[i]) * bPos; } #else @@ -99,7 +104,7 @@ void main() { outUV = inUV; fragPosLightSpace = (biasMat * scene.lightSpace * model) * vec4(inPosition, 1.0); - for(int i = 0; i < MAX_SPOT_LIGHTS; i++) { + for(int i = 0; i < max_spot_lights; i++) { fragPostSpotLightSpace[i] = (biasMat * scene.spotLightSpaces[i] * model) * vec4(inPosition, 1.0); } #else @@ -110,7 +115,7 @@ void main() { outUV = inUV; fragPosLightSpace = (biasMat * scene.lightSpace * model) * vec4(inPosition, 1.0); - for(int i = 0; i < MAX_SPOT_LIGHTS; i++) { + for(int i = 0; i < max_spot_lights; i++) { fragPostSpotLightSpace[i] = (biasMat * scene.spotLightSpaces[i] * model) * vec4(inPosition, 1.0); } #endif diff --git a/engine/shaders/omnishadow.frag.glsl b/engine/shaders/omnishadow.frag.glsl index 045f311..309630b 100644 --- a/engine/shaders/omnishadow.frag.glsl +++ b/engine/shaders/omnishadow.frag.glsl @@ -1,10 +1,12 @@ +layout (constant_id = 0) const int max_lights = 25; + layout (location = 0) in vec3 inPos; layout (location = 1) flat in int index; layout (location = 0) out float outFragColor; layout(std430, binding = 2) buffer readonly LightInformation { - vec4 light_locations[MAX_LIGHTS]; + vec4 light_locations[max_lights]; }; void main() { diff --git a/engine/shaders/scenecapture.vert.nocompile.glsl b/engine/shaders/scenecapture.vert.nocompile.glsl index 7f4a9c0..6d7451b 100644 --- a/engine/shaders/scenecapture.vert.nocompile.glsl +++ b/engine/shaders/scenecapture.vert.nocompile.glsl @@ -1,3 +1,7 @@ +layout (constant_id = 0) const int max_materials = 25; +layout (constant_id = 1) const int max_lights = 25; +layout (constant_id = 2) const int max_spot_lights = 4; + layout (location = 0) in vec3 inPosition; layout (location = 1) in vec3 inNormal; layout (location = 2) in vec2 inUV; @@ -23,9 +27,9 @@ layout(std430, binding = 5) buffer readonly SceneInformation { vec4 camPos; mat4 projection, lightSpace; vec4 skyColor; - mat4 spotLightSpaces[MAX_SPOT_LIGHTS]; - Material materials[MAX_MATERIALS]; - Light lights[MAX_LIGHTS]; + mat4 spotLightSpaces[max_spot_lights]; + Material materials[max_materials]; + Light lights[max_lights]; int numLights; } scene; diff --git a/engine/shaders/shadow.vert.nocompile.glsl b/engine/shaders/shadow.vert.nocompile.glsl index 66489ac..25ecb7a 100644 --- a/engine/shaders/shadow.vert.nocompile.glsl +++ b/engine/shaders/shadow.vert.nocompile.glsl @@ -1,3 +1,5 @@ +layout (constant_id = 0) const int max_lights = 25; + layout (location = 0) in vec3 inPosition; #ifdef BONE @@ -19,7 +21,7 @@ layout(std430, binding = 14) buffer readonly BoneInformation { #endif layout(std430, binding = 2) buffer readonly LightInformation { - vec4 light_locations[MAX_LIGHTS]; + vec4 light_locations[max_lights]; }; void main() { diff --git a/engine/utility/include/render_constants.hpp b/engine/utility/include/render_constants.hpp deleted file mode 100644 index d95a4eb..0000000 --- a/engine/utility/include/render_constants.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -constexpr int max_scene_materials = 25, max_scene_lights = 25; -const int max_spot_shadows = 4; -const int max_point_shadows = 4; -const int max_environment_probes = 4;