【发布时间】:2021-07-25 05:10:25
【问题描述】:
当我可以同时传递 image saturation value 这样的 https://gl-react-cookbook.surge.sh/saturation?menu=true 和 image colorscaling 这样的 https://gl-react-cookbook.surge.sh/colorscale?menu=true 时,我正在尝试编写一个着色器,因为我在 react native 中使用 opengl。从示例中,我可以分别运行图像饱和度和图像颜色缩放,但我不知道如何将它们加在一起。我是 opengl 的新手,我尝试阅读文档,但找不到任何帮助。请帮我弄清楚如何获得这两个功能。这是我的代码。
我遇到的错误
gl-shader: Error compiling shader:
Compile failed.
ERROR: 0:9: 'assign' : cannot convert from '4-component vector of float' to '3-component vector of float'
ERROR: 0:12: 'constructor' : too many arguments
ERROR: 0:13: Unexpected syntax error;
ERROR: 3 compilation errors. No code generated.
着色器
const shaders = Shaders.create({
colorify: {
frag: GLSL`
precision highp float;
varying vec2 uv;
uniform sampler2D children, colorScale;
uniform float contrast, saturation, brightness;
const vec3 L = vec3(0.2125, 0.7154, 0.0721);
float greyscale (vec3 c) { return 0.2125 * c.r + 0.7154 * c.g + 0.0721 * c.b; }
void main() {
vec4 c = texture2D(children, uv);
vec3 brt = c.rgba * brightness;
vec4 original = texture2D(children, uv);
vec4 newcolor = texture2D(colorScale, vec2(greyscale(original.rgb), 0.5));
gl_FragColor = vec4(mix(vec3(0.5), mix(vec3(dot(brt,L)),brt,saturation),contrast),c.a,newcolor.rgb, original.a * newcolor.a)
}
`,
},
});
export const Colorify = ({ url, colorScale, interpolation }) => (
<Node
shader={shaders.colorify}
uniformsOptions={{ colorScale: { interpolation } }}
uniforms={{
colorScale,
children: url,
contrast: 0.3,
saturation: 0.1,
brightness: 0.2,
}}
/>
);
const App = () => {
return (
<Surface style={{ ...StyleSheet.absoluteFill }}>
<Colorify
url={route.imageUrl}
colorScale={colorScales[color]}
interpolation={interpolation}
/>
</Surface>)}
任何帮助都会很棒。
【问题讨论】:
标签: c++ opengl expo react-native-android shader