Shader to turn sprite into grayscale

Shader to turn sprite into grayscale
0

I’m trying to use a shader to turn my sprites into grayscale.
All the examples I see use the GLProgram class which apparently doesn’t exist anymore (or at least I cannot find it)
Can anyone help me on this?

Hey, I wrote a utility to make shaders easier to use in v4 https://github.com/JRCocos/SimpleShader

for a simple grayscale shader you could try this

void main(void) {
	vec4 color = texture2D(u_texture, cc_FragTexCoord1);
	float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114));
	gl_FragColor = vec4(vec3(gray), color.a);
}
1 Like

Thanks.
This works really good on sprites, but nothing happens with a DrawNode?
Can we add a shader to a DrawNode?

I’ve never tried that, but with a DrawNode you can just specify the colors that you want to draw directly anyway.

for the colors yes, but DrawNode generates very pixelated lines.
I was trying to add a shader to get some anti aliasing and more smooth lines.

do you have a v3 version too? )

I’m using v4.0 of cocos2d-x

No, sorry I only work with v4

Hi @pccsoares,
you can do a search in the forum pertaining to this topic.

i’ve found one here