Trippy perlin distortion/color tweak postprocess & texture

Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.

Got a cool project idea but nothing else? Put it in the project ideas thread instead!

Projects for any Doom-based engine (especially 3DGE) are perfectly acceptable here too.

Please read the full rules for more details.
Post Reply
User avatar
Eliot_L
Posts: 34
Joined: Thu Mar 08, 2018 3:40 am
Contact:

Trippy perlin distortion/color tweak postprocess & texture

Post by Eliot_L »

Hey Folks,
I wanted to share my first GZDoom shader project I've been working on.
It's a multi-function shader that supports various effects which can be combined together. They are mostly based on a 3d simplex (perlin) noise function such as texture distortion and tint, in addition to some trippy effects like lerping the hue, saturation, or value.

I've exposed all the uniforms to ZScript and also hooked them up to CVars to make it easy to tweak these parameters at runtime. I added a description of what these CVars do to the README.

Here are some screencaps showing some of the different effects:
Perlin-based texture distortion - the distortion factor, time scale, and 2d noise scale is adjustable.
Image

Perlin-based subtractive pattern and tint - combined with distortion I think this might make a pretty good shader for being inside a fluid, like swimming in water/nukage. I know it's not the first one to do this but I do like the naturalistic look of the perlin noise.
Image

Animated shifting of hue, saturation, and value -
Image

My math for animating these properties is just in zscript so should be easy to modify. Currently you can toggle the animation of H, S & V separately.

Thanks to Major Cooke, I grabbed his distortion shader to figure out the boilerplate I needed to get all of this hooked up.

Feel free to use this for your own mods, etc as I've released it under an MIT-style license. The code is here: https://github.com/fadookie/gzdoom-shaders - you can load it as a file in unpacked pk3 format. I also uploaded a pk3.

I would appreciate a credit if you use it (not required by license though)! Also let me know if you have any feature requests, if I have time I will look into it. I am not a shader expert but I am trying to learn and improve my skills!
Last edited by Eliot_L on Thu Mar 15, 2018 3:01 am, edited 1 time in total.
User avatar
Pixel Eater
 
 
Posts: 667
Joined: Wed Aug 02, 2017 12:31 am
Location: In between the Moon and you, between the buried and me.

Re: Trippy perlin distortion/color tweak postprocess shader

Post by Pixel Eater »

Nice distortion! That would look good on the surface of water too if that's possible :D

I've been working on a hue shifting shader too but it's been giving me issues, GRR :?
User avatar
Eliot_L
Posts: 34
Joined: Thu Mar 08, 2018 3:40 am
Contact:

Re: Trippy perlin distortion/color tweak postprocess shader

Post by Eliot_L »

Thanks! 3d simplex noise is a bit heavy on the GPU but modern desktops seem to handle it fine. You can optimize it more using a texture lookup to pre-bake the permutation table but I don't think that would be possible inside the GZDoom hardware shader system.

Feel free to take my hue shift code if it's helpful.

And yeah I think doing this as a floor shader would be possible, if you can figure out how to project it like a regular texture. Should be doable although I don't know how off the top of my head - maybe just use the fragment UV as input to noise function instead of screen coordinates.
User avatar
Pixel Eater
 
 
Posts: 667
Joined: Wed Aug 02, 2017 12:31 am
Location: In between the Moon and you, between the buried and me.

Re: Trippy perlin distortion/color tweak postprocess shader

Post by Pixel Eater »

You can attach a .png file to your shader for sure, maybe other types as well. It's a bit more work if you need an animation but not too difficult.
Just pop it in a subfolder named 'Textures' then link to it in GLDefs as so:

Code: Select all

HardwareShader PostProcess scene
{
	Name "ShaderName"
	Shader "Shaders/ShaderFile.fp" 330
	Texture "TextureName" "Textures/TextureFile.png"
}
Then in the shader code use either the regular texture function or texelFetch to get the colour of a coordinate:

Code: Select all

texture( TextureName, <xcoord>, <ycoord> ) //when providing "float" style coordinates, or

texelFetch( TextureName, <xcoord>, <ycoord>, <miplevel> ) //for integer/pixel coordinates.
I only ever use zero for <miplevel>.

Cheers for the offer, but it's actually the lum weighting that's holding my hue shader back :)
User avatar
Eliot_L
Posts: 34
Joined: Thu Mar 08, 2018 3:40 am
Contact:

Re: Trippy perlin distortion/color tweak postprocess shader

Post by Eliot_L »

Cool- good to know! I think I'll stick with current implementation for now unless someone complains about performance, I've used the same function on a pretty old MacBook (2010) GPU and it works ok. So I think this is pretty reasonable as is unless someone's on very limited HW or running multiple postprocess effects.
User avatar
Pixel Eater
 
 
Posts: 667
Joined: Wed Aug 02, 2017 12:31 am
Location: In between the Moon and you, between the buried and me.

Re: Trippy perlin distortion/color tweak postprocess shader

Post by Pixel Eater »

Don't change anything based on this but I'm getting pretty significant lag on a late 2013 iMac. The 'stat gpu' console command shows that I'm getting just above 16 milliseconds delay. Most other shaders are around 1-3ms. Going bare-bones, no other processing, still has a lot of jerkiness. Treat this only as an anecdote though because it could just be my system :shrug:
User avatar
Eliot_L
Posts: 34
Joined: Thu Mar 08, 2018 3:40 am
Contact:

Re: Trippy perlin distortion/color tweak postprocess shader

Post by Eliot_L »

Thanks for the info. I have not profiled it on integrated GPUs so that might be an issue.

Also, the procedural texture idea totally works! Code is pushed to repo.
Image
User avatar
Pixel Eater
 
 
Posts: 667
Joined: Wed Aug 02, 2017 12:31 am
Location: In between the Moon and you, between the buried and me.

Re: Trippy perlin distortion/color tweak postprocess & textu

Post by Pixel Eater »

Glad I could be of help.

Whoa neat! :woh:
User avatar
Berserker
Posts: 27
Joined: Sat Dec 15, 2018 8:11 pm
Graphics Processor: nVidia with Vulkan support
Location: In my head, creating non-stop

Re: Trippy perlin distortion/color tweak postprocess & textu

Post by Berserker »

Hi there !

I've been searching for an effect like this for my water and just found the perfect one !
But I'm still a rookie with coding, so could you just please tell me how do you put the distortion effect to a water pool when you swim in it ?

Thanks and very nice job !
User avatar
Armaetus
Posts: 1255
Joined: Fri Mar 13, 2009 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10 Home
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Location: New York State
Contact:

Re: Trippy perlin distortion/color tweak postprocess & textu

Post by Armaetus »

I suppose this could be applied to the default liquid texture flats somehow?
User avatar
Eliot_L
Posts: 34
Joined: Thu Mar 08, 2018 3:40 am
Contact:

Re: Trippy perlin distortion/color tweak postprocess & textu

Post by Eliot_L »

Berserker wrote:Hi there !

I've been searching for an effect like this for my water and just found the perfect one !
But I'm still a rookie with coding, so could you just please tell me how do you put the distortion effect to a water pool when you swim in it ?

Thanks and very nice job !
Thanks! Sorry I did not see this before, I have not been checking my forums.
You can use ZScript to control the variables used by the shader to blend the various effects on and off. Have a look at my player class for some examples of this, although it contains some additional stuff you shouldn't need for hooking them up to the console. The available CVars are listed in the README.

As for how to wire this up, I don't know for sure (it may be better to ask on the ZScript forum), but generally I'd do something like so on each tick:
  1. If player was on dry land, check if they just entered water (Maybe HitWater can help with this?)
  2. If they did, begin a linear interpolation (lerp) of shader CVars you want (probably tint and distortion factor) from 0 to target value. You can do a 1-dimensional lerp like this function. Here's a good explanation of interpolation functions.
  3. On subsequent ticks, increment some counter and feed it into the lerp function again, then use the lerp output to update the CVars, until they reach their target values.
  4. Keep checking to see when the player exits the water. When they exit, repeat the process again, but lerp from max value back to 0.
Armaetus wrote:I suppose this could be applied to the default liquid texture flats somehow?
Yes, that's what I've done in my demo. I used GLFDEFS to override the patches for the FWATER1 - FWATER4 animation frames and it just uses the shader instead.
User avatar
Ozymandias81
Posts: 2063
Joined: Thu Jul 04, 2013 8:01 am
Graphics Processor: nVidia with Vulkan support
Location: Mount Olympus, Mars
Contact:

Re: Trippy perlin distortion/color tweak postprocess & textu

Post by Ozymandias81 »

Hey everyone, late necrobump but it is for a good reason. I am trying to implement an effect for Jazz Jackrabbit Doom that mimicks the Hookah-Smoking caterpillar attack, most of the on-screen code is there, but the trippy effect is not.
What I need is to turn this awesome shader a "pickupable" effect which doesn't involve making a new playerclass for the purpose, since the mod must work also on Zandronum and due the fact that zscript gets ignored there, it can't happen with player itself. So let's say, a pickupable shroom effect that has an additive duration, anyone can help with? :3:
XLightningStormL
Posts: 384
Joined: Mon May 09, 2016 1:38 am
Location: Anywhere but here
Contact:

Re: Trippy perlin distortion/color tweak postprocess & textu

Post by XLightningStormL »

Sounds like it'd be real nice for underwater and System Shock 1-esque berserk stuff.
Post Reply

Return to “Shaders”