Shader Input Color Incorrect
Posted: 06 Sep 2024, 23:43
Working with shaders, it seems like the color input comes in different than what I input into the xaml. I made a simple effect shader that simply outputs the input color. But on the screen the colors don't match. I input "#888888" but what is shown on the screen is "#c1c1c1". Is there some function or multiplier I need to get the original color? The color of the outer rectangle should be the same as the inner square. Thanks for your help!
Xaml:
Grayscale.noesiseffect
GrayscaleEffect.cs
Xaml:
Code: Select all
<Rectangle Fill="White">
<Rectangle.Effect>
<local:GrayscaleEffect Color="#888888"/>
</Rectangle.Effect>
</Rectangle>
<Rectangle Fill="#888888" Width="100" Height="100"/>
Code: Select all
#include "EffectHelpers.h"
uniforms
{
fixed4 _color;
};
fixed4 main_effect()
{
fixed4 c = GetInput();
return float4
(
_color.r,
_color.g,
_color.b,
_color.a
);
}
Code: Select all
using System;
using System.Runtime.InteropServices;
using Noesis;
namespace Quantum_Survivor
{
public class GrayscaleEffect : ShaderEffect
{
private static NoesisShader Shader;
public GrayscaleEffect()
{
if (Shader == null) Shader = CreateShader();
SetShader(Shader);
SetConstantBuffer(_constants);
}
#region Color
public Color Color
{
get { return (Color)GetValue(ColorProperty); }
set { SetValue(ColorProperty, value); }
}
public static readonly DependencyProperty ColorProperty = DependencyProperty.Register(
"Color", typeof(Color), typeof(GrayscaleEffect),
new PropertyMetadata(Colors.White, OnColorChanged));
private static void OnColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
GrayscaleEffect this_ = (GrayscaleEffect)d;
this_._constants.color = (Color)e.NewValue;
this_.InvalidateConstantBuffer();
}
#endregion
[StructLayout(LayoutKind.Sequential)]
private class Constants
{
public Color color = Colors.White;
}
private Constants _constants = new Constants();
}
}