[2.1] Distortion example
- SamiTheGreat
- Bronze Sponsor
- Posts: 102
- Joined: Sat Aug 30, 2008 11:57 am
- Location: Finland
- x 8
[2.1] Distortion example
Hi! I created distortion effect system for our newest title last week and I decided to share it to Ogre community. Effect is done by rendering distortion objects in separate render queue group to own texture. In postprocessing, the texture is used to offset UV coordinates to get distortion effect. "Distortion objects" are just any objects that ogre can render that use unlit material with displacement texture (Blend mode is changed and vertex colors are enabled). I made an example with simple textured spheres but we are using it with particle system.
Effect is pretty simple:
Distortion texture is cleared to values 0.5, 0.5, 0, 0, where R and G are vectors. Value 0.5 means no distortion, 0.0 for left/down and 1.0 right/up.
Alpha value is used to fine control distortion strenght. (That way you can use additive distortion, for example to stack particles to get bigger effect)
Distortion displacement texture looks something like this: (R for left/right and G for up/down)
My shader takes in count different light wavelenghts to add more realism. Blue colors are distored more than red colors and so on. That is an optional feature and can be disabled easily.
I will make a pull request soon after I've made some cleanup and commented shader files.
Last but not least, the video:
[youtube]Tm4qJjWSbx8[/youtube]
BTW: Don't worry about FPS, it is low because of video capture.
Any questions are welcome!
Effect is pretty simple:
Distortion texture is cleared to values 0.5, 0.5, 0, 0, where R and G are vectors. Value 0.5 means no distortion, 0.0 for left/down and 1.0 right/up.
Alpha value is used to fine control distortion strenght. (That way you can use additive distortion, for example to stack particles to get bigger effect)
Distortion displacement texture looks something like this: (R for left/right and G for up/down)
My shader takes in count different light wavelenghts to add more realism. Blue colors are distored more than red colors and so on. That is an optional feature and can be disabled easily.
I will make a pull request soon after I've made some cleanup and commented shader files.
Last but not least, the video:
[youtube]Tm4qJjWSbx8[/youtube]
BTW: Don't worry about FPS, it is low because of video capture.
Any questions are welcome!
- dark_sylinc
- OGRE Team Member
- Posts: 5292
- Joined: Sat Jul 21, 2007 4:55 pm
- Location: Buenos Aires, Argentina
- x 1278
- Contact:
Re: [2.1] Distortion example
Link for those whose flash plugin is broken.
Looks pretty! I like the colour wavelength distortion.
Believe it or not this is the fundamental idea on how screen space refractions work (usually the tweak is the need to account objects in front, as refractions shouldn't refract what's in front of the object).
Looks pretty! I like the colour wavelength distortion.
Believe it or not this is the fundamental idea on how screen space refractions work (usually the tweak is the need to account objects in front, as refractions shouldn't refract what's in front of the object).
- Thyrion
- Goblin
- Posts: 224
- Joined: Wed Jul 31, 2013 1:58 pm
- Location: germany
- x 8
Re: [2.1] Distortion example
Kudos for contributing another example!
not related to the gift, but what game/type are you making?SamiTheGreat wrote:Any questions are welcome!
-
- Gremlin
- Posts: 173
- Joined: Wed Feb 03, 2016 2:24 am
- x 17
- Contact:
Re: [2.1] Distortion example
@SamiTheGreat
Thank for sharing. I will waiting for your commit.
Just curious, did you do it without reading that nvidia screen-space-refractions link (in dark_sylinc's post)?
I mean, did the genius refraction-technique just ... FLASH in your head from nowhere?
Thank for sharing. I will waiting for your commit.
Just curious, did you do it without reading that nvidia screen-space-refractions link (in dark_sylinc's post)?
I mean, did the genius refraction-technique just ... FLASH in your head from nowhere?
- SamiTheGreat
- Bronze Sponsor
- Posts: 102
- Joined: Sat Aug 30, 2008 11:57 am
- Location: Finland
- x 8
Re: [2.1] Distortion example
I didn't read the article you linked. Modifying texture coordinates was first in mind because I already did wave-effect shader for our earlier game (http://store.steampowered.com/app/405950/). My artist showed me a texture and said that he wants this texture to do distortion effects since it does it in PopcornFX Editor. I noticed that there was colored distortions in PopcornFX editor, so that was my inspiration to separate color channels. I am not sure if is done physically correct because in real world there is much wider spectrum with all colors with different wavelengths but in my shader I just roughtly use different wavelength for each color channel RGB.hyyou wrote:@SamiTheGreat
Thank for sharing. I will waiting for your commit.
Just curious, did you do it without reading that nvidia screen-space-refractions link (in dark_sylinc's post)?
I mean, did the genius refraction-technique just ... FLASH in your head from nowhere?
It will be a twin stick shooter mixed with RPG elements (1-4 players splitscreen/online). The game engine is _almost_ ready and we have a prototype already made.Thyrion wrote:Kudos for contributing another example!not related to the gift, but what game/type are you making?SamiTheGreat wrote:Any questions are welcome!
- SamiTheGreat
- Bronze Sponsor
- Posts: 102
- Joined: Sat Aug 30, 2008 11:57 am
- Location: Finland
- x 8
Re: [2.1] Distortion example
I spotted a bug (or missing feature). Distortion is applied over objects that are in front of distortion objects. I assumed that using same depth pool and depth check == true would discard pixels in distortion pass that are behind objects but it seems not working as intented. Is there any way to get distortion render pass to use same depth buffer as render scene pass or do I have to copy depth to a texture and check it in the shader?
EDIT: Or is also depth buffer cleared when I clear distortion pass? There was mentioned in porting manual that clearing z-buffer is now default but how to disable it?
EDIT: Or is also depth buffer cleared when I clear distortion pass? There was mentioned in porting manual that clearing z-buffer is now default but how to disable it?
- dark_sylinc
- OGRE Team Member
- Posts: 5292
- Joined: Sat Jul 21, 2007 4:55 pm
- Location: Buenos Aires, Argentina
- x 1278
- Contact:
Re: [2.1] Distortion example
I've added a few comments to your PR on the exact lines you can change . You're indeed clearing the depth buffer thus causing the problem.
Submit a PR afterwards
Submit a PR afterwards
- SamiTheGreat
- Bronze Sponsor
- Posts: 102
- Joined: Sat Aug 30, 2008 11:57 am
- Location: Finland
- x 8
Re: [2.1] Distortion example
Yeah, I got your comments, thanks! I've fixed compositor clear pass to clear only color buffers and made pull request.dark_sylinc wrote:I've added a few comments to your PR on the exact lines you can change . You're indeed clearing the depth buffer thus causing the problem.
Submit a PR afterwards