C# 渲染具有效果的图像
我在画布上画图像。如果我在没有任何效果的情况下绘制图像,它的渲染效果会很好。如果添加自定义色调效果,则在渲染画布时会得到一些奇怪的结果。我不确定问题是来自我的着色器,还是我渲染它的方式 在底部是没有效果的。而在顶部是有效果的 以下是HLSL着色器:C# 渲染具有效果的图像,c#,wpf,wpf-controls,glsl,hlsl,C#,Wpf,Wpf Controls,Glsl,Hlsl,我在画布上画图像。如果我在没有任何效果的情况下绘制图像,它的渲染效果会很好。如果添加自定义色调效果,则在渲染画布时会得到一些奇怪的结果。我不确定问题是来自我的着色器,还是我渲染它的方式 在底部是没有效果的。而在顶部是有效果的 以下是HLSL着色器: float HueDegree : register(C0); sampler2D Samp : register(S0); float3x3 QuaternionToMatrix(float4 quat) { float3 cross
float HueDegree : register(C0);
sampler2D Samp : register(S0);
float3x3 QuaternionToMatrix(float4 quat)
{
float3 cross = quat.yzx * quat.zxy;
float3 square = quat.xyz * quat.xyz;
float3 wimag = quat.w * quat.xyz;
square = square.xyz + square.yzx;
float3 diag = 0.5 - square;
float3 a = (cross + wimag);
float3 b = (cross - wimag);
return float3x3(
2.0 * float3(diag.x, b.z, a.y),
2.0 * float3(a.z, diag.y, b.x),
2.0 * float3(b.y, a.x, diag.z));
}
static const float3 lumCoeff = float3(0.2125, 0.7154, 0.0721);
float4 main(float2 uv : TEXCOORD) : COLOR
{
float4 outputColor = tex2D(Samp, uv.xy);
outputColor.rgb /= outputColor.a;
float3 root3 = float3(0.57735, 0.57735, 0.57735);
float half_angle = 0.5 * radians(HueDegree); // 0 to 360 degree
float4 rot_quat = float4((root3 * sin(half_angle)), cos(half_angle));
float3x3 rot_Matrix = QuaternionToMatrix(rot_quat);
outputColor.rgb = mul(rot_Matrix, outputColor.rgb);
outputColor.rgb *= outputColor.a;
return outputColor;
}
下面是我如何呈现它的:
Rect rect = new Rect(0, 0, tmpCanvas.Width, tmpCanvas.Height);
RenderTargetBitmap rtb = new RenderTargetBitmap((int)rect.Right,
(int)rect.Bottom, 96d, 96d, System.Windows.Media.PixelFormats.Default);
rtb.Render(tmpCanvas);
如果我在画布上绘制具有效果的图像,它看起来很好。只有在渲染画布之前,问题才会出现。我已经像这样渲染了我所有的视觉效果,我还有其他自定义效果,它们工作得很好。我想不出来。如果我删除
从着色器中,我不会遇到白色背景的问题,但仍然会得到锯齿状的边缘。试试这个:
rect.Effect = new BlurEffect() { Radius = 0 };
rect.Effect.BeginAnimation(BlurEffect.RadiusProperty, new DoubleAnimation(5, TimeSpan.FromMilliseconds(500)));
rect.Effect.BeginAnimation(BlurEffect.RadiusProperty, new DoubleAnimation(0, TimeSpan.FromMilliseconds(500)));
我不知道这是。。。
rect.Effect = new BlurEffect() { Radius = 0 };
rect.Effect.BeginAnimation(BlurEffect.RadiusProperty, new DoubleAnimation(5, TimeSpan.FromMilliseconds(500)));
rect.Effect.BeginAnimation(BlurEffect.RadiusProperty, new DoubleAnimation(0, TimeSpan.FromMilliseconds(500)));