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.
Darkcrafter
Posts: 531
Joined: Sat Sep 23, 2017 8:42 am
Graphics Processor: nVidia with Vulkan support

Re: Shader Help Thread

Post by Darkcrafter »

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
}
You do not have the required permissions to view the files attached to this post.
illYay1337
Posts: 3
Joined: Tue Feb 01, 2022 4:19 am

Re: Shader Help Thread

Post by illYay1337 »

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?
illYay1337
Posts: 3
Joined: Tue Feb 01, 2022 4:19 am

Re: Shader Help Thread

Post by illYay1337 »

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:
Last edited by illYay1337 on Sat Nov 19, 2022 12:31 pm, edited 1 time in total.
illYay1337
Posts: 3
Joined: Tue Feb 01, 2022 4:19 am

Re: Shader Help Thread

Post by illYay1337 »

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;

Return to “Assets (and other stuff)”