I have been using ReShade and ENB to color grade my video games for a while now, and was wondering if this 3D LUT code (or any 3D LUT code for that matter) could be converted to an MMF 2.5 shader?
Original Source
Quote:
UE4, Unity compatible 256x16 look up table(LUT)
Base LUT Image: http://docs.unity3d.com/462/Document...astEnhance.png
Code:float2 CLut_pSize = float2(0.00390625, 0.0625);// 1 / float2(256, 16);
color.rgb = saturate(color.rgb);
color.b *= 15;
float4 CLut_UV = 0;
CLut_UV.w = floor(color.b);
CLut_UV.xy = color.rg * 15 * CLut_pSize + 0.5 * CLut_pSize ;
CLut_UV.x += CLut_UV.w * CLut_pSize.y;
color.rgb = lerp( tex2Dlod(_s7, CLut_UV.xyzz).rgb, tex2Dlod(_s7, CLut_UV.xyzz + float4(CLut_pSize.y, 0, 0, 0)).rgb, color.b - CLut_UV.w);
Further example for higher res LUT image:
If so, could it be modified to have multiple LUTs to define, and fade between them at runtime? If not with the multi-lut single texture shown below, then perhaps with multiple individual textures.Code://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);
Example of multiple LUTs in a single texture:
Another example from ReShade:Quote:
http://i.imgur.com/31hlz5F.png
UI:
Resources:Code: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};
Code: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: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);
}
Code:texture ColorLUTDstTex < string source = "ReShade/CustomFX/Textures/" TuningColorLUTDstTexture; > {Width = TuningColorLUTTileAmountX; Height = TuningColorLUTTileAmountY; Format = RGBA8;};
sampler ColorLUTDstColor { Texture = ColorLUTDstTex; };
#define TuningColorLUTNorm float2(1.0/float(TuningColorLUTTileAmountX),1.0/float(TuningColorLUTTileAmountY))
float4 PS_TuningPalette(float4 vpos : SV_Position, float2 texcoord : TEXCOORD) : SV_Target
{
float4 original = tex2D(RFX_backbufferColor, texcoord.xy);
float4 ColorLUTDst = float4((original.rg*float(TuningColorLUTTileAmountY-1)+0.5f)*TuningColorLUTNorm,original.b*float(TuningColorLUTTileAmountY-1),original.w);
ColorLUTDst.x += trunc(ColorLUTDst.z)*TuningColorLUTNorm.y;
ColorLUTDst = lerp(tex2D(ColorLUTDstColor, ColorLUTDst.xy),tex2D(ColorLUTDstColor, float2(ColorLUTDst.x+TuningColorLUTNorm.y,ColorLUTDst.y)),frac(ColorLUTDst.z));
original = lerp(original,ColorLUTDst,TuningColorLUTIntensity);
return original;
