我正在使用 Flutter 着色器,但收到以下错误:
语法错误,意外的 VEC3,需要逗号或分号
这是我的着色器:
#include <flutter/runtime_effect.glsl>
// Uniform variables passed from the application
uniform vec2 uResolution; // The resolution of the screen (width, height)
uniform float uTime; // The elapsed time in seconds
uniform vec2 uMouse; // The mouse position (x, y)
// Output color of the fragment
out vec4 fragColor;
// Function to plot a line on the Y-axis using a value between 0.0 and 1.0
float plot(vec2 normalizedCoords, float lineYPosition) {
// Create a smooth transition around the lineYPosition
return smoothstep(lineYPosition - 0.02, lineYPosition, normalizedCoords.y)
- smoothstep(lineYPosition, lineYPosition + 0.02, normalizedCoords.y);
}
void main() {
vec3 white = vec3(1.0); // White
vec3 black = vec3(0.0); // Black
vec3 red = vec3(1.0, 0.0, 0.0); // Red
vec3 green = vec3(0.0, 1.0, 0.0); // Green
vec3 blue = vec3(0.0, 0.0, 1.0); // Blue
// Get the rgba values of the color
vec3 color = blue;
// Multiply each color component by an alpha value
float alpha = 0.5;
vec3 colorWithAlpha = color * alpha;
float y = FlutterFragCoord().y / uResolution.y;
vec3 background = vec3(y);
// Normalized coordinates
vec2 st = FlutterFragCoord() / uResolution;
float y = pow(st.x, 5)
// Create a line at the center of the screen
vec3 line = mix(background, colorWithAlpha, plot(FlutterFragCoord() / uResolution, y));
// Output the final color with premultiplied alpha
fragColor = vec4(line, alpha);
}
如错误消息所示,
GLSL
或.frag
文件中的每一行都需要以分号结尾。我通过在该行末尾添加分号来修复它:
float y = pow(st.x, 5);
我正在使用 VS Code 扩展的 Shader 语言支持,所以我认为它会为我解决这个问题,但事实并非如此。