Last active
August 31, 2016 03:16
-
-
Save voidproc/14ed210f8067d22c8f3d3ceaf423ea36 to your computer and use it in GitHub Desktop.
Simple blinking effect using Siv3D PixelShader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Siv3D.hpp> | |
struct CB1 | |
{ | |
float strength; | |
float reserved1; | |
float reserved2; | |
float reserved3; | |
}; | |
void Main() | |
{ | |
const String s3dkunBase64Image = L"iVBORw0KGgoAAAANSUhEUgAAADAAAAAgCAMAAABjCgsuAAAARVBMVEUAAACfz7c/n29/v5//x5NwcHDf7+f/ll9QUFC/f/+/38+QkJB/AADPj0/fv//Pn///jIz+AAD////g4ODQ0NDAwMDAAADbxb57AAAAAXRSTlMAQObYZgAAAVlJREFUOMu1kNuWwiAMRRMChulFrbf//9Q54WLBocunOUtpu3eSQuk/wsjEPOAjwSmn0+nD8FhklIz9Gj4WeQiSb6aW96LnSJ00Jz4Slc/BxFw2EMgiyEgw+DwHh0fhEkpxbigEPEAEqDevHWNhHYaFxVmE6VBUDpCW++P+wB2VHAkgxD1vi95VbwvTF5GH6G17KbK9mBohAwGOev9cFo8sC7UNBwLYX6+gdqFdyFg4xKdsm/cA30XOumKhjo+FHUKwyCrAbcYCuERFOiOt+KznaWKk63CdeGOcSVzik3HfnaGKvkExinNE2wbMckU0XLVtWLU5A2bJ3waH7A3tmYPq3qANdyli37D/SGPBbOKnpH3BWAAbP58vF/uHEOr8XuRiklK/pj2q1xCjmV6oat0MV+wTsfrY13uYtCQMChxj3UetD1kQRQ1w0dedZkrvBirzS7kZpKzH+QXriRABIX6TjgAAAABJRU5ErkJggg=="; | |
const Texture texture(Base64::Decode(s3dkunBase64Image)); | |
PixelShader ps(L"white.hlsl"); | |
ConstantBuffer<CB1> cb1; | |
Graphics::SetBackground(Color(40)); | |
Graphics2D::SetSamplerState(SamplerState::ClampPoint); | |
Window::Resize(800, 600); | |
while (System::Update()) | |
{ | |
const int F = System::FrameCount(); | |
Graphics2D::BeginPS(ps); | |
cb1->strength = Saturate(sin(F / 20.0) * 0.5 + 0.5); | |
Graphics2D::SetConstant(ShaderStage::Pixel, 1, cb1); | |
texture(((F / 25) % 2) * texture.width / 2, 0, texture.width / 2, texture.height) | |
.scale(3) | |
.draw(100, 100); | |
Graphics2D::EndPS(); | |
ClearPrint(); | |
Println(L"strength = ", cb1->strength); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Texture2D texture0 : register( t0 ); | |
SamplerState sampler0 : register( s0 ); | |
cbuffer CB : register(b1) | |
{ | |
float strength; | |
float reserved1; | |
float reserved2; | |
float reserved3; | |
}; | |
struct VS_OUTPUT | |
{ | |
float4 position : SV_POSITION; | |
float2 tex : TEXCOORD0; | |
float4 color : COLOR0; | |
}; | |
float4 PS(VS_OUTPUT input) : SV_Target | |
{ | |
float4 srcColor = texture0.Sample(sampler0, input.tex); | |
srcColor.rgb += (float3(1.0, 1.0, 1.0) - srcColor.rgb) * strength; | |
return srcColor * input.color; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment