Array in shader

Ask about editing graphics, sounds, models, music, etc here!
Shaders (GLSL) and SNDINFO questions also go here!
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.

Array in shader

Postby Apeirogon » Wed Jul 04, 2018 12:13 pm

Can I create dynamic array in shader and how?
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: Array in shader

Postby Pixel Eater » Wed Jul 04, 2018 5:06 pm

Hi Apeirogon,

If I can add to the question, how should an array be declared in GLDefs:
Code: Select allExpand view
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
Pixel Eater
In my thoughts I have seen rings of smoke through the trees.
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.

Re: Array in shader

Postby Apeirogon » Thu Jul 05, 2018 8:47 am

I found out that
Code: Select allExpand view
   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 allExpand view
   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)
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: Array in shader

Postby Pixel Eater » Thu Jul 05, 2018 3:48 pm

How did you even? Nice sleuthing :ninja:
User avatar
Pixel Eater
In my thoughts I have seen rings of smoke through the trees.
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.

Re: Array in shader

Postby dpJudas » Thu Jul 05, 2018 3:55 pm

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.
dpJudas
 
 
 
Joined: 28 May 2016

Re: Array in shader

Postby Pixel Eater » Thu Jul 05, 2018 4:06 pm

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
Pixel Eater
In my thoughts I have seen rings of smoke through the trees.
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.

Re: Array in shader

Postby Apeirogon » Fri Jul 06, 2018 4:46 am

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 allExpand view
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>".
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: Array in shader

Postby Rachael » Fri Jul 06, 2018 4:48 am

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
Rachael
QZDoom + Webmaster
 
Joined: 13 Jan 2004

Re: Array in shader

Postby Pixel Eater » Fri Jul 06, 2018 5:11 am

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
Pixel Eater
In my thoughts I have seen rings of smoke through the trees.
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.

Re: Array in shader

Postby Apeirogon » Fri Jul 06, 2018 5:45 am

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!
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: Array in shader

Postby Pixel Eater » Fri Jul 06, 2018 6:40 am

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
Pixel Eater
In my thoughts I have seen rings of smoke through the trees.
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.

Re: Array in shader

Postby Apeirogon » Fri Jul 06, 2018 7:53 am

I think about just save same shader under different names several times, and then send vertices to it like
Code: Select allExpand view
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.
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: Array in shader

Postby Pixel Eater » Fri Jul 06, 2018 11:21 pm

User avatar
Pixel Eater
In my thoughts I have seen rings of smoke through the trees.
 
 
 
Joined: 02 Aug 2017
Location: In between the Moon and you, between the buried and me.


Return to Assets

Who is online

Users browsing this forum: Trendiction.de [Bot] and 1 guest