Index: cc/output/shader.cc |
diff --git a/cc/output/shader.cc b/cc/output/shader.cc |
index b5d163862d14e010aa19d5bcd083278366ed34b4..c5ae9af493eacb0a95ef6ecb54d4be7b0c4546fd 100644 |
--- a/cc/output/shader.cc |
+++ b/cc/output/shader.cc |
@@ -2023,6 +2023,8 @@ FragmentShaderYUVVideo::FragmentShaderYUVVideo() |
alpha_location_(-1), |
yuv_matrix_location_(-1), |
yuv_adj_location_(-1), |
+ ya_size_location_(-1), |
+ uv_size_location_(-1), |
ya_clamp_rect_location_(-1), |
uv_clamp_rect_location_(-1), |
resource_multiplier_location_(-1), |
@@ -2030,29 +2032,23 @@ FragmentShaderYUVVideo::FragmentShaderYUVVideo() |
void FragmentShaderYUVVideo::SetFeatures(bool use_alpha_texture, |
bool use_nv12, |
- bool use_color_lut) { |
+ bool use_color_lut, |
+ HighbitTexture highbit_texture) { |
use_alpha_texture_ = use_alpha_texture; |
use_nv12_ = use_nv12; |
use_color_lut_ = use_color_lut; |
+ highbit_texture_ = highbit_texture; |
} |
void FragmentShaderYUVVideo::Init(GLES2Interface* context, |
unsigned program, |
int* base_uniform_index) { |
static const char* uniforms[] = { |
- "y_texture", |
- "u_texture", |
- "v_texture", |
- "uv_texture", |
- "a_texture", |
- "lut_texture", |
- "resource_multiplier", |
- "resource_offset", |
- "yuv_matrix", |
- "yuv_adj", |
- "alpha", |
- "ya_clamp_rect", |
- "uv_clamp_rect", |
+ "y_texture", "u_texture", "v_texture", |
+ "uv_texture", "a_texture", "lut_texture", |
+ "yuv_matrix", "yuv_adj", "resource_multiplier", |
+ "resource_offset", "ya_size", "uv_size", |
+ "alpha", "ya_clamp_rect", "uv_clamp_rect", |
}; |
int locations[arraysize(uniforms)]; |
@@ -2074,15 +2070,21 @@ void FragmentShaderYUVVideo::Init(GLES2Interface* context, |
} |
if (use_color_lut_) { |
lut_texture_location_ = locations[5]; |
- resource_multiplier_location_ = locations[6]; |
- resource_offset_location_ = locations[7]; |
} else { |
- yuv_matrix_location_ = locations[8]; |
- yuv_adj_location_ = locations[9]; |
+ yuv_matrix_location_ = locations[6]; |
+ yuv_adj_location_ = locations[7]; |
+ } |
+ if (highbit_texture_ == HIGHBIT_LUMINANCE_F16) { |
+ resource_multiplier_location_ = locations[8]; |
+ resource_offset_location_ = locations[9]; |
+ } else if (highbit_texture_ == HIGHBIT_RG88) { |
+ resource_multiplier_location_ = locations[8]; |
+ ya_size_location_ = locations[10]; |
+ uv_size_location_ = locations[11]; |
} |
- alpha_location_ = locations[10]; |
- ya_clamp_rect_location_ = locations[11]; |
- uv_clamp_rect_location_ = locations[12]; |
+ alpha_location_ = locations[12]; |
+ ya_clamp_rect_location_ = locations[13]; |
+ uv_clamp_rect_location_ = locations[14]; |
} |
std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision, |
@@ -2099,6 +2101,50 @@ std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision, |
}); |
std::string functions = ""; |
+ if (highbit_texture_ == HIGHBIT_RG88) { |
+ head += " uniform float resource_multiplier;\n"; |
+ head += " uniform vec2 ya_size;\n"; |
+ head += " uniform vec2 uv_size;\n"; |
+ functions += SHADER0([]() { |
+ float GetFloat(SamplerType sampler, vec2 tex_coord) { |
+ vec2 rg = TextureLookup(sampler, tex_coord).xy; |
+ return ((rg.g * 256.0) + rg.r) * resource_multiplier; |
hubbe
2016/10/05 18:03:25
Instead of multiplying by resource_multiplier here
dshwang
2016/10/07 12:35:01
Good point! Done.
|
+ } |
+ |
+ float RGTextureLookupBilinear(SamplerType sampler, vec2 tex_coord, |
+ vec2 tex_size) { |
+ vec2 snap_tex_coord = |
+ (floor(tex_coord * tex_size) + vec2(0.5)) / tex_size; |
+ vec2 negativeOffset = |
+ -vec2(lessThan(tex_coord, snap_tex_coord)) / tex_size; |
+ // |snap_tex_coord| points out middle of texel. e.g. 1.5 |
+ // |snap_tex_coord| is always less than or equal to |tex_coord|. |
+ // When |tex_coord| points 1.6, sample |snap_tex_coord| texel and |
+ // |snap_tex_coord| + 1 texel. |
+ // When |tex_coord| points 1.4, sample |snap_tex_coord| texel and |
+ // |snap_tex_coord| - 1 texel. |
+ snap_tex_coord = snap_tex_coord + negativeOffset; |
+ vec2 unit_texel = 1.0 / tex_size; |
+ float s1 = GetFloat(sampler, snap_tex_coord); |
+ float s2 = GetFloat(sampler, snap_tex_coord + vec2(unit_texel.x, 0.)); |
+ float s3 = GetFloat(sampler, snap_tex_coord + vec2(0., unit_texel.y)); |
+ float s4 = GetFloat(sampler, snap_tex_coord + unit_texel); |
+ vec2 f = fract((tex_coord - snap_tex_coord) * tex_size); |
+ return mix(mix(s1, s2, f.x), mix(s3, s4, f.x), f.y); |
+ } |
+ |
+ float GetY(vec2 ya_clamped) { |
+ return RGTextureLookupBilinear(y_texture, ya_clamped, ya_size); |
+ } |
+ }); |
+ } else { |
+ functions += SHADER0([]() { |
+ float GetY(vec2 ya_clamped) { |
+ return TextureLookup(y_texture, ya_clamped).x; |
+ } |
+ }); |
+ } |
+ |
if (use_nv12_) { |
head += " uniform SamplerType uv_texture;\n"; |
functions += SHADER0([]() { |
@@ -2109,12 +2155,24 @@ std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision, |
} else { |
head += " uniform SamplerType u_texture;\n"; |
head += " uniform SamplerType v_texture;\n"; |
- functions += SHADER0([]() { |
- vec2 GetUV(vec2 uv_clamped) { |
- return vec2(TextureLookup(u_texture, uv_clamped).x, |
- TextureLookup(v_texture, uv_clamped).x); |
- } |
- }); |
+ if (highbit_texture_ == HIGHBIT_RG88) { |
+ functions += SHADER0([]() { |
+ vec2 GetUV(vec2 uv_clamped) { |
+ vec2 uv = |
+ vec2(RGTextureLookupBilinear(u_texture, uv_clamped, uv_size), |
+ RGTextureLookupBilinear(v_texture, uv_clamped, uv_size)); |
+ return uv; |
+ } |
+ }); |
+ } else { |
+ functions += SHADER0([]() { |
+ vec2 GetUV(vec2 uv_clamped) { |
+ vec2 uv = vec2(TextureLookup(u_texture, uv_clamped).x, |
+ TextureLookup(v_texture, uv_clamped).x); |
+ return uv; |
+ } |
+ }); |
+ } |
} |
if (use_alpha_texture_) { |
@@ -2132,8 +2190,6 @@ std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision, |
if (use_color_lut_) { |
head += " uniform sampler2D lut_texture;\n"; |
- head += " uniform float resource_multiplier;\n"; |
- head += " uniform float resource_offset;\n"; |
functions += SHADER0([]() { |
vec4 LUT(sampler2D sampler, vec3 pos, float size) { |
pos *= size - 1.0; |
@@ -2147,12 +2203,21 @@ std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision, |
texture2D(sampler, pos.yz + vec2(0, 1.0 / size)), |
pos.x - layer); |
} |
- |
- vec3 yuv2rgb(vec3 yuv) { |
- yuv = (yuv - vec3(resource_offset)) * resource_multiplier; |
- return LUT(lut_texture, yuv, 32.0).xyz; |
- } |
}); |
+ if (highbit_texture_ == HIGHBIT_LUMINANCE_F16) { |
+ head += " uniform float resource_multiplier;\n"; |
+ head += " uniform float resource_offset;\n"; |
+ functions += SHADER0([]() { |
+ vec3 yuv2rgb(vec3 yuv) { |
+ yuv = (yuv - vec3(resource_offset)) * resource_multiplier; |
+ return LUT(lut_texture, yuv, 32.0).xyz; |
+ } |
+ }); |
+ } else { |
+ functions += SHADER0([]() { |
+ vec3 yuv2rgb(vec3 yuv) { return LUT(lut_texture, yuv, 32.0).xyz; } |
+ }); |
+ } |
} else { |
head += " uniform mat3 yuv_matrix;\n"; |
head += " uniform vec3 yuv_adj;\n"; |
@@ -2165,7 +2230,7 @@ std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision, |
void main() { |
vec2 ya_clamped = |
max(ya_clamp_rect.xy, min(ya_clamp_rect.zw, v_yaTexCoord)); |
- float y_raw = TextureLookup(y_texture, ya_clamped).x; |
+ float y_raw = GetY(ya_clamped); |
vec2 uv_clamped = |
max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord)); |
vec3 yuv = vec3(y_raw, GetUV(uv_clamped)); |