FFmpeg
Loading...
Searching...
No Matches
vsrc_gfxcapture_shader.h
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef AVFILTER_VSRC_GFXCAPTURE_SHADER_H
20#define AVFILTER_VSRC_GFXCAPTURE_SHADER_H
21
22#define HLSL_SHADER(shader) #shader
23
24static const char render_shader_src[] = HLSL_SHADER(
25 struct VSOut {
26 float4 pos : SV_Position;
27 float2 uv : TEXCOORD0;
28 };
29
30 cbuffer cb : register(b0) {
31 float2 tS;
32 float2 dS;
33 float2 uvMin;
34 float2 uvMax;
35 uint to_unpremult;
36 uint to_srgb;
37 uint2 pad;
38 };
39
40 Texture2D t0 : register(t0);
41 SamplerState s0 : register(s0);
42
43 VSOut main_vs(uint id : SV_VertexID) {
44 VSOut o;
45 o.pos = float4(id == 2 ? 3.0 : -1.0, id == 1 ? 3.0 : -1.0, 0, 1);
46 o.uv = lerp(uvMin, uvMax, float2((o.pos.x + 1) * 0.5, 1 - (o.pos.y + 1) * 0.5));
47 return o;
48 }
49
50 float4 cubic(float v) {
51 float4 n = float4(1.0, 2.0, 3.0, 4.0) - v;
52 float4 s = n * n * n;
53 float x = s.x;
54 float y = s.y - 4.0 * s.x;
55 float z = s.z - 4.0 * s.y + 6.0 * s.x;
56 float w = 6.0 - x - y - z;
57 return float4(x, y, z, w) * (1.0 / 6.0);
58 }
59
60 float4 texBicubic(Texture2D t, SamplerState ss, float2 uv) {
61 float2 itS = 1.0 / tS;
62
63 float2 tc = uv * tS - 0.5;
64 float2 fxy = frac(tc);
65 tc -= fxy;
66
67 float4 xc = cubic(fxy.x);
68 float4 yc = cubic(fxy.y);
69
70 float4 s = float4(xc.xz + xc.yw, yc.xz + yc.yw);
71 float4 o = tc.xxyy + (float2(-0.5, 1.5)).xyxy + float4(xc.yw, yc.yw) / s;
72 o *= itS.xxyy;
73
74 float4 s0 = t.Sample(ss, o.xz);
75 float4 s1 = t.Sample(ss, o.yz);
76 float4 s2 = t.Sample(ss, o.xw);
77 float4 s3 = t.Sample(ss, o.yw);
78
79 float sx = s.x / (s.x + s.y);
80 float sy = s.z / (s.z + s.w);
81
82 return lerp(lerp(s3, s2, sx), lerp(s1, s0, sx), sy);
83 }
84
85 float4 unpremultiply(float4 c) {
86 if (c.a < 1e-6)
87 return float4(0.0, 0.0, 0.0, 0.0);
88 return float4(c.rgb / c.a, c.a);
89 }
90
91 float4 premultiply(float4 c) {
92 return float4(c.rgb * c.a, c.a);
93 }
94
95 float3 linear_to_srgb(float3 c) {
96 c = max(c, 0.0);
97 float3 lo = 12.92 * c;
98 float3 hi = 1.055 * pow(c, 1.0 / 2.4) - 0.055;
99 return saturate(lerp(hi, lo, step(c, 0.0031308)));
100 }
101
102 float4 fix_color(float4 c) {
103 if (to_unpremult || to_srgb)
104 c = unpremultiply(c);
105 if (to_srgb) {
106 c.rgb = linear_to_srgb(c.rgb);
107 if (!to_unpremult)
108 c = premultiply(c);
109 }
110 return c;
111 }
112
113 float4 main_ps(VSOut i) : SV_Target {
114 return fix_color(t0.Sample(s0, i.uv));
115 }
116
117 float4 main_ps_bicubic(VSOut i) : SV_Target {
118 if (all(tS == dS))
119 return main_ps(i);
120 return fix_color(texBicubic(t0, s0, i.uv));
121 }
122);
123
124#undef HLSL_SHADER
125
126#endif /* AVFILTER_VSRC_GFXCAPTURE_SHADER_H */
return
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define ss(width, name, subs,...)
Definition cbs_vp9.c:202
#define s(width, name)
Definition cbs_vp9.c:198
float2
float4
#define max(a, b)
static av_unused double cubic(double x, const double *params)
Definition filters.c:423
if(svq3)
uint8_t w
Definition llvidencdsp.c:39
static double lerp(double a, double b, double x)
Definition perlin.c:75
unsigned int pos
Definition spdifenc.c:431
static float saturate(float input)
static double cb(void *priv, double x, double y)
Definition vf_geq.c:247
static double b0(void *priv, double x, double y)
Definition vf_xfade.c:2033
#define HLSL_SHADER(shader)
static const char render_shader_src[]
static double c[64]