diff --git a/engine/core/include/scene.hpp b/engine/core/include/scene.hpp index e9b05a7..ecef2b7 100755 --- a/engine/core/include/scene.hpp +++ b/engine/core/include/scene.hpp @@ -7,6 +7,7 @@ #include "object.hpp" #include "components.hpp" #include "utility.hpp" +#include "render_constants.hpp" template using Pool = std::unordered_map; @@ -193,10 +194,6 @@ 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 7a5a9ee..50eace7 100755 --- a/engine/gfx/webgpu/include/gfx_webgpu.hpp +++ b/engine/gfx/webgpu/include/gfx_webgpu.hpp @@ -12,6 +12,7 @@ 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 f24d269..7a17226 100755 --- a/engine/gfx/webgpu/src/gfx_webgpu.cpp +++ b/engine/gfx/webgpu/src/gfx_webgpu.cpp @@ -196,10 +196,23 @@ 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); @@ -242,6 +255,7 @@ 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; @@ -260,6 +274,17 @@ 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; } @@ -278,6 +303,10 @@ 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; } @@ -296,8 +325,10 @@ 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 = info.label.c_str(); + descriptor.label = pipeline->label.c_str(); const bool has_vertex_stage = !info.shaders.vertex_src.empty(); if (has_vertex_stage) { @@ -309,7 +340,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.spv"), true); + auto vertex_shader = prism::open_file(prism::internal_domain / (info.shaders.vertex_src.as_path().string() + ".wgsl"), 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()); @@ -317,6 +348,7 @@ 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) { @@ -330,13 +362,15 @@ 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.spv"), true); + auto fragment_shader = prism::open_file(prism::internal_domain / (info.shaders.fragment_src.as_path().string() + ".wgsl"), 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("--------"); @@ -400,7 +434,6 @@ GFXPipeline* GFXWebGPU::create_graphics_pipeline(const GFXGraphicsPipelineCreate break; } - descriptor.primitive.stripIndexFormat = WGPUIndexFormat_Uint16; descriptor.primitive.topology = WGPUPrimitiveTopology_TriangleList; // create bind group layout @@ -416,9 +449,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: { @@ -439,6 +472,8 @@ 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(); @@ -465,15 +500,20 @@ 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.spv"), true); + auto compute_shader = prism::open_file(prism::internal_domain / (info.compute_src.as_path().string() + ".wgsl"), 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; } @@ -579,17 +619,18 @@ void GFXWebGPU::submit(GFXCommandBuffer* command_buffer, const platform::window_ if(current_pipeline == nullptr) return false; - if(last_bind_group_hash != get_bind_group_hash(current_pipeline)) { - if(!current_pipeline->cached_bind_groups.count(get_bind_group_hash(current_pipeline))) + const uint64_t hash = get_bind_group_hash(current_pipeline); + if(last_bind_group_hash != hash) { + if(!current_pipeline->cached_bind_groups.count(hash)) cache_bind_group_state(current_pipeline, current_pipeline->bind_group_layout); - auto& bind_group = current_pipeline->cached_bind_groups[get_bind_group_hash(current_pipeline)]; + auto bind_group = current_pipeline->cached_bind_groups[hash]; if(bind_group == nullptr) return false; wgpuRenderPassEncoderSetBindGroup(render_encoder, 0, bind_group, 0, nullptr); - last_bind_group_hash = get_bind_group_hash(current_pipeline); + last_bind_group_hash = hash; } return true; @@ -831,14 +872,18 @@ uint64_t GFXWebGPU::get_bind_group_hash(GFXWebGPUPipeline *pipeline) { } void GFXWebGPU::cache_bind_group_state(GFXWebGPUPipeline* pipeline, WGPUBindGroupLayout group_layout) { - uint64_t hash = get_bind_group_hash(pipeline); + const 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; @@ -853,9 +898,10 @@ 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); @@ -866,6 +912,8 @@ 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; @@ -874,10 +922,15 @@ 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); } @@ -892,3 +945,7 @@ 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 6519867..80d6c38 100644 --- a/engine/gfx/webgpu/src/gfx_webgpu_pipeline.hpp +++ b/engine/gfx/webgpu/src/gfx_webgpu_pipeline.hpp @@ -6,6 +6,8 @@ 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 5c9dfc0..cd95c20 100644 --- a/engine/gfx/webgpu/src/gfx_webgpu_texture.hpp +++ b/engine/gfx/webgpu/src/gfx_webgpu_texture.hpp @@ -7,5 +7,4 @@ 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 af2c10b..2608a8a 100755 --- a/engine/renderer/include/materialcompiler.hpp +++ b/engine/renderer/include/materialcompiler.hpp @@ -6,12 +6,12 @@ class Material; -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; +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; class MaterialCompiler { public: diff --git a/engine/renderer/include/renderer.hpp b/engine/renderer/include/renderer.hpp index b03f3cc..9b13396 100755 --- a/engine/renderer/include/renderer.hpp +++ b/engine/renderer/include/renderer.hpp @@ -31,8 +31,6 @@ 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 f358c7a..21c7a10 100755 --- a/engine/renderer/src/materialcompiler.cpp +++ b/engine/renderer/src/materialcompiler.cpp @@ -125,11 +125,7 @@ std::tuple MaterialCompiler::create_pipeline_permuta } constexpr std::string_view struct_info = -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 {{ +R"(struct Material {{ vec4 color, info; }}; struct Light {{ @@ -145,10 +141,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 texture2D sun_shadow; @@ -204,7 +200,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" @@ -353,7 +349,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 e451ac0..bb306c4 100755 --- a/engine/renderer/src/renderer.cpp +++ b/engine/renderer/src/renderer.cpp @@ -215,38 +215,39 @@ void renderer::render(GFXCommandBuffer* commandbuffer, Scene* scene, RenderTarge commandbuffer->end_render_pass(); // begin auto exposure - - 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; + if(render_options.tonemapping == TonemapOperator::AutoExposure) { + commandbuffer->set_compute_pipeline(histogram_pipeline); - 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_texture(target.offscreenColorTexture, 0); + commandbuffer->bind_shader_buffer(histogram_buffer, 0, 1, sizeof(uint32_t) * 256); - commandbuffer->bind_shader_buffer(histogram_buffer, 0, 1, sizeof(uint32_t) * 256); + const float lum_range = render_options.max_luminance - render_options.min_luminance; - 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); + 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); + } // continue post processing beginInfo.framebuffer = nullptr; diff --git a/engine/shadercompiler/src/shadercompiler.cpp b/engine/shadercompiler/src/shadercompiler.cpp index 0c5a6be..7cf69fe 100755 --- a/engine/shadercompiler/src/shadercompiler.cpp +++ b/engine/shadercompiler/src/shadercompiler.cpp @@ -8,6 +8,7 @@ #include "includer.hpp" #include "defaultresources.hpp" #include "spirv_hlsl.hpp" +#include "render_constants.hpp" static inline std::vector include_path; @@ -106,6 +107,14 @@ 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 93c1745..f2ca263 100644 --- a/engine/shaders/dof.vert.glsl +++ b/engine/shaders/dof.vert.glsl @@ -1,6 +1,3 @@ -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; @@ -14,10 +11,10 @@ layout(push_constant) uniform readonly PushConstant{ void main() { outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2); - ivec2 pixel = ivec2(gl_InstanceIndex % width, gl_InstanceIndex / width); + ivec2 pixel = ivec2(gl_InstanceIndex % DOF_WIDTH, gl_InstanceIndex / DOF_WIDTH); outPixel = pixel; - const float depth = texture(depth_sampler, vec2(pixel) / vec2(width, height)).r; + const float depth = texture(depth_sampler, vec2(pixel) / vec2(DOF_WIDTH, DOF_HEIGHT)).r; outDepth = depth; vec2 pos = vec2(outUV * 2.0 + -1.0); @@ -28,7 +25,7 @@ void main() { } pos += vec2(pixel.x, pixel.y); - pos *= 2.0 / vec2(width, height); + pos *= 2.0 / vec2(DOF_WIDTH, DOF_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 8ad675f..86ed83a 100644 --- a/engine/shaders/filter.frag.glsl +++ b/engine/shaders/filter.frag.glsl @@ -1,7 +1,5 @@ #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; @@ -37,7 +35,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 * texture_size * texture_size); + const float saTexel = 4.0 * PI / (6.0 * FILTER_SIZE * FILTER_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 f0bbaf3..9476f68 100644 --- a/engine/shaders/mesh.vert.nocompile.glsl +++ b/engine/shaders/mesh.vert.nocompile.glsl @@ -1,8 +1,3 @@ -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; @@ -19,7 +14,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 { @@ -40,10 +35,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; @@ -93,7 +88,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 @@ -104,7 +99,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 @@ -115,7 +110,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 309630b..045f311 100644 --- a/engine/shaders/omnishadow.frag.glsl +++ b/engine/shaders/omnishadow.frag.glsl @@ -1,12 +1,10 @@ -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 6d7451b..7f4a9c0 100644 --- a/engine/shaders/scenecapture.vert.nocompile.glsl +++ b/engine/shaders/scenecapture.vert.nocompile.glsl @@ -1,7 +1,3 @@ -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; @@ -27,9 +23,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 25ecb7a..66489ac 100644 --- a/engine/shaders/shadow.vert.nocompile.glsl +++ b/engine/shaders/shadow.vert.nocompile.glsl @@ -1,5 +1,3 @@ -layout (constant_id = 0) const int max_lights = 25; - layout (location = 0) in vec3 inPosition; #ifdef BONE @@ -21,7 +19,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 new file mode 100644 index 0000000..d95a4eb --- /dev/null +++ b/engine/utility/include/render_constants.hpp @@ -0,0 +1,6 @@ +#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;