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 / Overlay one Camera on another

Author
Message
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 25th Feb 2015 18:59
Now this is pretty much post processing, but I can't workout how to deal with the alpha without affecting the colour of the overlay.

Say we want to overlay a spinning cube. We'd make a camera, position somewhere, put a spinning cube infront of it and then take the image of that camera and combine it with the image of main camera. But the problem I've got is trying to display the spinning cube how it would be if it was in the main camera and I'm using a shader for the blending btw.

Does anyone know what this kind of blending or combine is called so I can look up the technique or has done this before?

"Get in the Van!" - Van B
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 25th Feb 2015 19:46
Just texture the quad with the render target?

A good indicator for your ability to be able to cope with life is your ability to joke about anything. If there are things that are off-limits to you, or things that you just don't think are funny and will never joke about, then you have problems you need to work out. -- Destiny
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 25th Feb 2015 20:00 Edited at: 25th Feb 2015 20:09
Um... That's not really a solution to combining images in a specific way

I'm rendering frame buffers that get combined with shaders using image kit, so no need for a quad

"Get in the Van!" - Van B
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 26th Feb 2015 00:34
Basically I'm doing this:




But as you can see there's the problem with how the orthogonal camera is combined with the main cam. So I figured if I turn them both into images and combined via a shader I could sort this. But that's where I'm stuck, no matter what I've tried the output is slightly transplant.

"Get in the Van!" - Van B
Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 26th Feb 2015 01:34
Quote: "So I figured if I turn them both into images and combined via a shader I could sort this."

Create a screen quad object (a plane that perfectly fits the screen; you can ensure this by manually setting the vertices based on vertex id in your vertex shader) and assign both images to it. Make sure that the "overlay" camera renders with a transparent backdrop clear colour; use backdrop on camId, 0x00000000. Just a single zero obviously works too, but to make it obvious that the alpha component is zero. Using rgb(0, 0, 0) will return a black colour with full alpha for reference so it's important to get this step right.
Now in your pixel shader you sample both input textures (render targets of the cameras) and blend them as you see fit. The easiest could be to just check if the sampled alpha value of the overlay image is zero or below some threshold value and if so return the colour of your scene camera, otherwise you return the overlay texture's sampled pixel from your pixel shader. You'll probably want to regard the scene camera texture as always having a full alpha value and then use the alpha values of the overlay texture for transparency blending.

Sorry if this text appears unstructured, it will be my last good deed before bed

Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 26th Feb 2015 01:44 Edited at: 26th Feb 2015 01:53
I'm not entirely sure how you'd do that in a shader, what I've got now:


Oh and I've played with various blending modes but that didn't help and I stated earlier, I'm rendering frame buffers (or whatever you'd call them) that get combined with shaders using image kit, so no need for a quad.

"Get in the Van!" - Van B
Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 26th Feb 2015 10:55 Edited at: 26th Feb 2015 10:57
Quote: "I'm rendering frame buffers (or whatever you'd call them) that get combined with shaders using image kit, so no need for a quad."

Maybe that's the reason then; it can be hard to figure out what is going on if you cannot control / see how the blending is being done.

Looking at your shader code, won't you have to declare another (the first) texture and initialize your s0 sampler?
The easiest way to blend the two sampled colours is probably something like this:


Whether it will look any good depends on your frame buffers' contents; if you have an alpha value of 0.5 of the overlay buffer at a pixel where the background frame is full green and the overlay frame is full red, the result will be an inbetween orange. However if your overlay mostly uses full/none alpha it will serve to efficiently replace whatever is in the background frame with the contents of the overlay frame. Unfortunately using branches is not very efficient at all in shader model 3 and lower, hence why I didn't just do that.

Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 26th Feb 2015 11:16
Quote: "Looking at your shader code, won't you have to declare another (the first) texture and initialize your s0 sampler?"


It's declared through Image Kit when using the paste function. So ik paste image imageNumber, x, y, effectNumber < the imageNumber seems to be passed into the shader and assigns itself. I found this by mistake

Quote: "Whether it will look any good depends on your frame buffers' contents; if you have an alpha value of 0.5 of the overlay buffer at a pixel where the background frame is full green and the overlay frame is full red, the result will be an inbetween orange. However if your overlay mostly uses full alpha it will serve to efficiently replace whatever is in the bavkground frame with the contents of the overlay frame."


Ah right I got you, so this kind of method should only be used for certain things really. As of your code, I get: error X3004 undeclared identifier 'Lerp'

"Get in the Van!" - Van B
Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 26th Feb 2015 12:37
Quote: "As of your code, I get: error X3004 undeclared identifier 'Lerp'"

My bad, it should be a lowercase L ("lerp").

TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 3rd Mar 2015 00:20
Did you get it to work?

Also, I answered your PM Sasuke. Not sure if you saw it or not. We really need a notification icon or something.

Need help with C/C++ game dev? PM me or add me on skype: the__comet.
Current active project: Light Ship

Login to post a reply

Server time is: 2025-05-12 13:00:23
Your offset time is: 2025-05-12 13:00:23