Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / 'Getting' a image with transparency

Author
Message
Zeal
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 12th Apr 2006 14:39
Im trying to take some snapshots of objects for my imposter billboards, and im not sure how to capture the alpha channel. Sure I could use a color key, but that would give me all or nothing transparency. Is there anyway to capture the alpha channel when using set camera to image?

Thanks in advance

All you need is zeal
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 12th Apr 2006 15:13
currenty i dont think theres any support for this, which is rather annoying, if you make a 2nd camera and draw it to a corner and remove the backdrop, you can get nice alpha`s annoying that you cant use that for billboards :/.

Halowed are the ori.
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 12th Apr 2006 15:38
You mean snapshots of 3d objects textured with an alpha layer? If so , you could do this (although it's a pretty messy workaround!):

Take a snapshot of your object as normal. Then, load up the textures again into a new image number, convert it to a memblock, and swap the rgb values for the alpha values, in other words creating a greyscale texture of alpha values. Texture the objects with this new image, take a second snapshot. COnvert both snapshots into memblocks and transfer the average rgb value of the second greyscale one to the alpha channel of the first normal one. Told you it was messy!

Chris Franklin
19
Years of Service
User Offline
Joined: 2nd Aug 2005
Location: UK
Posted: 12th Apr 2006 15:38
Just an idea not tested it been as dbp is not installed at the moment

Why not make a plain use a black on that then build another plain with tranpsarency put the second image over that then use get image because usally rgb 0,0,0 is transparent in dbp

JUST AN UNTESTED IDEA

Theme park simulator wip

Zeal
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 12th Apr 2006 15:46
@ric

But if you add ANY r, g, or b value to the alpha channel, then youre going to get transparency where there shouldnt be right? And...

"Texture the objects with this new image"

Shwa? If you apply this texture the uvs will be all jacked up.

You might be on to something, but I sure as hell dont get it :p

All you need is zeal
Zeal
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 7th May 2006 06:05
Well after a couple unsuccessful attempts im back to square one.

Anyone have any other ideas? Again imagine you wanted to take a snapshot of a tree, and then slap that image onto a 2d billboard. How would you capture the alpha of the scene/image?

All you need is zeal
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 7th May 2006 10:03
There are two methods of grabbing an area of an image and retaining transparency.

Method 1: Use the search button and you will find my code snippet which allows you to do it using memblocks. I will save you the trouble of searching (I know it can be a very difficult task for a lot of people).


Method 2. Install update 6 and use the new BITMAP FORMAT 21 command along with a flag of 2 on the GET IMAGE command.


Zeal
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 7th May 2006 10:30 Edited at: 7th May 2006 10:33
Thanks for the input but thats not what im talking about. Im trying to 'get' an image (from 3d space) and retain transparency. So if you took a snapshot of a tree (via set camera to image), I want the backdrop part of the image to be transparent. Sure you could just take the snapshot against a pure black backdrop, and call that area 100% transparent, but I want nice smooth transparent blend along the edges.

Ive tryed taking the snapshot at a ultrahigh resolution, then resampling it down (for the alpha channel) but it still didnt look that great. The main problem is, whatever color you set the backdrop to (when rendering the 3d scene to a texture) shows up in the final image. The 'backdrop' should be colorless.

All you need is zeal
Lost in Thought
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 7th May 2006 12:54
Does it matter how slow the code is?

Zeal
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 7th May 2006 13:52
Nope this is all pre processing stuff. Just need to make these things then ill save them to a file.

All you need is zeal
Lost in Thought
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 7th May 2006 13:57 Edited at: 7th May 2006 14:09
I'll come up with something then. I am assuming this is going with your bilboard stuff?

[edit] This isn't perfect, but is it good enough? You can always add a tolerance to clean it up a bit more.



Xander
22
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 7th May 2006 23:44
Wow, that is a great and simple method LIT. I was actually trying to think of something similar to this for making my game-processed drop shadows. I take a snapshot of the object with a gray texture and then blurred it in a bitmap. I had to use transparency mode 4 to get it to look right, but for some unknown reason, if I use transparency mode 4, then the hardware rendered shadows sporadically appear and dissapear depending on what angle the camera is and what objects are visible. But if I don't use mode 4 then everything is perfect again...

So I am going to base my code off of what you did, if you don't mind, but am going to change it to make a variable alpha channel, because my picture is just grayscale anyway.

Xander Moser - Bolt Software - Firewall
Zeal
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 8th May 2006 01:27
Thanks lost I think I may end up using a colorkey afterall. However I still dont think a simple check like this will work with a complex object. Imagine a semi transparent object like a window. No part of it would be true 000 'black', so not only would it be completely solid, but it would be tinted heavily by the black backdrop.

However this is the most elegant solution. And since this will be used mostly for trees (which dont have a lot of semi transparent parts) I think it will work just fine.

All you need is zeal
Lost in Thought
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 8th May 2006 02:02 Edited at: 8th May 2006 02:04
Yeah thats why I wrote this instead of using the colorkey (plus I can save the image file with alpha set for other programs). You can add a tolerance to it for some types of objects.

if memblock byte(1,location) >= 0 and memblock byte(1,location) < 10

and etc. But even this fails with some contrasting colors.

[edit] Also the closer you are to the object the cleaner it will be.

Zeal
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 21st May 2006 03:58 Edited at: 21st May 2006 04:19
Well im still struggling with this issue. While a color key type solution does work, it still has one major flaw. The alpha is all or nothing, so whatever color you pick for the backdrop, its going to leave a outline around your final image.

I took a 1024x1024 picture of my tree, then shrunk it down in photoshop to 256x256, and you can see a black outline around the whole thing, it looks like crap (kinda looks like ghetto cell shading).

I just dont see how this is possible unless we could somebow set the backdrop to 'colorless'. Could such a thing maybe be done via a shader? Or is there another solution...

*edit

@dark coder

meant to ask you, you said

Quote: " if you make a 2nd camera and draw it to a corner and remove the backdrop, you can get nice alpha`s annoying that you cant use that for billboards :/."


Whenever I turn off the backdrop, set camera to image just displays garbage in thebackground. Youre saying youve seen it transparent?

*edit again

Oh wait nm youre talking about rendering an actual camera to part of the screen. never tryed that

I think I may have an idea though... What if you set the fog to 100% and colored it pure red, then took a snapshot against a pure blue backdrop. You could use this to get your alpha map (depending on how much blue channel is showing through). Then combine this alpha map with a regular solid snapshot against a grey backdrop (grey is better than black I guess).

That might be as good as its gonna get...

All you need is zeal

Login to post a reply

Server time is: 2025-06-27 06:48:07
Your offset time is: 2025-06-27 06:48:07