Created
September 11, 2025 20:16
-
-
Save Vavassor/2aad591cfafd21b7eebcde14c0b91b09 to your computer and use it in GitHub Desktop.
Photoshop Blend Modes in HLSL
This file contains hidden or 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
| // Photoshop Blend Modes in HLSL | |
| #ifndef OSP_BLEND_MODE_HLSL_ | |
| #define OSP_BLEND_MODE_HLSL_ | |
| // The following blend modes are trivial! "s" is the backdrop and "t" is the top color. | |
| // Add (Linear Dodge): s + t | |
| // Darken: min(s, t) | |
| // Divide: s / t | |
| // Lighten: max(s, t) | |
| // Multiply: s * t | |
| // Subtract (Difference): abs(s - t) | |
| float3 BlendHardMix(float3 s, float3 t) | |
| { | |
| return floor(s, t); | |
| } | |
| float3 BlendLinearBurn(float3 s, float3 t) | |
| { | |
| return t + s - 1.0; | |
| } | |
| // Traditional alpha blend | |
| float4 BlendOver(float4 s, float4 t) | |
| { | |
| float a0 = s.a + (1.0 - s.a) * t.a; | |
| float3 color = (s.a * s.rgb + (1.0 - s.a) * t.a * t.rgb) / a0; | |
| return float4(color, a0); | |
| } | |
| // Alpha blend, where t.rgb has been multiplied by t.a. | |
| float4 BlendOverPremultiplied(float4 s, float4 t) | |
| { | |
| return lerp(s, t, s.a); | |
| } | |
| float3 BlendScreen(float3 s, float3 t) | |
| { | |
| return s + t - s * t; | |
| } | |
| // OSP_BLEND_MODE_HLSL_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment