Please use english language
It is currently 30 Mar 2017, 06:41

All times are UTC





Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: 02 Dec 2015, 22:05 
Offline
*sensei*

Joined: 05 Apr 2014, 10:29
Posts: 471
Location: Taiwan
A detail version of what is happening in APPLYGAMECOLORCORRECTION.

Here is the overall structure
Code:
#ifdef APPLYGAMECOLORCORRECTION
   //fallout4 vanilla post process. Just an example for modders, better not enable without know how to edit and what you need
   
// combines bloom, adaptation     
   float4   r0, r1, r2, r3;
   r0.xyz = color.xyz;
   r1.xy = Params01[4].zw * IN.txcoord0.xy;
   r1.xyz = TextureBloom.Sample(Sampler1, r1.xy).xyz;
   r0.w = TextureAdaptation.Sample(Sampler0, IN.txcoord0.xy).x;
   r1.w = Params01[1].z / (0.001 + r0.w);
   r2.x = r1.w < Params01[1].y;
   r1.w = r2.x ? Params01[1].y : r1.w;
   r2.x = Params01[1].x < r1.w;
   r1.w = r2.x ? Params01[1].x : r1.w;
   r0.xyz = r1.xyz + r0.xyz;
   r0.xyz = r0.xyz * r1.w;
// returns color_adapt
   
// filmic tonemapper   
   r1.xyz = r0.xyz + r0.xyz;
   r2.xyz = r0.xyz * 0.3 + 0.05;
   r3.xy = float2(0.2, 3.333333) * Params01[1].w;
   r2.xyz = r1.xyz * r2.xyz + r3.x;
   r0.xyz = r0.xyz * 0.3 + 0.5;
   r0.xyz = r1.xyz * r0.xyz + 0.06;
   r0.xyz = r2.xyz / r0.xyz;
   r0.xyz = -Params01[1].w * 3.333333 + r0.xyz;
   r1.x = Params01[1].w * 0.2 + 19.376;
   r1.x = r1.x * 0.0408564 - r3.y;
   r1.xyz = r0.xyz / r1.x;
// returns filmic result
   
// post process   
   r0.x = dot(r1.xyz, float3(0.2125, 0.7154, 0.0721));
   r1.xyz = r1.xyz - r0.x;
   r1.xyz = Params01[2].x * r1.xyz + r0.x;
   r2.xyz = r0.x * Params01[3].xyz - r1.xyz;
   r1.xyz = Params01[3].w * r2.xyz + r1.xyz;
   r1.xyz = Params01[2].w * r1.xyz - r0.w;
   r0.xyz = Params01[2].z * r1.xyz + r0.w;
   //last color filter used only for certain conditions, like rifle night scope
   color.xyz = lerp(r0.xyz, Params01[5].xyz, Params01[5].w);

   color.xyz=saturate(color);
   color.xyz = pow(color.xyz, 1.0/2.2);
#endif //APPLYGAMECOLORCORRECTION



And in detail:

the first part is to combine bloom and scale the result with adaption to get Color_adpt for tonemapper.
Code:
#ifdef APPLYGAMECOLORCORRECTION
   //fallout4 vanilla post process. Just an example for modders, better not enable without know how to edit and what you need
   
    float2 bloom_offset = Params01[4].zw;  //bloom coord scaling
    float3 adaptation   = Params01[1].xyz;  //.x = adaption max, .y = min, .z = scale/sensitivity

    float4 color        = TextureColor.Sample(Sampler0, IN.txcoord0.xy);
    float3 bloom        = TextureBloom.Sample(Sampler1, bloom_offset * IN.txcoord0.xy).rgb;
    float  middlegray   = TextureAdaptation.Sample(Sampler0, IN.txcoord0.xy).x;
   
    float  adapt = clamp(adaptation.z / (0.001 + middlegray), adaptation.y, adaptation.x); //auto exposure
    color.rgb    = (color.rgb + bloom.rgb) * adapt;    //bloom in add mode


then do tonemapping. bethesda and filmic operator, what do you know!
Code:
// Filmic operator   
    float A = 0.3;           // Shoulder Strength
    float B = 0.5;           // Linear Strength
    float C = 0.1;           // Linear Angle
    float D = 0.1;           // Toe Strength
    float E = Params01[1].w; // Toe Numerator
    float F = 0.3;           // Toe Denominator
    float W = 5.6;           // LinearWhite, white level

    color.rgb = Tonemap_Filmic(color.rgb, W, A, B, C, D, E, F);


Filmic function:
Code:
float3 Tonemap_Filmic(float3 color, float W, float A, float B, float C, float D, float E, float F)
{
    float4 res = float4(color.rgb, W);
    res        = (res * ( A * res + C * B) + D * E) / (res * ( A * res + B) + D * F);
    res       -= E / F;
    return res.rgb / res.a;
}



The final part is post color correction where the Params can be modded in the future through Creation Kit.
Code:
#define LUM_709  float3(0.2125, 0.7154, 0.0721)
//color corrections   
    float  saturation  = Params01[2].x;   // 0 == gray scale
    float3 tint_color  = Params01[3].rgb; // tint color
    float  tint_weight = Params01[3].w;   // 0 == no tint
    float  contrast    = Params01[2].z;   // 0 == no contrast
    float  brightness  = Params01[2].w;   // intensity
    float3 fade        = Params01[5].xyz; // fade current scene to specified color, mostly used in special effects
    float  fade_weight = Params01[5].w;   // 0 == no fade

    color.a   = dot(color.rgb, LUM_709);                            //get luminance
    color.rgb = lerp(color.a, color.rgb, saturation);               //saturation
    color.rgb = lerp(color.rgb, color.a * tint.rgb, tint.a);        //tint
    color.rgb = lerp(middlegray, brightness * color.rgb, contrast); //contrast & intensity
    color.rgb = lerp(color.rgb, fade, fade_weight);                 //fade current scene to specified color

    color.rgb = saturate(color.rgb);
    color.rgb = pow(color.rgb, 1.0/2.2);
#endif //APPLYGAMECOLORCORRECTION

THE END



Haven't tested ingame though, might have missing something.
⁄(⁄ ⁄•⁄ω⁄•⁄ ⁄)⁄

thanks to roxahris for testing, fix typo in filmic function & constant.
update Oct/30/16 fix a error on float adapt.

_________________
Intel Xeon L5639 6C12T @3.96GHz // Gigabyte ga-x58a-ud3r// MSI GTX680 4G// 24G RAM
Flickr
YouTube


Last edited by kingeric1992 on 30 Oct 2016, 10:09, edited 2 times in total.

Top
 Profile  
 
Tomoko
PostPosted: 03 Dec 2015, 00:15 
Offline
*blah-blah-blah maniac*
User avatar

Joined: 27 Dec 2011, 08:53
Posts: 10945
Location: St.Petersburg
I edited your post by adding "color.xyz = pow(color.xyz, 1.0/2.2);" lines from latest update. They are required to make proper ldr output instead of linear space.

_________________
Core i5-4690K 3.5 GHz, 16 Gb ram, GeForce 650 Ti 2 Gb, X-Fi Xtreme Music, WinXP/Win7
I am INFP, not the brutal, godamnit.


Top
 Profile  
 
PostPosted: 03 Dec 2015, 17:49 
Offline
*master*
User avatar

Joined: 08 Nov 2012, 15:24
Posts: 119
Testing it in-game, it appears the tonemapping is off compared to the original. Other sections are fine, however.
Other sections with original tonemapping code -/- All sections

_________________
Resonant ENB for Dragon's Dogma | IAXE2 for Fallout 4 | Luminous ENB for Skyrim SE


Top
 Profile  
 
PostPosted: 03 Dec 2015, 21:53 
Offline
*sensei*

Joined: 05 Apr 2014, 10:29
Posts: 471
Location: Taiwan
roxahris wrote:
Testing it in-game, it appears the tonemapping is off compared to the original. Other sections are fine, however.
Other sections with original tonemapping code -/- All sections


found a typo in filmic function & re calculate the W to 5.6. thanks.

_________________
Intel Xeon L5639 6C12T @3.96GHz // Gigabyte ga-x58a-ud3r// MSI GTX680 4G// 24G RAM
Flickr
YouTube


Top
 Profile  
 
PostPosted: 03 Dec 2015, 22:40 
Offline
*sensei*
User avatar

Joined: 27 Dec 2011, 21:33
Posts: 301
Location: Poland, Gdańsk
Delete

_________________
OS: Windows 10
CPU: Intel Core i7 3770 @4.2GHz
RAM: DDR3 24GB 1333 MHz
GPU: GeForce GTX 980TI MSI Gaming 6GB
Sound Card: X-FI Titanium HD
Mobo: Asrock Z77 EXTREME4
Monitor: M340CLZ 34" 3440x1440 100HZ AMD FREE Sync Curved Monitor


Last edited by MaxG3D on 28 Mar 2017, 00:25, edited 1 time in total.

Top
 Profile  
 
PostPosted: 30 Oct 2016, 10:10 
Offline
*sensei*

Joined: 05 Apr 2014, 10:29
Posts: 471
Location: Taiwan
update Oct/30/16 fix a error on float adapt.

_________________
Intel Xeon L5639 6C12T @3.96GHz // Gigabyte ga-x58a-ud3r// MSI GTX680 4G// 24G RAM
Flickr
YouTube


Top
 Profile  
 
PostPosted: 03 Nov 2016, 06:41 
Offline

Joined: 02 Nov 2016, 20:28
Posts: 2
Hi Kingeric :D

Glad to see you're still coding! Didn't think you were still around.

I just now posted something about your amazing ENBlensFX file (in the Effects section) and noticed your recent posts here as well.

Can you please have a look at this if you have time? Thx!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group