I’m trying to add swaying grass using both a vector and a fragment shader in a 2d game, and I’m up to the point where i need to add the image to the fragment shader. Right now I’m using image() to render the image, but the fragment shader isn’t receiving the texture, I’m not very sure how it works anymore as in the rework of the processing.org website they deleted the example of PShader
Frag
precision mediump float;
precision mediump int;
#endif
#define PROCESSING_TEXTURE_SHADER
uniform sampler2D texture;
uniform vec2 texOffset;
varying vec4 vertColor;
varying vec4 vertTexCoord;
uniform float dW;
uniform float dH;
void main(void) {
vec4 alpha = texture2D(texture, vertTexCoord.st);
gl_FragColor = vec4(alpha.xyz, 1.0);
}
Vertex
precision mediump float;
uniform float dW;
uniform float dH;
attribute vec4 vertex;
void main() {
vec4 newVecSet = vec4((vertex.x/dW*2)-1.0, -((vertex.y/dH*2)-1.0), vertex.z, vertex.w);
gl_Position = newVecSet;
}
Base code
shader(sh);
image(Img, 0, 0);
resetShader();