-3
$\begingroup$

o7

I am unable to find an answer to my question, because apparently it's not well enough defined to separate itself from a similar one. So I have to ask here.

My problem is quite simple. I have multiple shaderpasses and want to render each output into the same texture, which apparently isn't possible even using discard to, ahem, discard empty pixels each shaderpass isn't rendering to anyway. Each pass is supposed to only draw its own part to the texture.

I can use other methods of rendering only the necessary parts. I picked "discard", because it was the quickest to implement... and it's probably a bad idea compared to stencil.

Anyhow: The output-texture only contains one pass, which means it works, but not how I hoped.

Is it even possible to render multiple shaderpasses to the same texture without having each pass overwrite the output of the preceding pass?

And if it is... how?

Thank you!

$\endgroup$
  • 1
    $\begingroup$ It's unclear what you mean by "shaderpass" here. Are you rendering quads to the texture? You say that each pass should render to different locations; how are those locations determined? Is your shader trying to read from the same texture it's writing to? Please be more explicit (or post some code) as to exactly what you're trying to do. $\endgroup$ – Nicol Bolas May 19 '17 at 15:53
  • $\begingroup$ Actually my post is super explicit and to the point. I'm not sure why you come up with so many things not related to the question. It tells you exactly what i do and need to know. You confuse me. $\endgroup$ – z0rberg's May 19 '17 at 17:02
  • 1
    $\begingroup$ Well, the term "shaderpass" is not part of OpenGL or GLSL lexicon. I've heard it used in many different contexts for radically different things. It's been used to mean "multipass rendering over the same mesh", "full-screen quads over a scene", and other things. There is no one definition of "shaderpass", so I'm trying to ask what you mean by this term. As well as the other things. And FYI, whether you're reading from the texture you're rendering to is not unrelated to the question. $\endgroup$ – Nicol Bolas May 19 '17 at 17:05
  • 1
    $\begingroup$ "Everything else is just "flavour" and changes nothing about it being multiple shader passes" No, they're not "flavour". For example, if your multiple "shader passes" are actually rendering different geometry, then I would suggest you construct the geometry for the separate passes to simply not overlap. But if they're rendering the same geometry, then you'd need to do something else. And that "something else" would be based on how each pass knows what it should and shouldn't render to. This is not sophistry; these details directly impact what my answer would be. $\endgroup$ – Nicol Bolas May 19 '17 at 19:03
  • 2
    $\begingroup$ @z0rberg's Please reconsider your attitude toward people you are hoping to get free help from. And please do add more details—including screenshots and relevant rendering code—to your question. We can't read your mind and it is far from clear what exactly the problem you're trying to solve is. $\endgroup$ – Nathan Reed May 22 '17 at 3:33
0
$\begingroup$

You want to use blending,

This takes the previous color and the output color of your fragment shader and mixes them together based on the blend parameters and the alpha values.

This only works for simple math but when doing more complex things you will need to "ping-pong" between 2 textures making sure to draw to every pixel (or copy it over).

$\endgroup$
  • $\begingroup$ after rethinking... i'm not sure i follow. How would i blend one texture with itself? Read-modify-write in the shader isn't an option for me, it would kill performance. Remember, there is only one output texture.. and a dozen shaderpasses. $\endgroup$ – z0rberg's May 19 '17 at 17:05
  • $\begingroup$ @z0rberg's: "How would i blend one texture with itself?" You don't blend textures at all. Blending happens between the current render target and the outputs of the fragment shader. $\endgroup$ – Nicol Bolas May 19 '17 at 17:52
  • $\begingroup$ I must have struck a nerve somewhere in your ego. You're not helpful and actually annoying. :) sure, you wanna be super accurate, but you don't see how that only serves yourself and no one else. Can you stop being annoying? Cheers! :) ... or wait. You can have the last word, as that will make you feel better... and i will simply ignore you. :) $\endgroup$ – z0rberg's May 19 '17 at 18:18
  • $\begingroup$ @z0rberg's: I did answer your question. How do you blend a texture with itself? You don't; you blend the output of your rendering process with the texture. You render with blending. You render again with blending. Both are rendered to the same image, with the latter blended on top of the former. If you find it "annoying" to use the right words to describe things, I really can't help you. But that's how you do what ratchet freak was talking about. $\endgroup$ – Nicol Bolas May 19 '17 at 19:01
  • 3
    $\begingroup$ @z0rberg's Welcome to Computer Graphics Stack Exchange! Please understand that people are here to help you, and are not asking questions to annoy you. Narrowing down what you are aiming to do is part of helping you. All members of this community are expected to Be Nice. Please bear this in mind when responding to others. $\endgroup$ – trichoplax May 20 '17 at 0:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.