diff --git a/impeller/compiler/shader_lib/impeller/texture.glsl b/impeller/compiler/shader_lib/impeller/texture.glsl index 7979e897ea922..3bbb580fb275f 100644 --- a/impeller/compiler/shader_lib/impeller/texture.glsl +++ b/impeller/compiler/shader_lib/impeller/texture.glsl @@ -6,6 +6,7 @@ #define TEXTURE_GLSL_ #include +#include /// Sample from a texture. /// @@ -92,6 +93,26 @@ vec4 IPSampleWithTileMode(sampler2D tex, return texture(tex, coords); } +const float16_t kTileModeDecalHf = 3.0hf; + +/// Sample a texture, emulating a specific tile mode. +/// +/// This is useful for Impeller graphics backend that don't have native support +/// for Decal. +f16vec4 IPHalfSampleWithTileMode(f16sampler2D tex, + f16vec2 coords, + float16_t x_tile_mode, + float16_t y_tile_mode) { + if (x_tile_mode == kTileModeDecalHf && + (coords.x < 0.0hf || coords.x >= 1.0hf) || + y_tile_mode == kTileModeDecalHf && + (coords.y < 0.0hf || coords.y >= 1.0hf)) { + return f16vec4(0.0hf); + } + + return texture(tex, coords); +} + /// Sample a texture, emulating a specific tile mode. /// /// This is useful for Impeller graphics backend that don't have native support diff --git a/impeller/entity/BUILD.gn b/impeller/entity/BUILD.gn index 69c772605977d..15f745c470942 100644 --- a/impeller/entity/BUILD.gn +++ b/impeller/entity/BUILD.gn @@ -11,6 +11,8 @@ impeller_shaders("entity_shaders") { vulkan_language_version = 130 } + use_half_textures = true + shaders = [ "shaders/blending/advanced_blend.vert", "shaders/blending/advanced_blend_color.frag", diff --git a/impeller/entity/shaders/texture_fill.frag b/impeller/entity/shaders/texture_fill.frag index 78cb9d90b297e..85aae42445bc9 100644 --- a/impeller/entity/shaders/texture_fill.frag +++ b/impeller/entity/shaders/texture_fill.frag @@ -4,18 +4,18 @@ #include -uniform sampler2D texture_sampler; +uniform f16sampler2D texture_sampler; uniform FragInfo { - float alpha; + float16_t alpha; } frag_info; -in vec2 v_texture_coords; +in f16vec2 v_texture_coords; -out vec4 frag_color; +out f16vec4 frag_color; void main() { - vec4 sampled = texture(texture_sampler, v_texture_coords); + f16vec4 sampled = texture(texture_sampler, v_texture_coords); frag_color = sampled * frag_info.alpha; } diff --git a/impeller/entity/shaders/texture_fill.vert b/impeller/entity/shaders/texture_fill.vert index e0f2c7882936a..b6af412649d47 100644 --- a/impeller/entity/shaders/texture_fill.vert +++ b/impeller/entity/shaders/texture_fill.vert @@ -14,10 +14,10 @@ frame_info; in vec2 position; in vec2 texture_coords; -out vec2 v_texture_coords; +out f16vec2 v_texture_coords; void main() { gl_Position = frame_info.mvp * vec4(position, 0.0, 1.0); - v_texture_coords = - IPRemapCoords(texture_coords, frame_info.texture_sampler_y_coord_scale); + v_texture_coords = f16vec2( + IPRemapCoords(texture_coords, frame_info.texture_sampler_y_coord_scale)); } diff --git a/impeller/entity/shaders/tiled_texture_fill.frag b/impeller/entity/shaders/tiled_texture_fill.frag index 030a94ba09aba..9d4a916a88fbf 100644 --- a/impeller/entity/shaders/tiled_texture_fill.frag +++ b/impeller/entity/shaders/tiled_texture_fill.frag @@ -5,24 +5,25 @@ #include #include -uniform sampler2D texture_sampler; +uniform f16sampler2D texture_sampler; uniform FragInfo { - float x_tile_mode; - float y_tile_mode; - float alpha; + float16_t x_tile_mode; + float16_t y_tile_mode; + float16_t alpha; } frag_info; -in vec2 v_texture_coords; +in f16vec2 v_texture_coords; -out vec4 frag_color; +out f16vec4 frag_color; void main() { - frag_color = IPSampleWithTileMode(texture_sampler, // sampler - v_texture_coords, // texture coordinates - frag_info.x_tile_mode, // x tile mode - frag_info.y_tile_mode // y tile mode - ) * - frag_info.alpha; + frag_color = + IPHalfSampleWithTileMode(texture_sampler, // sampler + v_texture_coords, // texture coordinates + frag_info.x_tile_mode, // x tile mode + frag_info.y_tile_mode // y tile mode + ) * + frag_info.alpha; } diff --git a/impeller/entity/shaders/tiled_texture_fill.vert b/impeller/entity/shaders/tiled_texture_fill.vert index e0f2c7882936a..b6af412649d47 100644 --- a/impeller/entity/shaders/tiled_texture_fill.vert +++ b/impeller/entity/shaders/tiled_texture_fill.vert @@ -14,10 +14,10 @@ frame_info; in vec2 position; in vec2 texture_coords; -out vec2 v_texture_coords; +out f16vec2 v_texture_coords; void main() { gl_Position = frame_info.mvp * vec4(position, 0.0, 1.0); - v_texture_coords = - IPRemapCoords(texture_coords, frame_info.texture_sampler_y_coord_scale); + v_texture_coords = f16vec2( + IPRemapCoords(texture_coords, frame_info.texture_sampler_y_coord_scale)); }