I’m currently working on a two-dimensional Direct3D application, and I’m trying to figure out how to properly add a hue and alpha effect to different textures.
I had it working previously, but the way I was doing it was by:
- Locking the vertex buffer.
- Changing the diffuse colour on each of the vertices.
- Unlocking the vertex buffer.
I’ve heard and learned since then that this is a pretty heavy operation to do dozens of times per frame, so I want to know how else I could do it.
I was looking into diffuse lighting, but I’m not sure whether that allows me to add opacity to textures. If I add a diffuse light with 50% opacity to a texture, will the texture have 50% opacity?
Any guidance is appreciated, tutorials and sample code more so :),
Jengerer
I don’t think so – as per MSDN docs on D3D lighting:
Writing a shader to adjust the color for each vertex sounds like what you’re after, which runs in the GPU and has little performance overhead compared to modifying each vertex on the CPU. There’s lots of tutorials around for D3D on the web, e.g.
http://gpwiki.org/index.php/DirectX:Direct3D:Tutorials:Shaders_Introduction
http://www.toymaker.info/Games/html/shaders.html