Skip to content

Commit

Permalink
gfx: various small fixes, better handle when a shader does not have a…
Browse files Browse the repository at this point in the history
… material ubo
  • Loading branch information
jcelerier committed Feb 8, 2025
1 parent eefeb6d commit 3eeda20
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 31 deletions.
17 changes: 10 additions & 7 deletions src/plugins/score-plugin-gfx/3rdparty/libisf/src/isf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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 += ' ';
Expand All @@ -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
{
Expand All @@ -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";
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/score-plugin-gfx/Gfx/GeometryFilter/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/score-plugin-gfx/Gfx/Graph/CommonUBOs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand All @@ -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"_(
Expand All @@ -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...
Expand All @@ -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;
Expand Down Expand Up @@ -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%
Expand Down Expand Up @@ -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%
Expand Down Expand Up @@ -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%
Expand Down Expand Up @@ -635,9 +639,11 @@ class ModelDisplayNode::Renderer : public GenericNodeRenderer
{
if (auto c = safe_cast<score::gfx::GeometryFilterNodeRenderer*>(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;
}
Expand Down

0 comments on commit 3eeda20

Please sign in to comment.