Array in shader

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 a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: Array in shader

Re: Array in shader

by Pixel Eater » Fri Jul 06, 2018 10:21 pm

Re: Array in shader

by Apeirogon » Fri Jul 06, 2018 6:53 am

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.

Re: Array in shader

by Pixel Eater » Fri Jul 06, 2018 5: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...

Re: Array in shader

by Apeirogon » Fri Jul 06, 2018 4: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!

Re: Array in shader

by Pixel Eater » Fri Jul 06, 2018 4: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?

Re: Array in shader

by Rachael » Fri Jul 06, 2018 3: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.

Re: Array in shader

by Apeirogon » Fri Jul 06, 2018 3: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 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>".

Re: Array in shader

by Pixel Eater » Thu Jul 05, 2018 3: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 :(

Re: Array in shader

by dpJudas » Thu Jul 05, 2018 2: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.

Re: Array in shader

by Pixel Eater » Thu Jul 05, 2018 2:48 pm

How did you even? Nice sleuthing :ninja:

Re: Array in shader

by Apeirogon » Thu Jul 05, 2018 7:47 am

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)

Re: Array in shader

by Pixel Eater » Wed Jul 04, 2018 4:06 pm

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:

Array in shader

by Apeirogon » Wed Jul 04, 2018 11:13 am

Can I create dynamic array in shader and how?

Top