Skip to content

Instantly share code, notes, and snippets.

@voidproc voidproc/scale.cpp
Last active Nov 26, 2016

Embed
What would you like to do?
#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
You can’t perform that action at this time.