Weird Color Artifacts when trying to use Ping-Pong Framebuffers





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I am trying to write a shader for a multi step effect with ping-pong buffers using Java and Lwjgl. But it looks different from how it looks in ShaderToy. So in my searches for an answer, I stripped everything down to a much simpler shader which is basically just this:



glFragColor = texture2D(u_Texture, v_TexCoords) * 3.0;


I am multiplying the texture color for a 512x512 image, using ping-pong buffers of 512x512. When I run this 3 steps, this is the output:



problem



Top left is the original image, all pixels are completely black except white and yellow ones. Steps go clockwise to bottom left. As you can see some artifacts are creeping in, at first I thought it could be normal but this does not happen with the same shader in ShaderToy. If I do not multiply the color everything is ok and I get the same image out no matter how many ping-pongs. If I sample with a few pixels offset every step, image is displaced correctly to the sum of all steps without a problem (So I think the texture coordinates are not wrong).



I know I should have shared code but FrameBuffer allocations, Quad setup, shaders etc. are all spanning several source files and it would not be practical. I am sort of new at this, and just hoping this is common enough of a pitfall/setup problem that some experienced people can guess what may be going on by looking at the image.










share|improve this question




















  • 3





    Magic here is rare. WIth code you post, things get much more "guesseable"

    – Ripi2
    Nov 26 '18 at 20:12











  • Are you multiplying the values of the texture to the same texture? And that in a kind of loop? If so, maybe the initial value is 1 of 255 and the error is increasing over time...

    – Thomas
    Nov 26 '18 at 20:13











  • @Thomas no; I am drawing it onto a new Frame buffer with its own texture attachment, and I am clearing it to black before drawing.

    – sydnal
    Nov 27 '18 at 8:40











  • @Ripi2 I guess I should. I will try to port it over to webgl and arrange the main logic as a single source file that can be reasoned with. Thanks.

    – sydnal
    Nov 27 '18 at 18:55











  • @Ripi2 I have now ported the whole thing over to WebGL and opened a new topic here: link. It was the actual problem that I was trying to solve when I opened this question.

    – sydnal
    Dec 2 '18 at 11:26


















0















I am trying to write a shader for a multi step effect with ping-pong buffers using Java and Lwjgl. But it looks different from how it looks in ShaderToy. So in my searches for an answer, I stripped everything down to a much simpler shader which is basically just this:



glFragColor = texture2D(u_Texture, v_TexCoords) * 3.0;


I am multiplying the texture color for a 512x512 image, using ping-pong buffers of 512x512. When I run this 3 steps, this is the output:



problem



Top left is the original image, all pixels are completely black except white and yellow ones. Steps go clockwise to bottom left. As you can see some artifacts are creeping in, at first I thought it could be normal but this does not happen with the same shader in ShaderToy. If I do not multiply the color everything is ok and I get the same image out no matter how many ping-pongs. If I sample with a few pixels offset every step, image is displaced correctly to the sum of all steps without a problem (So I think the texture coordinates are not wrong).



I know I should have shared code but FrameBuffer allocations, Quad setup, shaders etc. are all spanning several source files and it would not be practical. I am sort of new at this, and just hoping this is common enough of a pitfall/setup problem that some experienced people can guess what may be going on by looking at the image.










share|improve this question




















  • 3





    Magic here is rare. WIth code you post, things get much more "guesseable"

    – Ripi2
    Nov 26 '18 at 20:12











  • Are you multiplying the values of the texture to the same texture? And that in a kind of loop? If so, maybe the initial value is 1 of 255 and the error is increasing over time...

    – Thomas
    Nov 26 '18 at 20:13











  • @Thomas no; I am drawing it onto a new Frame buffer with its own texture attachment, and I am clearing it to black before drawing.

    – sydnal
    Nov 27 '18 at 8:40











  • @Ripi2 I guess I should. I will try to port it over to webgl and arrange the main logic as a single source file that can be reasoned with. Thanks.

    – sydnal
    Nov 27 '18 at 18:55











  • @Ripi2 I have now ported the whole thing over to WebGL and opened a new topic here: link. It was the actual problem that I was trying to solve when I opened this question.

    – sydnal
    Dec 2 '18 at 11:26














0












0








0








I am trying to write a shader for a multi step effect with ping-pong buffers using Java and Lwjgl. But it looks different from how it looks in ShaderToy. So in my searches for an answer, I stripped everything down to a much simpler shader which is basically just this:



glFragColor = texture2D(u_Texture, v_TexCoords) * 3.0;


I am multiplying the texture color for a 512x512 image, using ping-pong buffers of 512x512. When I run this 3 steps, this is the output:



problem



Top left is the original image, all pixels are completely black except white and yellow ones. Steps go clockwise to bottom left. As you can see some artifacts are creeping in, at first I thought it could be normal but this does not happen with the same shader in ShaderToy. If I do not multiply the color everything is ok and I get the same image out no matter how many ping-pongs. If I sample with a few pixels offset every step, image is displaced correctly to the sum of all steps without a problem (So I think the texture coordinates are not wrong).



I know I should have shared code but FrameBuffer allocations, Quad setup, shaders etc. are all spanning several source files and it would not be practical. I am sort of new at this, and just hoping this is common enough of a pitfall/setup problem that some experienced people can guess what may be going on by looking at the image.










share|improve this question
















I am trying to write a shader for a multi step effect with ping-pong buffers using Java and Lwjgl. But it looks different from how it looks in ShaderToy. So in my searches for an answer, I stripped everything down to a much simpler shader which is basically just this:



glFragColor = texture2D(u_Texture, v_TexCoords) * 3.0;


I am multiplying the texture color for a 512x512 image, using ping-pong buffers of 512x512. When I run this 3 steps, this is the output:



problem



Top left is the original image, all pixels are completely black except white and yellow ones. Steps go clockwise to bottom left. As you can see some artifacts are creeping in, at first I thought it could be normal but this does not happen with the same shader in ShaderToy. If I do not multiply the color everything is ok and I get the same image out no matter how many ping-pongs. If I sample with a few pixels offset every step, image is displaced correctly to the sum of all steps without a problem (So I think the texture coordinates are not wrong).



I know I should have shared code but FrameBuffer allocations, Quad setup, shaders etc. are all spanning several source files and it would not be practical. I am sort of new at this, and just hoping this is common enough of a pitfall/setup problem that some experienced people can guess what may be going on by looking at the image.







opengl glsl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 20:06









Rabbid76

43.8k123354




43.8k123354










asked Nov 26 '18 at 19:35









sydnalsydnal

708




708








  • 3





    Magic here is rare. WIth code you post, things get much more "guesseable"

    – Ripi2
    Nov 26 '18 at 20:12











  • Are you multiplying the values of the texture to the same texture? And that in a kind of loop? If so, maybe the initial value is 1 of 255 and the error is increasing over time...

    – Thomas
    Nov 26 '18 at 20:13











  • @Thomas no; I am drawing it onto a new Frame buffer with its own texture attachment, and I am clearing it to black before drawing.

    – sydnal
    Nov 27 '18 at 8:40











  • @Ripi2 I guess I should. I will try to port it over to webgl and arrange the main logic as a single source file that can be reasoned with. Thanks.

    – sydnal
    Nov 27 '18 at 18:55











  • @Ripi2 I have now ported the whole thing over to WebGL and opened a new topic here: link. It was the actual problem that I was trying to solve when I opened this question.

    – sydnal
    Dec 2 '18 at 11:26














  • 3





    Magic here is rare. WIth code you post, things get much more "guesseable"

    – Ripi2
    Nov 26 '18 at 20:12











  • Are you multiplying the values of the texture to the same texture? And that in a kind of loop? If so, maybe the initial value is 1 of 255 and the error is increasing over time...

    – Thomas
    Nov 26 '18 at 20:13











  • @Thomas no; I am drawing it onto a new Frame buffer with its own texture attachment, and I am clearing it to black before drawing.

    – sydnal
    Nov 27 '18 at 8:40











  • @Ripi2 I guess I should. I will try to port it over to webgl and arrange the main logic as a single source file that can be reasoned with. Thanks.

    – sydnal
    Nov 27 '18 at 18:55











  • @Ripi2 I have now ported the whole thing over to WebGL and opened a new topic here: link. It was the actual problem that I was trying to solve when I opened this question.

    – sydnal
    Dec 2 '18 at 11:26








3




3





Magic here is rare. WIth code you post, things get much more "guesseable"

– Ripi2
Nov 26 '18 at 20:12





Magic here is rare. WIth code you post, things get much more "guesseable"

– Ripi2
Nov 26 '18 at 20:12













Are you multiplying the values of the texture to the same texture? And that in a kind of loop? If so, maybe the initial value is 1 of 255 and the error is increasing over time...

– Thomas
Nov 26 '18 at 20:13





Are you multiplying the values of the texture to the same texture? And that in a kind of loop? If so, maybe the initial value is 1 of 255 and the error is increasing over time...

– Thomas
Nov 26 '18 at 20:13













@Thomas no; I am drawing it onto a new Frame buffer with its own texture attachment, and I am clearing it to black before drawing.

– sydnal
Nov 27 '18 at 8:40





@Thomas no; I am drawing it onto a new Frame buffer with its own texture attachment, and I am clearing it to black before drawing.

– sydnal
Nov 27 '18 at 8:40













@Ripi2 I guess I should. I will try to port it over to webgl and arrange the main logic as a single source file that can be reasoned with. Thanks.

– sydnal
Nov 27 '18 at 18:55





@Ripi2 I guess I should. I will try to port it over to webgl and arrange the main logic as a single source file that can be reasoned with. Thanks.

– sydnal
Nov 27 '18 at 18:55













@Ripi2 I have now ported the whole thing over to WebGL and opened a new topic here: link. It was the actual problem that I was trying to solve when I opened this question.

– sydnal
Dec 2 '18 at 11:26





@Ripi2 I have now ported the whole thing over to WebGL and opened a new topic here: link. It was the actual problem that I was trying to solve when I opened this question.

– sydnal
Dec 2 '18 at 11:26












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53487856%2fweird-color-artifacts-when-trying-to-use-ping-pong-framebuffers%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53487856%2fweird-color-artifacts-when-trying-to-use-ping-pong-framebuffers%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen