Texture Alpha is Tranparency (sometimes)

Hi, i am new to Monogame, (few months in).

I am rasterizing a YPR 3D matrix and camera, to a quad model, and putting an image on it with alpha

the above image works

problem is, I want to use this image

a fading particle.
but i am getting these results

The code is the same, and as far as i can tell the image format is the same.

Not sure what the trouble could be. Aside formatting. (hm, i will investigate further)

Do you guys have any suggestions?

Seems like you are using wrong blendstate, make sure you are using Nonpremultiplied

1 Like

Yep… non-premultiplied has bitten me many times in the past! :smiley:

Check your blendstate in your spritebatch begin call but also make sure you check the content thinger (content.mgcb) for the texture in question, setting this to false.

The option can be found in the properties for the texture.


Sorry, please don’t use premultiplied content, use correct blendstate, that one multiplication won’t matter on modern HW, losing data in your assets for no reason will actually bite you hard at some point.

It’s been a while but I think I’ve had issues in the past where I don’t set that option above to False. If this isn’t consistent with your expectations I can do some tests later and follow up.

If the confusion here is that the value is set to true in the picture, my mistake, I was just intending to show where it was but do see how it was misleading.

Let’s align first and then, if required, I’ll fix the image :slight_smile:

It’s best to understand what it does.

Premultiplying alpha in your texture means that RGB values are going to be multiplied by value of Alpha channel. So if original pixel value is, lets say, (1, 0, 0, 0.5), resulting pixel is going to be (0.5, 0, 0, 0.5). Which means the moment Alpha is 0, resulting value no matter what is going to be 0, this is where you are irrecovarably losing data.

This matters in some place, thing is that you NEED TO UNDERSTAND where, because until you start perceiving textures as structured data carriers you are wastly limiting your capabilities.

When doing standard alpha blending against target surface, you generally have to multiply source RGB with source alpha, as you noticed that can be done either by having it premultiplied as a asset or by setting correct blendstate. If you premultiply in asset AND set nonpremultiplied blend state then you will do alpha multiplication twice, resulting in darkened edge.

I’m saying it should be set to false in asset. That’s not clear in my post, I will update.

For whatever help this is, I was exploring this a bit more since it’s been a while since I thought about it. This is with a texture that is transparent with a circle with colour {1.0, 1.0, 1.0, 0.5}. Drawing is alternated with Color.Red and Color.Green for the color parameter of the Draw call.


thanks guys looks like its going to be blend state. I don’t actually use the content importer to import my textures. I use Texture2D.FromFile, however I did check by importing one through the content pipe and it had no effect.Though i am not using spritebatch either.

The problem is i am currently using XNA basic effect so i’l take a crash course in declaring and applying custom techniques.

below is pretty nice, so therein lay the problems in my quad overlaps aswell. Material must be required.

Got it
GraphicsDevice.BlendState = BlendState.NonPremultiplied;

Stupid simple in the end :smiling_imp:
i knew it was stupid simple somehow.

ofc king was the additive.

I am impressed. :smiley:

I mean, that was literally in first comment :smiley:

Yes it was, i am sorry if i caused offense. I wasn’t aware that i had to tap the GraphicsDevice for the blend state, i am that much of a noob at shaders. I have used shaders in the past, but the framework for them was desgined for me and in a specific way. So i never saw the XNA side of it all. So i wasn’t capable of understanding at the time of posting. I thought i’d have to write a custom technique you know. Implement high level shader language.

For the record the overlaps are mainly caused as when i move through my matrix, i am holding spacebar to slam an object infront of me, at my forward. and not until additive was used did i realise how many objects i was slamming ontop of eachother, caused those strange missing texture areas, where transparency and alpha is resepected (in the case of the objects at far distance) but not respected for objects at overlap positons.

1 Like

No no, it’s fine, I just wasn’t sure if I was that unclear :slight_smile: