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.

Re: Shader Help Thread

Postby dpJudas » Wed Mar 28, 2018 6:14 am

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

Re: Shader Help Thread

Postby Pixel Eater » Wed Mar 28, 2018 8:28 am

Ok it sounds like we are on the same page (I just don't know the lingo :P ).

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 :cheers:
User avatar
Pixel Eater
I sense evil I fear it here today, Like a bad dream that never goes away -MBerry
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.

Re: Shader Help Thread

Postby dpJudas » Wed Mar 28, 2018 9:02 am

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

Re: Shader Help Thread

Postby Pixel Eater » Wed Mar 28, 2018 3:57 pm

Ah, no worries then. I'm happy just knowing it's doable B-)
User avatar
Pixel Eater
I sense evil I fear it here today, Like a bad dream that never goes away -MBerry
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.

Re: Shader Help Thread

Postby Paynamia » Thu Jun 14, 2018 1:46 am

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.
User avatar
Paynamia
 
Joined: 14 Jun 2018

Re: Shader Help Thread

Postby Diode » Sun Jul 01, 2018 12:05 pm

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.


Apply a shader to a texture used as a model's skin and it will work.
Diode
 
Joined: 29 Feb 2016

Re: Shader Help Thread

Postby Diode » Sat Jul 21, 2018 6:41 am

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:

Code: Select allExpand view
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);
}


What needs to be changed to get the mapping to properly shift with the camera?
Diode
 
Joined: 29 Feb 2016

Re: Shader Help Thread

Postby Dr. Van Nostrand » Thu Sep 06, 2018 11:55 pm

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:

Code: Select allExpand view
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);
   
}


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?
User avatar
Dr. Van Nostrand
 
Joined: 10 May 2015

Re: Shader Help Thread

Postby Pixel Eater » Fri Sep 07, 2018 12:00 am

Try 'FragColor = texCoord'.

If that doesn't work, try dropping the "v" from vTexCoord?
User avatar
Pixel Eater
I sense evil I fear it here today, Like a bad dream that never goes away -MBerry
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.

Re: Shader Help Thread

Postby Dr. Van Nostrand » Fri Sep 07, 2018 12:03 am

Thanks Pixel Eater. I tried both recommendations but now get:

0(14) : error C1035: assignment of incompatible types
User avatar
Dr. Van Nostrand
 
Joined: 10 May 2015

Re: Shader Help Thread

Postby Pixel Eater » Fri Sep 07, 2018 12:07 am

Oh, hold on FragColor wants a colour not a coordinate. Instead try 'FragColor = texture( InputTexture, texCoord )'.
User avatar
Pixel Eater
I sense evil I fear it here today, Like a bad dream that never goes away -MBerry
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.

Re: Shader Help Thread

Postby Dr. Van Nostrand » Fri Sep 07, 2018 12:20 am

Thanks again, now we're making some progress. I can get the shader to compile now with this code:

Code: Select allExpand view
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);
   
}


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...
User avatar
Dr. Van Nostrand
 
Joined: 10 May 2015

Re: Shader Help Thread

Postby Pixel Eater » Fri Sep 07, 2018 12:38 am

Ah, right. You'll need to add 'Uniform float timer' to the shader block in your GLDefs file which will look something like this:
Code: Select allExpand view
HardwareShader PostProcess scene
{
    Name "Shader Name"
    Shader "Shader Filename.fp" 330
    Uniform float timer
    Enabled
}

And in Zscript add 'Shader.SetUniform1f( players[ consoleplayer ], "Shader Name", "timer", gametic + e.FracTic )' into a RenderOverlay event handler.
Code: Select allExpand view
class "ShaderHandler" : EventHandler
{
   override void RenderOverlay( RenderEvent e )
   {
      Shader.SetUniform1f( players[consoleplayer], "Shader Name", "timer", gametic + e.FracTic );
   }
}
User avatar
Pixel Eater
I sense evil I fear it here today, Like a bad dream that never goes away -MBerry
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.

Re: Shader Help Thread

Postby Dr. Van Nostrand » Fri Sep 07, 2018 1:06 am

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!
Attachments
screenwarp.pk3
(914 Bytes) Downloaded 9 times
User avatar
Dr. Van Nostrand
 
Joined: 10 May 2015

Re: Shader Help Thread

Postby Pixel Eater » Fri Sep 07, 2018 1:16 am

No problems, it just needed the event handler declared :)
Attachments
screenwarp.pk3
(1.03 KiB) Downloaded 19 times
User avatar
Pixel Eater
I sense evil I fear it here today, Like a bad dream that never goes away -MBerry
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.

PreviousNext

Return to Assets (and other stuff)

Who is online

Users browsing this forum: No registered users and 2 guests