Hot answers tagged transparency
15
If I follow the issue correctly try calling Begin with BlendState.NonPremultiplied. This article may also help shed some light on how alpha blending works in XNA:
http://blogs.msdn.com/b/shawnhar/archive/2010/04/08/premultiplied-alpha-in-xna-game-studio-4-0.aspx
11
Your problem will solve rendering with 1bit alpha. Which means you specify some alpha of source texture which is not rendered (mostly 0.5).
You have to write your own shader for saving depth from light and use instruction discard. Discard exists in hlsl, glsl and in cg as well. It exists only in pixel/fragment shader and discards curent fragment from the ...
11
There are lots of ways to achieve order-independent transparency.
The first (and I think oldest) type of algorithm is called depth peeling and works by "peeling" one transparency layer per pass (in the most basic version). This Nvidia paper for Dual Depth Peeling shows peeling two layers at the same time.
The second type which I only know as ...
8
I've talked about this a few times before (see related answers at the bottom) but I'll repeat myself.
As you can imagine, checking every pixel against every other pixel would be very inefficient, even if you limited those pixels to the rectangle range that is actually intersecting. But like you mentioned, your second option also has its share of problems.
...
8
In addition to everything you've stated (textures with alpha channels, drawing the landscape before drawing the wall+window), you also need to do two more things.
First, you need to enable OpenGL's blending functionality:
glEnable(GL_BLEND);
Second, you need to tell OpenGL how to calculate the colors of blended pixels (which OpenGL calls "fragments", ...
8
This is a fairly common approach to transparency in games that use deferred shading. Proper transparency doesn't work well at all with deferred shading, since only one surface's data (depth, normal vector, color, etc.) can be stored at each pixel, and proper transparency involves multiple surfaces overlapping at a pixel, each requiring independent lighting.
...
7
This looks like a case of not drawing with a premultiplied alpha texture correctly. Here's a few helpful links on the subject:
http://www.youtube.com/watch?v=dU9AXzCabiM
http://blogs.msdn.com/b/shawnhar/archive/2009/11/06/premultiplied-alpha.aspx
If you search for "premultiplied alpha" and iOS you might find a direct solution to your problem. I suspect ...
6
Create a new SamplerState of your own and set it like this:
mySampler.Filter = TextureFilter.Linear;
mySampler.AddressU = TextureAddressMode.Clamp;
mySampler.AddressV = TextureAddressMode.Wrap;
mySampler.AddressW = TextureAddressMode.Wrap;
The V coordinate will be wrapped (since you want horizontal repeat) and the U will be clamped.
6
Fully agree with Alex's response, though if you stick with premultiplied alpha I believe you could also do it this way
new Color(new Vector4(alpha, alpha, alpha, alpha ))
Shawn also did a post explaining the difference between premultiplied and non-multiplied alpha - http://blogs.msdn.com/b/shawnhar/archive/2009/11/06/premultiplied-alpha.aspx
6
As thedaian mentioned in his comment, converting the magenta pixels to transparent in JavaScript is going to be slow. You should convert your images to a suitable format beforehand.
ImageMagick can be really useful for this kind of tasks. Converting your tile with magenta background to an image with transparency is as simple as this:
convert ...
6
Your alpha-blended objects should not participate in a depth pre-pass. For a given final pixel, its color will be a number of colors blended together at different depths: the portion of the color furthest away from the camera will either be the sky/background or an opaque object, and all the other contributions will be from semi-transparent objects. And if ...
6
Jens covered the different ways pretty well. I would like to add that additive blending is also order independent and it can be used in limited use cases to achieve pretty good results with very little programming effort.
The following image is rendered with a color something like (-0.5, 1.0, -0.5) with additive blending. Positive color values are given for ...
5
Judging from a quick look at the libgdx wiki's SpriteBatch entry, alpha blending is on by default.
Blending is enabled by default. This means that when a texture is drawn, translucent portions of the texture are merged with pixels already on the screen at that location.
This means that you can do what you said: open the Hero texture in Paint .NET and ...
5
I've been the graphics performance guy for a few big-name 3D iOS titles, so I completely feel your pain on this one.
My experience has been that transparent pixels are the most expensive thing you can render on modern iOS devices. Your conjecture is right; the greater number of pixels on the iPhone4 really kills its performance in general, and transparent ...
5
(No experience with 3D programming on iOS, but this should work on regular OpenGL devices.)
I can think of 2 options that might fix this.
Try separating the model in 2 parts, first render the opaque part and then render the transparent part.
Another option might be to disable alpha writing when rendering the object.
What I think is happening is that when ...
4
When rendering with multisampled anti-aliasing, a coverage value is computed for each fragment; this coverage value is based on the fraction of the pixel that would be covered by the fragment based on the triangle that created the fragment. The net result is that the edges of the triangle are anti-aliased. Because the coverage is based ultimately on what the ...
4
Here's what I would do.
Step 1: Don't sort. Just do it. See if it's a problem. Most likely isn't.
Step 2: Limit particles into such that do not really need sorting, such as:
Just solids (with possibly alpha-to-coverage edges)
let zbuffer take care of the sorting.
Just additive bits
a+b = b+a, so order doesn't matter
Step 3: if more is needed, ...
3
Let me give you the bad news straight away: there is no fix for this, not in Ogre, not in any engine.
This website explains the problem nicely:
http://blogs.msdn.com/b/shawnhar/archive/2009/02/18/depth-sorting-alpha-blended-objects.aspx
However, a solution in your case could be to first render all your opaque objects, turn off depth writing, render the ...
3
SOLVED:
Thanks to Demi. Here is the final code:
// Render opaque objects
[_scene render:renderer opaque:true];
// First planar shadow pass (if needed)
[self renderPlanarShadows:renderer];
// Render transparent objects
glColorMask(1, 1, 1, 0);
if (_zSortingEnabled) {
[_scene ...
3
What do you get if you try and swap the order you draw them in?
Transparent pixels still create depth buffer entries. If you're drawing the back one after the first it's not processing the pixels behind the front image, making it look like there's no alpha.
For reference, take a look at the Painter's alogrithm.
3
The problem is exactly what you say you aren't looking for. Drawing entirely transparent models is a non-trivial task, since to achieve correct blending closer polygons must be drawn after the further ones.
If you don't want to use more advanced techniques like depth peeling, try breaking your model in small pieces and draw them sorted from back to front, ...
3
In order to get proper blending you will probably have to break the object up into multiple models. And even then you are still limited since from certain angles you will be able to break the transparant blend again.
Transparancy is actually quite difficult to get correct without using some cool but fairly exotic solutions. One that comes to mind is Order ...
3
Changing the colours of a vertex buffer is relatively expensive. You'd have to use something like VertexPositionColor and then modify every vertex every time you want to change transparency!
It would be much easier, and faster, to add transparency using a shader (pixel or vertex). Fortunately BasicEffect does exactly what you need - it even has an ...
2
I found a good GDC presentation on how they did it in Halo Reach.
EDIT: Found another method, for upsampling in 1 pass without redrawing the effects. It uses Bilateral Upsampling, but that one upsampling pass is apparently very expensive.
And yet another method: Nearest-Depth Upsampling. This one looks more promising, faster than Bilateral Upsampling, and ...
2
You can't do this in a single pass.
Well, maybe I should clarify.
If you look at the way a triangle rasterizer works, is that it takes a bunch of triangles and puts them on the screen. But, for each pixel, it checks its z value to a value in the z-buffer. If the z of the pixel that wants to be drawn is greater than the pixel that was already there, the z ...
2
I'm pretty sure you have hit the fillrate limit; since PVR GPUs use a tile-based approach for rendering, drawing transparent parts that affect lots of pixels kills the performance.
Try moving to OES 2 and apply the overlay directly when drawing the geometry, or draw the entire scene to a framebuffer object and blend with your overlay manually. 3GS supports ...
2
It can't be done with Ogre. From Sinbad himself, on this thread:
It's basically impossible to sort between particle systems
efficiently. The reason is that to sort arbitrarily would require
every particle to be rendered independently, which would totally kill
performance.
You need to use workarounds like using 'hard' alpha and leaving
...
2
This looks like a culling issue, like Trevor Powell pointed out. A simple way to test if it really is a problem related to culling is to turn it off like this:
RasterizerState rasterizerState = new RasterizerState();
rasterizerState.CullMode = CullMode.None;
GraphicsDevice.RasterizerState = rasterizerState;
Please note that disabling culling is not the ...
2
I think the 0.5 falloff is really too strong and unnecessary; with 0.1 instead you will probably discard 95% of the fragments you already discard. You could even smooth the alpha to avoid remaining artifacts:
if (SampledColor.a < 0.1)
discard;
SampledColor.rgb *= smoothstep(0.1, 1.0, SampledColor.a);
2
There are ways to load images without premultiplication in Android as suggested in this thread. It's also possible to do that without any additional memory penalty at least by doing it completely on the native side, but I don't go to the details here.
If you can use premultiplied alpha and it doesn't e.g. make your content pipeline harder, you should. It ...
Only top voted, non community-wiki answers of a minimum length are eligible