We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi. I trying to draw texture on shader, but its not work. What I do wrong? bg drawn correct.
PShader mShader;
PImage bg;
PImage tex;
void setup() {
size(640, 360, P2D);
noStroke();
textureMode(NORMAL);
bg = loadImage("bg.jpg");
tex = loadImage("smoke.png");
mShader = loadShader("texfrag.glsl", "texvert.glsl");
mShader.set("texture", tex);
background(255);
}
void draw() {
image(bg,0,0);
shader(mShader);
}
texfrag.glsl:
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
uniform sampler2D texture;
varying vec4 vertColor;
varying vec4 vertTexCoord;
void main() {
gl_FragColor = texture2D(texture, vertTexCoord.st) * vertColor;
}
texvert.glsl:
uniform mat4 transform;
uniform mat4 texMatrix;
attribute vec4 position;
attribute vec4 color;
attribute vec2 texCoord;
varying vec4 vertColor;
varying vec4 vertTexCoord;
uniform sampler2D texture;
void main() {
gl_Position = transform * position;
vertColor = color;
vertTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0);
}
Or need sample code for texture draw on shader.
Answers
what exactly are you drawing? there's nothing after the shader in draw. try drawing a rectangle.
look at the example in the reference. it sets the shader and then draws an image. every pixel in the image is affected by the shader.
I want to draw the image and morph it. I read all reference but not found how to draw simple 2D texture on shader.
Correct way:
Like in the reference example:
What you are doing:
...that is wrong.
Check this in https://processing.org/tutorials/pshader/
Section: texture shaders, code listing 5.1
Also you should check https://processing.org/reference/texture_.html as it might do what you want in case you are feeding your texture externally.
Kf
Thanks, I set image(tex,0,0); after shader(mShader); and it works, but bg also morphed :|
Actual code is more useful than short descriptions of your problem.