Array in shader
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.
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
Can I create dynamic array in shader and how?
- 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
Hi Apeirogon,
If I can add to the question, how should an array be declared in GLDefs: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.SetUniform∞f()?
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
}
And what term can be used to send it from ZScript in place of Shader.SetUniform3f()... Shader.SetUniform∞f()?
Re: Array in shader
I found out that
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
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)
Code: Select all
uniform vec2 vertices_position[]
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);
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)
- 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
How did you even? Nice sleuthing
Re: Array in shader
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.
TL;DR: Uniform arrays are unsupported. Do not try to do it using hacks as this will just break your mod in the future.
- 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
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
Re: Array in shader
What? I write it in shader block of gldefsdpJudas 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.
Code: Select all
HardwareShader PostProcess beforebloom
{
Name
Shader
Texture
Uniform float
Uniform int
uniform vec2 vertices_position[]
}
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>".
Re: Array in shader
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.
- 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
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
@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?
@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?
Re: Array in shader
Copy-paste entyre shader....several times...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
@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?
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!
- 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
Oh niceI was thinking of adapting shader to stealth monsters.
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...So, you know what time it is now? Its feature suggestion time!
Re: Array in shader
I think about just save same shader under different names several times, and then send vertices to it like
But this is crutch.
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);
...
- 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
Got something sorta working: viewtopic.php?f=103&t=58470&start=75#p1062361