<p>You want to use blending, </p>

<p>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.</p>

<p>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). </p>

CC BY-SA 3.0
2017-05-19T17:05:18.600Z
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.
z0rberg's
CC BY-SA 3.0
2017-05-19T17:52:55.907Z
@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.
Nicol Bolas
CC BY-SA 3.0
2017-05-19T18:18:41.733Z
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. :)
z0rberg's
CC BY-SA 3.0
2017-05-19T19:01:15.010Z
@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.
Nicol Bolas
CC BY-SA 3.0
2017-05-20T00:02:37.117Z
@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](https://computergraphics.stackexchange.com/help/be-nice). Please bear this in mind when responding to others.
trichoplax is on Codidact now
CC BY-SA 3.0
2017-05-19T15:01:14.780Z
2017-05-19T15:01:14.780Z
ratchet freak
<p>o7</p>

<p>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.</p>

<p>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.</p>

<p>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.</p>

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

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

<p>And if it is... how?</p>

<p>Thank you!</p>

CC BY-SA 3.0
2017-05-19T15:53:22.607Z
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.
Nicol Bolas
CC BY-SA 3.0
2017-05-19T17:02:49.483Z
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.
z0rberg's
CC BY-SA 3.0
2017-05-19T17:05:35.920Z
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.
Nicol Bolas
CC BY-SA 3.0
2017-05-19T17:48:41.070Z
I didn't mention that i'm reading from the output texture, therefore I'm not doing it. If I did that, I'd mention it. :/ well, a shader pass is when you have a shader doing things. The question implied that there are multiple passes Everything else is just "flavour" and changes nothing about it being multiple shader passes. Your attempt at accuracy is kind of appreciated, but not leading anywhere.
z0rberg's
CC BY-SA 3.0
2017-05-19T19:03:33.073Z
"*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.
Nicol Bolas
CC BY-SA 3.0
2017-05-22T03:33:21.743Z
@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.
Nathan Reed
<opengl><glsl>
Multiple shader passes to the same texture?
z0rberg's
# Multiple shader passes to the same texture?

(Asked by: username_0 on 2017-05-19)

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!

**Tags:** opengl, glsl

> **Comments:**
> **username_1**: 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.  
> **username_0**: 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.  
> **username_1**: 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.  
> **username_0**: I didn't mention that i'm reading from the output texture, therefore I'm not doing it. If I did that, I'd mention it. :/ well, a shader pass is when you have a shader doing things. The question implied that there are multiple passes Everything else is just "flavour" and changes nothing about it being multiple shader passes. Your attempt at accuracy is kind of appreciated, but not leading anywhere.  
> **username_1**: "*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.  
> **username_2**: @username_0 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.  

---

## 1 answers

### Answer by username_3 on 2017-05-19. Score: 1

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).

> **Comments:**
> **username_0**: 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.  
> **username_1**: @username_0: "*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.  
> **username_0**: 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. :)  
> **username_1**: @username_0: 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 username_3 was talking about.  
> **username_4**: @username_0 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](https://computergraphics.stackexchange.com/help/be-nice). Please bear this in mind when responding to others.  

---

