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
Dr. Van Nostrand
Posts: 11
Joined: Sun May 10, 2015 4:33 pm
Graphics Processor: nVidia with Vulkan support

Re: Shader Help Thread

Post by Dr. Van Nostrand »

Ah I see... I've clearly got a lot to learn. I hadn't touched most of these newer features yet. Thanks again!

lol wow the effect is way too fast as I had it originally! Here's a more subtle version in case anyone else is looking for a simple underwater warp shader
You do not have the required permissions to view the files attached to this post.
User avatar
Pixel Eater
 
 
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

Post by Pixel Eater »

lol wow the effect is way too fast as I had it originally!
Yeah I think I went cross-eyed the first time :lol:
User avatar
Pixel Eater
 
 
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

Post by Pixel Eater »

I wonder if someone can explain how the alpha property works for texture shaders? It's always seemed non-linear to me and impossible to counteract. Something I've just tried doing is actually causing me to be suspicious it's a bug but I want to make sure I'm not missing something.

So I have a 3D floor with the line opacity property set to 254. I have the software fuzz shader being applied to it's texture, multiplying the pixels' alpha (ie. colour.a) by values between 0.1875 and 0.65625. But what I get are low alpha values being shunted to zero (or lower?) instead. Previously I've assumed it was my error and just abandoned projects until I can figure it out, only now I'm using someone else's proven code verbatim.



You can see the detail is greatly reduced in the bridge compared to the spectre even though they share identical code. Are we supposed to treat colour.a differently in custom shaders?
User avatar
Cherno
Posts: 1321
Joined: Tue Dec 06, 2016 11:25 am

Re: Shader Help Thread

Post by Cherno »

Hello, I have a question regarding shaders in zDoom. First of all, I have writen my own shaders before in some Unity projects so the basic concepts are not new to me.

I would like to know if it's possible to have a material for a md3 model that shows it's bitmap texture mapped to the viewport, as opposed to being uv-mapped to the model's local vertices. So, if the model moves on screen, the triangle(s) in question would just show a different part of the texture. If you remember the "fake specular" effect in Alone in the Dark (for thing like metallic and reflective surfaces), you know what I'm talking about.

The effect can be seen here, in the small mirror item:

https://www.youtube.com/watch?v=9lWaQe8 ... .be&t=1497

Can this be done?
User avatar
Cherno
Posts: 1321
Joined: Tue Dec 06, 2016 11:25 am

Re: Shader Help Thread

Post by Cherno »

I know that MD3s can use materials, but can they also use custom shaders?
User avatar
SPZ1
Posts: 365
Joined: Wed Aug 02, 2017 3:01 pm
Location: Illinois

Re: Shader Help Thread

Post by SPZ1 »

Instead of making a new thread I'm bumping this one

I'm looking to make a shader to rotate a graphic at the center but have been unsuccessful. I tried modifying the shader that is in the wiki all sorts of ways but the results were just varied wave patterns. Is this even possible?
User avatar
RSSwizard
Posts: 237
Joined: Mon Jan 11, 2016 3:55 pm

Re: Shader Help Thread

Post by RSSwizard »

All im interested in is using those screen shaders like the Blaarg CRT stuff from zsnes.
Old school scanlines and rf artifacts like a vcr recording.
How do you get that going in zdoom?
User avatar
Pixel Eater
 
 
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

Post by Pixel Eater »

SPZ1 wrote:I'm looking to make a shader to rotate a graphic at the center but have been unsuccessful. I tried modifying the shader that is in the wiki all sorts of ways but the results were just varied wave patterns. Is this even possible?
Give this one a try instead:

Code: Select all

uniform float timer ;
const float pi = 3.14159265358979323846 ;

vec4 Process( vec4 colour )
{
	vec2 pos = gl_TexCoord[0].st - .5 ;
	float hyp = sqrt( pos.x * pos.x + pos.y * pos.y );
	
	if( hyp < .5 ) //narrows the effect. max is .707 but just comment out this line at that point.
	{
		float rad = atan( pos.y / pos.x ) + timer ; //try radians( 45 ) instead of timer for a fixed angle.
		rad += pi * ( .5 - sign( pos.x ) * .5 );
		
		pos.x = cos( rad );
		pos.y = sin( rad );
		pos *= hyp ;
	}
	
	return getTexel( pos + .5 );
}
RSSwizard wrote:All im interested in is using those screen shaders like the Blaarg CRT stuff from zsnes.
Old school scanlines and rf artifacts like a vcr recording.
How do you get that going in zdoom?
There's scan lines in Retroshader and some other neat stuff.

I'm slowly working on a new Screem that will have them too:

It's also enabling pixelation with a softening filter.
User avatar
furyweb
Posts: 34
Joined: Thu Aug 30, 2018 3:23 pm
Location: UK

Re: Shader Help Thread

Post by furyweb »

Is it possible to add a shader just to the HUD weapon rather than the whole screen. I was hoping to get the Retro pixel shader working just on the weapons rather than the whole screen.

Thanks.
User avatar
Mav3r1ck
Posts: 262
Joined: Thu Jul 16, 2015 11:09 pm

Re: Shader Help Thread

Post by Mav3r1ck »

I'm looking for custom smooth liquid shaders for flats and waterfalls. Would someone be able to direct me to these types of shaders?
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 »

On the [wiki]GLDEFS[/wiki] wiki page, it says:
The following uniform variables are always available to your shaders:

int fogenabled
vec4 fogcolor
vec3 dlightcolor
vec3 camerapos
float desaturation_factor
vec4 topglowcolor
vec4 bottomglowcolor
int texturemode
sampler2D tex
float timer

If you wish to use the timer uniform, you must define it yourself at the top of your shader file.

If the DYNLIGHT define is defined, the following uniform variables available:

ivec3 lightrange
vec4 lights[256]

Only if MAXLIGHTS128 is not defined

vec4 lights[128]

Only if MAXLIGHTS128 is defined

The following varying variables are always available to your shaders:

float lightlevel
vec2 glowdist
vec4 pixelpos
vec4 fogparm
Is this list up to date? And where in the GZDoom source code are these values defined and passed to user shaders for textures?
Gabenslair
Posts: 11
Joined: Sat Jul 07, 2018 12:18 pm

Re: Shader Help Thread

Post by Gabenslair »

Is there a possibe way to have "shaders" encased in a texture?
Say I wanted to have this foggy glass texture that when viewed through blurs part of the screen to give the illusion that its affecting all them light beams and stuff.
User avatar
Nash
 
 
Posts: 17465
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: Shader Help Thread

Post by Nash »

Material textures do not have access to the current screen colour and depth, so no that's currently not possible. Those two things are needed to do any effects that seemingly affect what is "behind" a texture - for example, refraction behind a glass or water, or "heat haze".
Xabis
Posts: 63
Joined: Wed Mar 06, 2013 7:15 pm

Re: Shader Help Thread

Post by Xabis »

Is there anyway to get the viewport coordinates?

I want to create a shader, where the image is fixed to the viewport, not the 3d world. i.e: the texture bits shown is based on where the pixels are on the 2d rendered scene if that makes sense?

Essentially i want to create a nifty portal-type effect. Maybe like a space background or something, where the spacey background is fixed no matter where it is observed from or how the player angles the camera.

I do see these uniforms, but this is mainly the texture coords and camera coords i believe.

Code: Select all

layout(location = 0) out vec4 vTexCoord;
layout(location = 1) out vec4 vColor;
layout(location = 2) out vec4 pixelpos;
layout(location = 3) out vec3 glowdist;
layout(location = 4) out vec3 gradientdist;
layout(location = 5) out vec4 vWorldNormal;
layout(location = 6) out vec4 vEyeNormal;
Also this is compiled into the shader in the cpp:

Code: Select all

layout(std140) uniform ViewpointUBO {
	mat4 ProjectionMatrix;
	mat4 ViewMatrix;
	mat4 NormalViewMatrix;

	vec4 uCameraPos;
	vec4 uClipLine;

	float uGlobVis;			// uGlobVis = R_GetGlobVis(r_visibility) / 32.0
	int uPalLightLevels;	
	int uViewHeight;		// Software fuzz scaling
	float uClipHeight;
	float uClipHeightDirection;
	int uShadowmapFilter;
};
Is this possible?
User avatar
Mav3r1ck
Posts: 262
Joined: Thu Jul 16, 2015 11:09 pm

Re: Shader Help Thread

Post by Mav3r1ck »

I wanna add warp3 and warp4 shaders but I get a bad syntax error when booting up the game to test them. How do I properly add them in?

EDIT: Nvm, I made a topic for this issue.

Return to “Assets (and other stuff)”