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 / [Shader] Heat Haze / Distortion (Easy to Use)

Author
Message
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 1st Sep 2010 18:42 Edited at: 1st Sep 2010 20:53
I've been playing around with shaders recently (learning how to make them slowly but surely!), and I decided to make a heat haze shader. It's heavily based on EVOLVED's refraction shader (so kudos to him!) but has added support for texture scrolling and a transparency mask. All you have to do is create a normal map and a mask image. The normal map can be any old normal map, it just tells what the bumps on the heat haze look like. This texture scrolls across the object at a speed you specify. The mask controls transparency and is a black and white image where black means no heat haze and white means lots of heat haze. The mask does not scroll.

The heat haze effect can be applied to any object.

I've attached a demo with textures, lots of comments and some functions to help add the effect to any game very easily. With VSync off I get about 438 FPS. If you have any questions, feel free to ask. Also, if anyone wants to modify it/optimize it/make it better then please share what you've done . If people want I could try to add texture tiling too.

Screenshot (it really doesn't do it much justice)


Simplest example I could think of (function declarations not shown)


The attached demo should explain everything though.

Just a few ideas of things the shader could be used for (most of them are untested; they're just ideas!):
-Distortion near a fire.
-Distortion on the horizon in a desert.
-Distortion around an object (make a copy of the object, scale it up slightly and apply the heat haze effect to the copy)
-Water distortion (make a water plain of any texture and then make a heat haze object on top of it. Maybe if transparency permits you could make the water semi-transparent as well...)
-Distorted Tile Floor (same as water but don't scroll the heat haze.)
-Clear glass windows (don't scroll the heat haze.)
-Eerie distorted areas. (It's possible to change the color of the heat haze, see the SetHeatHazeColor command in the demo.)
-Circular ripple effect (make a mask image with a white unfilled circle on it.)


Guns, cinematics, stealth, items and more!

Attachments

Login to view attachments
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 1st Sep 2010 18:43
Uploading a screenshot...


Guns, cinematics, stealth, items and more!

Attachments

Login to view attachments
Dr Tank
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 1st Sep 2010 19:08
That works really well! Runs fast. About 80fps.

Effect seems a bit transparent. Like some of the light going through isn't bent at all, and the rest is. Also effect fails when viewed from above. Perhaps you can work on this.

Anyhow, I'm impressed. Will check out how you did it.
Indicium
15
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 1st Sep 2010 19:18
Quote: "Also effect fails when viewed from above."


Correct me if i'm wrong, but the real life effect of heat wouldn't be visible from above anyways because that's the direction of the heat?

If i'm wrong, just ignore me hahaa

Dr Tank
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 1st Sep 2010 19:28
Quote: "Correct me if i'm wrong, but the real life effect of heat wouldn't be visible from above anyways because that's the direction of the heat?
"

That's probably true for a mirage- since the air temperature is a function of altitude. Vertical rays are straight.

With this demo, where the air temperature has a sort of 3d "lumpy" distribution, you should see it from above too.
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 1st Sep 2010 19:35 Edited at: 1st Sep 2010 20:30
@Dr Tank: Thanks, most of the credit should go to EVOLVED though .

As for the invisibility from above issue, the effect is currently applied to a plain which is pointed at the camera's X/Z position. You could edit the POINT OBJECT command to point at the camera's Y position too, which would make it visible from above.
It might cover an unusual amount of space though. Perhaps two heat haze objects, one pointed up on top of the current object would work?

As for the transparency, modifying the mask image to be white instead of gray would probably fix it.


EDIT: I just found a tiny bug... for now, when using SetHeatHazeOffset, make sure to write it AFTER the SetHeatHazeUpdate function!

EDIT 2: It doubles nicely as a water shader w/out reflection . Just scale the plain up and xrotate it by 90 degrees. Instant water . I had to make a new normal map to make it look nice though. (to tell the truth I just used photoshop's cloud filter, spammed difference clouds for a while, used the normal map filter and then saved the image)


Remember, the color can be changed too...


Guns, cinematics, stealth, items and more!

Attachments

Login to view attachments
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 1st Sep 2010 20:44
Nice shader!

My signature is NOT a moderator plaything! Stop changing it!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Sep 2010 23:22
Looks good. Keep it up.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Sep 2010 00:21
Wow, this works really well on a box using your code. Great work!!

Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 2nd Sep 2010 03:50
@Mobiius: Thanks!

@Green Gandalf: Thanks, your various shader examples were quite helpful overall

@baxslash: Thanks . The box does look pretty good, but I'd imagine it might look even better with a better mask texture (maybe a solid white or gray mask). Right now there are these transparent spots on the box's edges .


Guns, cinematics, stealth, items and more!
Softwizz
14
Years of Service
User Offline
Joined: 14th May 2009
Location: U.K.
Posted: 4th Sep 2010 17:40
Quote: "I've been playing around with shaders recently (learning how to make them slowly but surely!)"


Good for you, if only more people did this instead of just posting for a complete solution to a problem.

Excellent shader BTW.

Timd
13
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Kentucky
Posted: 5th Sep 2010 10:25 Edited at: 5th Sep 2010 21:56
Hey, I was googling "hlsl heat effects" yesterday and happened upon this thread! And a recent thread too, not one created in 2002! Anyways, I played around with your shader and converted it into a post processing effect. I created a few little shaders to create a mask on the fly around heat sources like particle tails and explosions. I'm new as well to shaders so from one noob to another thanks!

Here's some footage of the shader working in my game. I'll post some action stuff a little later. The video is on facebook so let me know if you can't access it.

http://www.facebook.com/profile.php?id=512007245&v=app_2392950137#!/video/video.php?v=463326732245

Here's some action footage, it's difficult to see but you can really see the warping around the ring explosions.

http://www.facebook.com/video/video.php?v=463326732245#!/video/video.php?v=463338457245

I'll load these on youtube for the facebook impaired.
Quel
15
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 5th Sep 2010 22:07
...this may be worse than linking something from your local hard drive...
Timd
13
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Kentucky
Posted: 5th Sep 2010 23:19
@Quel ...probably...

Anyways, I uploaded them to youtube. The quality is garbage, but you get the idea.

http://www.youtube.com/watch?v=H_7NPRuoC-8

http://www.youtube.com/watch?v=Bk8z_OkS9yM
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 6th Sep 2010 00:15
@Softwizz: Thanks . The hardest part is finding tutorials and everything online ...

@Quel:
Quote: "...this may be worse than linking something from your local hard drive... "


What do you mean?


Guns, cinematics, stealth, items and more!
Quel
15
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 6th Sep 2010 00:53
..eyy.. There was a link here before pointing to a video uploaded to Facebook...

It was only watchable for users as i feared, and in my anger i had to share my thoughts about that service.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Sep 2010 01:34 Edited at: 6th Sep 2010 16:11
I think it was from a new user so their post has since disappeared while it's being moderated - at least I think it was on this thread.

Edit Looks like I was right - the posts have reappeared. For a while I thought I was imagining things.
Quel
15
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 6th Sep 2010 02:45
Umm, two posts from me already, an non in the theme of the thread, i'm sorry.

Do you think you could turn this into a full screen shader? (what's a full screen shader anyway, isn't it a built in plain having the effect on it in front of the camera?)

I was thinking a little tweaked and with the correct scroll speed, full screen this would be an awesome addition to a desert scene for example...

To be honest i kinda feel this is a little soft for the air to become distorting. But two plain with the effect, with different normal maps, and opposite scrolling direction would really by like the real stuff.

Using it above fires is a little overdo of the effect, even in real life you have to concentrate and look closely many times to spot that the air is actually 'noisy' above a fire. If not used full screen in a desert, it should be used as an indicator of heat where nothing else shows you that thing is hot, like some overheating machine imminent to blow up or something.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 6th Sep 2010 10:53
Quote: "Do you think you could turn this into a full screen shader? (what's a full screen shader anyway, isn't it a built in plain having the effect on it in front of the camera?)"

A full screen shader takes the output from a camera and returns an altered image (basically) but you could get the same effect the way you just decribed using a plain in front of the camera.

Quote: "Using it above fires is a little overdo of the effect, even in real life you have to concentrate and look closely many times to spot that the air is actually 'noisy' above a fire. If not used full screen in a desert, it should be used as an indicator of heat where nothing else shows you that thing is hot, like some overheating machine imminent to blow up or something."

That's not strictly true. I was a blacksmith for many years and can tell you that you do get a heat haze effect above a fire without looking too closely, the thing is that it tends to be more obvious if what you are looking at is in the distance behind the fire as close up objects are not so obviously distorted.

Because of this the effect is more obvious when you are close to the fire looking at something far away. My boss used to use this exact effect when doing pyrotechnics for film/TV (car adverts use it a lot). He would light gas from a length of copper tube with holes in the top held just out of sight under the camera.

The Slayer
Forum Vice President
14
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 6th Sep 2010 14:58
@Sixty Squares

Nice shader, man! Well done. This could well be used to simulate fire too, right? Just add a nice fire texture, and you have instant fire. And, changing the shape of the transparency mask to achieve the shape of fire.

Slayer rules!!! Yeaaah, man!
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 6th Sep 2010 16:45 Edited at: 6th Sep 2010 16:45
@Timd: Hey, your posts weren't there before...

Anyway, that game looks amazing and the fullscreen distortion effect really helps bring life to the particle effects. Very impressive, nice modifications! I'm glad to see the shader getting some use already. Good luck on your shader learning endeavors .

@Quel: Ah, I didn't see his post before but I understand now

@Green Gandalf: You were correct, thanks for pointing that out.

@Quel:
Quote: "Do you think you could turn this into a full screen shader? (what's a full screen shader anyway, isn't it a built in plain having the effect on it in front of the camera?)

I was thinking a little tweaked and with the correct scroll speed, full screen this would be an awesome addition to a desert scene for example..."


As baxslash said in the post after yours, a plain in front of the camera would work for that.

Quote: "To be honest i kinda feel this is a little soft for the air to become distorting. But two plain with the effect, with different normal maps, and opposite scrolling direction would really by like the real stuff.

Using it above fires is a little overdo of the effect, even in real life you have to concentrate and look closely many times to spot that the air is actually 'noisy' above a fire. If not used full screen in a desert, it should be used as an indicator of heat where nothing else shows you that thing is hot, like some overheating machine imminent to blow up or something."

I like the desert idea. There is a parameter called "Bumpyness" in the shader which you can change which affects how distorted the heat haze is. Right now I believe it is at 0.1. There is also a function for changing it. You can write SetHeatHazeBumpyness(-1,0.25) to change it to 0.25, for example. Or you can open up the shader and change that number yourself. The "f" after the number in the shader file just says that it is a float. You can also change the alpha using a similar method. In any case, you can always change how intense the distortion effect is.
To use multiple objects scrolling in different directions you would need to load the effect on your own. This just means that you need to use the LOAD EFFECT command to load the heat haze shader, and then you need to specify that effect number instead of -1 when using the heat haze functions.

@baxslash: Thanks for the info. I suppose one could adjust the bumpyness/alpha based on distance from the heat haze object. That could be interesting. Or the shader could be modified to do so based on distance from that particular vertex. This could be more accurate.

@The Slayer: Thanks! I guess it could if you put a fire plain directly behind it and applied a proper mask . Good idea.


Guns, cinematics, stealth, items and more!
Timd
13
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Kentucky
Posted: 6th Sep 2010 19:39
@Sixty Squares: Thanks man, eventually I'll have a demo so you can see it minus the poor compression!

Ill post some code:

@Quel: If you omit the mask from the following code it essentially becomes a fullscreen post processing haze.

The main shader edited from Sixty's code:


A simple shader I wrote to parse the colors from the particle scene. Black stays black but everything else becomes white so you get a nice black and white mask. The particle scene is just anything you deem a source of heat drawn to a black background.


The combination shader I wrote to merge the original scene and the heat scene. Certainly more color options could be added to customize the look, but I chose to go with a straight up combine.


I think the refraction shader is one of the cooler ones I've come across. It can be molded to create quite a lot of different effects. Just in playing around with the normal map I was getting some pretty different looking disto. I'll probably use Sixty's original shader to do a sort of blackhole effect in my game. Make a sort of Whirlpool normal map, set it to a circular mask on a spinning quad, should look wicked!
Timd
13
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Kentucky
Posted: 6th Sep 2010 22:41 Edited at: 6th Sep 2010 23:51
Sorry for the Spam, but it dawned on me that I didn't need a separate combination shader since all the the information is in the haze shader to do the combination there. Should make it a bit more efficient.

EDIT: Came to another realization that there's no need to convert to a black/white image. In fact using the original heat source texture allows for nice alpha calculations and an overall awesome look. So this is the only shader needed to create the effect. I'll post some new footage later.

P.S. Sorry to the moderator for all the work. Lets just agree I'm not an advertiser/troll/terrorist. "

Timd
13
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Kentucky
Posted: 7th Sep 2010 02:08 Edited at: 8th Sep 2010 06:01
The new version. Looks pretty tight.

In Flight:
http://www.youtube.com/watch?v=0Yeb-QNUePE

Stationary:
http://www.youtube.com/watch?v=lOgkmyzg-Hk
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 7th Sep 2010 03:39
@Timd: That's some interesting code you've got there. It all makes sense to me except for the fact that there's no vertex shader! Your video said it was created using glsl. What's the difference between that and hlsl? In the language that you're using, is it possible to apply shaders directly to the camera rather than to an object first?

(Actually, I think this may be possible with DBPro too. But still I've never seen a shader without a vertex shader before.)


Guns, cinematics, stealth, items and more!
Timd
13
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Kentucky
Posted: 7th Sep 2010 05:21
Quote: "
@Timd: That's some interesting code you've got there. It all makes sense to me except for the fact that there's no vertex shader! Your video said it was created using glsl. What's the difference between that and hlsl? In the language that you're using, is it possible to apply shaders directly to the camera rather than to an object first?
"


My bad man, it was supposed to say hlsl. Glsl is the opengl answer to the programmable pipelines and I always mistakenly type is instead of hlsl.

The reason there is no vertex shader is because there are no vertices! " The initial scene is rendered as normal with the exception that it is rendered to a texture surface instead of the monitor. That texture can then be run through a shader using the direct3d "Sprite" class. From the code below (C#) you can see that everything is done pretty standard. Hlsl can also grab the texture being drawn to screen from a register which is where this line in the shader comes from:

sampler ScreenSampler : register(s0);

So that texture being drawn by the "Draw2D" method is automatically assigned to "ScreenSampler."

So when all your shaders are applied you'll change your render target back to the "back buffer" and make one last call to the Draw2D method, but this time it draws your finished image to the screen.



By the time you see this you'll probably see my updated shader which packages everything into one program and looks a lot nicer. It's currently in moderator limbo.

Seeing that your game has a HUD I'm assuming whatever you use has some kind of 2D sprite class. Also if you want you could always add a vertex shader and draw a quad fullscreen to accomplish the same thing, I just find it cumbersome. It looks like your game has bloom? Whatever vertex shader you are applying that with could probably be cut and paste into mine.
Quel
15
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 7th Sep 2010 11:07
I was thinking and maybe it wouldn't be such a good idea to turn it into fullscreen?

I mean, if there is a HUD, which shouldn't be affected...
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 7th Sep 2010 13:44
Timd

Some interesting ideas there.

Quote: "The reason there is no vertex shader is because there are no vertices! " The initial scene is rendered as normal with the exception that it is rendered to a texture surface instead of the monitor. That texture can then be run through a shader using the direct3d "Sprite" class. From the code below (C#) you can see that everything is done pretty standard. Hlsl can also grab the texture being drawn to screen from a register which is where this line in the shader comes from:"


Do you have an implementation in DBPro that we can play with? That would be more useful to most people here.
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 7th Sep 2010 18:12
@Timd: Wow, I didn't see your other posts. They had a delayed appearance again . Anyway nice work. If your shader is still fullscreen though, then how are you creating the mask image? How can you tell what is an explosion and what is a ship, for example?

And as Green Gandalf said, it would be interesting to see an example of this in DBPro. I'm not sure if it's possible though, and you might not know DBPro ...

@Quel: Well you could always draw the HUD as sprites which would appear on top of the heat haze effect. Then they wouldn't be affected. Or perhaps using DISABLE OBJECT ZDEPTH on your HUD would work.


Guns, cinematics, stealth, items and more!
Timd
13
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Kentucky
Posted: 7th Sep 2010 18:48
@Sixty Squares The mask image is drawn the same way as the original scene, to a texture. So one regular scene, and one with a black background and only heat sources drawn(like particles and explosions).

Here's a screen shot of the mask in a random scene:
http://img191.imageshack.us/img191/6174/maskz.png

The only draw back is you have to draw those elements twice, once for the mask and once for the original scene. Though you could do it differently.

I'll look up some DBpro after class and see if I can translate a bit.

And ya about the HUD, you can just draw that after the fact and it won't be effected by the shader. Though I can't be sure exactly how its done in DBPro.

Oh and I swear this is hopefully the last version. It was optimized with some help over on game dev forums.

Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 7th Sep 2010 21:48
@Timd: Ah, I see what you mean now. Nice job! Let us know if you come up with anything in DBPro. If not, I (or someone else) could probably edit the shader to work in DBPro .


Guns, cinematics, stealth, items and more!
Timd
13
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Kentucky
Posted: 7th Sep 2010 22:20
Quote: "@Timd: Ah, I see what you mean now. Nice job! Let us know if you come up with anything in DBPro. If not, I (or someone else) could probably edit the shader to work in DBPro ."


Ya be my guest man. Chances are I won't get around to it for while. If you have experience rendering to texture I'd think it wouldn't take someone versed in DBPro to hack something together.
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 17th Sep 2010 15:29
I gave this a try and I just made a quick translation to DGDK:

[Shader] Heat Haze / Distortion (Easy to Use)

Sixty Squares, it seems that this effect is making it into the simulation, so let me know if you want your real name to be credited

Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 18th Sep 2010 15:23
@Morcilla: Nice job porting it over to DGDK, I'm glad you liked the shader



Quote: "Sixty Squares, it seems that this effect is making it into the simulation, so let me know if you want your real name to be credited "

Awesome . Sixty Squares is fine; don't forget to credit EVOLVED as well!


Guns, cinematics, stealth, items and more!
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 19th Sep 2010 20:58 Edited at: 19th Sep 2010 20:59
I think that pictures doesn't make justice on this shader, so there is a video you can donwload by clicking the pic:



Glad here too
Oh and don't worry, Evolved is already credited for many other things

Quel
15
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 20th Sep 2010 01:28
Well the use of the effect became very moderate... the scale and amount are both lacking, though the real problem is that this really wouldn't occur in space. But that's just as a big problem as the use of sound for spaceships, so keep it, just tone it up. This is not a good idea to implement it with nearly no effect but on the other hand it costs precious frames per screen.
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 20th Sep 2010 12:47
Thanks for the feedback, I tried to keep it subtle.
Not sure about remarking it that much, it is not a plain but a custom object, so the mask texture doesn't hide the edges of the object as designed.

Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 25th Sep 2010 02:01
Nice video . Are you considering using the shader around sun objects? I'm not sure if this would be easy to do but it might look cool. Maybe put a plain over the screen and fade it in/out based on the distance from the sun?


Guns, cinematics, stealth, items and more!
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 25th Sep 2010 12:26
Hey thanks SS
Quote: "Are you considering using the shader around sun objects?"

Yes, that idea poped up almost at the same time than the engine haze one.
Just started with the spaceship, as it is what the current update is about.
For the stars, it should work more or less as you describe, although I'll try to use two spheres (one of them upside down) surrounding the sun object. We will see. I'll keep you informed
Many thanks all along.

Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 25th Sep 2010 17:21
No problem, I look forward to seeing what you come up with .


Guns, cinematics, stealth, items and more!
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 30th Oct 2010 16:17
Here is a sample of how the heat haze looks applied to the stars:



Although the effect is applied to two 3d object spheres (one for scrolling UV up, and other for scrolling UV down), the spheres are so big that it has resulted as a full screen shader, at least when close to the stars.
Using smaller spheres, adjusted to the star size, resulted in a visible edge or a very low alpha (to not to see that spherical edge of distortion).

So far so good, the heat haze can be noticed in the edge of the stars, the particles, the background star, the background nebula and so on.

Very good looking effect, great that you posted it

Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 4th Nov 2010 04:22
Looking good .

If you're worried about the sphere edge distortion, maybe there's a way to make some sort of UV mapped circular mask to help hide the borders? Then you could just point the sphere at the camera so the mask would always be in front of the star.


Guns, cinematics, stealth, items and more!
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 4th Nov 2010 12:21 Edited at: 4th Nov 2010 12:22
Quote: "maybe there's a way to make some sort of UV mapped circular mask to help hide the borders?"

Yes that seems a good idea, as the sphere would be always pointing to the camera, it is possible to build a custom UV mapping that looks good from there. It even could take away the need for 2 spheres, as the UV scroll would be seen from pole to pole.

However that will only work for spheres. For other shapes there could be another improvement/workaround: To include a fast edge detection in the vertex shader, based on escalar (dot) product of the camera and vertex normals, so the alpha transparency goes down to zero (invisible) there.

Thanks for the tip and for making me think about it, although not really worried, but glad
So much to do, everything can be improved here and there. By now it has the job done, and definitively looking better! Thanks again

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 4th Nov 2010 12:26
Why not just make a circular plane? Must be much easier than messing with UV on a sphere...

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Nov 2010 12:57 Edited at: 4th Nov 2010 13:11
Quote: "Using smaller spheres, adjusted to the star size, resulted in a visible edge or a very low alpha (to not to see that spherical edge of distortion)."


That's easy to fix by modifying the shader and the way the alpha blending is done. (Assuming we're talking about the same thing, that is. )

I'll edit this post with some screenshots later today.

Edit Comparison screenshot:



There seems to be a slight change in the image's overall colour as well. I might have changed something else by mistake but you should get the idea.

Attachments

Login to view attachments
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 4th Nov 2010 18:51 Edited at: 4th Nov 2010 18:56
Quote: "Assuming we're talking about the same thing, that is."

Lol. We are talking about using a different mesh to apply the heat haze shader, other than the original Plane object.

It is easy to make the border (or 'edge') of a plane transparent, (like with the original effect texture). But with a different mesh, like an sphere, the limits of the alpha texture doesn't match the borders of the object anymore, so the 'heat haze' has a visible borderline in the screen, and therefore the visual result is less integrated into the scene.

Quote: "That's easy to fix by modifying the shader and the way the alpha blending is done."

Whatever the research that you are doing, it is always great to see what you come up with.
I did gave up because I don't have time to research further, but I'm sure you can surprise me once again

Didn't know that there was an edge misalignation, but in the 'new' version I can see more clearly where the heat haze starts and ends, not a good thing

[Edit: Oh sorry baxslash, I didn't see your post,

Quote: "Why not just make a circular plane? Must be much easier than messing with UV on a sphere..."

Well I try the effect to be '3d', I think it makes it even more interesting. Also it could be applied to areas that are not strictly 'circular', like I already did more or less succesfully with the engine flame, but the edges are still somewhat visible.]

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Nov 2010 19:04
Quote: "Didn't know that there was an edge misalignation"


I thought it was all too obvious.

Quote: "but in the 'new' version I can see more clearly where the heat haze starts and ends, not a good thing"


That's easy to fix in the mask image.

Quote: "But with a different mesh, like an sphere, the limits of the alpha texture doesn't match the borders of the object anymore, so the 'heat haze' has a visible borderline in the screen, and therefore the visual result is less integrated into the scene."


Why not use the sphere's view space normal z component to control the magnitude of the effect near the edge? No need for a mask texture at all. But then I'm not convinced I really understand what you're trying to do.
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 4th Nov 2010 21:03 Edited at: 4th Nov 2010 21:03
Quote: "I thought it was all too obvious."

Now I see what you are talking about. I thought it was part of the desired behaviour, to partially see both scenes.
Now I notice that the 'new' version totally hides the original view, seems quite interesting
What are the needed changes to the source code?

Quote: "Why not use the sphere's view space normal z component to control the magnitude of the effect near the edge?"

Seems a very straight idea, and in fact perhaps more realistic. That should make the borders less noticeable, shouldn't it?

Pictures doesn't make justice on this one, it is best viewed in motion. Here is a picture trying to show what I exposed:



Right now I solve it by using an adjusted alpha to a value as low as possible, while maintaining the object (and effect) still visible. Edges are only noticeable at certain moments, depending on what's behind the object, and on if a 'solid' part of the texture lies in the edge at that particular moment.

Attachments

Login to view attachments
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 4th Nov 2010 21:15
@Green Gandalf: What changes did you make to fix the edge issue? Also, wouldn't a white mask image with short faded borders have the same effect as your changes, or am I missing something here?

@Morcilla: I see what you're trying to do.

Quote: "Quote: "Why not use the sphere's view space normal z component to control the magnitude of the effect near the edge?""

This could work, but I'm not sure how it would be done without the edge misalignment issue popping up on the outer rim of the object. Now that I think about it, I'm also not entirely sure if the shader works properly with different shapes ... It might be worth a try though.


Guns, cinematics, stealth, items and more!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Nov 2010 02:30
Morcilla
Your images look like the same issue that my solution avoids.

Sixty Squares
I'll post the shader plus dba code and some explanation tomorrow.

If I try to do it now I'll make a right mess of it (it's way past midnight here already).

Login to post a reply

Server time is: 2024-04-26 16:28:15
Your offset time is: 2024-04-26 16:28:15