Array in shader

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.
Post Reply
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Array in shader

Post by Apeirogon »

Can I create dynamic array in shader and how?
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: Array in shader

Post by Pixel Eater »

Hi Apeirogon,

If I can add to the question, how should an array be declared in GLDefs:

Code: Select all

HardwareShader PostProcess beforebloom
{
	Name "FillSpectre"
	Shader "fillspectre.fp" 330
	Uniform ?-> array <-? vertices
}
The word 'array' hasn't worked so far btw.

And what term can be used to send it from ZScript in place of Shader.SetUniform3f()... Shader.SetUniformf()? :wink:
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Array in shader

Post by Apeirogon »

I found out that

Code: Select all

	uniform vec2 vertices_position[]
work.
At least gzdoom dont throw error "Compile Shader: error C1307" and shader works as it should, so I think this is how it must be done.

But zscript cant send vector to it. It need workaround with array from "doubles" numbers.
Nope, it can send vector to it

Code: Select all

	Shader.SetUniform2f( p, "shader name", "vertices_position", insert 2d vector);
work.
At least gzdoom dont throw error "Compile Shader: error C1307" and shader works as it should, so I think this is how it must be done.(2)
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: Array in shader

Post by Pixel Eater »

How did you even? Nice sleuthing :ninja:
dpJudas
 
 
Posts: 3040
Joined: Sat May 28, 2016 1:01 pm

Re: Array in shader

Post by dpJudas »

The postprocess shaders requires the gldefs file to declare the uniforms. Typing them directly in the GLSL file is undefined behavior and not supported. In fact, the syntax written here is guaranteed to break when Vulkan support lands for GZDoom.

TL;DR: Uniform arrays are unsupported. Do not try to do it using hacks as this will just break your mod in the future.
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: Array in shader

Post by Pixel Eater »

Oh damn. I didn't even realise that's how it was being done, I've put it in GLDefs but not tried to run it yet :(
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Array in shader

Post by Apeirogon »

dpJudas wrote:The postprocess shaders requires the gldefs file to declare the uniforms. Typing them directly in the GLSL file is undefined behavior and not supported. In fact, the syntax written here is guaranteed to break when Vulkan support lands for GZDoom.

TL;DR: Uniform arrays are unsupported. Do not try to do it using hacks as this will just break your mod in the future.
What? I write it in shader block of gldefs

Code: Select all

HardwareShader PostProcess beforebloom
{
	Name
	Shader 
	Texture

	Uniform float 
	Uniform int

	uniform vec2 vertices_position[]
}
All other methods throw error in range from "cannot conver <float> ato <float>" to insta-crash after loading opengl driver(show version of opengl and then "very fatal error" window).
Plus, I try send in this array simple number, to check, it works or no. And gzdoom, predictably, says "cannot convert <float> to struct<vector2>".
User avatar
Rachael
Posts: 13557
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: Array in shader

Post by Rachael »

What he is saying is, even if you find a work-around that makes it work, it WILL break, soon! He's telling you not to do it because otherwise it's your issue that you end up with a broken mod.
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: Array in shader

Post by Pixel Eater »

Thanks dpJudas and Rachael for giving us a heads up and for sparing us the misspent effort, even if it was a cool find by Apeirogon :thumb:

@Apeirogon: We may have to stack shaders after all in that case. And when it gets to 2 or 3 Spectres deep, switch to a translucent effect for the distant ones. How does that sound, possible?
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Array in shader

Post by Apeirogon »

Pixel Eater wrote:Thanks dpJudas and Rachael for giving us a heads up and for sparing us the misspent effort, even if it was a cool find by Apeirogon :thumb:

@Apeirogon: We may have to stack shaders after all in that case. And when it gets to 2 or 3 Spectres deep, switch to a translucent effect for the distant ones. How does that sound, possible?
Copy-paste entyre shader....several times...
Yes, it will work.
But I think about array not because it prevent copy-pasting, but because I was thinking of adapting shader to stealth monsters.

So, you know what time it is now? Its feature suggestion time!
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: Array in shader

Post by Pixel Eater »

I was thinking of adapting shader to stealth monsters.
Oh nice :)
So, you know what time it is now? Its feature suggestion time!
I have a feature suggestion... suggestion. There may be a better way to make the shader seamless and that is to have the engine send only flagged monsters to a sample texture. The back and foregrounds would need to be pitch black for it to work and the sprite would need to be invisible in the main view. It would put an end to the chroma keying altogether and all it's flaws. I suspect it would be much more complicated for anyone willing to implement the code though...
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Array in shader

Post by Apeirogon »

I think about just save same shader under different names several times, and then send vertices to it like

Code: Select all

shader.senduniform2f(player, shader name, vertex set);
shader.senduniform2f(player, shader name1, vertex set1);
shader.senduniform2f(player, shader name2, vertex set2);
shader.senduniform2f(player, shader name3, vertex set3);
shader.senduniform2f(player, shader name4, vertex set4);
shader.senduniform2f(player, shader name5, vertex set5);
shader.senduniform2f(player, shader name6, vertex set6);
shader.senduniform2f(player, shader name7, vertex set7);
shader.senduniform2f(player, shader name8, vertex set8);
...
 
But this is crutch.
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: Array in shader

Post by Pixel Eater »

Post Reply

Return to “Assets (and other stuff)”