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 / Object visible behind other object with transparency

Author
Message
Dark Goblin
20
Years of Service
User Offline
Joined: 19th May 2006
Location:
Posted: 31st Oct 2010 01:13
Hey guys.
I have a big problem.
I need to check, if a object is visible even if it is behind another object, but only if it enters the part, where the other object is transparent.

So I have a plain as a mountain and behind it spawns an object which I need to shoot. This will move on the y-axis and should not be shootable until it enters the transparent part of the other object.

For getting the object number I use "PICK OBJECT" but how do I get to know, if the object itself is visible to the player too.

Hope you can help me out!

... efxMod Developer!
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 31st Oct 2010 08:18
Tricky... you might need to use "point" to get the colour of the pixel on screen and say if it's the colour of your mountain it's a miss, if it's the colour of your sky it's a miss but if it's the colour of your target it's a hit.

"Point" is a bit slow but if you're only using it once when you fire a weapon it shouldn't be noticeable.

Dark Goblin
20
Years of Service
User Offline
Joined: 19th May 2006
Location:
Posted: 31st Oct 2010 12:33 Edited at: 31st Oct 2010 21:19
Okay I now created a shader for all images, which colors the image of the object to black (like for the mountains) and the color of the shootable object to green.

But the problem is, I do not want that the player can view the "color image" and the point() command only picks the color of the screen and not from any other camera, or is there a way to point the command to, lets say camera 4 instead of camera 0 and do not display the rendered image of camera 4.

I hope there is a way (maybe also with a plugin for DBP or something) to get the color of a pixel, which is not rendered on camera 0 and also not displayed on screen!

EDIT:
I know there is a way to write an image into a memblock and then read the color out of the memblock, but the image is locked by system (because of "set camera to image") and because of that I think there is no way to use this, am I right?
Otherwise maybe someone can provide a working code snippet for it (as I also haven't found a working on)!

... efxMod Developer!
Dark Goblin
20
Years of Service
User Offline
Joined: 19th May 2006
Location:
Posted: 1st Nov 2010 17:17 Edited at: 1st Nov 2010 17:21
no one any idea?

Sorry for the double post but I really need to find a way to get this to work.
If you need, I could also provide a screen of my scene so you might get a better way to do it!
Will upload one shortly!

EDIT:

The red "thing" is the object.
The arrow is to show the way the object could move (from behind the mountain to the top, into the alpha channel of the mountain layer).
Every layer has alpha layers for transparency, so if the object is between 2 layers, it could be seen if not under "texture".

... efxMod Developer!
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Nov 2010 17:31
Quote: "I know there is a way to write an image into a memblock and then read the color out of the memblock, but the image is locked by system (because of "set camera to image") and because of that I think there is no way to use this, am I right?
Otherwise maybe someone can provide a working code snippet for it (as I also haven't found a working on)!"

I think that you might need to convert the camera image to a bitmap and use the bitmap commands to get the colour but I don't have DBP here and can't check... anyone else know?

gbark
20
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 1st Nov 2010 17:35
Well I have an "idea", but how to actually implement it is beyond me.

Basically you'd use a raycast that goes between your gun and the target that you're shooting. If the ray intersects the mountain, you need to find that position of intersection. I believe Sparky's collision can handle all that pretty effortlessly.

Now, I think you'd need some way to convert that position on the mountain to UV coords. That's the tricky part, again I'm not sure of the method, but I know it can be done (this is a similar method used to add bloodsplats or bulletholes to models if they are shot, for example).

Once you have the UV coords, you should be able to look at the texture image, convert the UV coords to texture coords, and look at the pixel at that point to determine its alpha value. You'd want to have the mountain texture loaded into a memblock for that, and assuming you can get those texture coordinates, this step is not hard to do.

Based on the alpha value, you can determine whether the target object is behind an opaque part of the mountain or a transparent part.
Dark Goblin
20
Years of Service
User Offline
Joined: 19th May 2006
Location:
Posted: 1st Nov 2010 22:02 Edited at: 1st Nov 2010 22:02
Quote: "I think that you might need to convert the camera image to a bitmap and use the bitmap commands to get the colour"

Thats what would be nice, but I dont find a command to do that.
If I could get the camera image into a bitmap, all my problems would be killed

@gbark:
I basically understand what you mean, but I dont get to understand the way I could do it, as I basically use a "2D" type of game, only based on 3D objects and the gun is only a crosshair displayed as sprite on screen.
I dont know if a raycast could be used for that.

@all:
I would love to use the way baxslash told me, but I need to get a little snippet or something, which points me to the right commands!
Because I have no idea how to get an image into an bitmap (without displaying the image on screen)!

... efxMod Developer!
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Nov 2010 23:11
Aha! I just had a brainwave, you might be able to use the Image Kit (V2) by SvenB here:http://forum.thegamecreators.com/?m=forum_view&t=177340&b=5

As it has this command:


Which should give you the colour of the point you specify on your image (from the second camera)...

Hope this sorts your problem!

Dark Goblin
20
Years of Service
User Offline
Joined: 19th May 2006
Location:
Posted: 2nd Nov 2010 00:06
Unfortunately this does not work on (as said in the help file) for "target images" which such a "set camera to image" image is.
Also if I copy the image into a new one with Imake Kit, it becomes a target image.

So this does not work, maybe there is a way to get around the target image thing?

... efxMod Developer!
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 2nd Nov 2010 02:03
Make a memblock from your mountain image. Then each frame you can read a byte from the memblock containing the alpha value of the mountain image at the current object position. If the alpha is less than a certain threshold value, the object has come over the mountain.

Using point is slow

[b]
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Nov 2010 10:42
Quote: "Make a memblock from your mountain image. Then each frame you can read a byte from the memblock containing the alpha value of the mountain image at the current object position. If the alpha is less than a certain threshold value, the object has come over the mountain.

Using point is slow"

I knew someone would know a better way. I thought in this case point would be OK as it's only used when firing.

Dark Goblin
20
Years of Service
User Offline
Joined: 19th May 2006
Location:
Posted: 2nd Nov 2010 15:05
well I dont think this will work, as I have 7 layer with different textures and the mountain layer is only one of them.
And I dont think that I should convert every layer into an memblock and scan every "layer texture"??

... efxMod Developer!
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Nov 2010 15:59
Quote: "well I dont think this will work, as I have 7 layer with different textures and the mountain layer is only one of them.
And I dont think that I should convert every layer into an memblock and scan every "layer texture"??"

Nobody said you had to check every layer, just the mountain.

I'm thinking maybe you should come up with a working concept for this before making so many assets. Maybe try simplifying the game to start with by reducing it to just the mountain and your 'target'. Once you get that working you could think about expanding the game.

I'm only saying this because you seem to have planned everything except how this is going to 'work' and really it's fundamental to your game concept. Some good ideas for how this could work have been suggested and I wouldn't dismissed them just yet.

Dark Goblin
20
Years of Service
User Offline
Joined: 19th May 2006
Location:
Posted: 3rd Nov 2010 00:44
Got it to work.
After 3 days it does what it should, with the old idea I had with rendered objects etc.

@Mods:
If you want, you can close this thread!

... efxMod Developer!
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd Nov 2010 10:14
Quote: "@Mods:
If you want, you can close this thread!"

That would be a shame if you weren't going to share with us how you solved it? Maybe you could help someone else with a similar problem...

Dark Goblin
20
Years of Service
User Offline
Joined: 19th May 2006
Location:
Posted: 3rd Nov 2010 12:21
I created a camera with an 1*1 image which renders the screen, with a shader which renders all the shootable objects in green.
Now this 1ps*1px image is pasted on the bottom right corner of the screen.
Now I use the POiNT() command to get the color of this pixel.
This pixel is only visible, if you really shoot, otherwise it will not be visible.
The code itself is not 100% perfect, as I need to get the camera position z(ColCam) better, as the object gets a bit smaller if its far away, so I need to calculate this to get the camera as near as possible to the object.

Here I give you the code snippet of the camera creation and update, the rest should be easy to understand!



... efxMod Developer!
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 3rd Nov 2010 12:32
Quote: "This pixel is only visible, if you really shoot, otherwise it will not be visible."

Just an idea but if you make your HUD the same colour then nobody will ever notice this single pixel...

Dark Goblin
20
Years of Service
User Offline
Joined: 19th May 2006
Location:
Posted: 3rd Nov 2010 12:57
yeah that was also my idea, so I thought about this method and came to the same opinion.

Just as an addition for everyone who might have the same problem, here is the call function script, inside the shoot system



Thanks for all the help (well even if I haven't used it that much) and giving me something to start thinking about again.
If there are some more questions to the system, I think I can answer them.

*now trying to get the position right*

... efxMod Developer!
dark coder
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 3rd Nov 2010 14:56
You don't have to paste to the screen to get render target image data, you can use bitmaps like this:



Login to post a reply

Server time is: 2026-07-26 05:03:54
Your offset time is: 2026-07-26 05:03:54