Add imGui shaders

Signed-off-by: renderexpert <expert@renderconsulting.co.uk>
This commit is contained in:
renderexpert 2025-01-10 20:03:39 +00:00 committed by Konstantin Pastbin
parent 466b9365f6
commit a54f5268cd
16 changed files with 114 additions and 1 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

10
shaders/GL/imgui.fsh.glsl Normal file
View file

@ -0,0 +1,10 @@
varying vec2 v_texCoords;
varying vec4 v_color;
uniform sampler2D u_colorTex;
void main()
{
LOW_P vec4 color = texture2D(u_colorTex, v_texCoords);
gl_FragColor = color * v_color;
}

19
shaders/GL/imgui.vsh.glsl Normal file
View file

@ -0,0 +1,19 @@
attribute vec2 a_position;
attribute vec2 a_texCoords;
attribute vec4 a_color;
varying vec2 v_texCoords;
varying vec4 v_color;
uniform mat4 u_projection;
void main()
{
v_texCoords = a_texCoords;
v_color = a_color;
gl_Position = vec4(a_position, 0, 1) * u_projection;
#ifdef VULKAN
gl_Position.y = -gl_Position.y;
gl_Position.z = (gl_Position.z + gl_Position.w) * 0.5;
#endif
}

View file

@ -53,3 +53,4 @@ TrafficCircle traffic_circle.vsh.glsl traffic_circle.fsh.glsl
SmaaEdges smaa_edges.vsh.glsl smaa_edges.fsh.glsl SmaaEdges smaa_edges.vsh.glsl smaa_edges.fsh.glsl
SmaaBlendingWeight smaa_blending_weight.vsh.glsl smaa_blending_weight.fsh.glsl SmaaBlendingWeight smaa_blending_weight.vsh.glsl smaa_blending_weight.fsh.glsl
SmaaFinal smaa_final.vsh.glsl smaa_final.fsh.glsl SmaaFinal smaa_final.vsh.glsl smaa_final.fsh.glsl
ImGui imgui.vsh.glsl imgui.fsh.glsl

39
shaders/Metal/imgui.metal Normal file
View file

@ -0,0 +1,39 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
typedef struct
{
float2 a_position [[attribute(0)]];
float2 a_texCoords [[attribute(1)]];
float4 a_color [[attribute(2)]];
} Vertex_T;
typedef struct
{
float4 position [[position]];
float2 texCoords;
float4 color;
} Fragment_T;
typedef struct
{
float4x4 u_projection;
} Uniforms_T;
vertex Fragment_T vsImGui(const Vertex_T in [[stage_in]],
constant Uniforms_T & uniforms [[buffer(1)]])
{
Fragment_T out;
out.position = float4(in.a_position, 0.0, 1.0) * uniforms.u_projection;
out.texCoords = in.a_texCoords;
out.color = in.a_color;
return out;
}
fragment float4 fsImGui(const Fragment_T in [[stage_in]],
texture2d<float> u_colorTex [[texture(0)]],
sampler u_colorTexSampler [[sampler(0)]])
{
return in.color * u_colorTex.sample(u_colorTexSampler, in.texCoords);
}

View file

@ -230,4 +230,14 @@ void GLProgramParamsSetter::Apply(ref_ptr<dp::GraphicsContext> context,
Parameter::CheckApply(guard, "u_framebufferMetrics", params.m_framebufferMetrics); Parameter::CheckApply(guard, "u_framebufferMetrics", params.m_framebufferMetrics);
} }
void GLProgramParamsSetter::Apply(ref_ptr<dp::GraphicsContext> context,
ref_ptr<dp::GpuProgram> program,
ImGuiProgramParams const & params)
{
UNUSED_VALUE(context);
UniformsGuard guard(program, params);
Parameter::CheckApply(guard, "u_projection", params.m_projection);
}
} // namespace gpu } // namespace gpu

View file

@ -29,5 +29,7 @@ public:
ref_ptr<dp::GpuProgram> program, ScreenQuadProgramParams const & params) override; ref_ptr<dp::GpuProgram> program, ScreenQuadProgramParams const & params) override;
void Apply(ref_ptr<dp::GraphicsContext> context, void Apply(ref_ptr<dp::GraphicsContext> context,
ref_ptr<dp::GpuProgram> program, SMAAProgramParams const & params) override; ref_ptr<dp::GpuProgram> program, SMAAProgramParams const & params) override;
void Apply(ref_ptr<dp::GraphicsContext> context,
ref_ptr<dp::GpuProgram> program, ImGuiProgramParams const & params) override;
}; };
} // namespace gpu } // namespace gpu

View file

@ -31,6 +31,8 @@ public:
ScreenQuadProgramParams const & params) override; ScreenQuadProgramParams const & params) override;
void Apply(ref_ptr<dp::GraphicsContext> context, ref_ptr<dp::GpuProgram> program, void Apply(ref_ptr<dp::GraphicsContext> context, ref_ptr<dp::GpuProgram> program,
SMAAProgramParams const & params) override; SMAAProgramParams const & params) override;
void Apply(ref_ptr<dp::GraphicsContext> context, ref_ptr<dp::GpuProgram> program,
ImGuiProgramParams const & params) override;
}; };
} // namespace metal } // namespace metal
} // namespace gpu } // namespace gpu

View file

@ -101,5 +101,12 @@ void MetalProgramParamsSetter::Apply(ref_ptr<dp::GraphicsContext> context,
{ {
ApplyBytes(context, program, params); ApplyBytes(context, program, params);
} }
void MetalProgramParamsSetter::Apply(ref_ptr<dp::GraphicsContext> context,
ref_ptr<dp::GpuProgram> program,
ImGuiProgramParams const & params)
{
ApplyBytes(context, program, params);
}
} // namespace metal } // namespace metal
} // namespace gpu } // namespace gpu

View file

@ -102,6 +102,7 @@ std::array<ProgramInfo, static_cast<size_t>(Program::ProgramsCount)> const kMeta
ProgramInfo("vsSmaaEdges", "fsSmaaEdges", {{0, 1}}), // SmaaEdges ProgramInfo("vsSmaaEdges", "fsSmaaEdges", {{0, 1}}), // SmaaEdges
ProgramInfo("vsSmaaBlendingWeight", "fsSmaaBlendingWeight", {{0, 1}}), // SmaaBlendingWeight ProgramInfo("vsSmaaBlendingWeight", "fsSmaaBlendingWeight", {{0, 1}}), // SmaaBlendingWeight
ProgramInfo("vsSmaaFinal", "fsSmaaFinal", {{0, 1}}), // SmaaFinal ProgramInfo("vsSmaaFinal", "fsSmaaFinal", {{0, 1}}), // SmaaFinal
ProgramInfo("vsImGui", "fsImGui", {{0, 2}}), // ImGui
}}; }};
MTLVertexFormat GetFormatByDataType(MTLDataType dataType) MTLVertexFormat GetFormatByDataType(MTLDataType dataType)

View file

@ -18,6 +18,7 @@ void ProgramParams::Init()
DebugRectProgramParams::BindPrograms(m_boundParams); DebugRectProgramParams::BindPrograms(m_boundParams);
ScreenQuadProgramParams::BindPrograms(m_boundParams); ScreenQuadProgramParams::BindPrograms(m_boundParams);
SMAAProgramParams::BindPrograms(m_boundParams); SMAAProgramParams::BindPrograms(m_boundParams);
ImGuiProgramParams::BindPrograms(m_boundParams);
} }
// static // static

View file

@ -222,6 +222,14 @@ struct ALIGNMENT SMAAProgramParams
Program::SmaaFinal) Program::SmaaFinal)
}; };
struct ALIGNMENT ImGuiProgramParams
{
glsl::mat4 m_projection;
BIND_PROGRAMS(ImGuiProgramParams,
Program::ImGui)
};
#undef ALIGNMENT #undef ALIGNMENT
class ProgramParamsSetter class ProgramParamsSetter
@ -248,5 +256,7 @@ public:
ref_ptr<dp::GpuProgram> program, ScreenQuadProgramParams const & params) = 0; ref_ptr<dp::GpuProgram> program, ScreenQuadProgramParams const & params) = 0;
virtual void Apply(ref_ptr<dp::GraphicsContext> context, virtual void Apply(ref_ptr<dp::GraphicsContext> context,
ref_ptr<dp::GpuProgram> program, SMAAProgramParams const & params) = 0; ref_ptr<dp::GpuProgram> program, SMAAProgramParams const & params) = 0;
virtual void Apply(ref_ptr<dp::GraphicsContext> context,
ref_ptr<dp::GpuProgram> program, ImGuiProgramParams const & params) = 0;
}; };
} // namespace gpu } // namespace gpu

View file

@ -65,6 +65,7 @@ enum class Program
SmaaEdges, SmaaEdges,
SmaaBlendingWeight, SmaaBlendingWeight,
SmaaFinal, SmaaFinal,
ImGui,
ProgramsCount ProgramsCount
}; };
@ -128,6 +129,7 @@ inline std::string DebugPrint(Program p)
case Program::SmaaEdges: return "SmaaEdges"; case Program::SmaaEdges: return "SmaaEdges";
case Program::SmaaBlendingWeight: return "SmaaBlendingWeight"; case Program::SmaaBlendingWeight: return "SmaaBlendingWeight";
case Program::SmaaFinal: return "SmaaFinal"; case Program::SmaaFinal: return "SmaaFinal";
case Program::ImGui: return "ImGui";
case Program::ProgramsCount: case Program::ProgramsCount:
CHECK(false, ("Try to output ProgramsCount")); CHECK(false, ("Try to output ProgramsCount"));

View file

@ -229,5 +229,12 @@ void VulkanProgramParamsSetter::Apply(ref_ptr<dp::GraphicsContext> context,
{ {
ApplyImpl(context, program, params); ApplyImpl(context, program, params);
} }
void VulkanProgramParamsSetter::Apply(ref_ptr<dp::GraphicsContext> context,
ref_ptr<dp::GpuProgram> program,
ImGuiProgramParams const & params)
{
ApplyImpl(context, program, params);
}
} // namespace vulkan } // namespace vulkan
} // namespace gpu } // namespace gpu

View file

@ -55,6 +55,8 @@ public:
ScreenQuadProgramParams const & params) override; ScreenQuadProgramParams const & params) override;
void Apply(ref_ptr<dp::GraphicsContext> context, ref_ptr<dp::GpuProgram> program, void Apply(ref_ptr<dp::GraphicsContext> context, ref_ptr<dp::GpuProgram> program,
SMAAProgramParams const & params) override; SMAAProgramParams const & params) override;
void Apply(ref_ptr<dp::GraphicsContext> context, ref_ptr<dp::GpuProgram> program,
ImGuiProgramParams const & params) override;
private: private:
template<typename T> template<typename T>