[Impeller] Add FlutterFragCoord to impellerc shader lib (flutter/engine#37126)

This commit is contained in:
Brandon DeRosier
2022-11-01 01:00:06 -07:00
committed by GitHub
parent 3ac350e841
commit 5371c52ffe
5 changed files with 35 additions and 2 deletions

View File

@@ -1107,6 +1107,7 @@ FILE: ../../../flutter/impeller/compiler/reflector.cc
FILE: ../../../flutter/impeller/compiler/reflector.h
FILE: ../../../flutter/impeller/compiler/runtime_stage_data.cc
FILE: ../../../flutter/impeller/compiler/runtime_stage_data.h
FILE: ../../../flutter/impeller/compiler/shader_lib/flutter/runtime_effect.glsl
FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/blending.glsl
FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/branching.glsl
FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/color.glsl

View File

@@ -0,0 +1,25 @@
// 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.
#ifndef RUNTIME_EFFECT_GLSL_
#define RUNTIME_EFFECT_GLSL_
#if defined(IMPELLER_GRAPHICS_BACKEND)
in vec2 _fragCoord;
vec2 FlutterFragCoord() {
return _fragCoord;
}
#elif defined(SKIA_GRAPHICS_BACKEND)
vec2 FlutterFragCoord() {
return gl_FragCoord.xy;
}
#else
#error "Runtime effect builtins are not supported for this graphics backend."
#endif
#endif

View File

@@ -6,6 +6,8 @@
precision highp float;
#include <flutter/runtime_effect.glsl>
layout(location = 0) uniform vec4 u_color;
layout(location = 1) uniform float u_alpha;
layout(location = 2) uniform vec4 u_sparkle_color;
@@ -86,7 +88,7 @@ float turbulence(vec2 uv) {
}
void main() {
vec2 p = gl_FragCoord.xy;
vec2 p = FlutterFragCoord();
vec2 uv = p * u_resolution_scale;
vec2 density_uv = uv - mod(p, u_noise_scale);
float radius = u_max_radius * u_radius_scale;

View File

@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
out vec2 v_position;
void main() {
gl_Position = vec4(1.0);
v_position = vec2(1.0);
}

View File

@@ -11,6 +11,8 @@
precision highp float;
#include <flutter/runtime_effect.glsl>
layout(location = 0) uniform vec4 u_color;
layout(location = 1) uniform float u_alpha;
layout(location = 2) uniform vec4 u_sparkle_color;
@@ -93,7 +95,7 @@ float turbulence(vec2 uv) {
void main() {
// This block of code triggers the compiler to emit the uniforms out of order
// if they are not explicitly sorted.
vec2 p = gl_FragCoord.xy;
vec2 p = FlutterFragCoord();
vec2 uv = p * u_resolution_scale;
vec2 density_uv = uv - mod(p, u_noise_scale);
float radius = u_max_radius * u_radius_scale;