Shader Help Thread

Ask about editing graphics, sounds, models, music, etc here!
Shaders (GLSL) and SNDINFO questions also go here!
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.

Shader Help Thread

Postby Nash » Mon Jul 24, 2017 4:28 am

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

//////////////////////////////

Spoiler:
Last edited by Nash on Sat Oct 28, 2017 2:39 am, edited 2 times in total.
User avatar
Nash
Nash Muhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia

Re: Shader Help Thread

Postby dpJudas » Mon Jul 24, 2017 5:49 am

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.
dpJudas
 
 
 
Joined: 28 May 2016

Re: Shader Help Thread

Postby Nash » Mon Jul 24, 2017 6:08 am

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
Nash
Nash Muhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia

Re: Shader Help Thread

Postby Rachael » Mon Jul 24, 2017 12:13 pm

I unstickied my thread. This thread is much more suitable for asking general shader questions, as is suggested by the title.
User avatar
Rachael
QZDoom + Webmaster
 
Joined: 13 Jan 2004

Re: Shader Help Thread

Postby Talon1024 » Mon Jul 24, 2017 5:07 pm

Is there a way to use post-processing shaders on textures instead of the screen?
Talon1024
 
Joined: 27 Jun 2016

Re: Shader Help Thread

Postby Rachael » Mon Jul 24, 2017 5:35 pm

No.

You can, however, use fragment shaders on textures, but you won't have access to the uniform system.
User avatar
Rachael
QZDoom + Webmaster
 
Joined: 13 Jan 2004

Re: Shader Help Thread

Postby Major Cooke » Tue Jul 25, 2017 11:52 am

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
Slaughterer of Sewers
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: Shader Help Thread

Postby Major Cooke » Tue Jul 25, 2017 12:09 pm

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 allExpand view
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
Slaughterer of Sewers
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: Shader Help Thread

Postby Major Cooke » Tue Jul 25, 2017 9:13 pm

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?
Attachments
colourshader.pk3
(2.11 KiB) Downloaded 37 times
User avatar
Major Cooke
Slaughterer of Sewers
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: Shader Help Thread

Postby Nash » Wed Jul 26, 2017 2:22 am

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
Nash
Nash Muhandes
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia

Re: Shader Help Thread

Postby Major Cooke » Wed Jul 26, 2017 8:44 am

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.
User avatar
Major Cooke
Slaughterer of Sewers
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: Shader Help Thread

Postby dpJudas » Wed Jul 26, 2017 9:10 am

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.
dpJudas
 
 
 
Joined: 28 May 2016

Re: Shader Help Thread

Postby Major Cooke » Wed Jul 26, 2017 1:10 pm

Well... Partially works.


Oh and Nash, I did disable the y flip. Still does that.
Attachments
distortshader.pk3
(2.16 KiB) Downloaded 28 times
User avatar
Major Cooke
Slaughterer of Sewers
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: Shader Help Thread

Postby Major Cooke » Wed Jul 26, 2017 5:50 pm

ZZYZX fixed it.

He really knows his stuff when converting from shadertoy to gzdoom. :mrgreen:
Attachments
distortshader (2).pk3
(2.13 KiB) Downloaded 64 times
User avatar
Major Cooke
Slaughterer of Sewers
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: Shader Help Thread

Postby Amuscaria » Wed Sep 06, 2017 3:36 pm

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
User avatar
Amuscaria
The Sentient Mushroom
 
Joined: 26 Jul 2004
Location: Growing from mycelium near you.

Next

Return to Assets

Who is online

Users browsing this forum: No registered users and 1 guest