#162409 - sverx - Tue Sep 02, 2008 11:51 am
Hi there... I'm back again, always asking questions ;)
This time the question is: how can I blend two BGs so that the effect is that the resulting image is not the sum of the two BGs but the difference? I mean I want to subtract light so that I can obtain some areas darker than others (not simlpy fading the whole BG...)
Any idea?
Thanks! :)
#162424 - tepples - Tue Sep 02, 2008 8:12 pm
sverx wrote: |
This time the question is: how can I blend two BGs so that the effect is that the resulting image is not the sum of the two BGs but the difference? I mean I want to subtract light so that I can obtain some areas darker than others (not simlpy fading the whole BG...)
Any idea? |
If you want subtractive blending, you'll have to either A. do it in software, or B. program for a Super NES and not a GBA or a DS.
(If there's another answer, the SNEmulDS developers want to hear about it now.)
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#162428 - sgeos - Tue Sep 02, 2008 8:32 pm
tepples wrote: |
(If there's another answer, the SNEmulDS developers want to hear about it now.) |
Alpha blend a dark area with your BG. The results are less than ideal.
-Brendan
#162536 - sverx - Thu Sep 04, 2008 4:58 pm
sgeos wrote: |
Alpha blend a dark area with your BG. The results are less than ideal. |
? If I blend black (0,0,0) with something (r,g,b) I just obtain the same 'something' I had before...
I'm searching to blend say (2,2,2) with (r,g,b) so that I obtain (r-2,g-2,b-2) ...
Ah, on a DS! :)
Ideas?
#162548 - silent_code - Thu Sep 04, 2008 7:58 pm
Look up (alpha) blending in no$gba's gbatek.
I have managed to darken parts of a map with sprites, but it can also be done with another background.
Because the NDS' blending is additive, I expect you to find a solution very quick. ;^)
(Hint: You can "over-" and "under-blend.")
Good luck!
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
#162550 - sgeos - Thu Sep 04, 2008 8:19 pm
Try setting the result to half the source and half the target. That should cut your brightness in half if you blend with pure black, although I would have to run a test to make sure.
#162566 - sverx - Fri Sep 05, 2008 8:30 am
silent_code wrote: |
I expect you to find a solution very quick. ;^)
(Hint: You can "over-" and "under-blend.") |
mmm... no, really, you might have overestimated me :| ...
I've read about blending in gbatek and it seems to me I can only "sum" an x/16 of one BG with another (or a group of BGs with others...)
I've read also about "brightness decrease" color special effect but it works on a whole BG and it doesn't "mix" two BGs...
Any other hint? Please? ;)
sgeos wrote: |
Try setting the result to half the source and half the target. That should cut your brightness in half if you blend with pure black, although I would have to run a test to make sure. |
Yes, it will cut brightness in half but it won't change when blending with pure black. So I will just get 'half' (r/2,g/2,b/2) for every pixel. Not what I was trying to get :|
#162569 - Dwedit - Fri Sep 05, 2008 10:20 am
Rapid Flickering almost looks as good as a 50% blend.
If you flicker between 0%, 50%, and 100% of original brightness (possibly by using sprites?), you can get 0%, 25%, 50%, 75%, and 100% brightness levels.
But if you are able to display solid black, and solid notblack in addition to the blended colors, you can display one blend at 33% and the other at 66%, giving 0%, 16%, 33%, 50%, 66%, 83%, 100% levels through flickering.
You can also use dithering as well, but dithering looks ugly.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
Last edited by Dwedit on Fri Sep 05, 2008 10:55 am; edited 1 time in total
#162571 - sverx - Fri Sep 05, 2008 10:39 am
Dwedit wrote: |
Rapid Flickering almost looks as good as a 50% blend.
If you flicker between 0%, 50%, and 100% of original brightness (possibly by using sprites?), you can get 0%, 25%, 50%, 75%, and 100% brightness levels. |
This effects the whole screen, not just the areas I want to darken...
Dwedit wrote: |
Maybe use dithering as well... |
Yes, I was thinking about that too, but I'd prefer not to do dithering...
Dwedit wrote: |
And of course, you can use raster effects for vertical gradients. |
Don't know what's that... can you give me some more info?
Thanks
#162573 - Dwedit - Fri Sep 05, 2008 10:56 am
Sorry for repeatedly editing my post, changing it significantly each time..
For vertical brightness gradients, you can either use hblank interrupts and write a new palette for that scanline (worse), or use HDMA to write a new value for the blend value register for each scanline (better).
Quick HDMA cheat sheet: write 1 word, 16-bit, src increment, dest restart (or dest fixed), trigger on Hblank, repeat
or in libnds terms:
DMAx_SRC=array of 192 halfword values you want to write to BLEND_AB
DMAx_DEST=&BLEND_AB;
DMAx_SRC(DMA_START_HBL | DMA_16_BIT | DMA_REPEAT | DMA_SRC_INC | DMA_DST_RESET | DMA_ENABLE | 1);
And you need to reset DMAx_SRC every vblank, otherwise it will happily continue past your array.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
Last edited by Dwedit on Fri Sep 05, 2008 11:06 am; edited 1 time in total
#162574 - sverx - Fri Sep 05, 2008 11:03 am
Dwedit wrote: |
For vertical brightness gradients, you can either use hblank interrupts and write a new palette for that scanline, or use HDMA to write a new value for the blend value register for each scanline. |
I see. Well, I'm trying to get darker areas of different shapes, just like when you have clouds casting shadows on a grass, so I should find another method.
#162576 - Dwedit - Fri Sep 05, 2008 11:16 am
I think the answer's going to end up being flickering+dithering+blending. And you need to be able to independently display black and an alpha blended black, so you'd either need sprites or two layers.
Or just software blend it, but that would be slow for moving shadows.
Dithering doesn't look too bad with 7 level grayscale.
edit: doh, you don't get 7 level grayscale from two planes and alternating blending levels, you still only get 5 colors...
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#162580 - Dwedit - Fri Sep 05, 2008 12:45 pm
With one blended layer + flickering, you can alternate alpha values to get either the average of alpha on and alpha off, or the averages of both alphas on.
So if you had brightness values of 25% and 50% available, you could show 37.5%, 62.5%, 75%, and 100% with just one layer. This would be roughly equivalent to what the SNES could do with its 4-color Layer #3.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#162586 - sverx - Fri Sep 05, 2008 2:31 pm
Dwedit wrote: |
For vertical brightness gradients, you can either use hblank interrupts and write a new palette for that scanline (worse), or use HDMA to write a new value for the blend value register for each scanline (better). |
mmm... do you think it's possibile to change the value for the "Brightness (Fade-In/Out) Coefficient" register 4000054h more than once for every hblank so that I can decrease brightness almost for every pixel? How could I achieve something like that?
#162588 - sverx - Fri Sep 05, 2008 2:43 pm
silent_code wrote: |
I expect you to find a solution very quick |
wait wait wait... now I noticed that on gbatek it says:
Quote: |
For this effect, the top-most non-transparent pixel must be selected as 1st Target, and the next-lower non-transparent pixel must be selected as 2nd Target, if so - and only if so, then color intensities of 1st and 2nd Target are mixed together by using the parameters in BLDALPHA register, for each pixel each R, G, B intensities are calculated separately: I = MIN ( 31, I1st*EVA + I2nd*EVB ) |
so, does that means that blening works only when both the pixels aren't trasparent? So... can I have a BG with some dark areas and some trasparent pixel and then blend it with a BG with 8/16 EVA and it won't be blended when under a transparent pixel?
Going to try that...
#162598 - sgeos - Fri Sep 05, 2008 4:46 pm
If you make a black star (black + transparency), and set the alpha blend results to half first and half second target, then you will dim the color intensity (r/2, g/2, b/2) of the pixels in the shape of the star.
You can play around with first and second target levels and try to find results you like. When blending like this, first target plus second target should equal 1... Or, I suppose you could just dim (ie, 5/16 intensity) the lower layer and set the upper layer to zero.
#162617 - DensitY - Sat Sep 06, 2008 12:46 am
Possibly try using multiple palettes. use say 7 palettes as darking levels.
#162641 - sgeos - Sat Sep 06, 2008 8:55 pm
DensitY wrote: |
Possibly try using multiple palettes. use say 7 palettes as darking levels. |
The problem is that alpha blending and darkening are not the same thing. You can use alpha blending to darken, but it is sort of quirky and does not work very well with different "darkening levels", at least not on the GBA. Your best bet is the use the (global) alpha blending settings to blend against a pure black shadow layer, but you will only have one "level" any given frame.
#162644 - Dwedit - Sun Sep 07, 2008 1:33 am
Here is an example of 4-level alpha black blended on an image:
[Images not permitted - Click here to view it] Original Image
[Images not permitted - Click here to view it] Blended Image
[Images not permitted - Click here to view it] Mask
Screenshots are simulated.
To get the 4 level grayscale shown here:
You need two planes for your background mask.
On even frames: Display dark plane of the mask as black
On odd frames: Display light plane of the mask as 50% alpha blended black
You can have levels 25%, 50%, 75%, and 100% transparent for the black. (25% is darkest, 100% is no black blended)
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#162646 - sgeos - Sun Sep 07, 2008 1:56 am
Clever. Depending on how your VRAM is setup, you could probably use one BG layer, and switch the screen data it points to every other frame. The results will not be as dark.
#162647 - Dwedit - Sun Sep 07, 2008 2:10 am
These are the actual screen images being flickered:
[Images not permitted - Click here to view it] Image with Dark Plane
[Images not permitted - Click here to view it] Image with Light Plane
[Images not permitted - Click here to view it] Interframe Blended Image
Dark Plane uses solid black, Light Llane uses 50% transparent black.
This is one background layer being used here, it switches between two tilemaps. This is limited in that the darkest color it can include is 25% transparent black. In order to add solid black to the mask, you would need another background layer.
[Images not permitted - Click here to view it] Dark Plane of the mask
[Images not permitted - Click here to view it] Light Plane of the mask
[Images not permitted - Click here to view it] Interframe blended Mask
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#162648 - Dwedit - Sun Sep 07, 2008 2:37 am
If you want to use two layers, you can express these 8 alpha levels:
Code: |
[0 +0 ]/2
[X +0 ]/2
[0 +Y ]/2
[0 +100]/2
[X +Y ]/2
[X +100]/2
[100+Y ]/2
[100+100]/2
|
Substitute in any value for X and Y.
For example: X=25 and Y=62.5:
0, 12.5, 31.25, 43.75, 50, 62.5, 81.25, 100
or X=50 and Y=75:
0, 25, 37.5, 50, 62.5, 75, 87.5, 100
Example of 8 level darkness effect:
[Images not permitted - Click here to view it] Blended
[Images not permitted - Click here to view it] 8-level mask
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#162666 - sverx - Mon Sep 08, 2008 9:43 am
DensitY wrote: |
Possibly try using multiple palettes. use say 7 palettes as darking levels. |
That's what I've done before, result is good (I'm using 16 palettes) but I wanted to compare it also with another system :)
Dwedit: it's really interesting what you did, I'm going to study it deeply and see if it fits my needs. Thanks! :)
#162737 - sverx - Thu Sep 11, 2008 4:05 pm
Back again to this topic because I was thinking about the video capture capabilities of the DS...
Since the scene I want to darken is a quite complex composition of 3 tiled BGs and many sprites, I'm asking myself (well, I'm asking you also) if it would be possible to:
1) capture the 'scene',
2) do a software darken working pixel by pixel, and
3) display that instead of the 'un-post-processed' scene.
Is it possibile? How should I do that, operatively?
Thanks :)
#162883 - sverx - Mon Sep 15, 2008 4:03 pm
No hints about that? :|
And about that other?
Quote: |
mmm... do you think it's possibile to change the value for the "Brightness (Fade-In/Out) Coefficient" register 4000054h more than once for every hblank so that I can decrease brightness almost for every pixel? How could I achieve something like that? |
Thanks :)
#162887 - sgeos - Mon Sep 15, 2008 7:39 pm
sverx wrote: |
1) capture the 'scene',
2) do a software darken working pixel by pixel, and
3) display that instead of the 'un-post-processed' scene. |
This sounds ultra slow to me, but it might work if you are not doing much else at the same time.
Quote: |
mmm... do you think it's possibile to change the value for the "Brightness (Fade-In/Out) Coefficient" register 4000054h more than once for every hblank so that I can decrease brightness almost for every pixel? How could I achieve something like that? |
If you are happy changing values every scanline you are in luck, but if you want to modify each pixel I think you would be better off with a software filter.
#162917 - sverx - Tue Sep 16, 2008 11:29 am
sgeos wrote: |
sverx wrote: | 1) capture the 'scene',
2) do a software darken working pixel by pixel, and
3) display that instead of the 'un-post-processed' scene. |
This sounds ultra slow to me, but it might work if you are not doing much else at the same time. |
Yes, I guess it is, but actually I can't see any other option but this one and the other below...
The matter is that I didn't understand how to "pre-generate the frame" (so that I can capture it in memory) without showing it in the display :| ... any help?
sgeos wrote: |
Quote: | mmm... do you think it's possibile to change the value for the "Brightness (Fade-In/Out) Coefficient" register 4000054h more than once for every hblank so that I can decrease brightness almost for every pixel? How could I achieve something like that? |
If you are happy changing values every scanline you are in luck, but if you want to modify each pixel I think you would be better off with a software filter. |
Yes, the matter is that I'm not sure it's possible to do a software filter, what I wanted to do, as I said before... so I can darken pixel by bixel working on the "Brightness (Fade-In/Out) Coefficient" register... but how can I sync it with each pixel? There's a Hsync for each scanline, but I guess I've got to sync it "manually" when the display it's drawing the line... or is it there another option?
Thanks :)
#162919 - Dwedit - Tue Sep 16, 2008 11:55 am
Writing to registers pixel-by-pixel as a scanline renders is silly, and I don't know if it would even work.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#162921 - sverx - Tue Sep 16, 2008 12:22 pm
Dwedit wrote: |
Writing to registers pixel-by-pixel as a scanline renders is silly. |
I agree! The matter is that I'm already using 3BGs and also I'm already using the Alpha Blending register for achieving another effect (not the fade) so I cannot apply these other ideas you wrote earlier in this topic...
So, I should software fade the values of the captured frame, instead, but I don't know how could I generate it 'behind' the scene...
Some other help?
Thanks!
#162927 - sverx - Tue Sep 16, 2008 4:04 pm
Dwedit wrote: |
Writing to registers pixel-by-pixel as a scanline renders is silly, and I don't know if it would even work. |
It doesn't, at least in my little tests :| By the way that was really a silly idea, I forgot I can't do "alpha-blend" and "brightness decrease" at the same time, I can use just one of the color special effects at a time... (well, I could use flicker instead of alpha-blend... but anyway I can't darken the pixels while the scanline is rendered, it just doesn't work...)
Help! :| :|
#162939 - Dwedit - Tue Sep 16, 2008 8:12 pm
You could use one extra BG, then simulate the other BG layer with sprites.
The GBA has a sprite limit of over 1100 sprite pixels per scanline assuming you are not displaying any affine transformed sprites. I think the DS is probably the same.
Twenty 64x64 sprites should completely cover the screen at any scroll position, leaving 108 sprites for the rest of the screen, and still leave over 800 pixels worth of sprites per scanline.
More about sprite limits per scanline on GBATEK.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#162942 - Chano Marrano - Tue Sep 16, 2008 8:48 pm
You also can decrease/increase brightness by software.
_________________
Sh*tty RPG
#162955 - sgeos - Wed Sep 17, 2008 3:02 am
sverx wrote: |
I forgot I can't do "alpha-blend" and "brightness decrease" at the same time, I can use just one of the color special effects at a time... (well, I could use flicker instead of alpha-blend... but anyway I can't darken the pixels while the scanline is rendered, it just doesn't work...)
Help! :| :| |
Welcome to the limitations of the DS.
Sometime you can not do exactly what you want to do, and you have to decide which feature or effect is most important and cut what you can not do.
What is the specific problem (or set of problems) you are trying to solve?
#162958 - tepples - Wed Sep 17, 2008 3:52 am
Dwedit wrote: |
Writing to registers pixel-by-pixel as a scanline renders is silly |
Yet necessary on some platforms, such as Atari 2600, Hydra, or Uzebox.
Quote: |
and I don't know if it would even work. |
I've managed to change the palette in mid-scanline on a GBA. Do you want someone to make a GBA or DS demo that takes the next step by DMAing an image straight to the palette memory?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#162967 - sverx - Wed Sep 17, 2008 2:45 pm
Thanks for your replies and interesting ideas, first of all. :)
Then, yesterday evening I tried replacing the alpha blending effect with flicker effect, so I'm activating/deactivating one of the BGs thus showing/not showing what's on that BG on odd/even frames. Well... even if the effect on the hardware is much much better than on the emulator, it still flickers -I mean it's possible to notice its flickering- and that's a bad side effect. It's especially noticeable when screen brightness is at full (4/4ths) on my NDS Lite, it's less noticeable otherwise.
sgeos wrote: |
What is the specific problem (or set of problems) you are trying to solve? |
It's quite a long story. The short version of it is: I'm trying to write an engine to render an isometric world, using tiled graphics. I'm using one BG for the floor (it's a waste, I know, I'm thinking about removing it...) another BG for the walls "behind" and another BG for the walls "ahead" the main character, this last one using alpha blending so that I can still see the main character "thru" the walls. Actually I'm thinking also about replacing this BG with sprites, it could save me the color special effect I need to darken the parts that are "far" from the center, that is the effect I wanted to achieve when I started that topic :)
tepples wrote: |
I've managed to change the palette in mid-scanline on a GBA. |
Can you change the screen brightness in mid-scanline too? That would be interesting to me :)
Dwedit wrote: |
You could use one extra BG, then simulate the other BG layer with sprites. |
Yes, that's another good idea of yours, I'm going to try this soon :)
Again, thanks everybody. When I'll find what fits the best for me, a good (a better! lol... ) explanation will follow :)
#162975 - sgeos - Wed Sep 17, 2008 6:48 pm
What do you need to darken?
#162980 - tepples - Wed Sep 17, 2008 7:17 pm
sverx wrote: |
tepples wrote: | I've managed to change the palette in mid-scanline on a GBA. |
Can you change the screen brightness in mid-scanline too? |
By "screen brightness", do you mean one of the two registers that can fade to black, or do you mean the (Lite-only) backlight brightness? I'd suggest experimenting with DMA to the master brightness register (MASTER_BRIGHT) or the fade amount register (BLEND_Y), but watch your wait states to see how to format the data.
sgeos wrote: |
What do you need to darken? |
I take it from earlier posts in this topic that the OP needs to darken either clouds of smoke or the area on the map not lit by a torch. A program on the Super NES would use the subtractive blending mode (which neither the DS nor the GBA has) for this.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#162988 - M3d10n - Wed Sep 17, 2008 10:04 pm
Do you need the darkening effect in both screens? If not, you could use a 3D layer.
It supports alpha blending against 2D BGs and sprites using the final framebuffer alpha (just remember to set the clear color alpha to 0 and the clear polygon ID to something different than the polygons you want to blend). That way you could do it by using a dark texture with radial alpha gradient.
#163009 - sverx - Thu Sep 18, 2008 2:40 pm
tepples wrote: |
sverx wrote: | Can you change the screen brightness in mid-scanline too? |
By "screen brightness", do you mean one of the two registers that can fade to black, or do you mean the (Lite-only) backlight brightness? I'd suggest experimenting with DMA to the master brightness register (MASTER_BRIGHT) or the fade amount register (BLEND_Y), but watch your wait states to see how to format the data. |
I've been experimenting poking values into the BLEND_Y while the raster beam is drawing the pixels on the screen, and nothing changed, I could just change it during hblank periods, I guess it's because of something about the register (or the bus?) that cannot be accessed... I don't know much (much? lol...) about those things :|
Is it different if I use DMA with BLEND_Y register? And what does "watch your wait states" means? :|
Thanks :)
#163010 - sverx - Thu Sep 18, 2008 3:23 pm
M3d10n wrote: |
Do you need the darkening effect in both screens? If not, you could use a 3D layer. |
I need it on just one screen, but I really don't know anything about 3D :|
M3d10n wrote: |
It supports alpha blending against 2D BGs and sprites using the final framebuffer alpha (just remember to set the clear color alpha to 0 and the clear polygon ID to something different than the polygons you want to blend). That way you could do it by using a dark texture with radial alpha gradient. |
Sounds interesting, where can I read more about the "clear color alpha" and the "clear polygon ID"?
Thanks :)
#163074 - M3d10n - Sun Sep 21, 2008 8:19 pm
It has been discussed a while ago. I don't remember all the details, but seems you enable it by setting up blending using BG0 (3D) as source and ALPHA. Instead of using a constant EVA/EVB for the entire layer, it'll use the values from the final 3D image.
For this to work you need to make sure the 3D layer is cleared to fully transparent (via glClearColor()), and set the background polygon ID (glClearPolyID()) to something different than the ID you use for polygons.
Then draw a quad, using a GL_RGB8_A5 texture, so it blends against the background. Since the background is 100% transparent, when the that quad will alpha blend against the 2D layers you setup.
The thing is: seems this isn't supported by any emulator (I think the latest no$gba supports blending 3D against 2D).
#163101 - sverx - Mon Sep 22, 2008 4:04 pm
M3d10n wrote: |
Then draw a quad, using a GL_RGB8_A5 texture, so it blends against the background. Since the background is 100% transparent, when the that quad will alpha blend against the 2D layers you setup. |
Seems like this way I'll obtain the very same effect that I would obtain using a 2D layer alpha-blended over the other(s)... or am I wrong?
I'd like instead to control the brightness 'pixel by pixel', I need to change it from full to zero with as many levels as possible...
Thanks :)
#163146 - tepples - Tue Sep 23, 2008 11:05 pm
The _A5 allows you to control the alpha per pixel. So if you set the RGB channels to all black, you can vary the density of black (and hence the brightness of what's behind it) with the alpha channel.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#163168 - sverx - Wed Sep 24, 2008 9:21 am
tepples wrote: |
The _A5 allows you to control the alpha per pixel. So if you set the RGB channels to all black, you can vary the density of black (and hence the brightness of what's behind it) with the alpha channel. |
Wow! Now I understand this:
M3d10n wrote: |
Then draw a quad, using a GL_RGB8_A5 texture[...] |
and it seems to me that having a quad that is wide enough to cover the whole display, having a chance to specify the alpha value per pixel in the texture, having 32 possible values of alpha, I can obtain what I need.
Now I need to understand how the 3D works, I'm completely new to this.
Does some of you know where to read a good tutorial/where to read some very simple code/examples?
Thanks for the valuable help so far, guys! :)
#163174 - Sausage Boy - Wed Sep 24, 2008 2:16 pm
The textured_quad example in devkitPro should be a great starting point. Or, optionally, this, which is the same example, but with a paletted texture. You'll want to get rid of GL_TEXTURE_COLOR0_TRANSPARENT if you decide to use that though.
Now, you need to set 3D up so one pixel on the texture maps exactly to one pixel on the screen. This is done through orthographic projection. Replace gluPerspective() (EDIT: was glViewport) with something like this
Code: |
glOrthof32(0, 256, 0, 192, -1, 1) |
This means the screen will go from 0 to 256 horizontally in 3D space, and 0-192 vertically (obviously). It also sets the near clipping plane to -1, and the far clipping plane to 1. Anything in between will get drawn. Orthographic projection means we don't care about how far away something is from the camera, everything is drawn at the same size.
All you need to do now is put a quad with your texture in there, and update it every frame.
The greatest reference for all this is GBATEK. It might look complicated at first, but it really pays off when you get used to it.
_________________
"no offense, but this is the gayest game ever"
Last edited by Sausage Boy on Thu Sep 25, 2008 12:46 pm; edited 1 time in total
#163230 - sverx - Fri Sep 26, 2008 1:17 pm
While I'm waiting for help about how to set up correctly the orthographic projection, I want you to know that anyway it works! :)
Making the clear color completely transparent, giving the BG0 (3D) layer the highest priority, using a quad with a GL_RGB8_A5 texture, the 'decrease brightness blend' it's possible :)
unfortunatly it doesn't work with any of the emulators I'm using:
- no$gba & iDeaS both show a not semi-trasparent quad
- DualiS doesn't show anything, if 3D is enabled. I guess it's because the clear color doesn't get transparent
- NeonDS & DeSmuME seem they doesn't emulate the 3D at all.
but on the hardware the effect is very good :)
Thanks everybody for the help given in that topic! :) (the orthographic projection questions could be moved to a new topic eventually...)
Ciao! :D
#163248 - TwentySeven - Sat Sep 27, 2008 5:10 am
are you using the latest no$gba? It contained fixes that made blending a quad against a bg work for me.
#163259 - tepples - Sat Sep 27, 2008 1:19 pm
TwentySeven wrote: |
are you using the latest no$gba? It contained fixes that made blending a quad against a bg work for me. |
The latest NO$GBA is no longer available. Martin Korth has been missing for months.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#163262 - Dwedit - Sat Sep 27, 2008 2:57 pm
Latest NO$GBA debugger version
This file is publicly available, and is useless without a registration key.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#163305 - sverx - Mon Sep 29, 2008 10:39 am
TwentySeven wrote: |
are you using the latest no$gba? It contained fixes that made blending a quad against a bg work for me. |
I'm using the latest no$gba that is possible to download from Martin's website. Martin then disappeared before I could buy the debugger version :|
In that version -unfortunatly- the blending quad is rendered as a black (opaque) poly, no more. My code should be right, because the quad IS blending, on the real hardware. So maybe you've got a different no$gba version, or you're not blending 3D 'over' 2D... (?)
edit: the blending works when the clear color is opaque. I made a small test right now.
Unfortunatly, now, it seems that another problem arised :| Maybe it's another mistake of mine but now the blending effect I was using between two BGs (2D) 'disappear' when the quad goes over it :| So the upper BG simply hides the other one below it :| (I hope you can understand what I mean, I wish I had studied English a bit more when in high school... :| )
Any ideas? Is it normal that the 2D blending doesn't work for those pixel under the quad?
Thanks!
#163331 - Cydrak - Mon Sep 29, 2008 6:39 pm
sverx wrote: |
Maybe it's another mistake of mine but now the blending effect I was using between two BGs (2D) 'disappear' when the quad goes over it :| ... Any ideas? Is it normal ... ? |
Your code is fine. :-) This is just how 2D blending works. Essentially, it blends the first two matching layers from the top, ignoring transparent pixels and stopping at solid ones. Since the "search" happens for every pixel, and the blend "result" is solid, you get the hiding effect.
E.g.:
- 3D over BG3: Would blend as normal.
- 3D over BG2, BG2 over BG3: Would blend 3D over BG2, and ignore BG3... except where 3D is (completely--I think) transparent; then it will fall through and blend BG2 over BG3.
The main hardware solution to this is to do all the blending in 3D. This means the blended layers, and everything in between them. Of course, there are caveats here too:
1) No additive blends, only alpha available (but per-pixel is a plus);
2) Poly ID's must be different where the blend overlaps;
3) If you go and "re-blend" all this 3D, over 2D... incorrect alpha will be used! So particle/smoke effects, for example, may look wrong.
(3) is easily noticed if you toss a pile of quads over a BG (in fact I ran into it by accident). If they are all the same color/alpha, you can't tell them apart because the alpha doesn't "build up" like the color does. Pity, really.
#163349 - sverx - Tue Sep 30, 2008 10:10 am
Cydrak wrote: |
This is just how 2D blending works. Essentially, it blends the first two matching layers from the top, ignoring transparent pixels and stopping at solid ones. Since the "search" happens for every pixel, and the blend "result" is solid, you get the hiding effect. |
Right, unfortunatly :| I was thinking that the 2D blend would occur between the BGs before the blending with the 3D, so that, for example, I could blend BG3 over BG2 (and BG1) and, after that, blend my A5I3 textured quad over the already prepared 2D background. Unfortunatly it's not like that so the 2D blending still works, but only for those pixels where there's no quad over them :|
Is there a way to change this behaviour? What if I rip away the 2D blending BG and I replace it with some transparent sprites? Will I just stumble again in the same problem?
Thanks!
#163350 - Dwedit - Tue Sep 30, 2008 12:24 pm
Have we been forced back to my solution described 25 posts ago? :)
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#163352 - sverx - Tue Sep 30, 2008 1:12 pm
Dwedit wrote: |
Have we been forced back to my solution described 25 posts ago? :) |
You mean the flickering or you mean to replace the BG with sprites? If you mean using the sprites, yes, it can be a good idea, but I've got to test it because I'm afraid that I'll have the same problem (in the 2D blending) I'm having now with a BG. What's your idea?
Thanks :)
#163354 - M3d10n - Tue Sep 30, 2008 1:38 pm
The problem is that you can only have two layers blending against each other, 3D or not. Seems you have BG0 over BG3 over BG2, with both BG0 and BG3 as blend source and BG2 as blend destination. So, any pixel on BG0 that isn't fully transparent will blend against BG2 ignoring BG3 altogether. Only where BG0 is transparent you'll see BG3 blending against BG2.
When the 3D layer blends against 2D layers, it's using the same system as the 2D-on-2D blending, the only difference is that the 3D layer can provide per-pixel blend values.
Are you using the 3D layers and a 2D layer for darkening, or do you have other blending effect going on (smoke, water, etc)?
#163357 - sverx - Tue Sep 30, 2008 1:56 pm
M3d10n wrote: |
So, any pixel on BG0 that isn't fully transparent will blend against BG2 ignoring BG3 altogether. Only where BG0 is transparent you'll see BG3 blending against BG2. |
Right, in fact that's the reason why I'm thining about using semi-transparent sprites instead of a semi-transparent BG, but I don't know if it will work. I think I've got to spend some time and run some tests...
M3d10n wrote: |
When the 3D layer blends against 2D layers, it's using the same system as the 2D-on-2D blending, the only difference is that the 3D layer can provide per-pixel blend values. |
That per-pixel blend value is exactly what I was rearching when I opened that topic. Unfortunatly I already had a 2D blending BG that was working and now it's not :|
M3d10n wrote: |
Are you using the 3D layers and a 2D layer for darkening, or do you have other blending effect going on (smoke, water, etc)? |
Now I'm using that 3D BG0 for the darkening effect, but I was already using alpha-blending between two other BGs. That part now needs to be somehow replaced... I already tried flickering but it's not good enough, never tried dithering but I guess it won't be better...
... now I'm thinking about using a window to 'mask' the place where I want the 2D blending, but this means that in that window I won't have the darkening... so I'll work in that direction only if I cannot obtain the blending I need with sprites instead of a BG.
(quite a long topic, uh? ;) )
#163370 - Cydrak - Tue Sep 30, 2008 9:12 pm
sverx wrote: |
Right, in fact that's the reason why I'm thining about using semi-transparent sprites instead of a semi-transparent BG |
You'll probably notice that sprites won't blend with each other. Instead they are "drawn" as one OBJ layer, which is actually (or at least conceptually) what will blend. (Of course this is subtly different from normal BGs, which don't have per tile/per pixel priority. Heh, another cute SNES feature which has gone missing...)
Feel free to try (I could certainly be wrong), but I don't think OBJs will work any differently from a BG.
sverx wrote: |
I already tried flickering but it's not good enough, never tried dithering but I guess it won't be better... |
I've seen it work well on GB/GBA, but I guess they're "smearier"--on the DS it bothers me, although flicker and dither aren't as bad combined. I think the biggest caveat is you can't miss frames. If you do, the best case is ugly; the worst case, an epileptic mess. And it's hard to get 60fps all the time: In one project, loading music caused me to skip. Not noticable in a screenfade, but certain scripts called for songs ingame.
So. If none of this works, the question again is, what are you trying to do? I think you said isometric with lighting and transparency, right?
If you're okay with 8bpp, you might get away with extended palettes as different light levels. I don't mean for blending--but rather duplicating the whole BG palette at different brightness. This totally depends on your lighting needs, and how your sprites and tiles are arranged... (apologies to DensitY, if this is actually what s/he meant several pages back >_>)
However, this might be something the 3D is better suited for. The DS can't do point-lights, but you could pretty easily do it in "tile-space" yourself. Then you'd use that as a vertex color to darken the textures, and use poly alpha to blend the walls at the same time.
Whether you use true 3D or flat quads (a matter of taste IMHO, but I'd guess the latter if you drew tiles already), you can still have 2D or 3D clouds or other fancy stuff in front. Another cool thing this gets you (over the "Zelda lamp texture") is the possibility of dynamic lighting--having torchlight constrained to the shape of the dungeon, or whatever, so you don't see rooms you shouldn't...
sverx wrote: |
(quite a long topic, uh? ;) ) |
Yeah... if it all sounds overcomplicated, well, I wouldn't blame you. I struggle with it too--all the palettes, formats, banks, modes... sure, it's easy to make demos with. But for real work, the DS offers enough tradeoffs, quirks (and the occasional outright bugs ;p) to quibble forever. :-)
#163389 - sverx - Wed Oct 01, 2008 9:43 am
Cydrak wrote: |
[...] but I don't think OBJs will work any differently from a BG. |
I guess it is so. Then I'm trying another way...
Cydrak wrote: |
So. If none of this works, the question again is, what are you trying to do? I think you said isometric with lighting and transparency, right?
If you're okay with 8bpp, you might get away with extended palettes as different light levels. |
Yes, isometric with transparency (so that the player can see the main character even when behind a wall) and lighting so that everything is darker when far from the main character.
When I started this topic I already had transparency and I was using 16 palettes (the 'same' but with different light levels, exactly as you said) so I had palette 0 with 16/16 light, palette 1 with 15/16 ... palette 15 with 1/16, you know... but the effect was 'blocky', of course, since the light was 'per tile'. We (my friend who's 'directing' the project and I) didn't like enough the resulting look so I started exploring other options, that's when I asked for a 'brainstorming' in this forum.
Now I'm running some tests having a completely transparent area at the center of my quad so that, at least there, I can still use 2D blending between those two other BGs. The tests are going well, let's see what's the best I can squeeze out from that approach ;)
Thanks! :)
Ciao!
#163412 - silent_code - Wed Oct 01, 2008 10:00 pm
For the "obscured" character I recommend "striple alpha," which is pretty much like dithering. It was used in games like "Max Payne" on the GBA for the exact same purpose. Quake2 had also an option to turn all transparency into striple alpha.
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
#163436 - sverx - Thu Oct 02, 2008 12:00 pm
silent_code wrote: |
For the "obscured" character I recommend "striple alpha," which is pretty much like dithering. It was used in games like "Max Payne" on the GBA for the exact same purpose. Quake2 had also an option to turn all transparency into striple alpha. |
Forgive me, I never heard that before :| What's that "striple alpha"? Where can I read about that? (I made a search on the Net but I didn't find anything! 8| )
#163438 - tepples - Thu Oct 02, 2008 12:47 pm
Try searching for stipple alpha instead. Imagine dithering the alpha channel down to 2 levels.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#163442 - sverx - Thu Oct 02, 2008 1:26 pm
tepples wrote: |
Try searching for stipple alpha instead. Imagine dithering the alpha channel down to 2 levels. |
Thanks, I'm reading something about it, now :)
#163488 - silent_code - Fri Oct 03, 2008 9:41 am
I am sorry! It was quite late and I wrote it just before going to bed. :^)
It's stipple alpha, of course! :^D
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
#163489 - sverx - Fri Oct 03, 2008 1:04 pm
silent_code wrote: |
I am sorry! It was quite late and I wrote it just before going to bed. :^)
It's stipple alpha, of course! :^D |
Don't worry :) I've read it and it's a good idea, in general. But in my case it seems to me that the solution I'm using now it's good enough :)
Thanks everybody once more :) [well, there's still an open question about the orthographic projection in this very same topic...]
Bye! :D
[The projection question has been split. --MOD]