Guest User

Skybox darkening shader?

a guest
Jun 8th, 2026
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OpenGL Shading 3.51 KB | Source Code | 0 0
  1. #include "ReShade.fxh"
  2.  
  3. // I hereby decree this shader to be version 1
  4.  
  5. // Spectral power distribution
  6. static const float3 SPD = float3(0.412656, 0.715158, 0.072186);
  7.  
  8. static const float SPD_MAG = 1.73205;
  9.  
  10. uniform float amount <
  11.     ui_category = "General";
  12.     ui_label = "Amount";
  13.     ui_max = 4;
  14.     ui_min = -4;
  15.     ui_step = 0.0000001;
  16.     ui_tooltip = "Effect intensity";
  17.     ui_type = "slider";
  18. > = 1;
  19.  
  20. uniform float skyboxDepth <
  21.     ui_category = "General";
  22.     ui_label = "Skybox Depth";
  23.     ui_max = 1;
  24.     ui_min = -1;
  25.     ui_step = 0.0001;
  26.     ui_tooltip = "Objects at or past this threshold will be treated as part of the skybox. Use negative values if the skybox has a zero depth.";
  27.     ui_type = "slider";
  28. > = 1;
  29.  
  30. uniform float skyboxKnee <
  31.     ui_category = "General";
  32.     ui_label = "Skybox Depth Knee";
  33.     ui_max = 1;
  34.     ui_min = 0;
  35.     ui_step = 0.0001;
  36.     ui_tooltip = "I guess this might prevent the threshold from being visible? Leave at 1 if not seeing any issues";
  37.     ui_type = "slider";
  38. > = 1;
  39.  
  40. uniform float darkenAmount <
  41.     ui_category = "Darkening";
  42.     ui_label = "Strength";
  43.     ui_max = 4;
  44.     ui_min = -4;
  45.     ui_step = 0.0000001;
  46.     ui_tooltip = "How much darker would dark areas be";
  47.     ui_type = "slider";
  48. > = 0;
  49.  
  50. uniform float darkenKnee <
  51.     ui_category = "Darkening";
  52.     ui_label = "Knee";
  53.     ui_max = 4;
  54.     ui_min = 0;
  55.     ui_step = 0.0000001;
  56.     ui_tooltip = "How smooth will the transition between affected and unaffected areas be";
  57.     ui_type = "slider";
  58. > = 1;
  59.  
  60. uniform float saturateAmount <
  61.     ui_category = "Saturation";
  62.     ui_label = "Strength";
  63.     ui_max = 4;
  64.     ui_min = -4;
  65.     ui_step = 0.0000001;
  66.     ui_tooltip = "Darker colors appear more saturated to a human eye; use this slider to account for that";
  67.     ui_type = "slider";
  68. > = 1;
  69.  
  70. uniform float saturateKnee <
  71.     ui_category = "Saturation";
  72.     ui_label = "Knee";
  73.     ui_max = 4;
  74.     ui_min = 0;
  75.     ui_step = 0.0000001;
  76.     ui_tooltip = "How smooth will the transition between affected and unaffected areas be";
  77.     ui_type = "slider";
  78. > = 1;
  79.  
  80. // PD80 Base Effects
  81. float getLuma(in float3 col)
  82. {
  83.     return dot(col, SPD);
  84. }
  85.  
  86. // PD80 Base Effects
  87. float3 sat(float3 col, float fac)
  88. {
  89.     return saturate(lerp(getLuma(col.rgb), col.rgb, fac));
  90. }
  91.  
  92. float3 exposure(float3 col, float fac)
  93. {
  94.     // Why? Hell if I know, I'm just not gonna touch that
  95.     fac = fac < 0.0f ? fac * 0.333f : fac;
  96.  
  97.     float3 preexp = col * exp2(fac);
  98.     float3 blowout = (max(0, preexp - 1));
  99.     float3 adjust = float3(blowout.g + blowout.b, blowout.r + blowout.b, blowout.r + blowout.g);
  100.  
  101.     return preexp + adjust;
  102. }
  103.  
  104. float3 PS_SkyboxDarkenFXmain(float4 vpos : SV_Position, float2 texcoord : TexCoord) : SV_Target
  105. {
  106.     float3 input = tex2D(ReShade::BackBuffer, texcoord).rgb;
  107.     float fragDepth = pow(ReShade::GetLinearizedDepth(texcoord), skyboxKnee);
  108.    
  109.     float3 result = input;
  110.    
  111.     if(skyboxDepth <= 0.0)
  112.     {
  113.         skyboxDepth = -skyboxDepth;
  114.         fragDepth = 1.0 - fragDepth;
  115.     }
  116.  
  117.     if(fragDepth >= skyboxDepth)
  118.     {
  119.         float shadow = 1.0 - getLuma(input) / SPD_MAG;
  120.         result = exposure(result, pow(shadow, darkenKnee) * -darkenAmount);
  121.         result = lerp(result, sat(result, saturateAmount), pow(shadow, saturateKnee));
  122.     }
  123.  
  124.     return lerp(input, result, amount);
  125. }
  126.  
  127. technique SkyboxDarken
  128. {
  129.     pass draw
  130.     {
  131.         VertexShader = PostProcessVS;
  132.         PixelShader = PS_SkyboxDarkenFXmain;
  133.     }
  134. }
  135.  
Advertisement
Add Comment
Please, Sign In to add comment