Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Semi-fake HDR shader for MGE XE
- // Artificially extends the brightness range and then compresses it differently based on overall screen brightness
- // Made by 748923
- // Version 9.27.2012.2105
- //////////////////////////////
- // Configurable variables:
- // How much to artifically exaggerate the brightness range (1.0 would be none)
- // Increasing this makes the range of brightness per pixel go beyond the range of 0-1, the maximum range that may be displayed. Higher means more adaptation is necessary.
- // Recommended: 1.0-1.2
- static const float range = 1.05f;
- // How much to negatively offset the brightness range before adapting. Higher means brightest possible scene will be darker.
- static const float rangeoffset = 0.002f;
- // How much to brighten the scene when adapting
- static const float brightmult = 0.2f;
- // Adaptation black level adjustment
- static const float minInputAdapt = 0.9f;
- // Adaptation gamma adjustment
- static const float gammaAdapt = 1.0f;
- // Overall black level adjustment
- static float minInput = 0.148f;
- // Overall gamma adjustment
- static float gamma = 1.0f;
- // Overall saturation adjustment ( >1 = less saturated and <1 = more saturated )
- static const float saturation = 1.15f;
- // You can adjust the gamma for interiors and nights here if the switches are enabled
- #define NIGHTSWITCH 1
- #define INTERIORSWITCH 1
- // Night gamma
- static const float nightGamma = 0.92f;
- // Interior gamma
- static const float intGamma = 0.98f;
- // You can adjust gamma based on distance here if the switch is enabled (only happens at night)
- #define DEPTHDARK 1
- // How much to offset the gamma - Recommended: <0.1
- static const float nightDepthGammaOffset = 0.02f;
- // Distance scale - Recommended: 0.0001-0.0004
- static const float nightDepthScale = 0.0002;
- // End configurable variables
- //////////////////////////////
- bool isInterior;
- static const float pi = 3.14159265f;
- static const float3 coef = {0.3f, 0.7f, 0.11f};
- #if NIGHTSWITCH > 0
- float3 suncol;
- #endif
- float4 HDR;
- texture lastshader;
- #if NIGHTSWITCH == 1 && DEPTHDARK == 1
- texture depthframe;
- #endif
- sampler s0 = sampler_state { texture=<lastshader>; minfilter = linear; magfilter = linear; mipfilter = linear; addressu=mirror; addressv=mirror; };
- #if NIGHTSWITCH == 1 && DEPTHDARK == 1
- sampler s1 = sampler_state {texture=<depthframe>; AddressU=Clamp; AddressV=Clamp;};
- #endif
- float4 tone(float2 tex : TEXCOORD) : COLOR0
- {
- #if NIGHTSWITCH == 1 && DEPTHDARK == 1
- float depth = tex2D(s1, tex).r;
- #endif
- float3 c = tex2D(s0, tex).rgb;
- float HDRavg = (HDR.r + HDR.g + HDR.b) / 3;
- //Extend range (linear)
- c = c * range - rangeoffset;
- //Recompress range with arctangent to fix "burned" colors
- c = 0.33 * (pi*0.5 - atan(-4*c+2));
- //maxInput based on HDRavg
- float maxInput = clamp((HDRavg * brightmult) + (1-brightmult), 0.1, 1.0);
- //Adjust minInput based on HDRavg?
- minInput = minInput*max(minInputAdapt, 1-HDRavg);
- //Adjust gamma based on HDRavg?
- gamma = gamma*max(gammaAdapt, 1-HDRavg);
- #if NIGHTSWITCH == 1
- if ( !isInterior )
- {
- // Day/night interpolation from the sun color, yay!!!
- float daynight = 1 - saturate(suncol.r*3.0);
- gamma *= gamma - daynight*(1.0 - nightGamma);
- #if DEPTHDARK == 1
- // Night depth gamma!
- gamma -= saturate(depth*nightDepthScale)*nightDepthGammaOffset*daynight;
- #endif
- }
- #endif
- #if INTERIORSWITCH == 1
- if ( isInterior )
- {
- gamma *= intGamma;
- }
- #endif
- //correct gamma
- c = pow(c, 1.0/gamma);
- //Adjust saturation
- c.rgb = lerp(c.rgb, dot(coef.xyz, c.rgb), saturation-1 );
- //Adjust with black and white levels
- c = min( max(c - minInput, 0.0) / (maxInput-minInput), 1.0);
- return float4( saturate(c) , 1.0);
- }
- technique T0 < string MGEinterface = "MGE XE 0"; bool requiresHDR = true; >
- {
- pass { PixelShader = compile ps_3_0 tone(); }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement