Shader Help Thread
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.
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.
-
-
- Posts: 3109
- Joined: Sat May 28, 2016 1:01 pm
Re: Shader Help Thread
When a shader runs it can have multiple outputs. Each such output is called a gbuffer. Traditionally, the first output was called the frame buffer (or color buffer), but in a modern engine the output from the scene shaders rarely go directly to screen - instead, when the postprocessing shaders run they get those buffers as texture input and eventually the final output end up in the system frame buffer.
The shader producing the initial output, the "hardware shaders" as they are called in GZDoom, don't have to always output pre-shaded information. They could be made to output anything you'd like. As it is today, the shaders already output extra gbuffers when SSAO is active: the normal vector of the face and the color of the fog. Naturally, postprocessing shaders would have to also be able to read what the hardware shaders wrote.
The shader producing the initial output, the "hardware shaders" as they are called in GZDoom, don't have to always output pre-shaded information. They could be made to output anything you'd like. As it is today, the shaders already output extra gbuffers when SSAO is active: the normal vector of the face and the color of the fog. Naturally, postprocessing shaders would have to also be able to read what the hardware shaders wrote.
-
-
- Posts: 667
- Joined: Wed Aug 02, 2017 12:31 am
- Location: In between the Moon and you, between the buried and me.
Re: Shader Help Thread
Ok it sounds like we are on the same page (I just don't know the lingo ).
So I need a "hardware shader" from before the lighting is added to output a texture into a g-buffer which my post-processing shader can then read and compare with the regular input texture. By calculating the difference it should be possible to change colour depending on depth (rainbow fog anyone?).
Seeing as this is not on the horizon anyhow, should I make a feature suggestion anyway in case it gets placed in the "on-hold" queue?
Thanks for taking the time to write that BTW
So I need a "hardware shader" from before the lighting is added to output a texture into a g-buffer which my post-processing shader can then read and compare with the regular input texture. By calculating the difference it should be possible to change colour depending on depth (rainbow fog anyone?).
Seeing as this is not on the horizon anyhow, should I make a feature suggestion anyway in case it gets placed in the "on-hold" queue?
Thanks for taking the time to write that BTW
-
-
- Posts: 3109
- Joined: Sat May 28, 2016 1:01 pm
Re: Shader Help Thread
You're welcome.
I think this feature request is probably too big to get implemented by the usual suspects. It requires a lot of work.
I think this feature request is probably too big to get implemented by the usual suspects. It requires a lot of work.
-
-
- Posts: 667
- Joined: Wed Aug 02, 2017 12:31 am
- Location: In between the Moon and you, between the buried and me.
Re: Shader Help Thread
Ah, no worries then. I'm happy just knowing it's doable
-
- Posts: 4
- Joined: Thu Jun 14, 2018 12:35 am
Re: Shader Help Thread
Is it at all possible to apply shaders to models at this point? I know it can be managed in Zandronum (and I think older versions of GZDoom) by placing a texture in the textures folder, but it doesn't seem to work in the current version of GZD.
-
- Posts: 53
- Joined: Mon Feb 29, 2016 2:34 pm
Re: Shader Help Thread
Apply a shader to a texture used as a model's skin and it will work.Paynamia wrote:Is it at all possible to apply shaders to models at this point? I know it can be managed in Zandronum (and I think older versions of GZDoom) by placing a texture in the textures folder, but it doesn't seem to work in the current version of GZD.
-
- Posts: 53
- Joined: Mon Feb 29, 2016 2:34 pm
Re: Shader Help Thread
So, I've been trying to fake lighting on 3D models in areas without attenuated lights. Which is difficult when you have no clue about the calculations needed and next to no real coding ability. Oh well.
Here's a model in sector light, but I'm using a matcap texture to fake the look of a dynamic light coming from the camera . It looks pretty convincing for the most part, but the mapping is wrong - if we view the model from the other side, we can see that the highlight is no longer in the center, but around the edges:
It isn't working correctly because... This is an environment mapping shader:
What needs to be changed to get the mapping to properly shift with the camera?
Here's a model in sector light, but I'm using a matcap texture to fake the look of a dynamic light coming from the camera . It looks pretty convincing for the most part, but the mapping is wrong - if we view the model from the other side, we can see that the highlight is no longer in the center, but around the edges:
It isn't working correctly because... This is an environment mapping shader:
Code: Select all
vec4 ProcessTexel()
{
vec3 eyedir = normalize(uCameraPos.xyz-pixelpos.xyz);
vec3 reflected = reflect(eyedir.xyz,normalize(vWorldNormal.xyz));
float m = 2.8284271247461903 * sqrt(reflected.z+ 1.0);
return getTexel(reflected.xy / m + 0.5);
}
-
- Posts: 11
- Joined: Sun May 10, 2015 4:33 pm
- Graphics Processor: nVidia with Vulkan support
Re: Shader Help Thread
I've been beating my head against this for hours and could use a hand if anyone's feeling charitable.
This is my attempt at a simple conversion of the "warp1" shader that comes with gzdoom to a post-processing shader:
At compile time I get this error:
0(18) : error C1031: swizzle mask element not present in operand "rgba
Where have I gone wrong exactly?
This is my attempt at a simple conversion of the "warp1" shader that comes with gzdoom to a post-processing shader:
Code: Select all
void main()
{
vec2 texCoord = vTexCoord.st;
const float pi = 3.14159265358979323846;
vec2 offset = vec2(0,0);
offset.y = sin(pi * 2.0 * (texCoord.x + timer * 0.125)) * 0.1;
offset.x = sin(pi * 2.0 * (texCoord.y + timer * 0.125)) * 0.1;
texCoord += offset;
FragColor = vec4(texCoord.rgba);
}
0(18) : error C1031: swizzle mask element not present in operand "rgba
Where have I gone wrong exactly?
-
-
- Posts: 667
- Joined: Wed Aug 02, 2017 12:31 am
- Location: In between the Moon and you, between the buried and me.
Re: Shader Help Thread
Try 'FragColor = texCoord'.
If that doesn't work, try dropping the "v" from vTexCoord?
If that doesn't work, try dropping the "v" from vTexCoord?
-
- Posts: 11
- Joined: Sun May 10, 2015 4:33 pm
- Graphics Processor: nVidia with Vulkan support
Re: Shader Help Thread
Thanks Pixel Eater. I tried both recommendations but now get:
0(14) : error C1035: assignment of incompatible types
0(14) : error C1035: assignment of incompatible types
-
-
- Posts: 667
- Joined: Wed Aug 02, 2017 12:31 am
- Location: In between the Moon and you, between the buried and me.
Re: Shader Help Thread
Oh, hold on FragColor wants a colour not a coordinate. Instead try 'FragColor = texture( InputTexture, texCoord )'.
-
- Posts: 11
- Joined: Sun May 10, 2015 4:33 pm
- Graphics Processor: nVidia with Vulkan support
Re: Shader Help Thread
Thanks again, now we're making some progress. I can get the shader to compile now with this code:
but the effect isn't what I expected. The screen is warped but doesn't update... if I stand still the warp effect doesn't move at all. I must be missing something with the timer...
Code: Select all
uniform float timer;
void main()
{
vec2 texCoord = TexCoord.st;
const float pi = 3.14159265358979323846;
vec2 offset = vec2(0,0);
offset.y = sin(pi * 2.0 * (texCoord.x + timer * 0.125)) * 0.1;
offset.x = sin(pi * 2.0 * (texCoord.y + timer * 0.125)) * 0.1;
texCoord += offset;
FragColor = texture(InputTexture, texCoord);
}
-
-
- Posts: 667
- Joined: Wed Aug 02, 2017 12:31 am
- Location: In between the Moon and you, between the buried and me.
Re: Shader Help Thread
Ah, right. You'll need to add 'Uniform float timer' to the shader block in your GLDefs file which will look something like this:
And in Zscript add 'Shader.SetUniform1f( players[ consoleplayer ], "Shader Name", "timer", gametic + e.FracTic )' into a RenderOverlay event handler.
Code: Select all
HardwareShader PostProcess scene
{
Name "Shader Name"
Shader "Shader Filename.fp" 330
Uniform float timer
Enabled
}
Code: Select all
class "ShaderHandler" : EventHandler
{
override void RenderOverlay( RenderEvent e )
{
Shader.SetUniform1f( players[consoleplayer], "Shader Name", "timer", gametic + e.FracTic );
}
}
-
- Posts: 11
- Joined: Sun May 10, 2015 4:33 pm
- Graphics Processor: nVidia with Vulkan support
Re: Shader Help Thread
I'm not sure why but it's still not working. Here's a pk3 with all of the files. Thanks again for your help!
You do not have the required permissions to view the files attached to this post.
-
-
- Posts: 667
- Joined: Wed Aug 02, 2017 12:31 am
- Location: In between the Moon and you, between the buried and me.
Re: Shader Help Thread
No problems, it just needed the event handler declared
You do not have the required permissions to view the files attached to this post.