Page 1 of 3

[HLSL code] Original postprocess SSE.ver

Posted: 03 Nov 2016, 14:12
by kingeric1992
It start with loading textures:
The UV coord of bloom texture has a scaling factor controlled by clamps and a on/off switch.

Code: Select all

    bool   scalebloom  = (0.5<=Params01[0].x);
    float2 scaleduv    = clamp(0.0, Params01[6].zy, Params01[6].xy * IN.txcoord0.xy);
    float4 color       = TextureColor.Sample(Sampler0, IN.txcoord0.xy); //hdr scene color, point sampler
    float4 bloom       = TextureBloom.Sample(Sampler1, (scalebloom)? IN.txcoord0.xy: scaleduv); //linear sampler
    float2 middlegray  = TextureAdaptation.Sample(Sampler1, IN.txcoord0.xy).xy; //.x == current, .y == previous
    middlegray.y = 1.0; //bypass for enbadaptation format

then, the tonemapper"s"
A additional switch for switching between Reinhard-modified and Filmic ALU by Heji

Code: Select all

    bool   UseFilmic   = (0.5<Params01[2].z);
    float  WhiteFactor = Params01[2].y;
    
    float  original_lum = max( dot(LUM_709, color.rgb), DELTA);
    float  lum_scaled   = original_lum * middlegray.y / middlegray.x;
           
    float  lum_filmic = max( lum_scaled - 0.004, 0.0); 
           lum_filmic = lum_filmic * (lum_filmic * 6.2 + 0.5)  / (lum_filmic * (lum_filmic * 6.2 + 1.7) + 0.06);
           lum_filmic = pow(lum_filmic, 2.2);          //de-gamma-correction for gamma-corrected tonemapper
           lum_filmic = lum_filmic * WhiteFactor;    //linear scale
    
    float lum_reinhard = lum_scaled * (lum_scaled * WhiteFactor + 1.0) / (lum_scaled + 1.0);
    
    float lum_mapped   = (UseFilmic)? lum_filmic : lum_reinhard; //if filmic
    
    color.rgb = color.rgb * lum_mapped / original_lum;

then do the bloom blending, this part is identical to the old Skyrim.

Code: Select all

    float bloomfactor = Params01[2].x;
    color.rgb = color.rgb + bloom.rgb * saturate(bloomfactor - lum_mapped); 
And the imagespace modifiers, mostly the same as the old Skyrim,
but it has a inactive process with Params01[6].w, seemly supposed to have a gamma ops there.

Code: Select all

    float  saturation  = Params01[3].x;   // 0 == gray scale
    float  contrast    = Params01[3].z;   // 0 == no contrast
    float  brightness  = Params01[3].w;   // intensity
    
    
    float3 tint_color  = Params01[4].rgb; // tint color
    float  tint_weight = Params01[4].w;   // 0 == no tint

    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);
    color.rgb = lerp(color.a, color.rgb, saturation);
    color.rgb = lerp(color.rgb, tint_color * color.a , tint_weight);
    color.rgb = lerp(middlegray.x, color.rgb * brightness, contrast);
//    color.rgb = pow(saturate(color.rgb), Params01[6].w); //this line is unused??
    color.rgb = lerp(color.rgb, fade, fade_weight);
    color.a = 1.0;

Re: [HLSL code] Original postprocess SEE.ver

Posted: 03 Nov 2016, 23:49
by abc75179778300
Hell yeah~ ;) ;)

Re: [HLSL code] Original postprocess SEE.ver

Posted: 04 Nov 2016, 00:53
by roxahris
This is really interesting. Thank you very much.

Re: [HLSL code] Original postprocess SEE.ver

Posted: 05 Nov 2016, 23:00
by ibbanez
Now to learn how to take that and apply it :) lol..... baby steps... one day....

Re: [HLSL code] Original postprocess SEE.ver

Posted: 13 Nov 2016, 08:43
by roxahris
A small bug - tint_color and tint_weight should refer to Params01[4], not Params01[3].

While this may be obvious to some people, I feel I should note that as ENB doesn't have a UseOriginalAdaptation option, you'll need to replace the code for lum_scaled with one designed around ENB's adaptation system, which is single channel. Otherwise, you'll get a black screen.

Re: [HLSL code] Original postprocess SEE.ver

Posted: 13 Nov 2016, 09:28
by kingeric1992
@roxahris

Indeed. thanks for the reply.

post updated.

Re: [HLSL code] Original postprocess SEE.ver

Posted: 03 Jan 2017, 09:46
by l00
I found what is the coef definition for LUM_709 (just in case, is that right: "0.2126, 0.7152, 0.0722"?) but what should be used for DELTA, what is this variable ?

Re: [HLSL code] Original postprocess SEE.ver

Posted: 03 Jan 2017, 14:52
by Marty McFly
Assuming from the code, just some very small value, so the original lum can never be 0, hence avoiding the division through 0 in the last line of the tonemapper. It's very common in shadercode to do stuff like this, max(x,0.00000001) for instance.

Re: [HLSL code] Original postprocess SEE.ver

Posted: 03 Jan 2017, 16:40
by l00
Ho I see, it works.
Thanks both of you McFly and Kingeric, my AGCC is working great now !

Re: [HLSL code] Original postprocess SEE.ver

Posted: 04 Jan 2017, 06:27
by Oyama
l00
Would you mind sharing your effect.fx ?