Swapped R and B channels in lut-default.png, and adjusted D3D9 LUT-application behaviour. (#11004) [Ryan Holtz]

* lut-default.png: Swapped red and blue channels (fixes GitHub #11001).
* render/d3d/d3dlsl.cpp: Changed screen LUT application to be applied during the color convolution pass on raster systems.
This commit is contained in:
MooglyGuy 2023-03-19 17:59:44 +01:00 committed by GitHub
parent 4ff301b134
commit ba5ec29211
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 11 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 480 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -1,14 +1,23 @@
// license:BSD-3-Clause // license:BSD-3-Clause
// copyright-holders:Ryan Holtz // copyright-holders:Ryan Holtz, W. M. Martinez
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Color-Convolution Effect // Color-Convolution Effect
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Macros
//-----------------------------------------------------------------------------
#define LUT_TEXTURE_WIDTH 4096.0f
#define LUT_SIZE 64.0f
#define LUT_SCALE float2(1.0f / LUT_TEXTURE_WIDTH, 1.0f / LUT_SIZE)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Sampler Definitions // Sampler Definitions
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
texture Diffuse; texture Diffuse;
texture LutTexture;
sampler DiffuseSampler = sampler_state sampler DiffuseSampler = sampler_state
{ {
@ -21,6 +30,35 @@ sampler DiffuseSampler = sampler_state
AddressW = CLAMP; AddressW = CLAMP;
}; };
sampler2D LutSampler = sampler_state
{
Texture = <LutTexture>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
AddressW = CLAMP;
};
//-----------------------------------------------------------------------------
// Utilities
//-----------------------------------------------------------------------------
float3 apply_lut(float3 color)
{
// NOTE: Do not change the order of parameters here.
float3 lutcoord = float3((color.rg * (LUT_SIZE - 1.0f) + 0.5f) *
LUT_SCALE, color.b * (LUT_SIZE - 1.0f));
float shift = floor(lutcoord.z);
lutcoord.x += shift * LUT_SCALE.y;
color.rgb = lerp(tex2D(LutSampler, lutcoord.xy).rgb, tex2D(LutSampler,
float2(lutcoord.x + LUT_SCALE.y, lutcoord.y)).rgb,
lutcoord.z - shift);
return color;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Vertex Definitions // Vertex Definitions
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -83,11 +121,15 @@ uniform float3 BluRatios = float3(0.0f, 0.0f, 1.0f);
uniform float3 Offset = float3(0.0f, 0.0f, 0.0f); uniform float3 Offset = float3(0.0f, 0.0f, 0.0f);
uniform float3 Scale = float3(1.0f, 1.0f, 1.0f); uniform float3 Scale = float3(1.0f, 1.0f, 1.0f);
uniform float Saturation = 1.0f; uniform float Saturation = 1.0f;
uniform bool LutEnable;
float4 ps_main(PS_INPUT Input) : COLOR float4 ps_main(PS_INPUT Input) : COLOR
{ {
float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord); float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord);
if (LutEnable)
BaseTexel.rgb = apply_lut(BaseTexel.rgb);
float3 OutRGB = BaseTexel.rgb; float3 OutRGB = BaseTexel.rgb;
// RGB Tint & Shift // RGB Tint & Shift

View File

@ -166,11 +166,7 @@ uniform bool UiLutEnable;
float4 ps_screen_main(PS_INPUT Input) : COLOR float4 ps_screen_main(PS_INPUT Input) : COLOR
{ {
float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord); return tex2D(DiffuseSampler, Input.TexCoord);
if (LutEnable)
BaseTexel.rgb = apply_lut(BaseTexel.rgb);
return BaseTexel;
} }
float4 ps_vector_buffer_main(PS_INPUT Input) : COLOR float4 ps_vector_buffer_main(PS_INPUT Input) : COLOR

View File

@ -879,6 +879,7 @@ int shaders::create_resources()
color_effect->add_uniform("Scale", uniform::UT_VEC3, uniform::CU_COLOR_SCALE); color_effect->add_uniform("Scale", uniform::UT_VEC3, uniform::CU_COLOR_SCALE);
color_effect->add_uniform("Saturation", uniform::UT_FLOAT, uniform::CU_COLOR_SATURATION); color_effect->add_uniform("Saturation", uniform::UT_FLOAT, uniform::CU_COLOR_SATURATION);
color_effect->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS); color_effect->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS);
color_effect->add_uniform("LutEnable", uniform::UT_BOOL, uniform::CU_LUT_ENABLE);
deconverge_effect->add_uniform("ConvergeX", uniform::UT_VEC3, uniform::CU_CONVERGE_LINEAR_X); deconverge_effect->add_uniform("ConvergeX", uniform::UT_VEC3, uniform::CU_CONVERGE_LINEAR_X);
deconverge_effect->add_uniform("ConvergeY", uniform::UT_VEC3, uniform::CU_CONVERGE_LINEAR_Y); deconverge_effect->add_uniform("ConvergeY", uniform::UT_VEC3, uniform::CU_CONVERGE_LINEAR_Y);
@ -932,9 +933,6 @@ int shaders::create_resources()
prescale_point_effect->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS); prescale_point_effect->add_uniform("SourceDims", uniform::UT_VEC2, uniform::CU_SOURCE_DIMS);
default_effect->add_uniform("LutEnable", uniform::UT_BOOL, uniform::CU_LUT_ENABLE);
default_effect->add_uniform("UiLutEnable", uniform::UT_BOOL, uniform::CU_UI_LUT_ENABLE);
ui_effect->add_uniform("LutEnable", uniform::UT_BOOL, uniform::CU_LUT_ENABLE); ui_effect->add_uniform("LutEnable", uniform::UT_BOOL, uniform::CU_LUT_ENABLE);
ui_effect->add_uniform("UiLutEnable", uniform::UT_BOOL, uniform::CU_UI_LUT_ENABLE); ui_effect->add_uniform("UiLutEnable", uniform::UT_BOOL, uniform::CU_UI_LUT_ENABLE);
@ -942,7 +940,6 @@ int shaders::create_resources()
ui_wrap_effect->add_uniform("UiLutEnable", uniform::UT_BOOL, uniform::CU_UI_LUT_ENABLE); ui_wrap_effect->add_uniform("UiLutEnable", uniform::UT_BOOL, uniform::CU_UI_LUT_ENABLE);
vector_buffer_effect->add_uniform("LutEnable", uniform::UT_BOOL, uniform::CU_LUT_ENABLE); vector_buffer_effect->add_uniform("LutEnable", uniform::UT_BOOL, uniform::CU_LUT_ENABLE);
vector_buffer_effect->add_uniform("UiLutEnable", uniform::UT_BOOL, uniform::CU_UI_LUT_ENABLE);
return 0; return 0;
} }
@ -1159,6 +1156,8 @@ int shaders::color_convolution_pass(d3d_render_target *rt, int source_index, pol
uint32_t tint = (uint32_t)poly->tint(); uint32_t tint = (uint32_t)poly->tint();
float prim_tint[3] = { ((tint >> 16) & 0xff) / 255.0f, ((tint >> 8) & 0xff) / 255.0f, (tint & 0xff) / 255.0f }; float prim_tint[3] = { ((tint >> 16) & 0xff) / 255.0f, ((tint >> 8) & 0xff) / 255.0f, (tint & 0xff) / 255.0f };
curr_effect->set_vector("PrimTint", 3, prim_tint); curr_effect->set_vector("PrimTint", 3, prim_tint);
curr_effect->set_texture("LutTexture", !lut_texture ? nullptr : lut_texture->get_finaltex());
curr_effect->set_bool("UiLutEnable", false);
next_index = rt->next_index(next_index); next_index = rt->next_index(next_index);
blit(rt->source_surface[next_index].Get(), false, D3DPT_TRIANGLELIST, 0, 2); blit(rt->source_surface[next_index].Get(), false, D3DPT_TRIANGLELIST, 0, 2);
@ -1467,6 +1466,7 @@ int shaders::vector_buffer_pass(d3d_render_target *rt, int source_index, poly_in
curr_effect->set_texture("Diffuse", rt->target_texture[next_index].Get()); curr_effect->set_texture("Diffuse", rt->target_texture[next_index].Get());
curr_effect->set_texture("LutTexture", !lut_texture ? nullptr : lut_texture->get_finaltex()); curr_effect->set_texture("LutTexture", !lut_texture ? nullptr : lut_texture->get_finaltex());
curr_effect->set_bool("UiLutEnable", false);
// we need to clear the vector render target here // we need to clear the vector render target here
next_index = rt->next_index(next_index); next_index = rt->next_index(next_index);
@ -1486,7 +1486,9 @@ int shaders::screen_pass(d3d_render_target *rt, int source_index, poly_info *pol
curr_effect->update_uniforms(); curr_effect->update_uniforms();
curr_effect->set_texture("Diffuse", rt->target_texture[next_index].Get()); curr_effect->set_texture("Diffuse", rt->target_texture[next_index].Get());
curr_effect->set_texture("LutTexture", !lut_texture ? nullptr : lut_texture->get_finaltex()); curr_effect->set_texture("LutTexture", nullptr);
curr_effect->set_bool("LutEnable", false);
curr_effect->set_bool("UiLutEnable", false);
blit(backbuffer.Get(), false, poly->type(), vertnum, poly->count()); blit(backbuffer.Get(), false, poly->type(), vertnum, poly->count());