[RESOLVED] Render to Texture and Alphablend problem (VB6/DX8)
I’m trying to render to texture, by using the SetRenderTarget method. I create the texture using the D3DFMT_A8R8G8B8 format but when I render a sprite, for example, that has an 8bit alpha channel to the texture, the alpha blending doesn’t seem to be right. The “translucent pixels” in my image are more “clear” than it supposed to be. It’s better to look at an example, see http://www.auriterminal.com/view/Alpha.png (attached below)
There is a checkered image rendered first on to the backbuffer (which is presented). On top of that is an 8bit alpha channel image (black rectangle with three “holes” with varying opacity, that’s what it supposed to look like on the left. On the right is the render to texture surface. As you can see, the opacity for each hole is less with the right image. You can see the logic in the code snippet below.
Using VB6 and DX8.1
VB Code:
' Declarations
Dim pRendertexture As Direct3DTexture8
Dim pRendersurface As Direct3DSurface8
Dim pBackbuffer As Direct3DSurface8
Dim Zbuffer As Direct3DSurface8
' ... (Code) ....
' Create texture
Set pRendertexture = d3dx.CreateTexture(device, 256, 256, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT)
Set pRendersurface = pRendertexture.GetSurfaceLevel(0)
Re: Render to Texture and Alphablend problem (VB6/DX8)
Are both your images 32 bit?
Plus, you should check out my alphablending demo in my Massive DX8 2D tutorial over in my signature. With the D3DColorRGBA(255, 255, 255, 255), you can change how much it has alphablended, but only from 128 - 255. Maybe if you alphablend it my way, it should work.
Re: Render to Texture and Alphablend problem (VB6/DX8)
Are both your images 32 bit?
It's the same image, the one on the left is rendered directly on the backbuffer, the one on the right is first rendered to a texture surface, and that texture is rendered to the backbuffer. And, it is a 32 bit PNG file.
Thank you for the tutorial reference, I'll look at it tonight, it looks very in depth. I have used D3DColorRGBA before, but that applies to the whole texture. I want DirectX to accurately do the per-pixel alpha blending, and it doesn’t seem to be doing it properly when you first render to texture, and then render that texture to the backbuffer.
[RESOLVED] Re: Render to Texture and Alphablend problem (VB6/DX8)
After much consternation, I finally figured it out. It’s all how the surface is cleared.
The line
VB Code:
device.Clear 0, ByVal 0, D3DCLEAR_TARGET Or D3DCLEAR_ZBUFFER, &H0, 1#, 0
Should be
VB Code:
device.Clear 0, ByVal 0, D3DCLEAR_TARGET Or D3DCLEAR_ZBUFFER, &HFFFFFF, 1#, 0
I cleared the surface with black, it should be cleared with white. Despite the fact that the alpha setting is totally transparent (&H00 as in &H00FFFFFF) for the surface, the color modulates the elements rendered.
Re: [RESOLVED] Render to Texture and Alphablend problem (VB6/DX8)
@Politano, do you have question related to this thread?
The thread is dated 2006, that's 16 years ago, so I don't think jsmallberry is still working on this.
Re: [RESOLVED] Render to Texture and Alphablend problem (VB6/DX8)
Jeez I didn't notice that I had so much time, so I have a similar problem, I'm developing a game, I need to insert a system of day and night and lights, day and night is simple with images, but making the lights work is pretty bad.
This link was the most similar to what I'm looking for, I saw something about D3DRS_LIGHTING, but information about directx8 is very difficult to find and I'm not able to proceed.
Re: [RESOLVED] Render to Texture and Alphablend problem (VB6/DX8)
That is because VB6 only supported directX up until Directx8. Although there are hacks to get it to support directx9, I wouldn't recommend it as even that is old. Now and days, most graphic related applications now use DirectX12, OpenGL 4.6, or Vulkan 1.2, none of which is supported by VB6 due to its age. And those use high level shaders to render the polygons with special effects, not necessarily hardcoded code. And now, we have libraries which make game creation easier such as with Unity 2021 or Unreal Engine 5, both of which support not only PC's, but Virtual Reality (Quest 2, Oculus Rift, and HTC Vive), PS4, PS5, XBox Series S, XBox Series X, Android, iOS, MacOS, and even the Hololens. So your applications can easily become multiplatform! You can even do full blown Ray Tracing. It's more hands on and a lot less coding as it gives you plenty of tools at your disposal and lots of tutorials on YouTube. And from my experience, it makes game creation faster, easier, and impressive!
I also would like to point out that you will find it much easier to get Visual Studio 2022 Community Edition as it is now free, which can easily link up with Unity or Unreal Engine, whichever you decide. And you will have no worries about any sort of DX initialization, ZBuffers, DepthStencils, or clear colors as it is all handled for you. Btw here is a screenshot of me working with Unity. I used zero code. And if I were coding, it would be scripting using CSharp