You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This thread seems to indicate that ((PGraphicsOpenGL)g).textureSampling(3); does the trick - perhaps noSmooth could be made to do this under the hood on the P2D renderer?
I think in Java2D it goes to nearest neighbor, because noSmooth() was used to improve performance and turning off image interpolation helped a lot.
When we got OpenGL, texture filtering was left separate, because it has negligible impact on performance, but lowers image quality a lot compared to AA. Users usually don't want to get pixellated textures, unless it is for artistic reasons (and those would probably want to leave AA on).
Other reason is that smooth()/noSmooth() can be called only once per sketch, but it should be possible to change texture filtering multiple times. Plus FX does not even support nearest neighbor.
If we change the behavior, I suggest separating these two in Java2D, because they are two different things used for different purposes (although in Java2D the performance effect overlaps).
Nah, it's implemented in Java2D for the effect of it, more than anything else. Things look crummy enough (and performance isn't the factor) that it's really the only reason to do noSmooth() nowadays. I know @codeanticode and I discussed a separate imageSmooth() method but at the end of the day decided to keep things as one. I suppose we could revisit the discussion…
But at the moment, we're still dealing with buggy behavior in terms of expectations. I say noSmooth() at the beginning of my sketch, and then I see (ugly) smoothed gradients on images, I'm gonna be disappointed (as was the OP).
There is `noSmooth()` override (which should implement this) commented out
in `PGraphicsOpenGL`. That's probably the problem. I might check it out
tomorrow/Sunday.
On Sat, 13 Jan 2018, 01:11 Ben Fry, ***@***.***> wrote:
Nah, it's implemented in Java2D for the effect of it, more than anything
else. Things look crummy enough (and performance isn't the factor) that
it's really the only reason to do noSmooth() nowadays. I know
@codeanticode <https://github.com/codeanticode> and I discussed a
separate imageSmooth() method but at the end of the day decided to keep
things as one. I suppose we could revisit the discussion…
But at the moment, we're still dealing with buggy behavior in terms of
expectations. I say noSmooth() at the beginning of my sketch, and then I
see (ugly) smoothed gradients on images, I'm gonna be disappointed (as was
the OP).
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#5363 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADB6ijNLZD2sbZlymxwduxHTlTY6Q6dhks5tJ_SggaJpZM4RZRdh>
.
((PGraphicsOpenGL)g).textureSampling(3) doesn't seem to help when I draw an ellipse. Why is that so? It smooths the edges but the lines are not continuous. I scaled the image down also but its the same. Somehow the ellipse is downsampled for some reason.
Note: in P2D, this textureSampling(3) has no effect when drawing a PGraphics canvas object with image(). For example zooming in 2x on a surface half the size of our main canvas results in this same smoothing issue. Any tips?
I am also having issues with noSmooth().
When I use a PShader to create a simple scrolling effect, my test pattern quickly fills with artifacts if noSmooth() or target.noSmooth() has been called. Note that these images were both captured on frame 400. It seems like some parts of the pattern are scrolling faster than others when target.noSmooth() has ben called.
PGraphicstarget;
PShadersimpleFrag;
voidsetup() {
size(200, 200, P2D);
target=createGraphics(200, 200, P2D);
//UNCOMMENTING EITHER OF THESE TWO LINES CAUSES ARTIFACTS//noSmooth();//target.noSmooth();simpleFrag=loadShader("simpleFrag.glsl");
/*EDIT: I realized that these two lines are required to draw the pattern if running this codein Processing 3. Otherwise, you just get an empty black window. I originally composed the test in Processing 4.*/target.beginDraw();//EDITtarget.endDraw();//EDITdrawTestPatternToTarget();
}
voiddraw() {
background(0);
target.beginDraw();
simpleFrag.set("previousFrame", target);
target.shader(simpleFrag);
target.rect(0, 0, width, height);
target.endDraw();
image(target, 0, 0);
}
voiddrawTestPatternToTarget() {
target.beginDraw();
target.background(0);
target.stroke(255);
target.strokeWeight(5);
target.line(0, 0, target.width, target.height);
target.line(0, target.height, target.width, 0);
target.fill(255, 0, 0);
target.circle(target.width/2, target.height/2, 100);
target.endDraw();
}
simpleFrag.glsl:
outvec4 col;
uniformsampler2D previousFrame;
void main(){
ivec2 res=textureSize(previousFrame,0);
ivec2 texel=ivec2(gl_FragCoord.xy);
texel.x=(texel.x+2)%(res.x);//scroll to the left by 2 pixelsvec4 newColor=texelFetch(previousFrame,texel,0);
col=newColor;
}
@clankill3r I tried calling gl_nearest_for_texture(target) right after the call to target.noSmooth(), and the artifact problem persists. I also tried it with plain old noSmooth() instead of/ in addition to target.noSmooth() and the results are the same. A couple notes:
The code I posted only shows the test pattern if run from processing 4. Expected (though still buggy) behaivior can be restored in processing 3 by adding target.beginDraw(); target.endDraw() right before drawTestPattern(); P3 is a little weird about PGraphics initialization. I have edited my original post to reflect this.
Similarly, in Processing 4, calling gl_nearest_for_texture(target) before the first target.beginDraw(); target.endDraw() pair causes the console to complain that "pixels array is null". Adding a beginDraw-endDraw pair right before the function call has expected behavior (still full of artifacts)
gl_nearest_for_texture(target) must be called after target.noSmooth() as it contains a "beginDraw()"
Activity
gohai commentedon Jan 10, 2018
This thread seems to indicate that
((PGraphicsOpenGL)g).textureSampling(3);does the trick - perhapsnoSmoothcould be made to do this under the hood on the P2D renderer?clankill3r commentedon Jan 10, 2018
Nice. It can also be used after setup.
benfry commentedon Jan 12, 2018
Hm, it should be working, so long as it's in
settings()(orsetup()in the PDE)… so it's a bug.JakubValtar commentedon Jan 12, 2018
noSmooth()in OpenGL sets only multisampling, not texture filtering. We currently don't have public API to set texture filtering.benfry commentedon Jan 12, 2018
But in 2D,
noSmooth()affects images as well, so the expectation would be the same for OpenGL. (Maybe I'm misunderstanding something?)JakubValtar commentedon Jan 12, 2018
I think in Java2D it goes to nearest neighbor, because
noSmooth()was used to improve performance and turning off image interpolation helped a lot.When we got OpenGL, texture filtering was left separate, because it has negligible impact on performance, but lowers image quality a lot compared to AA. Users usually don't want to get pixellated textures, unless it is for artistic reasons (and those would probably want to leave AA on).
Other reason is that
smooth()/noSmooth()can be called only once per sketch, but it should be possible to change texture filtering multiple times. Plus FX does not even support nearest neighbor.If we change the behavior, I suggest separating these two in Java2D, because they are two different things used for different purposes (although in Java2D the performance effect overlaps).
benfry commentedon Jan 13, 2018
Nah, it's implemented in Java2D for the effect of it, more than anything else. Things look crummy enough (and performance isn't the factor) that it's really the only reason to do
noSmooth()nowadays. I know @codeanticode and I discussed a separateimageSmooth()method but at the end of the day decided to keep things as one. I suppose we could revisit the discussion…But at the moment, we're still dealing with buggy behavior in terms of expectations. I say
noSmooth()at the beginning of my sketch, and then I see (ugly) smoothed gradients on images, I'm gonna be disappointed (as was the OP).JakubValtar commentedon Jan 13, 2018
clankill3r commentedon Dec 23, 2018
Here is another bug when using noSmooth.
Expected result:

Actual result:

eulphean commentedon Jan 11, 2019
((PGraphicsOpenGL)g).textureSampling(3) doesn't seem to help when I draw an ellipse. Why is that so? It smooths the edges but the lines are not continuous. I scaled the image down also but its the same. Somehow the ellipse is downsampled for some reason.
'PGraphics pg;
void setup() {
size(640, 640, P2D);
noSmooth();
((PGraphicsOpenGL)g).textureSampling(3);
pg = createGraphics(32, 32);
}
void draw() {

pg.beginDraw();
pg.background(128);
pg.ellipseMode(CENTER);
pg.ellipse(16, 16, 10, 10);
pg.endDraw();
image(pg, 0, 0, width, height);
}'
chrsmlls333 commentedon Sep 30, 2019
Note: in P2D, this textureSampling(3) has no effect when drawing a PGraphics canvas object with image(). For example zooming in 2x on a surface half the size of our main canvas results in this same smoothing issue. Any tips?
clankill3r commentedon Nov 7, 2019
@chrsmlls333 can you post an example?
OpenSauce04 commentedon Oct 12, 2023
This is still an issue nearly 6 years later
aphid91 commentedon Oct 16, 2023
I am also having issues with noSmooth().
When I use a PShader to create a simple scrolling effect, my test pattern quickly fills with artifacts if noSmooth() or target.noSmooth() has been called. Note that these images were both captured on frame 400. It seems like some parts of the pattern are scrolling faster than others when target.noSmooth() has ben called.
simpleFrag.glsl:
clankill3r commentedon Oct 17, 2023
@aphid91 I have limited time, but can you try to call
gl_nearest_for_texturefor yourtargetPGraphics?aphid91 commentedon Oct 19, 2023
@clankill3r I tried calling gl_nearest_for_texture(target) right after the call to target.noSmooth(), and the artifact problem persists. I also tried it with plain old noSmooth() instead of/ in addition to target.noSmooth() and the results are the same. A couple notes:
IntangibleMatter commentedon Feb 26, 2025
Remains an issue in 2025, making it really hard to have pixel graphics and shaders at once.
github-actions commentedon Jul 15, 2026
This issue has been automatically closed and locked.
Processing 3.x is no longer actively developed. Since January 2020, development moved to the Processing 4 repository.
If this issue is still relevant to Processing 4, we'd love to hear from you. Please open a new issue at:
https://github.com/processing/processing4/issues/new/choose
Thank you for helping improve Processing.