Shader Help Thread

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.

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: Shader Help Thread

Re: Shader Help Thread

by DELTAtheDboi005 » Fri Apr 14, 2023 12:13 am

Caligari87 wrote: Thu Apr 13, 2023 7:57 am What you're referring to is (I believe) affine texture mapping, and so far as I'm aware there's no way to accomplish it in GZDoom because mods don't have access to the vertex shader.

See this topic on PS1 rendering for some relevant discussion.

8-)
I think I came across that thread recently whilst researching how to do this and I pretty much came to the same conclusion as everyone else at the end of that thread. Bummer :(

Re: Shader Help Thread

by Caligari87 » Thu Apr 13, 2023 7:57 am

What you're referring to is (I believe) affine texture mapping, and so far as I'm aware there's no way to accomplish it in GZDoom because mods don't have access to the vertex shader.

See this topic on PS1 rendering for some relevant discussion.

8-)

Re: Shader Help Thread

by DELTAtheDboi005 » Wed Apr 12, 2023 10:18 pm

Not sure if this is the right thread, but how would I go about making a shader that creates a ps1-style texture warp like metal gear solid or other games from that particular point in time?

Re: Shader Help Thread

by illYay1337 » Wed Nov 23, 2022 11:19 pm

Ah it's actually hilarious what a mistake I made.  It was brighter because of a mistake in the triplanar shader not because the engine was making things brighter.



I tried regular solid colored textures and the same odd artifacts were visible for me.  The brightness came from this:

return
        // North / South
        getTexel(northSouthUVs) * blendWeights.z
        // Floor / Ceiling
        + getTexel(floorCeilUVs) * blendWeights.y
        // East / West
        + getTexel(eastWestUVs) * blendWeights.x;

I was over brightening the pixels which happens with any angled surface but never with 90 degree surfaces.  BlendWeights came from a normalized vector, but the sum of the components wasn't 1.  I somehow forgot that a normalized vector is of length 1 but the sum of its components is not 1, which caused the 3 colors to blend incorrectly resulting in an overbrigthened pixel.

Had to add this earlier in the shader.

    // make it so the sum of all components is 1
    blendWeights /= blendWeights.x + blendWeights.y + blendWeights.z;

Re: Shader Help Thread

by illYay1337 » Sat Nov 19, 2022 12:29 pm

My account works again so I'm able to post here. Made the original post here just now but I'm sure this is a better thread to ask questions. https://www.doomworld.com/forum/topic/1 ... m-shaders/

I normally consider myself somewhat of an expert with GLSL and computer graphics so I was able to piece together how to make a custom shader in GZDoom after poking around.

Basically I'm running into issues where surfaces that have a shader applied seem brighter and are lit differently than surfaces without shaders.

Here the walls that are not at 90 degree angles are really showing the effect. The darker walls are the non-shader version. The 90 degree walls on the right have no issues, which I'm guessing is because it's in the default shading mode on this map right now.
Spoiler:
Here the surfaces with my shader are flat shaded instead of using sector lighting, which actually makes things look a bit uglier. Seems like we don't have access to the vertex shader and I'm not really sure how to even do smooth shading in Doom with normal geometry short of using a 3D model. I'd rather it actually used sector lighting so I just get the shader effect.
Spoiler:
Also surfaces with a shader exhibit this pinprick effect, which is especially visible on slopes. It's easier to see against a solid color with a super simple shader that outputs red.
Spoiler:
The shader code itself, which I think I'll post in the shaders section later once I think it's fully ready.
Spoiler:

Re: Shader Help Thread

by illYay1337 » Sat Nov 19, 2022 3:16 am

I agree. This needs to be better documented for sure. I had to peice info together from looking at other shaders. There are keywords that aren’t documented.
Talon1024 wrote: Mon Sep 09, 2019 10:40 pm 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?

Re: Shader Help Thread

by Darkcrafter » Mon Jun 06, 2022 3:51 pm

I would like to make at least a semidecent fake environment map based shader. I already got one working in GZDoom but I'd like to mix that shader result to a texture applied so the effect of "reflection" would have an effect amount (opacity).

Here is the shader by Marisa:

Code: Select all

vec4 Process(vec4 color)
{
    vec3 eyedir = normalize(uCameraPos.xyz - pixelpos.xyz);
    vec3 norm = reflect(eyedir, normalize(vWorldNormal.xyz));
    return getTexel(norm.xz * 0.5) * color ;
}
It basicaly takes a texture (environment map) and applies it over a surface so it renders in a sky manner.
Here is what it looks like:
The shader.jpg
Here is what I'd like to get (I put a thin opaque 3D floor above the surface with the shader texture applied):
Desired result.jpg
Here is the enivornment map texture:
EnvironmentMap.jpg
So what I'd like to get is to being able to define a particular environment map texture in GLDEFS per texture so the shader would kind of process both textures at once, like that:

Code: Select all


material texture "FLOOR7_2"
{
	shader "shaders/EnvMapRefl_Marisa.fp"
        reflectionmap "textures/reflectionmaps/environmentmap1.jpg"
        opacity 0.5
}

Re: Shader Help Thread

by Mav3r1ck » Wed May 06, 2020 4:11 pm

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.

Re: Shader Help Thread

by Xabis » Sat Apr 11, 2020 1:29 pm

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?

Re: Shader Help Thread

by Nash » Mon Oct 28, 2019 2:22 am

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".

Re: Shader Help Thread

by Gabenslair » Sun Oct 27, 2019 3:54 pm

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.

Re: Shader Help Thread

by Talon1024 » Mon Sep 09, 2019 10:40 pm

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?

Re: Shader Help Thread

by Mav3r1ck » Mon Jun 10, 2019 9:02 am

I'm looking for custom smooth liquid shaders for flats and waterfalls. Would someone be able to direct me to these types of shaders?

Re: Shader Help Thread

by furyweb » Sat Apr 06, 2019 6:38 pm

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.

Re: Shader Help Thread

by Pixel Eater » Wed Mar 27, 2019 12:23 am

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.

Top