Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shader language: implement arrays support #10751

Closed
curly-brace opened this issue Aug 29, 2017 · 21 comments
Closed

Shader language: implement arrays support #10751

curly-brace opened this issue Aug 29, 2017 · 21 comments

Comments

@curly-brace
Copy link

curly-brace commented Aug 29, 2017

as i understand there is no way right now to declare and use any arrays inside shaders like float arr[] = float[] (1,2,3,4);
would be even more better to be able to declare them as uniforms or varying. and even better ( 🙄 ) to have multidimensional arrays.

@reduz
Copy link
Member

reduz commented Sep 7, 2017

makes sense but not for now, kicking to 3.1

@reduz reduz modified the milestones: 3.1, 3.0 Sep 7, 2017
@Zylann
Copy link
Contributor

Zylann commented Apr 11, 2018

Was asked in a Q&A thread: https://godotengine.org/qa/27228/array-godot-shader
It would be a nice way to avoid additional textures if they are just small data containers, because texture fetchs are expensive... not necessarily in processing time, but in how many you can have: Zylann/godot_heightmap_plugin#22

@nobuyukinyuu
Copy link
Contributor

Hi, I'm throwing in my support for this feature. Currently trying to implement a simple 1d LUT for palette shifting and finding it difficult to work with my data since it's in an integer array format and not textures due to the relatively lopsided amount of outputs I need for a given input. Having arrays in-language would help a lot to avoid converting the tables I already have to sparse textures.

@AssjackGames
Copy link

I assume this is still being worked on for 3.1? Trying to implement a particle system that can reverse speed and go backward in time (like Prince of Persia rewind), but seeing how I can only access the individual particle data through a particle shader it'd be useful to store them in a uniform array to access by gdScript.

@nobuyukinyuu
Copy link
Contributor

nobuyukinyuu commented Jul 16, 2018

bumping this because I need an array of arrays for an 8-bit mask to perform some autotiling functions now and I'm not sure of another way to work around this. Arrays are really sorely missing from the shading language....

edit: (and I'm not sure if even shader model 3 would be very happy with a 256-way branching function..)

@MrMinimal
Copy link
Contributor

My water shader uses lots of copies of similar variables because array support is lacking right now. Would really need such a feature to make code neat.

@arkinsamedi
Copy link

I started working on this.
I got some basic types to work for uniforms (float[], int[], uint[]). There's still a long way to go, and I'm still getting the hang of godot so it might take a while.

@akien-mga akien-mga changed the title 3.0 Shader Language: implement arrays Shader language: implement arrays support Sep 15, 2018
@thimenesup
Copy link
Contributor

Apparently @arkinsamedi finished adding arrays in this commit? , can he confirm that its done and ready to merge?

@akien-mga akien-mga modified the milestones: 3.1, 3.2 Jan 9, 2019
@poke1024
Copy link
Contributor

I really hope this is going to be in 3.2.

@ConnorBP

This comment has been minimized.

@Overblob
Copy link
Contributor

Overblob commented Apr 7, 2019

For those wondering, here is a workaround using texture uniforms for the time being.
It might be useful depending on your case (better examples are also welcome :) )

gdscript

extends ColorRect

# ColorRect is the Node on which I have my shader material attached

func _ready():
	# The array I want to send to my shader
	var array = [1, 1, 1, 0, 2, 2, 2, 0, 0, 3]

	# You'll have to get thoose the way you want
	var array_width = 10
	var array_heigh = 1

	# The following is used to convert the array into a Texture
	var byte_array = PoolByteArray(array)
	var img = Image.new()

	# I don't want any mipmaps generated : use_mipmaps = false
	# I'm only interested with 1 component per pixel (the corresponding array value) : Format = Image.FORMAT_R8
	img.create_from_data(array_width, array_heigh, false, Image.FORMAT_R8, byte_array)

	var texture = ImageTexture.new()

	# Override the default flag with 0 since I don't want texture repeat/filtering/mipmaps/etc
	texture.create_from_image(img, 0)

	# Upload the texture to my shader
	material.set_shader_param("my_array", texture)

Shader

uniform sampler2D my_array;

int get_array_value(ivec2 coord)
{
	// retrieve r component on the desired array position
	float texture_value = texelFetch(my_array, coord, 0).r;
	// the resulting value is in srgb space, so convert it back to linear space
	texture_value *= 255.;
	return int(texture_value);	
}

@MightyPrinny
Copy link
Contributor

sampler arrays would be nice to have, you can't use a texture as a texture array after all.

@nobuyukinyuu
Copy link
Contributor

I see a 4.0 milestone. Sooo close... I'll settle for any type of uniform array support tbh 😁

@IanGClifton
Copy link

@nobuyukinyuu
Copy link
Contributor

3.2 has some array support! http://docs.godotengine.org/en/latest/tutorials/shading/shading_reference/shading_language.html#arrays

Quite a number of people are still holding out specifically for uniform support, since transport seems to be what's necessitating the use case for most as compared to internal processing.

@Chaosus
Copy link
Member

Chaosus commented Mar 9, 2020

Better if @reduz implements uniform arrays himself since I'm stuck with them hardly...

@butkeim
Copy link
Contributor

butkeim commented May 5, 2020

Hi guys, currently working on a ray marching shader, hoping to dynamically create/modify shapes.
I have absolutely no other option but to use textures for data, and you can imagine the butchery.

Just to remind that this feature is really important in the eyes of some.

@akien-mga
Copy link
Member

Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine.

The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker.

If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance!

@panicq

This comment has been minimized.

@Calinou
Copy link
Member

Calinou commented May 29, 2020

@panicq Please don't bump issues without contributing significant new information. Use the 👍 reaction button on the first post instead.

@nathanfranke
Copy link
Contributor

Proposal: godotengine/godot-proposals#931
PR: #49485

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests