[HLSL CODE] 3D LUT

share shaders here
  • Author
  • Message
Offline
User avatar
Posts: 19
Joined: 04 Jan 2016, 14:59

Re: [HLSL CODE] 3D LUT

Thanks for your fast answer kingeric!

The "problem" I have is that I've implemented your 3DLUT code through JawZ modular shader library and the DNI separation mentioned earlier. What I'm planning to do is to switch the 3 textures (D, N, I) independently ingame (didn't mention that, sorry).

I might be wrong with the following statement: using techniques would not only require to implement the code directly without helper files but also to set up techniques with numerous combinations of those three textures. I'm planning to start off with 10 textures to choose from, which leads to n!/((n-k)!*k!)= 120 sets of techniques if I want to have the maximum of combinations to choose from.

I've never seen this, but having a dropdown list for D, N, I 3DLUT texture, each with 10 textures to choose from would be the most convenient way.

Offline
*blah-blah-blah maniac*
Posts: 565
Joined: 05 Apr 2014, 10:29
Location: Taiwan

Re: [HLSL CODE] 3D LUT

then do this instead. you would need to combine your textures into texture atlas. so for DNI, you would end up with 3 of this.
Image ( by MS paint)

UI:

Code: Select all

int	lut_D <	string UIName="lut_D";	float UIMin=0;	float UIMax=9;> = {0};
int	lut_N <	string UIName="lut_N";	float UIMin=0;	float UIMax=9;> = {0};
int	lut_I <	string UIName="lut_I";	float UIMin=0;	float UIMax=9;> = {0};
resources:

Code: Select all

Texture2D          LUTtex_D< string UIName = "3DLut0";  string ResourceName = "LUTtex_D.png"; >; //day
Texture2D          LUTtex_N< string UIName = "3DLut0";  string ResourceName = "LUTtex_N.png"; >; //night
Texture2D          LUTtex_I< string UIName = "3DLut0";  string ResourceName = "LUTtex_I.png"; >; // interior

Code: Select all

if(enablelut)
{
    float2 CLut_pSize = {0.00390625, 0.0625};// 1 / float2(256, 16)
    color.rgb         = saturate(color.rgb) * 15;
    
    float3 CLut_UV;    
    CLut_UV.z = floor(color.z);
    color.z  -= CLut_UV.z;
    color.xy  = (color.xy + 0.5) * CLut_pSize;
    color.x  += CLut_UV.z * CLut_pSize.y;
    color.y  *= 0.1; // 1 / 10

    CLut_UV.x = color.x;
    CLut_UV.z = CLut_UV.x + CLut_pSize.y;
    CLut_UV.y = color.y + lut_D * 0.1;
    float3 lutcolor_D = lerp(LUTtex_D.SampleLevel(Sampler1, CLut_UV.xy, 0).rgb, LUTtex_D.SampleLevel(Sampler1, CLut_UV.zy, 0).rgb, color.z);
    CLut_UV.y = color.y + lut_N * 0.1;
    float3 lutcolor_N = lerp(LUTtex_N.SampleLevel(Sampler1, CLut_UV.xy, 0).rgb, LUTtex_N.SampleLevel(Sampler1, CLut_UV.zy, 0).rgb, color.z);
    CLut_UV.y = color.y + lut_I * 0.1;
    float3 lutcolor_I = lerp(LUTtex_I.SampleLevel(Sampler1, CLut_UV.xy, 0).rgb, LUTtex_I.SampleLevel(Sampler1, CLut_UV.zy, 0).rgb, color.z);

    color.rgb         = lerp(lerp( lutcolor_N, lutcolor_D, ENightDayFactor), lutcolor_I, EInteriorFactor);
}
_________________
Intel Xeon L5639 6C12T @3.96GHz | Gigabyte ga-x58a-ud3r | MSI GTX680 4G | 48G RAM | Intel 760p Nvme w clover bootloader
Flickr
YouTube

Offline
User avatar
Posts: 19
Joined: 04 Jan 2016, 14:59

Re: [HLSL CODE] 3D LUT

Now that looks neat! Thanks alot! I'm going to test it rightaway.

Works like a charm! Implemented it straightaway for my OLYMPUS preset.

Offline
*master*
Posts: 187
Joined: 18 Mar 2015, 18:39

Re: [HLSL CODE] 3D LUT

Awesome job, but can 4096 x 64 LUT be supported? It would be more accurate than 256 x 16, which is important for those who would use this feature to calibrate their display.
_________________
i7 8700K @ 5Ghz | ASUS Z370 Hero X WiFi | Corsair 16GB @ 3200Mhz | RTX 2070 Super @ 1950Mhz | Xonar DGX | 768GB NVMe SSD | 2TB HDD | Corsair 850W | LG 32GK850G-B 1440p 32' G-Sync 165Hz VA | Logitech G402 | Corsair K70 Rapidfire | Windows 10 LTSC 1809

Offline
*blah-blah-blah maniac*
Posts: 565
Joined: 05 Apr 2014, 10:29
Location: Taiwan

Re: [HLSL CODE] 3D LUT

Code: Select all

//dx10/11
    float2 CLut_pSize =  1 / float2(4096, 64);
    color.rgb  = saturate(color.rgb) * 63;
    float4 CLut_UV;
    CLut_UV.w  = floor(color.b);
    CLut_UV.xy = (color.rg + 0.5) * CLut_pSize;
    CLut_UV.x += CLut_UV.w * CLut_pSize.y;
    CLut_UV.z  = CLut_UV.x + CLut_pSize.y;
    color.rgb  = lerp(LUTtex.SampleLevel(Sampler1, CLut_UV.xy, 0).rgb, LUTtex.SampleLevel(Sampler1, CLut_UV.zy, 0).rgb, color.b - CLut_UV.w);
if possible, can you upload a comparison shot on 16 vs 64 ?
_________________
Intel Xeon L5639 6C12T @3.96GHz | Gigabyte ga-x58a-ud3r | MSI GTX680 4G | 48G RAM | Intel 760p Nvme w clover bootloader
Flickr
YouTube

Offline
User avatar
Posts: 19
Joined: 04 Jan 2016, 14:59

Re: [HLSL CODE] 3D LUT

MonarchX wrote:Awesome job, but can 4096 x 64 LUT be supported? It would be more accurate than 256 x 16, which is important for those who would use this feature to calibrate their display.
Could you upload your neutral 4096 x 64 LUT for testing? If there's a noticeable effect I'd like to implement that too.

Offline
User avatar
Posts: 19
Joined: 04 Jan 2016, 14:59

Re: [HLSL CODE] 3D LUT

The difference between 4096x64 to 256x16 is pretty subtle (at least for me). The difference is visible if you blend two screenhots with "difference" in photoshop. Seems like edges are affected especially.

256x16
4096x64
difference

Offline
*blah-blah-blah maniac*
Posts: 565
Joined: 05 Apr 2014, 10:29
Location: Taiwan

Re: [HLSL CODE] 3D LUT

Thanks.

the difference will be more visible if there are drastic change applied on LUT.
It use linear interpolation where the texture scale represent total segment count.
the larger the scale, the more detailed manipulation can be preserved in lut texture.
_________________
Intel Xeon L5639 6C12T @3.96GHz | Gigabyte ga-x58a-ud3r | MSI GTX680 4G | 48G RAM | Intel 760p Nvme w clover bootloader
Flickr
YouTube

Offline
User avatar
*sensei*
Posts: 391
Joined: 03 Oct 2012, 06:12
Location: Ottawa, Canada

Re: [HLSL CODE] 3D LUT

Is there code to tie in adaptation/brightness (much like how Palette has adaptation/brightness) to the LUT shader?
_________________
Intel Core i9 10900K @4.9GHz | ASUS ROG Strix Z490-G | NVIDIA - EVGA RTX 2080 XC Ultra | 32GB DDR4 Corsair Vengeance RGB PRO | 2x ADATA XPG SX8200 Pro 1TB

Flickr
Twitter

Offline
*blah-blah-blah maniac*
Posts: 565
Joined: 05 Apr 2014, 10:29
Location: Taiwan

Re: [HLSL CODE] 3D LUT

You can use both of them at the same time, just add the 3dlut part after enbpalette.

Here is the code to load additional texture

Code: Select all

texture2D 3dlut < string ResourceName="lutname.png"; >; 
sampler2D 3dlutSampler = sampler_state 
{
    Texture = <3dlut>;
    AddressU  = Clamp; 
    AddressV  = Clamp;
    MinFilter = Linear; 
    MagFilter = Linear; 
    MipFilter = NONE;
    MaxMipLevel  = 0; 
    MipMapLodBias  = 0;
    SRGBTexture   =   FALSE;
};
And replace the "_s7" in LUT code with 3dlutSampler.
_________________
Intel Xeon L5639 6C12T @3.96GHz | Gigabyte ga-x58a-ud3r | MSI GTX680 4G | 48G RAM | Intel 760p Nvme w clover bootloader
Flickr
YouTube
Post Reply