Page 1 of 1

Trippy perlin distortion/color tweak postprocess & texture

PostPosted: Tue Mar 13, 2018 12:19 pm
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!

Re: Trippy perlin distortion/color tweak postprocess shader

PostPosted: Tue Mar 13, 2018 10:46 pm
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 :?

Re: Trippy perlin distortion/color tweak postprocess shader

PostPosted: Wed Mar 14, 2018 10:14 am
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.

Re: Trippy perlin distortion/color tweak postprocess shader

PostPosted: Wed Mar 14, 2018 3:51 pm
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 allExpand view
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 allExpand view
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 :)

Re: Trippy perlin distortion/color tweak postprocess shader

PostPosted: Wed Mar 14, 2018 6:44 pm
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.

Re: Trippy perlin distortion/color tweak postprocess shader

PostPosted: Wed Mar 14, 2018 7:32 pm
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:

Re: Trippy perlin distortion/color tweak postprocess shader

PostPosted: Thu Mar 15, 2018 1:41 am
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

Re: Trippy perlin distortion/color tweak postprocess & textu

PostPosted: Thu Mar 15, 2018 7:52 pm
by Pixel Eater
Glad I could be of help.

Whoa neat! :woh:

Re: Trippy perlin distortion/color tweak postprocess & textu

PostPosted: Sat Dec 15, 2018 8:14 pm
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 !

Re: Trippy perlin distortion/color tweak postprocess & textu

PostPosted: Sun Dec 16, 2018 10:51 pm
by Armaetus
I suppose this could be applied to the default liquid texture flats somehow?

Re: Trippy perlin distortion/color tweak postprocess & textu

PostPosted: Fri Aug 16, 2019 11:05 am
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.

Re: Trippy perlin distortion/color tweak postprocess & textu

PostPosted: Thu Sep 30, 2021 3:36 am
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:

Re: Trippy perlin distortion/color tweak postprocess & textu

PostPosted: Tue Nov 16, 2021 3:38 am
by XLightningStormL
Sounds like it'd be real nice for underwater and System Shock 1-esque berserk stuff.