Shader Help Thread

Ask about editing graphics, sounds, models, music, etc here!
Shaders (GLSL) and SNDINFO questions also go here!

Moderators: GZDoom Developers, Raze Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
User avatar
Nash
 
 
Posts: 17465
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Shader Help Thread

Post by Nash »

Beginner shader tutorial: https://gamedevelopment.tutsplus.com/tu ... -cms-23313

//////////////////////////////
Spoiler:
Last edited by Nash on Sat Oct 28, 2017 1:39 am, edited 2 times in total.
dpJudas
 
 
Posts: 3134
Joined: Sat May 28, 2016 1:01 pm

Re: Shader Help Thread

Post by dpJudas »

Texture sampling isn't that slow. SSAO samples 8/16/32 times per pixel depending on which quality you pick. After that it also blurs the entire thing, which requires even more sampling.

The expensive part is all the math it is doing. There are a few for loops: 8 iterations in turbulence, 2 iterations in fBM. That means the snoise function is called 16 times. snoise is an absolute monster doing 14 dot products and tons of other math operations too. That's 224 dot products right there.

You can't make this shader faster without simplifying the noise math. You could lower the number of iterations it is using, but that would make it look less good I'm sure. It might been possible to put the noise math into some kind of texture and sample the value from there, but that would require a deeper understanding of what snoise is doing.

If you had bigger control over the PP pipeline you could have generated a lower resolution texture with the result of this shader, and then used that as input to a second shader that combined it with the InputTexture contents. Unfortunately that option is out as you can't specify such a complex setup in the GLDEFS file today.
User avatar
Nash
 
 
Posts: 17465
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: Shader Help Thread

Post by Nash »

Understood. I suspected as much. The calculations are just too much, as nice as it looks. I've found a much cheaper, but also nice-looking water shader, so that's all good.
User avatar
Rachael
Posts: 13794
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her

Re: Shader Help Thread

Post by Rachael »

I unstickied my thread. This thread is much more suitable for asking general shader questions, as is suggested by the title.
Talon1024
 
 
Posts: 375
Joined: Mon Jun 27, 2016 7:26 pm
Preferred Pronouns: He/Him
Graphics Processor: nVidia with Vulkan support

Re: Shader Help Thread

Post by Talon1024 »

Is there a way to use post-processing shaders on textures instead of the screen?
User avatar
Rachael
Posts: 13794
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her

Re: Shader Help Thread

Post by Rachael »

No.

You can, however, use fragment shaders on textures, but you won't have access to the uniform system.
User avatar
Major Cooke
Posts: 8196
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Shader Help Thread

Post by Major Cooke »

Nash wrote:These two shaders look pretty close to that special effect:

https://www.shadertoy.com/view/XlXXR4
https://www.shadertoy.com/view/llj3Dz
Thanks! I'll give these a try, though I'm still pouring over how to properly implement them.
User avatar
Major Cooke
Posts: 8196
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Shader Help Thread

Post by Major Cooke »

Another curiosity, would it be possible to have multiple of the same image created? Because similarly to water effects, or resembling that of stun effects I might want to try having the scene duplicated a couple of times each with their own transparency.

Also can someone be so kind as to update the wiki with the documentation on how to set this all up? (That is, for GZDoom itself and adding any notes upon what to do -- I am too thoroughly dumbfounded right now, so I am disqualified at the moment).

Putting this down here because it's important:

Code: Select all

void main()
{
    vec4 c = texture(InputTexture, TexCoord);
// INSERT CODE HERE.
    FragColor = c;
}
dpJudas wrote:you have to assign the 'c' variable to FragColor to have it output something
and strictly speaking you don't have to read from the input texture, but it sure will be a lame PP effect if it doesn't use any data from the scene texture

there are two varying in/out variables always: in vec2 TexCoord and out vec4 FragColor
User avatar
Major Cooke
Posts: 8196
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Shader Help Thread

Post by Major Cooke »

So I'm trying to make a simple shader where all it does is double the RGB values of the screen on the right hand side (took this idea from this guide), but download the attached file and try to run it. It uh... royally fucks up by only showing one pixel.

Help?
You do not have the required permissions to view the files attached to this post.
User avatar
Nash
 
 
Posts: 17465
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: Shader Help Thread

Post by Nash »

Two things:

1) The wrong shader was called in your ZScript. Your shader's name is "colour", but in your ZScript it's calling the nonexistent shader "distort".
2) Change line 6 in your colour shader to vec2 xy = TexCoord; Explanation from dpJudas:
"where fragCoord contains the pixel coordinates for which the shader needs to compute a color. The coordinates are in pixel units, ranging from 0.5 to resolution-0.5, over the rendering surface, where the resolution is passed to the shader through the iResolution uniform (see below)."
that's from https://www.shadertoy.com/howto
however, TexCoord is in 0-1 range
you don't have to "vec2 uv = TexCoord.xy / texSize.xy;" because TexCoord is already scaled to 0-1
ShaderToy tip: Generally when you see something assigning something to fragCoord / [something], it's safe to omit the division and just replace fragCoord with TexCoord (because GZDoom doesn't recognize fragCoord). Also generally for this step, people seem to like naming the vec2 uv, so keep a look out for that.
User avatar
Major Cooke
Posts: 8196
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Shader Help Thread

Post by Major Cooke »

Wait a second, is distort already the name of an internal shader? That might explain why it wasn't working when I originally had it named "distort"...

Well I managed to get that working, so thanks Nash!

Also started working on the distortion shader... Not sure what else needs converting at this point.
dpJudas
 
 
Posts: 3134
Joined: Sat May 28, 2016 1:01 pm

Re: Shader Help Thread

Post by dpJudas »

No, there's no internal shader with that name. What Nash meant is that the name you give the shader in the GLDEFS file must match the shader name you pass into the ZScript SetUniform functions. If the name doesn't match it will not be setting the uniforms.
User avatar
Major Cooke
Posts: 8196
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Shader Help Thread

Post by Major Cooke »

Well... Partially works.


Oh and Nash, I did disable the y flip. Still does that.
You do not have the required permissions to view the files attached to this post.
User avatar
Major Cooke
Posts: 8196
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Shader Help Thread

Post by Major Cooke »

ZZYZX fixed it.

He really knows his stuff when converting from shadertoy to gzdoom. :mrgreen:
You do not have the required permissions to view the files attached to this post.
User avatar
Amuscaria
Posts: 6634
Joined: Mon Jul 26, 2004 12:59 pm
Location: Growing from mycelium near you.

Re: Shader Help Thread

Post by Amuscaria »

Has this been implemented into GZdoom yet? If so, how might I make use of it? Been looking for something likes this got a long time in Doom, now. :D

Return to “Assets (and other stuff)”