Shaders in materials..

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom 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.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
Viper
Posts: 30
Joined: Tue Oct 08, 2019 12:54 pm

Shaders in materials..

Post by Viper »

I have got a handle on converting shaders from shaderToy, which can make for some pretty nice screen overlays, however I'm more interested in getting them to work overtop/underneath/or in place of a texture.

The code is changed from "void main()" to "vec4 Process (vec4 color)" and the "uniform float timer" is within the shader at the top (global). TexCoords are gathered by "vec2 uv = gl_TexCoord[0].st;", and output is "return vec4 (color)" . It loads without any trouble but I see no effect...

Are material shaders limited to pixel movement? (no color changes?) Or am I missing something? <-- was missing something

*This particular shader doesn't read from a texture and just replaces all color.

gldef example for a texture:

material Texture LAVA1
{
Shader "SHADERS/LAVATEXTURE.fp"
Speed 1.0
}
Last edited by Viper on Sun Nov 10, 2019 12:18 am, edited 4 times in total.
Viper
Posts: 30
Joined: Tue Oct 08, 2019 12:54 pm

Re: Shaders in materials..

Post by Viper »

It does actually work but you have to replace the Material function, (dont use vec4 Process(), or void main() ).
eg.
Material ProcessMaterial()
{
Material material;
vec2 uv = vTexCoord.st; //gl_TexCoord[0].st; (either one works)
material.Base = getTexel(uv);
material.Base.rgb = vec3(1.0,0.0,0.0);
return material;
}
This should make your texture's diffuse map solid red.

I just don't have any animation yet.. timer isn't working..

--update>

*the timer is working, its just 10 times slower for some reason. When used as a hud overlay it plays at the desired speed.

-fixed by adding "Speed 10.0"

material Texture <matname>
{
Shader "SHADERS/<filename>"
Speed 10.0
}

So, it's working pretty good, just tiling seems to be an issue, most likely just the way the shader is programmed..

*note the timer is predefined for material shaders..

--update>
Couple notes..
-It can be tiled, but the offset can't be more than the width of the scaled image, so every second tile the offset must be set back to zero and so on..
-Running a healthy pc there is a noticeable drop in fps when close to the texture.
Post Reply

Return to “Scripting”