gpt4 book ai didi

java - Mac 上的 GLSL 着色器错误,但不是 Windows : cannot convert from 'const int' to '4-component vector of float'

转载 作者:搜寻专家 更新时间:2023-10-31 20:13:41 24 4
gpt4 key购买 nike

我是着色器的新手,我昨天开始玩弄其中的一些着色器。它们在我的 Windows PC 上编译得很好,但是当它们在 Mac 上运行时,两者都出现错误:

ERROR: 0:14: '=' : cannot convert from 'const int' to '4-component vector of float'

在 Android 上只有第二个着色器给我一个错误。它有上面提到的错误,没有匹配的功能点被重载。

它们使用相同的顶点着色器:

attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord0;

uniform mat4 u_projTrans;

varying vec4 vColor;
varying vec2 vTexCoord;

void main() {
vColor = a_color;
vTexCoord = a_texCoord0;
gl_Position = u_projTrans * a_position;
}

一个片段着色器(Mac 上的错误):

#ifdef GL_ES
#define LOWP lowp
precision mediump float;
#else
#define LOWP
#endif

varying LOWP vec4 vColor;
varying vec2 vTexCoord;
uniform sampler2D u_texture;
void main() {
vec4 texColor = texture2D(u_texture, vTexCoord);
texColor.rgb = 1.0 - texColor.rgb;
gl_FragColor = texColor * vColor;
}

另一个片段着色器(在mac和android上出错):

#ifdef GL_ES
#define LOWP lowp
precision mediump float;
#else
#define LOWP
#endif

varying LOWP vec4 vColor;
varying vec2 vTexCoord;
uniform sampler2D u_texture;
void main() {
vec4 texColor = texture2D(u_texture, vTexCoord);
vec3 gray = vec3(0.2125, 0.7154, 0.0721);
vec4 color = dot(gray, texColor);
color.a = texColor.a;
gl_FragColor = color * vColor;
}

最佳答案

在第一个着色器中,这一行有错误 - texColor.rgb = 1.0 - texColor.rgb; 你需要这样写:

texColor.rgb = vec3(1.0) - texColor.rgb;

在第二个着色器中,这一行有错误 - vec4 color = dot(gray, texColor); Gray 是 vec3,texcolor 是 vec4。 vec3 和 vec4 的点积是多少?没有这样的 dot 函数可以做到这一点。您可以调用 float dot(vec3, vec3)float dot(vec4, vec4)。所以将该行更改为:

vec4 color = vec4(dot(gray, texColor.rgb));

vec4 color = vec4(dot(vec4(gray, ???), texColor)); // put in ??? float number you want

(下次请告诉我们具体错误发生在哪一行)

关于java - Mac 上的 GLSL 着色器错误,但不是 Windows : cannot convert from 'const int' to '4-component vector of float' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13906101/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com