Skip to content

Instantly share code, notes, and snippets.

@equinox2k
Created February 4, 2019 02:43
Show Gist options
  • Select an option

  • Save equinox2k/0ca6aedf1ee2b0f1bfb3af704ab8ede3 to your computer and use it in GitHub Desktop.

Select an option

Save equinox2k/0ca6aedf1ee2b0f1bfb3af704ab8ede3 to your computer and use it in GitHub Desktop.
Texture2D ShaderTexture : register(t0);
SamplerState Sampler : register(s0);
cbuffer PerObject: register(b0)
{
float4x4 ViewMatrix;
float2 TextureSize;
int Emboss;
float Unused1;
};
struct VertexShaderInput
{
float4 Position : SV_Position;
float2 TextureUV : TEXCOORD0;
};
struct VertexShaderOutput
{
float4 Position : SV_Position;
float2 TextureUV : TEXCOORD0;
};
VertexShaderOutput VSMain(VertexShaderInput input)
{
VertexShaderOutput output = (VertexShaderOutput)0;
output.Position = mul(input.Position, ViewMatrix);
output.TextureUV = input.TextureUV;
return output;
}
float4 PSMain(VertexShaderOutput input) : SV_Target
{
float2 step = float2(1.0f, 1.0f) / TextureSize;
float2 blv = float2(input.TextureUV.x - step.x, input.TextureUV.y - step.y);
float2 trv = float2(input.TextureUV.x + step.x, input.TextureUV.y + step.y);
float3 color = float3(0.5f, 0.5f, 0.5f);
color -= ShaderTexture.Sample(Sampler, blv).rgb;
color += ShaderTexture.Sample(Sampler, trv).rgb;
float level = (((color.r + color.g + color.b) / 3.0f) - 0.5f) * 2.0f;
float value1 = Emboss == 1 ? 0.0f : 1.0f;
float value2 = Emboss == 1 ? 1.0f : 0.0f;
if (level > 0)
{
return float4(value1, value1, value1, abs(level));
}
return float4(value2, value2, value2, abs(level));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment