[2.1] Distortion example

Design / architecture / roadmap discussions related to future of Ogre3D (version 2.0 and above)
Post Reply
User avatar
SamiTheGreat
Bronze Sponsor
Bronze Sponsor
Posts: 102
Joined: Sat Aug 30, 2008 11:57 am
Location: Finland

[2.1] Distortion example

Post by SamiTheGreat » Sat Aug 13, 2016 5:47 pm

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)
Image

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! :)
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 3622
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 95
Contact:

Re: [2.1] Distortion example

Post by dark_sylinc » Sat Aug 13, 2016 7:19 pm

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).
0 x

User avatar
Thyrion
Goblin
Posts: 224
Joined: Wed Jul 31, 2013 1:58 pm
Location: germany

Re: [2.1] Distortion example

Post by Thyrion » Sat Aug 13, 2016 11:53 pm

Kudos for contributing another example!
SamiTheGreat wrote:Any questions are welcome! :)
not related to the gift, but what game/type are you making? :)
0 x

hyyou
Gremlin
Posts: 150
Joined: Wed Feb 03, 2016 2:24 am
x 2

Re: [2.1] Distortion example

Post by hyyou » Sun Aug 14, 2016 4:31 am

@SamiTheGreat
Thank for sharing. I will waiting for your commit. :mrgreen:

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?
0 x

User avatar
SamiTheGreat
Bronze Sponsor
Bronze Sponsor
Posts: 102
Joined: Sat Aug 30, 2008 11:57 am
Location: Finland

Re: [2.1] Distortion example

Post by SamiTheGreat » Sun Aug 14, 2016 7:07 am

hyyou wrote:@SamiTheGreat
Thank for sharing. I will waiting for your commit. :mrgreen:

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?
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. :D 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.
Thyrion wrote:Kudos for contributing another example!
SamiTheGreat wrote:Any questions are welcome! :)
not related to the gift, but what game/type are you making? :)
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. :D
0 x

User avatar
SamiTheGreat
Bronze Sponsor
Bronze Sponsor
Posts: 102
Joined: Sat Aug 30, 2008 11:57 am
Location: Finland

Re: [2.1] Distortion example

Post by SamiTheGreat » Mon Aug 15, 2016 4:21 pm

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?
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 3622
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 95
Contact:

Re: [2.1] Distortion example

Post by dark_sylinc » Mon Aug 15, 2016 9:08 pm

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 ;)
0 x

User avatar
SamiTheGreat
Bronze Sponsor
Bronze Sponsor
Posts: 102
Joined: Sat Aug 30, 2008 11:57 am
Location: Finland

Re: [2.1] Distortion example

Post by SamiTheGreat » Tue Aug 16, 2016 6:41 am

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 ;)
Yeah, I got your comments, thanks! I've fixed compositor clear pass to clear only color buffers and made pull request. :)
0 x

Post Reply