テクスチャを白く点滅させるピクセルシェーダ
https://gyazo.com/90ff68c23d5cd8e53d81bf1a14288021
code:pixelshader_white.cpp
# include <Siv3D.hpp> // OpenSiv3D v0.6.11
struct WhiteEffectConstants
{
float strength;
};
void Main()
{
Scene::SetBackground(Color{ 30, 30, 30 });
const Texture texture{ U"example/siv3d-kun.png" };
const PixelShader psWhite = HLSL{ U"shader/white.hlsl", U"PS" };
if (not psWhite)
{
throw Error{ U"Failed to load a shader file" };
}
ConstantBuffer<WhiteEffectConstants> cb;
while (System::Update())
{
cb->strength = Saturate(Math::Sin(Scene::Time() * 5) * 0.5 + 0.5);
{
Graphics2D::SetPSConstantBuffer(1, cb);
const ScopedCustomShader2D shader(psWhite);
texture.scaled(0.75).drawAt(Scene::Center());
}
}
}
code:shader/white.hlsl
Texture2D g_texture0 : register(t0);
SamplerState g_sampler0 : register(s0);
namespace s3d
{
struct PSInput
{
float4 position : SV_POSITION;
float4 color : COLOR0;
float2 uv : TEXCOORD0;
};
}
cbuffer PSConstants2D : register(b0)
{
float4 g_colorAdd;
float4 g_sdfParam;
float4 g_sdfOutlineColor;
float4 g_sdfShadowColor;
float4 g_internal;
}
cbuffer WhiteEffectConstants : register(b1)
{
float strength;
float3 unused;
}
float4 PS(s3d::PSInput input) : SV_TARGET
{
float4 srcColor = g_texture0.Sample(g_sampler0, input.uv);
srcColor.rgb += (float3(1.0, 1.0, 1.0) - srcColor.rgb) * strength;
return (srcColor * input.color) + g_colorAdd;
}