Moderators: Despellanion, Dr. Best

Dr. Best
Forum God
Dr. Best
Forum God
Joined: March 16th, 2005, 8:47 pm

June 17th, 2013, 8:20 pm #11

Monty wrote:by my thinking that overlaying black and multiplying are the same thing
It is the same thing.

x*(1-alpha)+0*alpha=x*(1-alpha)
Quote
Like
Share

Monty
Forum Leader
Monty
Forum Leader
Joined: September 13th, 2009, 3:58 pm

June 17th, 2013, 9:25 pm #12

@Gandalf nah it's not really that bad because I'm still doing almost everything in C++. Actually, in the past couple days I've been doing more PHP than anything else.

Ah so with what Doctor Best has so kindly pointed out, it seems like the drawTex method looks like it should work.

Now the question is: Does U3D's renderToTexture function (or whatever it's called) render alpha to the texture too? I can't remember. If it does, then doing the gun is all set because it can be overlaid also with DrawTex just like the spot light texture is.

Am I making sense here?
Quote
Like
Share

Gandalf20000
Forum God
Joined: March 4th, 2008, 9:19 pm

June 17th, 2013, 10:31 pm #13

Monty wrote:@Gandalf nah it's not really that bad because I'm still doing almost everything in C++. Actually, in the past couple days I've been doing more PHP than anything else.

Ah so with what Doctor Best has so kindly pointed out, it seems like the drawTex method looks like it should work.

Now the question is: Does U3D's renderToTexture function (or whatever it's called) render alpha to the texture too? I can't remember. If it does, then doing the gun is all set because it can be overlaid also with DrawTex just like the spot light texture is.

Am I making sense here?
I think Dr. Best's point was that overlaying black is the same as multiplying by black: it creates black. Believe me, I've tried using an alpha texture in DrawTex() before to create a flashlight, and it didn't go over well. It requires multiplicative blending on all RGB channels and ignoring the alpha channel, which, if I am correct, is not possible with DrawTex().

I could be wrong, but if you don't draw anything to a particular spot (meaning no sky sphere or sky cube), I'm pretty sure the render texture is transparent in that spot. You may need to cheat to get U3D to stop clearing the backbuffer or something, but I don't really remember. I know I saw the situation a few times.
Quote
Like
Share

Monty
Forum Leader
Monty
Forum Leader
Joined: September 13th, 2009, 3:58 pm

June 18th, 2013, 12:02 am #14

Gandalf20000 wrote:I think Dr. Best's point was that overlaying black is the same as multiplying by black: it creates black. Believe me, I've tried using an alpha texture in DrawTex() before to create a flashlight, and it didn't go over well. It requires multiplicative blending on all RGB channels and ignoring the alpha channel, which, if I am correct, is not possible with DrawTex().
Maybe the color wasn't all black? Because when I look at his screenshot I see a multiplication lighting effect with a 2D texture like this:

http://www.mediafire.com/view/bf5xfeaoq85bnt1/light.png

And I'm pretty sure an overlay can substitute for multiplication. Think about it: overlaying a pixel of (0, 0, 0, 0.5) yields a color that is exactly between the current color and black, because the black color is lerp'ed on with at a position of 50% between the two colors. Multiplying by 0.5 yields a color that is also halfway between the current color and black, because it is half the value.

So if he overlayed a texture like this:

http://www.mediafire.com/view/9g0tjyvnw ... verlay.png (Might have to save that and view that with a background to see the alpha)

It would have the same effect.

You may be right though about it looking very fake. Might as well try it since it is so easy though.
Quote
Like
Share

Gandalf20000
Forum God
Joined: March 4th, 2008, 9:19 pm

June 18th, 2013, 1:58 am #15

The problem with that is it works for black, but it doesn't work for all colors.

Here's a quick example:
We'll take the color (.3,.5,.3,.5) and overlay it against (.6,.4,.3,1). That would result in .5(.3-.6,.5-.4,.3-.3)+(.6,.4,.3)=(-.15,.05,0)+(.6,.4,.3)=(.45,.45,.3), which should be a yellow-tinted grey color.
If we do component-wise multiplication, it becomes (.3*.6,.5*.4,.3*.3,.5*1)=(.18,.20,.09,.5). If we ignore the alpha value, that is still (.18,.20,.09), which is a much darker yellow-tinted grey.

By the way, my internet filter is going bananas, so I can't view the pictures.

EDIT: Here we go:
[+] Spoiler
[+] Spoiler
As you can see, where the image is filled with black they're the same, and where the multiplied image is white and the overlaid image is transparent they are the same. Everything in between is different. The multiplied image looks like a bluish-green-tinted spotlight and the overlaid image looks like, well, an overlay.
overlay.png
multiply.png
Quote
Like
Share

Monty
Forum Leader
Monty
Forum Leader
Joined: September 13th, 2009, 3:58 pm

June 18th, 2013, 2:42 am #16

We are both saying correct things but different things.

You are multiplying (and overlaying) two arbitrary colors. In this case, it's true that you get different results. I am simply taking an arbitrary color and scaling the R,G,B values by a certain scalar value. Using the overlay method, only grayscale lighting is therefore achievable.

The image of a scene can be multiplied by a single-colored bitmap full of (0.5, 0.5, 0.5, 1) pixels to make it half as dark right?
Math: (a,b,c,1)*(0.5, 0.5, 0.5, 1)=(0.5a, 0.5b, 0.5c, 1)

However, it can also be overlaid with a completely black, image with an alpha of 0.5.
(a,b,c,1) overlaid with (0,0,0,0.5): Math: 0.5(0-a,0-b,0-c)+(a,b,c) = (-0.5a,-0.5b,-0.5c)+(a,b,c) = (0.5a,0.5b,0.5c), which is the exact same color result with the alpha still 1. Swap 0.5 for 0.75 or 0.25 and it still works, although (the gray color you would multiply by) = 1 - (the alpha of the overlay)

(a,b,c,1) is the arbitrary screen pixel of the game, and (0,0,0,0.5) is a sample pixel from the light overlay. It could also be (0,0,0,0.25) for example, or (0,0,0,0.6), depending on the part of the overlay texture.

Your overlay in the images looks like the clear pixels are (1,1,1,0), the pixels in between are (0.5,0.5,0.5,0.5), and only the black pixels are (0,0,0,1). That's not what we want.
We want the clear pixels to be (0,0,0,0), the pixels in between to be (0,0,0,0.5), and the black pixels (0,0,0,1)
Quote
Like
Share

Gandalf20000
Forum God
Joined: March 4th, 2008, 9:19 pm

June 18th, 2013, 6:39 pm #17

And my point is this: I don't think you'll want that effect. It would, quite frankly, look terrible.
Quote
Like
Share

alexmach1
Forum God
alexmach1
Forum God
Joined: February 18th, 2011, 5:04 am

June 18th, 2013, 7:53 pm #18

In halo 1, cubemaps were used to simulate real-time lights, such as 343 guilty spark; the cube was rotated with the model and applied to the level geometry's normals in an additive layer to give him a glowing effect, most noticeable near walls. would that kind of method work in U3D? it may solve the flashlight issue.
Quote
Like
Share

Monty
Forum Leader
Monty
Forum Leader
Joined: September 13th, 2009, 3:58 pm

June 19th, 2013, 1:35 am #19

alexmach1 wrote:In halo 1, cubemaps were used to simulate real-time lights, such as 343 guilty spark; the cube was rotated with the model and applied to the level geometry's normals in an additive layer to give him a glowing effect, most noticeable near walls. would that kind of method work in U3D? it may solve the flashlight issue.
Is it called precomputed radiance transfer?

If so then no.
Quote
Like
Share

ScottyAnimation
Advanced Member
ScottyAnimation
Advanced Member
Joined: May 7th, 2010, 3:04 pm

June 30th, 2013, 9:43 am #20

@Monty, thanks for the idea of "lagging" the flashlight, that's going in my next game update. As for me and lights.... Using a real light in 3D looks good but then, "Aw man, that needs to cast shadows!" but casting shadows is super expensive. If speed is an issue, the "flashlight" texture idea works pretty good and just have "baked" textures on your models. No real-time lights + no real_time shadows = no real-time speed issues.
Don't get upset, it's just zeros and ones. -Scotty
Quote
Like
Share