Sign in to follow this  

Is it possible to erase instead of drawing?

This topic is 2656 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone,

Yes, this is sort of a strange issue.
I am drawing sort of a mask/stencil to a framebuffer, whos texture i sample
in my fragment shader.

The fragment shader decides how to draw, or whether to draw at all, by examining
this sampled pixel.

If the pixel has an alpha value of 0.0, its skipped.

Now, is it possible to render geometry that clears the color? As in, at least setting the alpha value to 0.0? I guess if i rendered with alpha == 0,
it would leave what was already there before, right?

What should i do? I'm doing this often, so i wonuldn't like to lock pixels or clear the framebuffer... :S

Share this post


Link to post
Share on other sites
I'm not totally clear on what you're trying to do. Are you trying to actually erase something that has already been drawn to the framebuffer, to uncover what was previously underneath it?

If that's the case then no you can't do that, there is no memory of what used to be in a pixel stored anywhere. Once you write to something, whatever old value was there is gone. You can't just lower the alpha later to make something transparent.



Share this post


Link to post
Share on other sites
No, no, that's not what I want to do.
But thanks for trying to get my intentions. ;)
I want to erase, not to uncover anything, but to end up with

RGBA(dontcare_r, dontcare_g, dontcare_b, 0.0)

I'm asking how I can draw to get this colour, as my texture sampler
can see the difference between solid black, (0,0,0,1) and nothing (0,0,0,0)

As for instance, if I have random colour 'A' (r,g,b,1) in my framebuffer,
and i would like to erase it, I suppose the geometry i draw should
have an alpha value of > 0 to even change what was there before.

If colour 'B' is (0,0,0,0), the colour in the framebuffer at the place of the newly drawn geometry remains at it's previous value, colour 'A'.

If colour 'B' is (0,0,0,1), the colour in the framebuffer at the place of the newly drawn geometry completely changes as the new geometry is opaque, to colour 'B'.

I end up with alpha values > 0. I want an alpha value of 0.

Does this explain better?

Share this post


Link to post
Share on other sites
Well, it is quite difficult to understand your goal. When I understood you right, then you are using alpha blending (src=alpha,dst=inv_alpha) and alpha test >0 ?

In this case it is difficult to clear the alpha channel in the framebuffer
without changing the blend mode. This gets even more complicated when you want to decide if to clear or draw a pixel depending on the value of a sampled texture.

In opengl you can use different blend modes for color and alpha channel. Try to write the alpha channel always while doing alpha blending for the color channel


color: src=alpha, dst = inv_alpha
alpha: src=one , dst = zero



If you need alpha testing enabled, try to discard the pixel in your pixel shader:

..
if(ereaseFrameBuffer==true)
{
alpha = 0
}
else
{
// alpha test
if(alpha<0.1) discard;
}

..

Share this post


Link to post
Share on other sites
Thanks,

Yes, I wanted to clear the alpha channel in the rendered area.
I'll try changing the DST blendmode, then.

As i said; it is a strange problem. It works by clearing the framebuffer
before drawing, but that's just heavy.

Share this post


Link to post
Share on other sites
Sure, just set the color mask bits. I don't remember how to do this offhand in OpenGL, but look for something called output write masks. Just off the top of my head it should involve doing a bitwise OR of a few constants for each of the channels you want to disable writing to, in this case red, green, and blue. Sort of similar to depth write masking.

EDIT: This is going to be application-side, not shader-side, just in case that wasn't clear.

EDIT 2: Thanks, karwosts!

Share this post


Link to post
Share on other sites
Quote:
Original post by InvalidPointer
Sure, just set the color mask bits. I don't remember how to do this offhand in OpenGL, but look for something called output write masks. Just off the top of my head it should involve doing a bitwise OR of a few constants for each of the channels you want to disable writing to, in this case red, green, and blue. Sort of similar to depth write masking.


Ah, good point. glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_TRUE); will freeze the RGB and only allow changes to alpha channel.

Share this post


Link to post
Share on other sites
Dig-dig-dig. There's the thread up again.
A bit smelly, but still relevant. :) Thanks for all the input!

Now i'm trying to use:


glEnable(GL_ALPHA);
glDisable(GL_BLEND);
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_TRUE);
glColor4f(0.0f, 0.0f, 0.0f, 0.0f);
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, block_boundary_vbo);
glVertexPointer(3, GL_FLOAT, 0, 0);
glDrawArrays(GL_QUADS, 0, 24 );


But it still works like not clearing the area inside the projected scaled cube,
that I render.

I see the point with using colormask, though, as i only want to change the alpha component.
But i think that would work additively... ?
Any more good ideas? - Otherwise, I'll change the understood 0.0-1.0 interval
of the 3 primary color channels to span the same intention between 0.1-1.0,
and then test if .r, .g or .b is < 0.1 rather than test whether a == 0.0

Share this post


Link to post
Share on other sites
Why don't you explain what you are actually trying to do for your end goal. Not "clear a color", but really what is your application doing that you need to do this. Explain from a user's point of view what I'm seeing and what you're 'erasing'.

I think there is some miscommunication here because I don't really understand what you are talking about. What you are trying to do probably isn't as strange as you think, but you're not currently making any sense to me.

Share this post


Link to post
Share on other sites
Hey, it's great with such a fast response.
What I'm trying to optimize is my implementation of Polygon Aided Roasting, on the GPU.
The mentioned texture holds the ray offset, and will be skipped completely if the alpha component is zero.
Otherwise, RGB means offset as scaled cartesian coordinates.

After one volume has been rendered, the texture is not cleared now, as it would be very demanding to do that for each volume. And I don't want an old offset to trick my caster into thinking that "Oh, it would be appropriate to position the ray offset here."

-That's why I'd like a local clearing of the texture. Of course, as I mentioned,
I could get by with reserving some space in the RGB part, such that I won't need to examine the alpha value.

That's what I'm trying to do. Hope that helps.

Share this post


Link to post
Share on other sites

This topic is 2656 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this