Skip to content

Instantly share code, notes, and snippets.

@voidproc
Last active November 26, 2016 12:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save voidproc/8bf4379412cfb01a2760507b3c401922 to your computer and use it in GitHub Desktop.
#include <Siv3D.hpp>
struct ParamScale
{
float scale;
float unused[3];
};
void setScale(const int scale)
{
ConstantBuffer<ParamScale> cb;
cb->scale = scale;
PostEffect::SetConstant(ShaderStage::Pixel, 1, cb);
}
void Main()
{
Window::Resize(640, 480);
Graphics::SetBackground(Palette::Black);
int scale = 2;
PostEffect::Register(PixelShader(L"scale.hlsl"));
setScale(scale);
const Texture texture(L"Example/Siv3D-kun.png");
while (System::Update())
{
if (Input::KeyUp.clicked)
{
scale = Min(scale + 1, 4);
setScale(scale);
}
else if (Input::KeyDown.clicked)
{
scale = Max(scale - 1, 1);
setScale(scale);
}
texture.draw();
PutText(L"scale = ", scale).from(2, 2);
}
}
Texture2D texture0 : register( t0 );
SamplerState sampler0 : register( s0 );
struct VS_OUTPUT
{
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float4 color : COLOR0;
};
cbuffer psConstants1 : register( b1 )
{
float g_scale;
};
float4 PS(VS_OUTPUT input) : SV_Target
{
return texture0.Sample(sampler0, input.tex / g_scale) * input.color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment