Dynamically set colors during runtime

This commit is contained in:
loki
2021-05-03 22:06:55 +02:00
parent 37a9256587
commit 900d59b3ac
5 changed files with 130 additions and 53 deletions

View File

@@ -6,27 +6,23 @@ struct FragTexWide {
float3 uuv : TEXCOORD0;
};
cbuffer ColorMatrix : register(b0) {
float4 color_vec_y;
float4 color_vec_u;
float4 color_vec_v;
};
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float2 PS(FragTexWide input) : SV_Target
{
// float4 color_vec_y = { 0.301f, 0.586f, 0.113f, 0.0f };
// float4 color_vec_u = { -0.168f, -0.328f, 0.496f, 128.0f / 256.0f };
// float4 color_vec_v = { 0.496f, 0.414f, 0.082f, 128.0f / 256.0f };
float4 color_vec_y = { 0.299, 0.587, 0.114, 0.0625 };
float4 color_vec_u = { -0.168736, -0.331264, 0.5, 0.5 };
float4 color_vec_v = { 0.5, -0.418688, -0.081312, 0.5 };
// float4 color_vec_y = { 0.2578f, 0.5039f, 0.0977, 0.0625 };
// float4 color_vec_u = { -0.1484, 0.2891, 0.4375, 128.0f / 256.0f };
// float4 color_vec_v = { 0.4375, -0.3672, -0.0703, 128.0f / 256.0f };
float3 rgb_left = image.Sample(def_sampler, input.uuv.xz).rgb;
float3 rgb_right = image.Sample(def_sampler, input.uuv.yz).rgb;
float3 rgb = (rgb_left + rgb_right) * 0.5;
float u = dot(color_vec_u.xyz, rgb) + color_vec_u.w;
float v = dot(color_vec_v.xyz, rgb) + color_vec_v.w;
return float2(u, v);
}

View File

@@ -3,12 +3,15 @@ struct VertTexPosWide {
float4 pos : SV_POSITION;
};
cbuffer info : register(b0) {
float width_i;
};
//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
VertTexPosWide VS(uint vI : SV_VERTEXID)
{
float width_i = 1.0f / 1920.0f;
float idHigh = float(vI >> 1);
float idLow = float(vI & uint(1));

View File

@@ -5,6 +5,12 @@ Texture2D image : register(t0);
SamplerState def_sampler : register(s0);
cbuffer ColorMatrix : register(b0) {
float4 color_vec_y;
float4 color_vec_u;
float4 color_vec_v;
};
struct PS_INPUT
{
float4 pos : SV_POSITION;
@@ -16,11 +22,8 @@ struct PS_INPUT
//--------------------------------------------------------------------------------------
float PS(PS_INPUT frag_in) : SV_Target
{
float4 color_vec_y = { 0.299, 0.587, 0.114, 0.0625 };
float4 color_vec_u = { -0.168736, -0.331264, 0.5, 0.5 };
float4 color_vec_v = { 0.5, -0.418688, -0.081312, 0.5 };
float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
float y = dot(color_vec_y.xyz, rgb) + color_vec_y.w;
return y;
}