Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added new kernel shader
  • Loading branch information
gaaclarke committed Jan 4, 2024
commit 337bd13100663dfcbcc99639d09af97d135fd628
2 changes: 2 additions & 0 deletions impeller/entity/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ impeller_shaders("entity_shaders") {
"shaders/gaussian_blur/gaussian_blur.vert",
"shaders/gaussian_blur/gaussian_blur_noalpha_decal.frag",
"shaders/gaussian_blur/gaussian_blur_noalpha_nodecal.frag",
"shaders/gaussian_blur/kernel_decal.frag",
"shaders/gaussian_blur/kernel_nodecal.frag",
"shaders/glyph_atlas.frag",
"shaders/glyph_atlas_color.frag",
"shaders/glyph_atlas.vert",
Expand Down
8 changes: 8 additions & 0 deletions impeller/entity/contents/content_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
#include "impeller/entity/gaussian_blur.vert.h"
#include "impeller/entity/gaussian_blur_noalpha_decal.frag.h"
#include "impeller/entity/gaussian_blur_noalpha_nodecal.frag.h"
#include "impeller/entity/kernel_decal.frag.h"
#include "impeller/entity/kernel_nodecal.frag.h"

#include "impeller/entity/position_color.vert.h"

Expand Down Expand Up @@ -137,6 +139,12 @@ using GaussianBlurDecalPipeline =
using GaussianBlurPipeline =
RenderPipelineT<GaussianBlurVertexShader,
GaussianBlurNoalphaNodecalFragmentShader>;
using KernelDecalPipeline =
RenderPipelineT<GaussianBlurVertexShader,
KernelDecalFragmentShader>;
using KernelPipeline =
RenderPipelineT<GaussianBlurVertexShader,
KernelNodecalFragmentShader>;
using BorderMaskBlurPipeline =
RenderPipelineT<BorderMaskBlurVertexShader, BorderMaskBlurFragmentShader>;
using MorphologyFilterPipeline =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
const Matrix& effect_transform,
const Rect& coverage,
const std::optional<Rect>& coverage_hint) const {
using VS = GaussianBlurPipeline::VertexShader;
using FS = GaussianBlurPipeline::FragmentShader;
using VS = KernelPipeline::VertexShader;
using FS = KernelPipeline::FragmentShader;

//----------------------------------------------------------------------------
/// Handle inputs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

namespace impeller {

using GaussianBlurVertexShader = GaussianBlurPipeline::VertexShader;
using GaussianBlurFragmentShader = GaussianBlurPipeline::FragmentShader;
using GaussianBlurVertexShader = KernelPipeline::VertexShader;
using GaussianBlurFragmentShader = KernelPipeline::FragmentShader;

namespace {

Expand Down Expand Up @@ -431,9 +431,9 @@ Scalar GaussianBlurFilterContents::ScaleSigma(Scalar sigma) {
return clamped * scalar;
}

GaussianBlurPipeline::FragmentShader::KernelSamples GenerateBlurInfo(
KernelPipeline::FragmentShader::KernelSamples GenerateBlurInfo(
BlurParameters parameters) {
GaussianBlurPipeline::FragmentShader::KernelSamples result{
KernelPipeline::FragmentShader::KernelSamples result{
.sample_count =
((2 * parameters.blur_radius) / parameters.step_size) + 1};
FML_CHECK(result.sample_count < 24);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct BlurParameters {
int step_size;
};

GaussianBlurPipeline::FragmentShader::KernelSamples GenerateBlurInfo(
KernelPipeline::FragmentShader::KernelSamples GenerateBlurInfo(
BlurParameters parameters);

/// Performs a bidirectional Gaussian blur.
Expand Down
46 changes: 46 additions & 0 deletions impeller/entity/shaders/gaussian_blur/kernel.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <impeller/constants.glsl>
#include <impeller/gaussian.glsl>
#include <impeller/texture.glsl>
#include <impeller/types.glsl>

uniform f16sampler2D texture_sampler;

struct KernelSample {
f16vec2 uv_offset;
float16_t coefficient;
};

uniform KernelSamples {
int sample_count;
KernelSample samples[24];
}
blur_info;

f16vec4 Sample(f16sampler2D tex, vec2 coords) {
#if ENABLE_DECAL_SPECIALIZATION
return IPHalfSampleDecal(tex, coords);
#else
return texture(tex, coords);
#endif
}

in vec2 v_texture_coords;

out f16vec4 frag_color;

void main() {
f16vec4 total_color = f16vec4(0.0hf);

for (int i = 0; i < blur_info.sample_count; ++i) {
float16_t coefficient = blur_info.samples[i].coefficient;
total_color +=
coefficient * Sample(texture_sampler,
v_texture_coords + blur_info.samples[i].uv_offset);
}

frag_color = total_color;
}
9 changes: 9 additions & 0 deletions impeller/entity/shaders/gaussian_blur/kernel_decal.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

precision mediump float;

#define ENABLE_DECAL_SPECIALIZATION 1

#include "kernel.glsl"
9 changes: 9 additions & 0 deletions impeller/entity/shaders/gaussian_blur/kernel_nodecal.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

precision mediump float;

#define ENABLE_DECAL_SPECIALIZATION 0

#include "kernel.glsl"