Blending Surfaces (without using vertices)

Started by
5 comments, last by kauna 10 years, 11 months ago

Hi guys

Is there a way to blend or "layer" multiple IDirect3DSurface9 images on top of eachother using alpha blending and if so, how would i go about it? I would like to avoid having to create vertex buffers and applying textures to them as such since this is a 2D not a 3D operation.

Thanks

JB

Advertisement

Gee....no one who can help? Surely there must be a way using pixel shaders? anyone got an example?

I guess you must do exactly what you don't want to do. Create a vertex buffer defining a full screen quad and a pixel shader defining the blending operation you want to perform.

What is the usage of the final result?

Cheers!

I don't see "2D not 3D" as a valid reason to not use vertex buffers and textures here. There's absolutely nothing about 2D that precludes their use. Perhaps you're drawing using StretchRect calls instead of DrawPrimitive? If so, then maybe you should look at the ID3DXSprite interface for an alternative, or else use vertex buffers and textures with the D3DFVF_XYZRHW option in an FVF (or D3DDECLUSAGE_POSITIONT in a declaration) to specify 2D coords without needing to worry about transforms (you can also use DrawPrimitiveUP to totally avoid vertex buffers if you wish - generally not recommended but good enough for simple programs where absolute performance isn't a requirement).

StretchRect itself can't do alpha blending; it merely transfers the contents of one surface to another. You can't use a surface in a shader; you need to use textures. So if you're using surfaces and StretchRect then you need to get away from that.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

The reason i want to avoid vertex buffers is because this blended surface is going to become part of a single texture and all this has to happen offscreen before i apply the texture to the scene. However since you say i can use textures with pixel shaders, you say it is possible to blend multiple textures with a pixel shader into 1 texture surface? Are there any examples of this?

You need to look into render to texture; one example for D3D9 is here: http://www.two-kings.de/tutorials/dxgraphics/dxgraphics16.html

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

The reason i want to avoid vertex buffers is because this blended surface is going to become part of a single texture and all this has to happen offscreen before i apply the texture to the scene.

You can draw to an offscreen surface, but any kind of drawing under D3D9 requires vertex buffers or at least using Draw...UP commands where you can leave the vertex buffer management for the API.

Cheers!

This topic is closed to new replies.

Advertisement