0

I'm completely new to shaders and trying to do something for a game I'm currently working on. I am trying to achieve something like this:

IMG. I have a simple passthrough shader setup, but I don't know how to remove the exact pixels at the top of the texture. I'm assuming in the fragment shader I need to change the alpha value to 0.0, but how do check if the pixels are at the top? I'm also using libGDX as my game engine which uses OpenGL ES 2.0 by default.

Here is my simple passthrough (vertex) shader:

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;
}

Fragment shader:

#ifdef GL_ES
#define PRECISION mediump
precision PRECISION float;
precision PRECISION int;
#else
#define PRECISION
#endif

varying vec4 v_color;
varying vec2 v_texCoords;

uniform sampler2D u_texture;
uniform sampler2D u_other;

void main() {
    vec4 color = texture2D(u_texture, v_texCoords);
    vec4 other_colors = texture2D(u_other, v_texCoords);

    gl_FragColor = other_colors;
}

Thank you for the help :). Been stuck on this for quite some time.

Additional information:

  1. I am not rendering pixel perfect.
  2. I need to be able for any side of the texture to make it rough/bumpy (randomly or not).
mantasarm
  • 3
  • 3
  • 1
    Its unclear what you want to achieve. Blending is configured on CPU side and alpha is the 4th component of the fragment shader output color. However maybe you want just `discard;` to skip pixels instead of blending. If you have height/layers then either render in order or use depth buffer ... – Spektre Jun 14 '21 at 13:18
  • My goal is to be able to procedurally generate rough surfaces for 2D textures just like in the example I provided. You mention something about discarding the pixels. What do you mean by that? – mantasarm Jun 14 '21 at 13:49
  • It's not clear what exactly you're trying to do. It looks like you removed/made invisible some assortment of pixels from the top row. Is it just random? Do you only want to modify the top row of pixels? Also relevant to being able to answer this is, are you rendering pixel perfect where each pixel of the source texture is equal in size to one pixel on the frame buffer? We need to see your viewport set-up and how/if you're scaling your textures when drawing them. – Tenfour04 Jun 14 '21 at 16:21
  • so you mean add something like [bump/normal maping](https://stackoverflow.com/a/28541305/2521214) to textured surface? or what? as all we see are just two "identical" pictures where one has cut of some part on top for unknown reasons to us. – Spektre Jun 14 '21 at 16:35
  • I need to be able for any side of the texture to make it rough/bumpy (randomly or not). I am not rendering pixel perfect. – mantasarm Jun 15 '21 at 09:35

0 Answers0