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

Instance uniforms are not implemented for 2D shaders #62943

Closed
Knand1861 opened this issue Jul 12, 2022 · 7 comments · Fixed by #99230
Closed

Instance uniforms are not implemented for 2D shaders #62943

Knand1861 opened this issue Jul 12, 2022 · 7 comments · Fixed by #99230

Comments

@Knand1861
Copy link

Knand1861 commented Jul 12, 2022

Godot version

4.11 alpha

System information

Windows 11

Issue description

Instance keyword makes hints disappear and makes GDscript helpless in controlling the value in any way [It defaults to 0, as for float];
Delete instance keyword, and it works again.

Untitled

Steps to reproduce

shader:

shader_type canvas_item;
instance uniform float opacity :hint_range(0.0, 1.0, 0.1)=0.5;

void fragment(){
	vec4 color = texture(TEXTURE,UV);
	color.a-=opacity;
	COLOR = color;
}

sprite with an area2d and collisionshape:

extends Sprite2D


func _on_area_2d_area_entered(area):
	material.set_shader_param("opacity",1.0)
@Knand1861 Knand1861 changed the title Shaders : instance uniform Shaders : Instance uniform Jul 12, 2022
@Knand1861 Knand1861 changed the title Shaders : Instance uniform Shaders : Instance keyword makes the uniform useless Jul 12, 2022
@Calinou
Copy link
Member

Calinou commented Jul 12, 2022

I guess this is because the editor isn't aware of per-instance uniforms. These were likely designed to be changed via code first and foremost.

Edit: The issue is that per-instance uniforms (and likely global uniforms) aren't implemented for use in 2D (canvas_item) shaders yet. They only work with 3D (spatial) shaders.
As per the other linked issues, can you test this in a 3D (spatial) shader instead of a 2D (canvas_item) shader?

@clayjohn
Copy link
Member

Edit: The issue is that per-instance uniforms (and likely global uniforms) aren't implemented for use in 2D (canvas_item) shaders yet.

Just to note, Global Uniforms should work with every shader type including sky, particles, and fog. Per-instance uniforms are a different story (although they could likely be made to work with FogVolumes)

Instance keyword makes hints disappear and makes GDscript helpless in controlling the value in any way [It defaults to 0, as for float];

Instance Uniforms belong to the GeometryInstance, not to the shader, so you don't set them using material.set_shader_param() you set them with mesh_instance.set_shader_instance_uniform()

@SmartySmart702
Copy link

Instance Uniforms belong to the GeometryInstance, not to the shader, so you don't set them using material.set_shader_param() you set them with mesh_instance.set_shader_instance_uniform()

Had some trouble debugging this issue because I used material.set_shader_param(). This should trigger a warning in the debugger.

@Chaosus Chaosus changed the title Shaders : Instance keyword makes the uniform useless Instance uniforms are not implemented for 2D shaders Aug 22, 2022
@KoBeWi
Copy link
Member

KoBeWi commented Sep 12, 2022

I tried :<
KoBeWi@9220e5e
The uniforms show up in the inspector, but in a wrong place and editing them has no effect. Also the implementation is trash. But maybe it will be useful as a starting point for someone.

@riazey
Copy link

riazey commented Oct 4, 2022

This is still a major issue in the beta, I noticed it wasn't included in the 4.0 roadmap was it decided that having this new shader feature be unavailable for 2D in the full 4.0 release?

I might be blind so just double checking cuz I was super looking forward to it for my color palette* swapping xD

@Calinou
Copy link
Member

Calinou commented Oct 4, 2022

I noticed it wasn't included in the 4.0 roadmap was it decided that having this new shader feature be unavailable for 2D in the full 4.0 release?

We don't know whether this feature will be added in time for 4.0. It all depends on a motivated contributor being able to implement this 🙂

@Chaosus Chaosus moved this to To Assess in 4.x Priority Issues Oct 8, 2022
@Chaosus Chaosus moved this from To Assess to Todo in 4.x Priority Issues Oct 8, 2022
@clayjohn clayjohn added enhancement and removed bug labels Dec 16, 2022
@clayjohn clayjohn modified the milestones: 4.0, 4.x Dec 16, 2022
@Praytic
Copy link
Contributor

Praytic commented Jan 4, 2024

What is the workaround for instance uniforms for canvas_item shaders? We have like 600 instances of duplicated shader code...

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