Below is sample code that uses custom shaders to change color and make a small shift on position of edges. This code was tested on HPS 2025.7.0.
Screenshot:
Sample code:
void CHPSView::OnUserCode2()
{
// drawing test, simple shaders change color or position
static char const ps_source[] = { "void custom_main(inout PixelShaderContext ctx) { \n"
"\tctx.poutput.FinalColor = float4(0.0, 1.0, 0.0, 0.0);\n"
"}\n\n" };
static char const vs_source[] = { "void custom_main(inout VertexShaderContext ctx) { \n"
"\tctx.voutput.position.x += 0.5f;\n"
"\tctx.voutput.position.y += 0.1f;\n"
"}\n\n" };
PixelShaderKit real_psk;
real_psk.SetSource(ps_source);
PixelShaderKey real_ps = Database::DefinePixelShader();
real_ps.Set(real_psk);
VertexShaderKit real_vsk;
real_vsk.SetSource(vs_source);
VertexShaderKey real_vs = Database::DefineVertexShader();
real_vs.Set(real_vsk);
Point points[] = { Point(-0.5f, -0.5f, 0), Point(0.5f, -0.5f, 0), Point(0.5f, 0.5f, 0), Point(-0.5f, 0.5f, 0) };
int facelist[] = { 4, 0, 1, 2, 3 };
SegmentKey geometry = Database::CreateRootSegment();
geometry.GetVisibilityControl().SetEdges(true);
geometry.InsertShell(4, points, 5, facelist);
IncludeKey include = GetCanvas().GetFrontView().GetAttachedModel().GetSegmentKey().IncludeSegment(geometry);
geometry.SetPixelShader(real_ps, Shader::Primitives::Lines);
geometry.SetVertexShader(real_vs, Shader::Primitives::Lines);
GetCanvas().UpdateWithNotifier().Wait();
}
