Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
// Bloom pixel shader snippets (remainder of shaders omitted)
// AJ Weeks 2017
// High pass filter pixel shader
float4 PS(PS_INPUT input) : SV_Target
{
float3 finalColor = gTexture.Sample(SamPoint, input.TexCoord).rgb;
float brightness = dot(finalColor, float3(0.2126f, 0.7152f, 0.0722f));
if (brightness > gMinBrightness)
{
float4 result = float4(finalColor, 1.0f);
return result;
}
return float4(0, 0, 0, 1);
}
// ...
// Blur pixel shader
float4 PS(PS_INPUT input) : SV_Target
{
uint width, height, levels;
gTexture.GetDimensions(0, width, height, levels);
float dx = 1.0 / width;
float dy = 1.0 / height;
float weights[5] = { 0.227027, 0.1945946, 0.1216216, 0.054054, 0.016216 };
// Start with current fragment's contribution
float3 finalColor = gTexture.Sample(SamPoint, input.TexCoord).rgb * weights[0];
// 5 in each direction
int passes = 5;
if (gHorizontal)
{
for (int i = 1; i < passes; ++i)
{
finalColor += gTexture.Sample(SamPoint, input.TexCoord + float2(i * dx, 0.0)).rgb * weights[i];
finalColor += gTexture.Sample(SamPoint, input.TexCoord - float2(i * dx, 0.0)).rgb * weights[i];
}
}
else
{
for (int i = 1; i < passes; ++i)
{
finalColor += gTexture.Sample(SamPoint, input.TexCoord + float2(0.0, i * dy)).rgb * weights[i];
finalColor += gTexture.Sample(SamPoint, input.TexCoord - float2(0.0, i * dy)).rgb * weights[i];
}
}
float4 result = float4(finalColor, 1.0f);
return result;
}
// ...
// Combine pixel shader
float4 PS(PS_INPUT input) : SV_Target
{
float4 original = gTexturePrevious.Sample(SamPoint, input.TexCoord);
float4 blurredHighPass = gTextureBlurredHighpass.Sample(SamPoint, input.TexCoord);
return original + lerp(float4(0.0f, 0.0f, 0.0f, 0.0f), blurredHighPass, gStrength);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment