A
AzureCube
Guest
Hello,
I am currently using GMS 1.4.9999 and I wish to create a simple shader that replaces every black pixel in a sprite with white and then converts the sprite to grayscale. By searching the Internet, I have found a functional grayscale shader (code included below). However, I have not figured out how to convert all black pixels to white.
Does anyone know a simple way of testing the color of a pixel and, only if it is a certain value, changing that pixel to a different color?
Grayscale shader code (/3.5 to darken from default value):
Fragment shader:
varying vec2 vTc;
void main() {
vec4 irgba=texture2D(gm_BaseTexture,vTc);
float luminance=dot(irgba.rgb,vec3(0.2125,0.7154,0.0721));
gl_FragColor=vec4(luminance/3.5,luminance/3.5,luminance/3.5,irgba.a);
}
Vertex shader:
attribute vec4 in_Position;
attribute vec2 in_TextureCoord;
varying vec2 vTc;
void main() {
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * in_Position;
vTc = in_TextureCoord;
}
I am currently using GMS 1.4.9999 and I wish to create a simple shader that replaces every black pixel in a sprite with white and then converts the sprite to grayscale. By searching the Internet, I have found a functional grayscale shader (code included below). However, I have not figured out how to convert all black pixels to white.
Does anyone know a simple way of testing the color of a pixel and, only if it is a certain value, changing that pixel to a different color?
Grayscale shader code (/3.5 to darken from default value):
Fragment shader:
varying vec2 vTc;
void main() {
vec4 irgba=texture2D(gm_BaseTexture,vTc);
float luminance=dot(irgba.rgb,vec3(0.2125,0.7154,0.0721));
gl_FragColor=vec4(luminance/3.5,luminance/3.5,luminance/3.5,irgba.a);
}
Vertex shader:
attribute vec4 in_Position;
attribute vec2 in_TextureCoord;
varying vec2 vTc;
void main() {
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * in_Position;
vTc = in_TextureCoord;
}