Matrix - Vector multiply Bug
- Fu-Bama
-
Topic Author
- Offline
Less More
2 years 10 months ago - 2 years 10 months ago #1 by Fu-Bama
Matrix - Vector multiply Bug was created by Fu-Bama
It seems that DirectX Matrix * Vector is interpreted as Vector * Matrix when using OpenGL game.
Same goes with mul() function.
Converting RGB - YUV - RGB works when:
in OpenGL games I use mul(Vector, Matrix)
in DirecX games I use mul(Matrix, Vector)
Here's little test:
EDIT*
Otherwise it gives green tint.
Games that I used, were Blender and Mirrors Edge.
Same goes with mul() function.
Converting RGB - YUV - RGB works when:
in OpenGL games I use mul(Vector, Matrix)
in DirecX games I use mul(Matrix, Vector)
Here's little test:
Warning: Spoiler!
/*
Bug test Vector * Matrix
*/
////////////////////
/////// MENU ///////
////////////////////
uniform int API <
ui_tooltip = "To see right result change API";
ui_type = "combo";
ui_items = "Now Im using DirectX\0Now Im using OpenGL\0";
> = 0;
uniform int Coefficients <
ui_label = "YUV coefficients";
ui_tooltip = "For digital signal use BT.709, analog (like VGA) use BT.601";
ui_type = "combo";
ui_items = "BT.709\0BT.601\0";
> = 0;
//////////////////////
/////// SHADER ///////
//////////////////////
#include "ReShade.fxh"
// RGB to YUV709
static const float3x3 ToYUV709 =
float3x3(
float3(0.2126, 0.7152, 0.0722),
float3(-0.09991, -0.33609, 0.436),
float3(0.615, -0.55861, -0.05639)
);
// RGB to YUV601
static const float3x3 ToYUV601 =
float3x3(
float3(0.299, 0.587, 0.114),
float3(-0.14713, -0.28886, 0.436),
float3(0.615, -0.51499, -0.10001)
);
// YUV709 to RGB
static const float3x3 ToRGB709 =
float3x3(
float3(1, 0, 1.28033),
float3(1, -0.21482, -0.38059),
float3(1, 2.12798, 0)
);
// YUV601 to RGB
static const float3x3 ToRGB601 =
float3x3(
float3(1, 0, 1.13983),
float3(1, -0.39465, -0.58060),
float3(1, 2.03211, 0)
);
// Shader
void RGB_YUV_RGB_PS(float4 vois : SV_Position, float2 texcoord : TexCoord, out float3 Display : SV_Target)
{
bool YUV709 = (Coefficients == 0);
bool OK = (API == 0);
// Sample display image
// Convert to YUV
Display = OK ?
mul(YUV709 ? ToYUV709 : ToYUV601, tex2D(ReShade::BackBuffer, texcoord).rgb)
:
mul(tex2D(ReShade::BackBuffer, texcoord).rgb, YUV709 ? ToYUV709 : ToYUV601)
;
Display.x *= 0.5; // Changing image Luma
// Convert YUV to RGB
Display = OK ?
mul(YUV709 ? ToRGB709: ToRGB601, Display)
:
mul(Display, YUV709 ? ToRGB709: ToRGB601)
;
}
technique RGB_YUV_RGB
{
pass
{
VertexShader = PostProcessVS;
PixelShader = RGB_YUV_RGB_PS;
}
}
EDIT*
Otherwise it gives green tint.
Games that I used, were Blender and Mirrors Edge.
Last edit: 2 years 10 months ago by Fu-Bama.
Please Log in or Create an account to join the conversation.
- crosire
-
- Offline
Less More
- Posts: 3836
2 years 10 months ago - 2 years 10 months ago #2 by crosire
Replied by crosire on topic Matrix - Vector multiply Bug
Good catch. The GLSL code generator didn't handle literal matrices correctly. This is fixed in commit 77bdd3ac9d5c9fde4dc93b31a2fc05deef9d6dfa.
Last edit: 2 years 10 months ago by crosire.
Please Log in or Create an account to join the conversation.