Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: HDR/Tone-Mapping example  (Read 5056 times)

0 Members and 1 Guest are viewing this topic.
HDR/Tone-Mapping example
« on: October 02, 2011, 01:17:08 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 16
Hello!

This is an example I've made for tweaking the light in the screen!
I'm not good at explaing how the code works, but theres some values to change and it has been documented.

Tweaks in-game:
Left key = reduce light intensity on screen
Right key = add light intensity on screen
Up key = add darkness to dark areas on screen
Down key = reduce darkness to dark areas on screen
A key = reduce light spread(bloom)
S key = add light spread(bloom)
Space key = Toggle effect

I used a screenshot from the awesome looking OoT2D remake someone is doing, hope you don't mind!
Check in the step event for more things to tweak!
Every time you use screen_redraw(), GM calls the draw event on all the objects. So that means that if you redraw the image in the step event, the drawing will "duplicated". That's why I added a global named redraw so that you can seperate in the draw event what's redraw or not, so the current image is not blended to the next buffer etc etc.
Also, I think you need to be registred!

Try it out and I hope you can use it for something! :)


Credit wouldn't hurt :D
« Last Edit: October 02, 2011, 01:20:12 am by dalin024 »
Logged
Re: HDR/Tone-Mapping example
« Reply #1 on: October 23, 2011, 09:07:28 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 16
Did anyone try this? :)

Added screenshot!
« Last Edit: October 23, 2011, 09:24:22 am by dalin024 »
Logged
Re: HDR/Tone-Mapping example
« Reply #2 on: October 23, 2011, 10:57:04 am »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Posts: 61
This looks really nice, and I WOULD definitely try it, if I could! I still only have GM 7 and can't open a GM 8 file.
But I'm very interested in how this effect works, and I already have an idea where I could use this ...

Could you please try to save the gmk as a GM 7 file and upload it?
Maybe the effect can't be done in GM 7, but maybe it works just fine.

Also, your gmk was downloaded 16 times apparently, so I guess someone tried it.
Logged

Sinkin

Team Dekunutz
Re: HDR/Tone-Mapping example
« Reply #3 on: October 23, 2011, 11:28:46 am »
  • Idk
  • *
  • Reputation: +5/-0
  • Offline Offline
  • Gender: Male
  • Posts: 564
Really cool. This example could be helpful for making a day/night cycle.
Logged
Re: HDR/Tone-Mapping example
« Reply #4 on: October 23, 2011, 01:50:35 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 16
This method uses surfaces. It basically work like this... You render the screen to a surface, then you shrink it and resize it a couple of times(passes) to make it blurry. Every time you do the pass, you blend it with bm_add. That's how you get the bleeding :)

I don't have GM7, but here's the code for the controller object:

The code is pretty "rough", so there's probably some optimizing you can do. Set the depth for the controller so it's over all the objects.
Also make some tweak buttons for the variables :) Also set interpolition on in the global settings!

Create Event
Code: [Select]
global.hdr=1;
global.redraw=0;
buffer1=surface_create(640, 480);
buffer2=surface_create(640, 480);
buffer3=surface_create(640, 480);

a=0;//Light variable
l=0.2;//Darkness variable
p=1;//Blur passes

Step event
Code: [Select]
global.redraw=1;
//Draw screen to buffer
surface_set_target(buffer1);
screen_redraw();
//Add color to the buffer(e.g sky light color)
draw_set_blend_mode(bm_add);
//Set color
draw_set_color(c_blue);
//Set alpha
draw_set_alpha(0);
draw_rectangle(0, 0, 640, 480, 0);
//Blur buffer over passes(more passes, more light spread)
for (i=1; i<=p; i+=1)
{
  surface_set_target(buffer2);
  draw_clear(c_black);
  draw_surface_ext(buffer1, 0, 0, 1/(i*2), 1/(i*2), 0, c_white, 1);
  surface_set_target(buffer1)
  draw_set_blend_mode(bm_add);
  draw_surface_ext(buffer2, 0, 0, 1*(i*2), 1*(i*2), 0, c_white, a);
}
draw_set_blend_mode(bm_normal);
surface_reset_target();
global.redraw=0;
if a < 0
{
  a=0;
}
if a > 1
{
  a=1;
}
if l < 0.1
{
  l=0.1;
}
if l > 1
{
  l=1;
}
if p < 1
{
  p=1;
}

Draw Event

Code: [Select]
if !global.redraw
{
  if global.hdr
  {  
    draw_set_blend_mode(bm_add);
    draw_surface_ext(buffer1, view_xview[0], view_yview[0], 1, 1, 0, c_white, 1);
    draw_set_blend_mode_ext(bm_dest_color, bm_zero);
    repeat (l*10) draw_surface_ext(buffer1, view_xview[0], view_yview[0], 1, 1, 0, c_white, 1);
    draw_set_blend_mode(bm_normal);
  }
}

Hope that works for you!
« Last Edit: October 23, 2011, 02:11:17 pm by dalin024 »
Logged
Re: HDR/Tone-Mapping example
« Reply #5 on: October 23, 2011, 05:04:37 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Posts: 61
Yes, it works!  XD Thanks!

I'm having some troubles integrating it into my game, but as a standalone GM file, your code works nicely.
Thank you again!
Logged
Re: HDR/Tone-Mapping example
« Reply #6 on: October 23, 2011, 05:08:21 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 16
Im glad you liked it  :) what ptoblems occur when you try to intergate it?
Logged
Re: HDR/Tone-Mapping example
« Reply #7 on: October 23, 2011, 05:28:59 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Posts: 61
Im glad you liked it  :) what ptoblems occur when you try to intergate it?

Well, the light part of the surface is only drawn in the upper left corner of the room, while the darkening part of the surface is drawn where it's supposed to be. Or something like that. (See attached image)

Also, Link's shadow and things he carries lag one frame behind him (and outside the light part there is a small motion-blur - the current frame and the last frame are drawn)

And when you load the game, two Links are created (how the hell did THAT happen?!?).

But I think those problems are very specific problems of my game, and don't happen because your code is wrong somehow.
Logged
Re: HDR/Tone-Mapping example
« Reply #8 on: October 23, 2011, 06:10:12 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 16
Try changing the step event to end step event. Did you change the resolution for the surfaces? The light buffer seems a bit odd :P Intergating someones system to another system is almost always glitchy at the beginning :)
Logged
Re: HDR/Tone-Mapping example
« Reply #9 on: October 23, 2011, 07:23:43 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Posts: 61
Okay, it works now without any problems!  XD

Changing the step event to end step solved the motion-blur/lag problems (why didn't I think of that? It's so obvious!), and the other problem was countered by drawing a rectangle of color (0,0,0) with blend mode subtract across another, totally unrelated surface  :huh:.

This is great; it's exactly what I've been looking for for that one special area in my game.
Thank you, and I'll certainly credit you!
Logged
Re: HDR/Tone-Mapping example
« Reply #10 on: October 23, 2011, 07:34:04 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 16
I'm glad you found it useful :) You probably know that u can change the "sky light" for more night feeling or something else in the frame:) It can also be used as a transition between rooms, like coming out of a dark dungeon to the bright light :)

ALSO!

To draw the hud for the game, do like this in the draw event....

Code: [Select]
if !global.redraw
{
//draw hud code
}

Do this or the hud will be blended too!
« Last Edit: October 23, 2011, 07:44:31 pm by dalin024 »
Logged
Re: HDR/Tone-Mapping example
« Reply #11 on: October 25, 2011, 01:23:13 am »
  • AKA "Micah DS"
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1347
Wow, thanks for this. I wasn't aware of the uses of blend modes.
I will definitely give you proper credit if I ever use this.
Logged
  • My Music
Re: HDR/Tone-Mapping example
« Reply #12 on: December 16, 2011, 06:56:57 pm »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
Wow, I love to download and test the file. I have GM8. But Something is wrong with the forum and I can only download something called "index.php"
Logged
Re: HDR/Tone-Mapping example
« Reply #13 on: December 17, 2011, 02:00:53 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 16
Did you try to right click and save as?  :)
Logged
Re: HDR/Tone-Mapping example
« Reply #14 on: December 17, 2011, 04:40:16 pm »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
Yes I did. But it was an error with SMF2.0 and some versions of FireFox. 4Sword has fixed it already.

I must say it is a nice feature. However I would not use this to create a day/night system. What it actually does is play with the brightness and contrast. For a day/night system it has the same result as using a semi transparent overlay. Which actually makes a lot of things hard to see instead of creating a night time environment.

This is something that can be usefull to create sudden flashes or dark moments. Just as some lighting effect. Or for the game to have an additional brightness and contrast system on top of the monitor's system.


And one minor coding thing. When using multiple if's on the same variable or mutually exclusive statements use "if ... else (if ... else)" instead of "if ... if ..."
Logged

thestig

Re: HDR/Tone-Mapping example
« Reply #15 on: December 19, 2011, 01:13:48 pm »
HDR Toning's cool. Also @ niek ^^ what?
« Last Edit: December 19, 2011, 02:08:20 pm by thestig »
Logged
Re: HDR/Tone-Mapping example
« Reply #16 on: December 19, 2011, 04:12:51 pm »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
Meh, just forget about it.

I was considering what use this bit has in a GM game. The blue part seemed as if it would be usefull in a day/night system. However I could only get a range from white to black and very red. I completely forgot to check whether it was a specific color. I am quite a dunce.

I would like to know how Dalin024 sees his example being used.

Something I did notice though is the "screen_redraw()" in the step event. Which means that the draw step is performed twice each step. I don't know how much this influences the framerate.

For the rest does the code seem to do do what it needs to be doing. And my respect for that.
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.067 seconds with 68 queries.