Skip to content

Commit

Permalink
[shaders] Implement more use cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Nov 14, 2024
1 parent 5ca4e64 commit df66774
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 23 deletions.
128 changes: 111 additions & 17 deletions Threedim/ModelDisplay/ModelDisplayNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,24 @@ layout(std140, binding = 2) uniform material_t {
layout(binding = 3) uniform sampler2D y_tex;
%vtx_define_filters%
%vtx_output%
void main()
{
esVertex = position;
esNormal = normal;
v_texcoord = texcoord;
gl_Position = renderer.clipSpaceCorrMatrix * mat.matrixModelViewProjection * vec4(position.xyz, 1.0);
vec3 in_position = position;
vec3 in_normal = normal;
vec2 in_uv = texcoord;
vec3 in_tangent = vec3(0);
vec4 in_color = vec4(1);
%vtx_do_filters%
esVertex = in_position;
esNormal = in_normal;
v_texcoord = in_uv;
gl_Position = renderer.clipSpaceCorrMatrix * mat.matrixModelViewProjection * vec4(in_position.xyz, 1.0);
%vtx_output_process%
}
Expand Down Expand Up @@ -175,12 +185,22 @@ layout(std140, binding = 2) uniform material_t {
layout(binding = 3) uniform sampler2D y_tex;
%vtx_define_filters%
%vtx_output%
void main()
{
v_texcoord = texcoord;
gl_Position = renderer.clipSpaceCorrMatrix * mat.matrixModelViewProjection * vec4(position.xyz, 1.0);
vec3 in_position = position;
vec3 in_normal = vec3(0);
vec2 in_uv = texcoord;
vec3 in_tangent = vec3(0);
vec4 in_color = vec4(1);
%vtx_do_filters%
v_texcoord = in_uv;
gl_Position = renderer.clipSpaceCorrMatrix * mat.matrixModelViewProjection * vec4(in_position.xyz, 1.0);
%vtx_output_process%
}
)_";
Expand Down Expand Up @@ -238,13 +258,23 @@ layout(std140, binding = 2) uniform material_t {
layout(binding = 3) uniform sampler2D y_tex;
%vtx_define_filters%
%vtx_output%
void main()
{
v_normal = normal;
v_coords = (mat.matrixModel * vec4(position.xyz, 1.0)).xyz;
gl_Position = renderer.clipSpaceCorrMatrix * mat.matrixModelViewProjection * vec4(position.xyz, 1.0);
vec3 in_position = position;
vec3 in_normal = normal;
vec2 in_uv = vec2(0);
vec3 in_tangent = vec3(0);
vec4 in_color = vec4(1);
%vtx_do_filters%
v_normal = in_normal;
v_coords = (mat.matrixModel * vec4(in_position.xyz, 1.0)).xyz;
gl_Position = renderer.clipSpaceCorrMatrix * mat.matrixModelViewProjection * vec4(in_position.xyz, 1.0);
%vtx_output_process%
}
)_";
Expand Down Expand Up @@ -311,14 +341,25 @@ layout(std140, binding = 2) uniform material_t {
layout(binding = 3) uniform sampler2D y_tex;
%vtx_define_filters%
%vtx_output%
void main()
{
vec3 in_position = position;
vec3 in_normal = normal;
vec2 in_uv = vec2(0);
vec3 in_tangent = vec3(0);
vec4 in_color = vec4(1);
%vtx_do_filters%
// https://www.clicktorelease.com/blog/creating-spherical-environment-mapping-shader.html
vec4 p = vec4( position, 1. );
vec4 p = vec4( in_position, 1. );
v_e = normalize( vec3( mat.matrixModelView * p ) );
v_n = normal; //normalize( mat.matrixNormal * normal );
gl_Position = renderer.clipSpaceCorrMatrix * mat.matrixModelViewProjection * vec4(position.xyz, 1.0);
v_n = normal; //normalize( mat.matrixNormal * in_normal );
gl_Position = renderer.clipSpaceCorrMatrix * mat.matrixModelViewProjection * vec4(in_position.xyz, 1.0);
%vtx_output_process%
}
)_";
Expand Down Expand Up @@ -381,19 +422,31 @@ layout(std140, binding = 2) uniform material_t {
layout(binding = 3) uniform sampler2D y_tex;
%vtx_define_filters%
%vtx_output%
float atan2(in float y, in float x)
{
bool s = (abs(x) > abs(y));
return mix(3.141596/2.0 - atan(x,y), atan(y,x), s);
}
void main()
{
vec3 in_position = position;
vec3 in_normal = normal;
vec2 in_uv = vec2(0);
vec3 in_tangent = vec3(0);
vec4 in_color = vec4(1);
%vtx_do_filters%
// https://www.clicktorelease.com/blog/creating-spherical-environment-mapping-shader.html
vec4 p = vec4( position, 1. );
vec4 p = vec4( in_position, 1. );
v_e = normalize( vec3( mat.matrixModelView * p ) );
v_n = normalize( mat.matrixNormal * normal );
gl_Position = renderer.clipSpaceCorrMatrix * mat.matrixModelViewProjection * vec4(position.xyz, 1.0);
v_n = normalize( mat.matrixNormal * in_normal );
gl_Position = renderer.clipSpaceCorrMatrix * mat.matrixModelViewProjection * vec4(in_position.xyz, 1.0);
%vtx_output_process%
}
)_";
Expand Down Expand Up @@ -447,11 +500,21 @@ layout(std140, binding = 2) uniform material_t {
layout(binding = 3) uniform sampler2D y_tex;
%vtx_define_filters%
%vtx_output%
void main()
{
gl_Position = renderer.clipSpaceCorrMatrix * mat.matrixModelViewProjection * vec4(position.xyz, 1.0);
vec3 in_position = position;
vec3 in_normal = vec3(0);
vec2 in_uv = vec2(0);
vec3 in_tangent = vec3(0);
vec4 in_color = vec4(1);
%vtx_do_filters%
gl_Position = renderer.clipSpaceCorrMatrix * mat.matrixModelViewProjection * vec4(in_position.xyz, 1.0);
%vtx_output_process%
}
)_";
Expand Down Expand Up @@ -502,15 +565,25 @@ layout(std140, binding = 2) uniform material_t {
layout(binding = 3) uniform sampler2D y_tex;
%vtx_define_filters%
%vtx_output%
void main()
{
vec3 in_position = position;
vec3 in_normal = vec3(0);
vec2 in_uv = vec2(0);
vec3 in_tangent = vec3(0);
vec4 in_color = vec4(1);
%vtx_do_filters%
if(gl_VertexIndex % 3 == 0) v_bary = vec2(0, 0);
else if(gl_VertexIndex % 3 == 1) v_bary = vec2(0, 1);
else if(gl_VertexIndex % 3 == 2) v_bary = vec2(1, 0);
gl_Position = renderer.clipSpaceCorrMatrix * mat.matrixModelViewProjection * vec4(position.xyz, 1.0);
gl_Position = renderer.clipSpaceCorrMatrix * mat.matrixModelViewProjection * vec4(in_position.xyz, 1.0);
%vtx_output_process%
}
)_";
Expand Down Expand Up @@ -882,9 +955,30 @@ class ModelDisplayNode::Renderer : public GenericNodeRenderer
{
case 0:
initPasses_impl(renderer, mesh, triangle);
for (auto& [e, pass] : this->m_p)
{
pass.pipeline->destroy();
pass.pipeline->setTopology(QRhiGraphicsPipeline::Triangles);
pass.pipeline->create();
}
break;
case 1:
initPasses_impl(renderer, mesh, point);
for (auto& [e, pass] : this->m_p)
{
pass.pipeline->destroy();
pass.pipeline->setTopology(QRhiGraphicsPipeline::Points);
pass.pipeline->create();
}
break;
case 2:
initPasses_impl(renderer, mesh, triangle);
for (auto& [e, pass] : this->m_p)
{
pass.pipeline->destroy();
pass.pipeline->setTopology(QRhiGraphicsPipeline::Lines);
pass.pipeline->create();
}
break;
}
}
Expand Down
11 changes: 6 additions & 5 deletions Threedim/ModelDisplay/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ Model::Model(
m_inlets.push_back(new GeometryInlet{Id<Process::Port>(1), this});

m_inlets.push_back(new Process::XYZSpinboxes{
ossia::vec3f{-1000., -1000., -1000.},
ossia::vec3f{1000., 1000., 1000.},
ossia::vec3f{},
ossia::vec3f{-10000., -10000., -10000.},
ossia::vec3f{10000., 10000., 10000.},
ossia::vec3f{-1., -1., -1.},
"Position",
Id<Process::Port>(2),
this});
m_inlets.push_back(new Process::XYZSpinboxes{
ossia::vec3f{-1000., -1000., -1000.},
ossia::vec3f{1000., 1000., 1000.},
ossia::vec3f{-10000., -10000., -10000.},
ossia::vec3f{10000., 10000., 10000.},
ossia::vec3f{},
"Center",
Id<Process::Port>(3),
Expand Down Expand Up @@ -63,6 +63,7 @@ Model::Model(
std::vector<std::pair<QString, ossia::value>> modes{
{"Triangles", 0},
{"Points", 1},
{"Lines", 2},
};

m_inlets.push_back(
Expand Down
2 changes: 1 addition & 1 deletion Threedim/ObjLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ObjLoader
{
struct obj_t : halp::file_port<"3D file">
{
halp_meta(extensions, "*.obj, *.ply");
halp_meta(extensions, "3D files (*.obj *.ply)");
static std::function<void(ObjLoader&)> process(file_type data);
} obj;
PositionControl position;
Expand Down

0 comments on commit df66774

Please sign in to comment.