B4A Library SpecialFX for libGDX

ilan

Expert
Licensed User
Longtime User
You have to learn how to use shaders. They require two source files: the vertex and the fragment shaders, which are written in GLSL. Look at the libGDX examples (e.g. BrightnessContrast).

now i understand your code snipped above.
i had to change it in the .txt file. i thought it is a java snipped and i need to convert it to b4a

thank you very much fred, i will remember your great help when i become rich from my box2d games

btw i put a little bit green to it to get the old gameboy style

B4X:
vec4 inputTexture = texture2D(u_texture, vTexCoord.xy);
float grayscale = inputTexture.r * 0.299 + inputTexture.g * 0.587 + inputTexture.b * 0.114; 
gl_FragColor = vec4(grayscale, grayscale + 0.1, grayscale, 1.0);
 

ilan

Expert
Licensed User
Longtime User
ok i was celebrating to early

changing the txt file work on the example project but when i add it to my game (just for testing) i am not getting the result i need.
i was expecting everything will be drawn gray but this is not the case.
do i have to do something with the vertex.txt file too?
 

ilan

Expert
Licensed User
Longtime User
ok i got it.

the alpha settings was the problem, if it is set to 1.0 then transparent turns to white (or something else..) end everything looks weird.
changing it by using the texture alpha solved the problem.

fragment shader program:

B4X:
precision mediump float;

varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
uniform mat4 u_projTrans;

void main() {
vec4 color = texture2D(u_texture, v_texCoords);
float gray =  color.r * 0.299 + color.g * 0.587 + color.b * 0.114;
gl_FragColor =  vec4(gray, gray + 0.08, gray, color.a);
}

vertex.txt:

B4X:
attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord0;

uniform mat4 u_projTrans;

varying vec4 v_color;
varying vec2 v_texCoords;

void main() {
    v_color = a_color;
    v_texCoords = a_texCoord0;
    gl_Position = u_projTrans * a_position;
}

RESULT:



ps, i have uploaded both txt files if someone would like to make an old gameboy style game (something i am planing to do)
he can use it. if you would like to reduce/add more green to it just change the green value in gl_FragColor = vec4(gray, gray + 0.08, gray, color.a)
 

Attachments

  • vertex.txt
    282 bytes · Views: 195
  • gameboy.txt
    327 bytes · Views: 200
Cookies are required to use this site. You must accept them to continue using the site. Learn more…