java - LIBGDX- Unwanted texture blending in the shader -


I am trying to add two textures (PNG) images to LibGDX in my own shader. Everything works great, except for the math / compositing part. Hopefully someone can help me with this mixture problem!

Enter image details here

This is my base texture (256 x 256 px, 32-bit texture)

Enter image details here < / p>

This is my "top" texture (256 x 256 px, 32-bit texture)

 Enter image details here

I want the effect of transparency work as well as a simple base texture with other textures.

Enter the image details here

and the current result texture Between blending, a bit bright where there are "dots" of texture.

I have tried many different solutions. This is from the renderer, my class which applies the shield of lbgdx:

  Gdx.gl20.glEnable (Gdx.gl20.GL_BLEND); & Lt; - No matter Gdx.gl20.glBlendFunc (Gdx.gl20.GL_ONE, Gdx.gl20.GL_ONE_MINUS_SRC_ALPHA); & Lt; - Have not made any difference with the cube, but make transparent on a more advanced net.   

Piece Shader:

  #ifdef GL_ES Accurate Medium Pommel Float; #endif Separate vec2 v_texCoord0; Uniform Sampler 2DU_text1; Uniform Sampler 2DU_text2; Zero main () {vec4 bodyColor = texture2D (u_texture1, v_texCoord0); Vec4 addColor = texture2D (u_texture2, v_texCoord0); Gl_FragColor = bodyColor + addColor; }   

Something is clearly wrong.

Since you do not have to do anything from Shader to do two texture mixes, mix functions.

Your current shider only adds two colors, which is similar if you have drawn two tables, using the other GL_ONE, GL_ONE .

You really want to change the second texture completely based on your alpha, just like if you have drawn two tables, using the other GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA . This means that RGB Texture Two is multiplied by its alpha, whereas the texture is multiplied by RGB (1- alphabet of Texture 2). And then two results are added together.

So you create the equation that is a mixing function, but now we do it in the shader.

  gl_FragColor = Vec4 (bodyColor.rgb * (1.0-addColor.a) + addColor.rgb * addColor.a, 1.0);   

I think you can write it like this; The display is probably equivalent, but it is probably better that if there is a way to optimize the GPU mixing function:

  gl_FragColor = vec4 (mix (bodyColor.rgb, addColor.rgb, addColor.a ), 1.0);   

This final 1.0 is your output alpha You did not specify what type of alpha you want for the final output if you want the whole thing to be your Get the alphabet of the base texture, then replace 1.0 to bodyColor.a .

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -