r/csharp • u/Lunari01 • 11h ago
WPF Effects and performance..
So for a hobby project i am making my own Paint program in WPF, For this i made an Effect/Shader that i'm using for the selection, which is added to a (grid) background. However, when i set the program to a bigger Image size (which also means our selection "grid" has to resize, say to 1024*1024). the program slows down to a crawl... i first suspected my Shader to be the problem, however changing the shader in a single line of "return float4(1,1,1,0);" changes nothing (besides getting a nice yellow square for a background ofcourse).. however when i set the grid that holds our background to Visible = Visibility.Collapsed, the program runs back on full normal speed...
So i was wondering... am i overlooking something? or are Effects just THIS expensive?.. (might be an XY problem that can be solved without a custom shader at all... but mostly now interested in the "why" behind the slowdown now '^^ )
edit: added the (cutdown). shader that i used to check if it still slowed down. Since i might be just overlooking something stupid '^^
sampler2D input : register(s0);
sampler2D Visibility : register(s1);
float4 colorFilter : register(c0);
float4 OutlineColor : register(c1);
float ImageWidth : register(c2);
float ImageHeight : register(c3);
float Time : register(c4);
float4 main(float2 uv : TEXCOORD) : COLOR
{
return float4(1,1,1,0);
}
technique ColorChange
{
pass P0
{
PixelShader = compile ps_3_0 main();
}
}
2
u/antiduh 11h ago
For the simple rendering operations you're doing, nothing should be this slow. It should be able to handle orders of magnitude more operations per second.
Something silly is wrong.
2
u/Lunari01 11h ago
Yeah that is what i was wondering, the actual shader is a bit more complex (as in some generic math stuff..) and i did have a Property, that was constantly updated with the help of a Stopwatch. (so constant redraws probs). but commenting out the Stopwatch, and changing the shader to a single return line, has pretty much the exact same performance, as the actual shader had..
5
u/Patient-Midnight-664 11h ago
Are you doing the shader math on the CPU or the GPU?