Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**CC BY-SA 4.0 Kermles (Graham E. Hemsley) 06/17/14 14:15
- =======================================================================================================================
- ------------------------------------------------------------------------------------------------------------
- Kabloom! Kermles was here~! Thanks to prod80 for assistance and many others around enbdev and web for ideas!
- Find me on enbdev.com and nexusmods.com if you need help or want to let me know what you think!
- ------------------------------------------------------------------------------------------------------------
- Credits:
- Prod80
- Darel Rex Finley
- Boris Vorontsov
- ------------------------------------------------------------------------------------------------------------
- This file and its contents are licensed under Creative Commons Attribution-ShareAlike 4.0 International
- Usage, modification and redistribution of this file is permitted under the terms of this license
- http://creativecommons.org/licenses/by-sa/4.0/
- ------------------------------------------------------------------------------------------------------------
- =======================================================================================================================
- **/
- /*
- * Blend modes:
- * 0: Off
- * 1: Addition
- * 2: Opacity
- * 3: Lighten
- * 4: Lighten/opacity hybrid
- * 5: Luma-based
- * 6: Screen/add hybrid
- * 7: Screen/opacity hybrid
- * 8: Screen/lighten/opacity hybrid
- */
- /*
- =======================================================================================================================
- Globals
- =======================================================================================================================
- */
- //===================================================================================================================//
- float InBlackD /* Any bloom darker than this will map to the minimum output value */
- <
- string UIName = "Kabloom levels: black input day" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 1.0f;
- > = { 0.0f };
- float InBlackN
- <
- string UIName = "Kabloom levels: black input night" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 1.0f;
- > = { 0.0f };
- float InBlackI
- <
- string UIName = "Kabloom levels: black input interior" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 1.0f;
- > = { 0.0f };
- //===================================================================================================================//
- float InWhiteD /* Any bloom brighter than this will map to the maximum output value */
- <
- string UIName = "Kabloom levels: white input day" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 1.0f;
- > = { 1.0f };
- float InWhiteN
- <
- string UIName = "Kabloom levels: white input night" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 1.0f;
- > = { 1.0f };
- float InWhiteI
- <
- string UIName = "Kabloom levels: white input interior" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 1.0f;
- > = { 1.0f };
- //===================================================================================================================//
- float InGammaD /* Preprocessing gamma curve */
- <
- string UIName = "Kabloom levels: input gamma day" ; string UIWidget = "Spinner" ; float UIMin = 0.0f; float UIMax = 10.0f;
- > = { 1.0f };
- float InGammaN
- <
- string UIName = "Kabloom levels: input gamma night" ; string UIWidget = "Spinner" ; float UIMin = 0.0f; float UIMax = 10.0f;
- > = { 1.0f };
- float InGammaI
- <
- string UIName = "Kabloom levels: input gamma interior" ; string UIWidget = "Spinner" ; float UIMin = 0.0f; float UIMax = 10.0f;
- > = { 1.0f };
- //===================================================================================================================//
- float OutBlackD /* Minimum preprocessing bloom output */
- <
- string UIName = "Kabloom levels: black output day" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 1.0f;
- > = { 0.0f };
- float OutBlackN
- <
- string UIName = "Kabloom levels: black output night" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 1.0f;
- > = { 0.0f };
- float OutBlackI
- <
- string UIName = "Kabloom levels: black output interior" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 1.0f;
- > = { 0.0f };
- //===================================================================================================================//
- float OutWhiteD /* Maximum preprocessing bloom output */
- <
- string UIName = "Kabloom levels: white output day" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 1.0f;
- > = { 1.0f };
- float OutWhiteN
- <
- string UIName = "Kabloom levels: white output night" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 1.0f;
- > = { 1.0f };
- float OutWhiteI
- <
- string UIName = "Kabloom levels: white output interior" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 1.0f;
- > = { 1.0f };
- //===================================================================================================================//
- float BloomBrightnessD /* Controls bloom intensity before haze reduction */
- <
- string UIName = "Kabloom spread control: input intensity day" ; string UIWidget = "Spinner" ; float UIMin = -100.0f; float UIMax = 100.0f;
- > = { 0.0f };
- float BloomBrightnessN
- <
- string UIName = "Kabloom spread control: input intensity night" ; string UIWidget = "Spinner" ; float UIMin = -100.0f; float UIMax = 100.0f;
- > = { 0.0f };
- float BloomBrightnessI
- <
- string UIName = "Kabloom spread control: input intensity interior" ; string UIWidget = "Spinner" ; float UIMin = -100.0f; float UIMax = 100.0f;
- > = { 0.0f };
- //===================================================================================================================//
- float BloomSaturationD /* Determines how colorful bloom looks */
- <
- string UIName = "Kabloom spread control: saturation day" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 10.0f;
- > = { 1.0f };
- float BloomSaturationN
- <
- string UIName = "Kabloom spread control: saturation night" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 10.0f;
- > = { 1.0f };
- float BloomSaturationI
- <
- string UIName = "Kabloom spread control: saturation interior" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 10.0f;
- > = { 1.0f };
- //===================================================================================================================//
- float BloomContrastD /* Controls bloom contrast */
- <
- string UIName = "Kabloom spread control: contrast day" ; string UIWidget = "Spinner" ; float UIMin = 0.0f; float UIMax = 100.0f;
- > = { 1.0f };
- float BloomContrastN
- <
- string UIName = "Kabloom spread control: contrast night" ; string UIWidget = "Spinner" ; float UIMin = 0.0f; float UIMax = 100.0f;
- > = { 1.0f };
- float BloomContrastI
- <
- string UIName = "Kabloom spread control: contrast interior" ; string UIWidget = "Spinner" ; float UIMin = 0.0f; float UIMax = 100.0f;
- > = { 1.0f };
- //===================================================================================================================//
- float BloomSensitivityD /* Reduces haze based on brightness */
- <
- string UIName = "Kabloom spread control: sensitivity day" ; string UIWidget = "Spinner" ; float UIMin = 0.0f; float UIMax = 100.0f;
- > = { 1.0f };
- float BloomSensitivityN
- <
- string UIName = "Kabloom spread control: sensitivity night" ; string UIWidget = "Spinner" ; float UIMin = 0.0f; float UIMax = 100.0f;
- > = { 1.0f };
- float BloomSensitivityI
- <
- string UIName = "Kabloom spread control: sensitivity interior" ; string UIWidget = "Spinner" ; float UIMin = 0.0f; float UIMax = 100.0f;
- > = { 1.0f };
- //===================================================================================================================//
- float BloomIntensityD /* Controls bloom intensity after to haze reduction */
- <
- string UIName = "Kabloom spread control: output intensity day" ; string UIWidget = "Spinner" ; float UIMin = -100.0f; float UIMax = 100.0f;
- > = { 0.0f };
- float BloomIntensityN
- <
- string UIName = "Kabloom spread control: output intensity night" ; string UIWidget = "Spinner" ; float UIMin = -100.0f; float UIMax = 100.0f;
- > = { 0.0f };
- float BloomIntensityI
- <
- string UIName = "Kabloom spread control: output intensity interior" ; string UIWidget = "Spinner" ; float UIMin = -100.0f; float UIMax = 100.0f;
- > = { 0.0f };
- //===================================================================================================================//
- float3 RGBBalanceD /* Strength of rgb channels */
- <
- string UIName = "Kabloom color control: color balance day" ; string UIWidget = "Color" ; float UIMin = 0.0f; float UIMax = 1.0f;
- > = { float3(1.0f, 1.0f, 1.0f) };
- float3 RGBBalanceN
- <
- string UIName = "Kabloom color control: color balance night" ; string UIWidget = "Color" ; float UIMin = 0.0f; float UIMax = 1.0f;
- > = { float3(1.0f, 1.0f, 1.0f) };
- float3 RGBBalanceI
- <
- string UIName = "Kabloom color control: color balance interior" ; string UIWidget = "Color" ; float UIMin = 0.0f; float UIMax = 1.0f;
- > = { float3(1.0f, 1.0f, 1.0f) };
- //===================================================================================================================//
- float3 RGBWeightsD /* How much each colour in the scene will be bloomed */
- <
- string UIName = "Kabloom misc: bloom strength weights day" ; string UIWidget = "Color" ; float UIMin = 0.0f; float UIMax = 1.0f;
- > = { float3(0.0, 0.0f, 0.0f) };
- float3 RGBWeightsN
- <
- string UIName = "Kabloom misc: bloom strength weights night" ; string UIWidget = "Color" ; float UIMin = 0.0f; float UIMax = 1.0f;
- > = { float3(0.0, 0.0f, 0.0f) };
- float3 RGBWeightsI
- <
- string UIName = "Kabloom misc: bloom strength weights interior" ; string UIWidget = "Color" ; float UIMin = 0.0f; float UIMax = 1.0f;
- > = { float3(0.0, 0.0f, 0.0f) };
- //===================================================================================================================//
- int BlendMode /* Decides how the bloom gets added to the scene */
- <
- string UIName = "Kabloom blending: blend mode" ; string UIWidget = "Slider" ; float UIMin = 0; float UIMax = 8;
- > = { 1 };
- //===================================================================================================================//
- float BlendAmountD /* Controls opacity for certain blend modes */
- <
- string UIName = "Kabloom blending: blend amount day" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 100.0f;
- > = { 1.0f };
- float BlendAmountN
- <
- string UIName = "Kabloom blending: blend amount night" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 100.0f;
- > = { 1.0f };
- float BlendAmountI
- <
- string UIName = "Kabloom blending: blend amount interior" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 100.0f;
- > = { 1.0f };
- //===================================================================================================================//
- float BlendOpacityD /* Controls opacity for certain blend modes */
- <
- string UIName = "Kabloom blending: blend opacity day" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 100.0f;
- > = { 1.0f };
- float BlendOpacityN
- <
- string UIName = "Kabloom blending: blend opacity night" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 100.0f;
- > = { 1.0f };
- float BlendOpacityI
- <
- string UIName = "Kabloom blending: blend opacity interior" ; string UIWidget = "Slider" ; float UIMin = 0.0f; float UIMax = 100.0f;
- > = { 1.0f };
- //===================================================================================================================//
- /*
- =======================================================================================================================
- Functions
- =======================================================================================================================
- */
- /*
- =======================================================================================================================
- Takes a 3 component vector input and alters it so that the sum of its components will equal the specified sum value
- //thanks prod80
- =======================================================================================================================
- */
- float3 sumTo(in float3 weights, in float sumValue)
- {
- if(any(weights.rgb))
- {
- return weights.rgb / dot(weights.rgb, 1.0f / sumValue);
- }
- else
- {
- return sumValue.xxx / 3.0f;
- }
- }
- /*
- ===================================================================================================c====================
- Perceptually-weighted euclidean-distance luma calculation //thanks Darel Rex Finley
- =======================================================================================================================
- */
- float pLuma(in float3 color)
- {
- return sqrt(dot(pow(color.rgb, 2.0f), float3(0.299f, 0.587f, 0.114f)));
- }
- /*
- =======================================================================================================================
- Configurable luma calculation with perceptual weighting enforced for a vector of (0, 0, 0)
- =======================================================================================================================
- */
- float cLuma(in float3 color, in float3 lumaWeights)
- {
- if(any(lumaWeights.rgb))
- {
- lumaWeights.rgb = sumTo(lumaWeights.rgb, 1.0f);
- }
- else
- {
- lumaWeights.rgb = float3(0.299f, 0.587f, 0.114f);
- }
- return sqrt(dot(pow(color.rgb, 2.0f), lumaWeights.rgb));
- }
- /*
- =======================================================================================================================
- Saturation shader that maintains color ratios (thanks prod80) //TODO: Test saturation above 2.0
- =======================================================================================================================
- */
- float3 adjustSaturation(in float3 color, in float saturation)
- {
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- float grey = dot( color.rgb, float3(0.3333f, 0.3333f, 0.3333f));
- float3 desat = lerp(grey, color.rgb, saturation);
- float cmin = min(min(color.r, color.g), color.b);
- float cmax = max(max(color.r, color.g), color.b);
- float csaturation = cmax - cmin;
- float vibrance = saturation - 1.0f;
- float3 sat = lerp(grey, color.rgb, (1.0f + (vibrance * (1.0f - (sign(vibrance) * csaturation)))));
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- if(saturation < 1.0f)
- {
- color.rgb = desat.rgb;
- }
- else
- {
- color.rgb = sat.rgb;
- }
- return color.rgb;
- }
- /*
- =======================================================================================================================
- Simple contrast adjustment //TODO: Try basic add/subtract/multiply version
- =======================================================================================================================
- */
- float3 adjustContrast(in float3 color, in float contrast )
- {
- color.rgb = max
- (
- 0.0f,
- pow(color.rgb, max(0.0f, contrast.xxx)) /
- (
- pow(saturate(color.rgb), max(0.0f, contrast.xxx)) + pow
- (
- 1.0f - saturate(color.rgb),
- max(0.0f, contrast.xxx)
- )
- )
- );
- return color.rgb;
- }
- /*
- =======================================================================================================================
- Photoshop-style levels adjustment with gamma control //thanks prod80
- =======================================================================================================================
- */
- float3 levelsAdjust
- (
- in float3 color,
- in float inBlack,
- in float inGamma,
- in float inWhite,
- in float outBlack,
- in float outWhite
- )
- {
- color = saturate(color.rgb);
- color.rgb = pow(max(color.rgb - inBlack, 0.0f)
- / max(inWhite - inBlack, 0.0001f), inGamma)
- * max(outWhite - outBlack, 0.0001f) + outBlack;
- return color.rgb;
- }
- /*
- =======================================================================================================================
- Main effect code //TODO: Add and get rid of some blend modes, feedback? :)
- =======================================================================================================================
- */
- float3 kaBloom
- (
- in sampler2D _s3,
- in float4 _v0,
- in float3 color,
- in float ENightDayFactor,
- in float EInteriorFactor,
- in float InBlackD,
- in float InBlackN,
- in float InBlackI,
- in float InWhiteD,
- in float InWhiteN,
- in float InWhiteI,
- in float InGammaD,
- in float InGammaN,
- in float InGammaI,
- in float OutBlackD,
- in float OutBlackN,
- in float OutBlackI,
- in float OutWhiteD,
- in float OutWhiteN,
- in float OutWhiteI,
- in float BloomBrightnessD,
- in float BloomBrightnessN,
- in float BloomBrightnessI,
- in float BloomContrastD,
- in float BloomContrastN,
- in float BloomContrastI,
- in float BloomSaturationD,
- in float BloomSaturationN,
- in float BloomSaturationI,
- in float BloomSensitivityD,
- in float BloomSensitivityN,
- in float BloomSensitivityI,
- in float BloomIntensityD,
- in float BloomIntensityN,
- in float BloomIntensityI,
- in float3 RGBBalanceD,
- in float3 RGBBalanceN,
- in float3 RGBBalanceI,
- in float3 RGBWeightsD,
- in float3 RGBWeightsN,
- in float3 RGBWeightsI,
- in int BlendMode,
- in float BlendAmountD,
- in float BlendAmountN,
- in float BlendAmountI,
- in float BlendOpacityD,
- in float BlendOpacityN,
- in float BlendOpacityI
- )
- {
- if(BlendMode)
- {
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- /* Load bloom texture */
- float4 kabloom = tex2D(_s3, _v0.xy);
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- /* Levels// */
- kabloom.rgb = levelsAdjust( kabloom.rgb,
- lerp( lerp( InBlackN, InBlackD, ENightDayFactor ), InBlackI, EInteriorFactor ),
- lerp( lerp( InGammaN, InGammaD, ENightDayFactor ), InGammaI, EInteriorFactor ),
- lerp( lerp( InWhiteN, InWhiteD, ENightDayFactor ), InWhiteI, EInteriorFactor ),
- lerp( lerp( OutBlackN, OutBlackD, ENightDayFactor ), OutBlackI, EInteriorFactor ),
- lerp( lerp( OutWhiteN, OutWhiteD, ENightDayFactor ), OutWhiteI, EInteriorFactor )
- );
- /* Color Balance// */
- kabloom.rgb *= sumTo( lerp( lerp( RGBBalanceN.rgb, RGBBalanceD, ENightDayFactor ), RGBBalanceI, EInteriorFactor ), 3);
- /* Input intensity// */
- kabloom.rgb *= pow(2.0f, lerp( lerp( BloomBrightnessN, BloomBrightnessD, ENightDayFactor ), BloomBrightnessI, EInteriorFactor ) );
- /* Contrast// */
- kabloom.rgb = adjustContrast( kabloom.rgb, lerp( lerp( BloomContrastN, BloomContrastD, ENightDayFactor ), BloomContrastI, EInteriorFactor ) );
- /* Saturation// */
- kabloom.rgb = adjustSaturation(kabloom.rgb, lerp( lerp( BloomSaturationN, BloomSaturationD, ENightDayFactor ), BloomSaturationI, EInteriorFactor ) );
- /* Sensitivity for haze reduction// */
- float3 RGBWeights = lerp( lerp( RGBWeightsN.rgb, RGBWeightsD, ENightDayFactor ), RGBWeightsI.rgb, EInteriorFactor );
- kabloom.rgb = max
- (
- 0.0f,
- pow
- (
- kabloom.rgb,
- max( 0.0f, ( 1.0f / max( 0.0001f, ( lerp( lerp( BloomSensitivityN, BloomSensitivityD, ENightDayFactor ), BloomSensitivityI, EInteriorFactor ) * cLuma( kabloom.rgb, RGBWeights.rgb ) ) ) ) )
- )
- );
- /* Output intensity// */
- kabloom.rgb *= pow(2.0f, lerp( lerp( BloomIntensityN, BloomIntensityD, ENightDayFactor ), BloomIntensityI, EInteriorFactor ) );
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- float tempLuma = cLuma(kabloom.rgb, RGBWeights.rgb);
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- /* Blend modes// */
- float BlendAmount = lerp( lerp( BlendAmountN, BlendAmountD, ENightDayFactor ), BlendAmountI, EInteriorFactor );
- float BlendOpacity = lerp( lerp( BlendOpacityN, BlendOpacityD, ENightDayFactor ), BlendOpacityI, EInteriorFactor );
- if(BlendMode == 2) /* Opacity */
- {
- color.rgb = lerp(color.rgb, kabloom.rgb * BlendAmount, BlendOpacity);
- }
- else if(BlendMode == 3) /* Lighten */
- {
- color.rgb = max(color.rgb, kabloom * BlendAmount);
- }
- else if(BlendMode == 4) /* Lighten/opacity */
- {
- color.rgb = max(color.rgb, lerp(color.rgb, kabloom.rgb * BlendAmount, BlendOpacity));
- }
- else if(BlendMode == 5) /* Brightness-dependent */
- {
- color.rgb = lerp(color.rgb, kabloom.rgb, saturate(pow(tempLuma, 1.0f / tempLuma) * BlendAmount));
- }
- else if(BlendMode == 6) /* Screen add */ //thanks prod80
- {
- color.rgb += 1.0f - (1.0f - saturate(kabloom.rgb)) * (1.0f - saturate(kabloom.rgb * BlendAmount));
- }
- else if(BlendMode == 7) /* Screen/opacity */
- {
- color.rgb = max
- (
- 0.0f,
- lerp
- (
- color.rgb,
- (1.0f - (1.0f - saturate(kabloom.rgb)) * (1.0f - saturate(kabloom.rgb * BlendAmount))),
- BlendOpacity
- )
- );
- }
- else if(BlendMode == 8) /* Screen/lighten/opacity */
- {
- color.rgb = max
- (
- 0.0f,
- max
- (
- color.rgb,
- lerp
- (
- color.rgb,
- (
- 1.0f - (1.0f - saturate(kabloom.rgb)) *
- (1.0f - saturate(kabloom.rgb * BlendAmount))
- ),
- BlendOpacity
- )
- )
- );
- }
- else /* Addition */
- {
- color.rgb += kabloom.rgb * BlendAmount;
- }
- }
- return color.rgb;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement