Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Blending: Only draw pixel if it's value is higher?  (Read 1061 times)
Shadowsong
Customers
Community Member
*****
Posts: 328


« on: January 08, 2010, 07:30:55 AM »

Basically, I want my Shader to only draw the pixel if it's color is "lighter", meaning the total value is higher than the current pixel.

Is it possiblem to set this with blending modes?

Instead of (for additive blending):
Code:
SrcBlend = One;
DestBlend = One;

Spoken in Pseudo Code:
Code:
If SourcePixelValue < NewPixelValue
   return NewPixelValue //Draw my pixel
Else
   return SourcePixelValue //Keep the old one
« Last Edit: January 08, 2010, 07:57:51 AM by Shadowsong » Logged
jviper
Community Member
*
Posts: 2127

Discipline in training


« Reply #1 on: January 08, 2010, 09:03:43 AM »

That depends on where you are reading SourcePixelValue from.

But I know one thing you probably forgot to do: I have to disable the z-buffer when you are dealing with transparency. If you do not disable the z-buffer, then you have to make sure everything gets sorted from back to front.
« Last Edit: January 08, 2010, 09:10:42 AM by jviper » Logged

JAbstract.....Don't just imagine, make it happen!
Shadowsong
Customers
Community Member
*****
Posts: 328


« Reply #2 on: January 08, 2010, 09:26:53 AM »

Yeah that is the problem, where do I read SourcePixel from??

I disabled the z buffer by the way.

However how would you do this? Is there a way to read the "current" pixel from the buffer? Or would I have to render to a rendersurface and use that as a texture to read from?

Logged
jviper
Community Member
*
Posts: 2127

Discipline in training


« Reply #3 on: January 08, 2010, 10:03:04 AM »

You have to read SourcePixelValue from a texture. There is no way to directly access a pixel from the target the fragment program is writing to.

Now the way around this would be to render to a rendersurface, and have that rendersurface passed to the shader as a texture constant:

Shader.SetVariableTexture("Buffer",RenderSurface)

RenderSurface.StartRender
.....Do the Rendering.....
RenderSurface.EndRender

This way, you kinda tricked it. Its actually rendering to texture, but that texture is a variable that can be read from.

Now keep in mind I was told not to do this. I was told that this would at best lead to artifacts in the rendersurface. I know also that when you try to rend from a texture that is being rendered to, that forces the fragment shader to serialize (by the way the fragment shader is usually suppose to operate in parallel). When it does this, it can lead to performance issues. I was told the solution would be to not read from the texture that it is rendering to, but instead have two textures, one will be read from in the fragment shader, while the other the fragment shader will be writing to. Then after the render copy the rendersurface to the other one.

But this means you are not reading from the same texture you are writing to, which it appears you are trying to do. You can try, but it probably can't be done, because fragment shaders are suppose to operate in parallel. What you are trying to do will break that.
Logged

JAbstract.....Don't just imagine, make it happen!
Shadowsong
Customers
Community Member
*****
Posts: 328


« Reply #4 on: January 08, 2010, 10:42:59 AM »

Yeah that totally makes sense to me.
Never mind it, I also got around it by doing something completely different.
Anyway thanks and I learned something Smiley
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks