Gelzo
1
I want to be able to select color in editor but it doesnt work. I looked at docs but I can’t figure it out. What am I doing wrong?
uniform lowp vec4 tint;
varying mediump vec2 var_texcoord0;
uniform sampler2D texture_sampler;
void main() {
gl_FragColor = texture2D(texture_sampler, var_texcoord0) * tint;
}
Because you get a conflict between the names uniform tint and the tint as vertex attribute.
Rename the attribute to color and add it to the vertex and fragment shaders like this:
// positions are in world space
attribute highp vec4 position;
attribute mediump vec2 texcoord0;
attribute mediump vec4 color;
uniform highp mat4 view_proj;
varying mediump vec2 var_texcoord0;
varying mediump vec4 var_color;
void main()
{
gl_Position = view_proj * vec4(position.xyz, 1.0);
var_texcoord0 = texcoord0;
var_color = vec4(color.xyz * color.w, color.w);
}
varying mediump vec2 var_texcoord0;
uniform lowp sampler2D texture_sampler;
uniform lowp vec4 tint;
varying mediump vec4 var_color;
void main()
{
// Pre-multiply alpha since all runtime textures already are
lowp vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
gl_FragColor = texture2D(texture_sampler, var_texcoord0) *tint_pm * var_color;
}
5 Likes
Gelzo
3
thanks, this worked for me:
varying mediump vec2 var_texcoord0;
uniform lowp sampler2D texture_sampler;
uniform lowp vec4 tint;
varying mediump vec4 var_color;
void main()
{
// Pre-multiply alpha since all runtime textures already are
lowp vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
gl_FragColor = texture2D(texture_sampler, var_texcoord0) *tint_pm * var_color;
}
// positions are in world space
attribute highp vec4 position;
attribute mediump vec2 texcoord0;
attribute mediump vec4 color;
uniform highp mat4 view_proj;
varying mediump vec2 var_texcoord0;
varying mediump vec4 var_color;
void main()
{
gl_Position = view_proj * vec4(position.xyz, 1.0);
var_texcoord0 = texcoord0;
var_color = vec4(color.xyz * color.w, color.w);
}
1 Like