Refactor shaders
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
#include "include/base_vs_types.hlsl"
|
||||
|
||||
#if defined(LEFT_SUBSAMPLING)
|
||||
vertex_t generate_fullscreen_triangle_vertex(uint vertex_id, float subsample_offset, int rotate_texture_steps)
|
||||
#elif defined (TOPLEFT_SUBSAMPLING)
|
||||
vertex_t generate_fullscreen_triangle_vertex(uint vertex_id, float2 subsample_offset, int rotate_texture_steps)
|
||||
#else
|
||||
vertex_t generate_fullscreen_triangle_vertex(uint vertex_id, int rotate_texture_steps)
|
||||
#endif
|
||||
{
|
||||
vertex_t output;
|
||||
float2 tex_coord;
|
||||
|
||||
if (vertex_id == 0) {
|
||||
output.viewpoint_pos = float4(-1, -1, 0, 1);
|
||||
tex_coord = float2(0, 1);
|
||||
}
|
||||
else if (vertex_id == 1) {
|
||||
output.viewpoint_pos = float4(-1, 3, 0, 1);
|
||||
tex_coord = float2(0, -1);
|
||||
}
|
||||
else if (vertex_id == 2) {
|
||||
output.viewpoint_pos = float4(3, -1, 0, 1);
|
||||
tex_coord = float2(2, 1);
|
||||
}
|
||||
|
||||
if (rotate_texture_steps != 0) {
|
||||
float rotation_radians = radians(90 * rotate_texture_steps);
|
||||
float2x2 rotation_matrix = { cos(rotation_radians), -sin(rotation_radians),
|
||||
sin(rotation_radians), cos(rotation_radians) };
|
||||
float2 rotation_center = { 0.5, 0.5 };
|
||||
tex_coord = round(tex_coord + mul(rotation_matrix, tex_coord - rotation_center));
|
||||
}
|
||||
|
||||
#if defined(LEFT_SUBSAMPLING)
|
||||
output.tex_right_left_center = float3(tex_coord.x, tex_coord.x - subsample_offset, tex_coord.y);
|
||||
#elif defined (TOPLEFT_SUBSAMPLING)
|
||||
output.tex_right_left_top = float3(tex_coord.x, tex_coord.x - subsample_offset.x, tex_coord.y - subsample_offset.y);
|
||||
output.tex_right_left_bottom = float3(tex_coord.x, tex_coord.x - subsample_offset.x, tex_coord.y);
|
||||
#else
|
||||
output.tex_coord = tex_coord;
|
||||
#endif
|
||||
|
||||
return output;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
struct vertex_t
|
||||
{
|
||||
float4 viewpoint_pos : SV_Position;
|
||||
#if defined(LEFT_SUBSAMPLING)
|
||||
float3 tex_right_left_center : TEXCOORD;
|
||||
#elif defined (TOPLEFT_SUBSAMPLING)
|
||||
float3 tex_right_left_top : TEXCOORD;
|
||||
float3 tex_right_left_bottom : TEXCOORD;
|
||||
#else
|
||||
float2 tex_coord : TEXCOORD;
|
||||
#endif
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
// This is a fast sRGB approximation from Microsoft's ColorSpaceUtility.hlsli
|
||||
float3 ApplySRGBCurve(float3 x)
|
||||
{
|
||||
return x < 0.0031308 ? 12.92 * x : 1.13005 * sqrt(x - 0.00228) - 0.13448 * x + 0.005719;
|
||||
}
|
||||
|
||||
float3 NitsToPQ(float3 L)
|
||||
{
|
||||
// Constants from SMPTE 2084 PQ
|
||||
static const float m1 = 2610.0 / 4096.0 / 4;
|
||||
static const float m2 = 2523.0 / 4096.0 * 128;
|
||||
static const float c1 = 3424.0 / 4096.0;
|
||||
static const float c2 = 2413.0 / 4096.0 * 32;
|
||||
static const float c3 = 2392.0 / 4096.0 * 32;
|
||||
|
||||
float3 Lp = pow(saturate(L / 10000.0), m1);
|
||||
return pow((c1 + c2 * Lp) / (1 + c3 * Lp), m2);
|
||||
}
|
||||
|
||||
float3 Rec709toRec2020(float3 rec709)
|
||||
{
|
||||
static const float3x3 ConvMat =
|
||||
{
|
||||
0.627402, 0.329292, 0.043306,
|
||||
0.069095, 0.919544, 0.011360,
|
||||
0.016394, 0.088028, 0.895578
|
||||
};
|
||||
return mul(ConvMat, rec709);
|
||||
}
|
||||
|
||||
float3 scRGBTo2100PQ(float3 rgb)
|
||||
{
|
||||
// Convert from Rec 709 primaries (used by scRGB) to Rec 2020 primaries (used by Rec 2100)
|
||||
rgb = Rec709toRec2020(rgb);
|
||||
|
||||
// 1.0f is defined as 80 nits in the scRGB colorspace
|
||||
rgb *= 80;
|
||||
|
||||
// Apply the PQ transfer function on the raw color values in nits
|
||||
return NitsToPQ(rgb);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
#define CONVERT_FUNCTION saturate
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "include/common.hlsl"
|
||||
|
||||
float3 CONVERT_FUNCTION(float3 input)
|
||||
{
|
||||
return ApplySRGBCurve(saturate(input));
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "include/common.hlsl"
|
||||
|
||||
#define CONVERT_FUNCTION scRGBTo2100PQ
|
||||
@@ -0,0 +1,35 @@
|
||||
Texture2D image : register(t0);
|
||||
SamplerState def_sampler : register(s0);
|
||||
|
||||
cbuffer color_matrix_cbuffer : register(b0) {
|
||||
float4 color_vec_y;
|
||||
float4 color_vec_u;
|
||||
float4 color_vec_v;
|
||||
float2 range_y;
|
||||
float2 range_uv;
|
||||
};
|
||||
|
||||
#include "include/base_vs_types.hlsl"
|
||||
|
||||
float2 main_ps(vertex_t input) : SV_Target
|
||||
{
|
||||
#if defined(LEFT_SUBSAMPLING)
|
||||
float3 rgb_left = image.Sample(def_sampler, input.tex_right_left_center.xz).rgb;
|
||||
float3 rgb_right = image.Sample(def_sampler, input.tex_right_left_center.yz).rgb;
|
||||
float3 rgb = CONVERT_FUNCTION((rgb_left + rgb_right) * 0.5);
|
||||
#elif defined(TOPLEFT_SUBSAMPLING)
|
||||
float3 rgb_top_left = image.Sample(def_sampler, input.tex_right_left_top.xz).rgb;
|
||||
float3 rgb_top_right = image.Sample(def_sampler, input.tex_right_left_top.yz).rgb;
|
||||
float3 rgb_bottom_left = image.Sample(def_sampler, input.tex_right_left_bottom.xz).rgb;
|
||||
float3 rgb_bottom_right = image.Sample(def_sampler, input.tex_right_left_bottom.yz).rgb;
|
||||
float3 rgb = CONVERT_FUNCTION((rgb_top_left + rgb_top_right + rgb_bottom_left + rgb_bottom_right) * 0.25);
|
||||
#endif
|
||||
|
||||
float u = dot(color_vec_u.xyz, rgb) + color_vec_u.w;
|
||||
float v = dot(color_vec_v.xyz, rgb) + color_vec_v.w;
|
||||
|
||||
u = u * range_uv.x + range_uv.y;
|
||||
v = v * range_uv.x + range_uv.y;
|
||||
|
||||
return float2(u, v);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
Texture2D image : register(t0);
|
||||
SamplerState def_sampler : register(s0);
|
||||
|
||||
cbuffer color_matrix_cbuffer : register(b0) {
|
||||
float4 color_vec_y;
|
||||
float4 color_vec_u;
|
||||
float4 color_vec_v;
|
||||
float2 range_y;
|
||||
float2 range_uv;
|
||||
};
|
||||
|
||||
#include "include/base_vs_types.hlsl"
|
||||
|
||||
float main_ps(vertex_t input) : SV_Target
|
||||
{
|
||||
float3 rgb = CONVERT_FUNCTION(image.Sample(def_sampler, input.tex_coord, 0).rgb);
|
||||
|
||||
float y = dot(color_vec_y.xyz, rgb) + color_vec_y.w;
|
||||
|
||||
return y * range_y.x + range_y.y;
|
||||
}
|
||||
Reference in New Issue
Block a user