From 3eeda2007bd17d898a8ab313053f37b1f88ade05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Sat, 8 Feb 2025 10:25:21 -0500 Subject: [PATCH] gfx: various small fixes, better handle when a shader does not have a material ubo --- .../3rdparty/libisf/src/isf.cpp | 17 ++++--- .../Gfx/GeometryFilter/Process.cpp | 3 +- .../score-plugin-gfx/Gfx/Graph/CommonUBOs.hpp | 2 +- .../ModelDisplay/ModelDisplayNode.cpp | 50 +++++++++++-------- 4 files changed, 41 insertions(+), 31 deletions(-) diff --git a/src/plugins/score-plugin-gfx/3rdparty/libisf/src/isf.cpp b/src/plugins/score-plugin-gfx/3rdparty/libisf/src/isf.cpp index 398262cbf6..d57a0e6aae 100644 --- a/src/plugins/score-plugin-gfx/3rdparty/libisf/src/isf.cpp +++ b/src/plugins/score-plugin-gfx/3rdparty/libisf/src/isf.cpp @@ -886,7 +886,7 @@ void parser::parse_isf() // Setup the parameters UBOs std::string material_ubos = GLSL45.defaultUniforms; - int binding = 3; + int sampler_binding = 3; if(!d.inputs.empty() || !d.pass_targets.empty()) { @@ -900,7 +900,7 @@ void parser::parse_isf() if(isSampler) { samplers += "layout(binding = "; - samplers += std::to_string(binding); + samplers += std::to_string(sampler_binding); samplers += ") "; samplers += type; samplers += ' '; @@ -910,10 +910,13 @@ void parser::parse_isf() auto imgRect_varname = "_" + val.name + "_imgRect"; material_ubos += "vec4 " + imgRect_varname + ";\n"; // See comment above regarding little dance to make spirv-cross happy - globalvars += "vec4 " + imgRect_varname + " = isf_material_uniforms." - + imgRect_varname + ";\n"; + globalvars += "vec4 "; + globalvars += imgRect_varname; + globalvars += " = isf_material_uniforms."; + globalvars += imgRect_varname; + globalvars += ";\n"; - binding++; + sampler_binding++; } else { @@ -935,14 +938,14 @@ void parser::parse_isf() for(const std::string& target : d.pass_targets) { samplers += "layout(binding = "; - samplers += std::to_string(binding); + samplers += std::to_string(sampler_binding); samplers += ") uniform sampler2D "; samplers += target; samplers += ";\n"; material_ubos += "vec4 _" + target + "_imgRect;\n"; - binding++; + sampler_binding++; } material_ubos += "} isf_material_uniforms;\n"; diff --git a/src/plugins/score-plugin-gfx/Gfx/GeometryFilter/Process.cpp b/src/plugins/score-plugin-gfx/Gfx/GeometryFilter/Process.cpp index e86d73edf8..c39b4af6c9 100644 --- a/src/plugins/score-plugin-gfx/Gfx/GeometryFilter/Process.cpp +++ b/src/plugins/score-plugin-gfx/Gfx/GeometryFilter/Process.cpp @@ -60,9 +60,10 @@ layout(std140, binding = 1) uniform process_t { int PASSINDEX; int FRAMEINDEX; + vec2 RENDERSIZE; vec4 DATE; vec4 MOUSE; - vec4 CHANNELTIME; + vec4 CHANNEL_TIME; float SAMPLERATE; } isf_process_uniforms; diff --git a/src/plugins/score-plugin-gfx/Gfx/Graph/CommonUBOs.hpp b/src/plugins/score-plugin-gfx/Gfx/Graph/CommonUBOs.hpp index a386bb4c55..2e7a91f927 100644 --- a/src/plugins/score-plugin-gfx/Gfx/Graph/CommonUBOs.hpp +++ b/src/plugins/score-plugin-gfx/Gfx/Graph/CommonUBOs.hpp @@ -18,7 +18,7 @@ struct ProcessUBO int32_t frameIndex{}; float padding0[1]; - float renderSize[2]{}; + float renderSize[2]{2048, 2048}; float date[4]{0.f, 0.f, 0.f, 0.f}; float mouse[4]{0.5f, 0.5f, 0.5f, 0.5f}; float channelTime[4]{0.5f, 0.5f, 0.5f, 0.5f}; diff --git a/src/plugins/score-plugin-threedim/Threedim/ModelDisplay/ModelDisplayNode.cpp b/src/plugins/score-plugin-threedim/Threedim/ModelDisplay/ModelDisplayNode.cpp index dd70affdbe..3b0692dfef 100644 --- a/src/plugins/score-plugin-threedim/Threedim/ModelDisplay/ModelDisplayNode.cpp +++ b/src/plugins/score-plugin-threedim/Threedim/ModelDisplay/ModelDisplayNode.cpp @@ -30,6 +30,7 @@ layout(std140, binding = 0) uniform renderer_t { \n\ vec2 renderSize; \n\ } renderer; \n\ \n\ +mat4 clipSpaceCorrMatrix = renderer.clipSpaceCorrMatrix; \n\ // Time-dependent uniforms, only relevant during execution \n\ layout(std140, binding = 1) uniform process_t { \n\ float TIME; \n\ @@ -39,29 +40,32 @@ layout(std140, binding = 1) uniform process_t { \n\ int PASSINDEX; \n\ int FRAMEINDEX; \n\ \n\ + vec2 RENDERSIZE; \n\ vec4 DATE; \n\ vec4 MOUSE; \n\ - vec4 CHANNELTIME; \n\ + vec4 CHANNEL_TIME; \n\ \n\ float SAMPLERATE; \n\ } isf_process_uniforms; \n\ \n\ -layout(std140, binding = 2) uniform material_t { \n\ - mat4 matrixModelViewProjection; \n\ - mat4 matrixModelView; \n\ - mat4 matrixModel; \n\ - mat4 matrixView; \n\ - mat4 matrixProjection; \n\ - mat3 matrixNormal; \n\ - float fov; \n\ -} mat; \n\ - \n\ float TIME = isf_process_uniforms.TIME; \n\ float TIMEDELTA = isf_process_uniforms.TIMEDELTA; \n\ float PROGRESS = isf_process_uniforms.PROGRESS; \n\ int PASSINDEX = isf_process_uniforms.PASSINDEX; \n\ int FRAMEINDEX = isf_process_uniforms.FRAMEINDEX; \n\ +vec2 RENDERSIZE = isf_process_uniforms.RENDERSIZE; \n\ vec4 DATE = isf_process_uniforms.DATE; \n\ +\n\ +layout(std140, binding = 2) uniform camera_t { \n\ + mat4 matrixModelViewProjection; \n\ + mat4 matrixModelView; \n\ + mat4 matrixModel; \n\ + mat4 matrixView; \n\ + mat4 matrixProjection; \n\ + mat3 matrixNormal; \n\ + float fov; \n\ +} camera; \n\ + \n\ " const constexpr auto vtx_output_triangle = R"_( @@ -77,12 +81,12 @@ float gl_PointSize; )_"; const constexpr auto vtx_projection_perspective = R"_( -vec4 v_projected = mat.matrixModelViewProjection * vec4(in_position.xyz, 1.0); +vec4 v_projected = camera.matrixModelViewProjection * vec4(in_position.xyz, 1.0); )_"; const constexpr auto vtx_projection_fulldome = R"_( vec4 v_projected = vec4(1.0); { - vec4 viewspace = mat.matrixModelView * vec4(in_position.xzy, 1.0); + vec4 viewspace = camera.matrixModelView * vec4(in_position.xzy, 1.0); // Code from Emmanuel Durand: // https://emmanueldurand.net/spherical_projection/ // - inlined as another function injected could be called toSphere or do #define pi. yay GLSL... @@ -96,7 +100,7 @@ vec4 v_projected = vec4(1.0); float second = asin(clamp(val, -1.0, 1.0)); float phi = mix(2.0 * 3.14159265358979323846264338327 - first, first, second >= 0.0); - const float proj_ratio = 3.14159265358979323846264338327 / (360.0 / mat.fov); + const float proj_ratio = 3.14159265358979323846264338327 / (360.0 / camera.fov); v_projected.x = theta * cos(phi); v_projected.y = theta * sin(phi); v_projected.y /= proj_ratio; @@ -277,7 +281,7 @@ void main() %vtx_do_filters% v_normal = in_normal; - v_coords = (mat.matrixModel * vec4(in_position.xyz, 1.0)).xyz; + v_coords = (camera.matrixModel * vec4(in_position.xyz, 1.0)).xyz; %vtx_do_projection% @@ -342,8 +346,8 @@ void main() // https://www.clicktorelease.com/blog/creating-spherical-environment-mapping-shader.html vec4 p = vec4( in_position, 1. ); - v_e = normalize( vec3( mat.matrixModelView * p ) ); - v_n = normal; //normalize( mat.matrixNormal * in_normal ); + v_e = normalize( vec3( camera.matrixModelView * p ) ); + v_n = normal; //normalize( camera.matrixNormal * in_normal ); %vtx_do_projection% @@ -397,8 +401,8 @@ void main() // https://www.clicktorelease.com/blog/creating-spherical-environment-mapping-shader.html vec4 p = vec4( in_position, 1. ); - v_e = normalize( vec3( mat.matrixModelView * p ) ); - v_n = normalize( mat.matrixNormal * in_normal ); + v_e = normalize( vec3( camera.matrixModelView * p ) ); + v_n = normalize( camera.matrixNormal * in_normal ); %vtx_do_projection% @@ -635,9 +639,11 @@ class ModelDisplayNode::Renderer : public GenericNodeRenderer { if (auto c = safe_cast(n)) { - additional_bindings.push_back(QRhiShaderResourceBinding::uniformBuffer( - cur_binding, QRhiShaderResourceBinding::VertexStage, c->material())); - + if(auto mat = c->material()) + { + additional_bindings.push_back(QRhiShaderResourceBinding::uniformBuffer( + cur_binding, QRhiShaderResourceBinding::VertexStage, mat)); + } cur_binding++; break; }