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

Implement 2D instance shader parameters #87966

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

EIREXE
Copy link
Contributor

@EIREXE EIREXE commented Feb 5, 2024

Rebased from @KoBeWi 's PR #77594

I also fixed it, so it actually works, although I am not entirely sure the code I wrote is fine, if someone from rendering could comb over it I'd be thankful.

Original PR text:

Closes #62943

I wrote this a while ago and decided to rebase and test it again now. This seems to work the same as in 3D (no wonder, since it's a 1:1 copy-paste), i.e. the parameters appear in the inspector, they have correct default value etc.

The only problem is that changing the parameter has no effect. It always uses the default for the given type (not even the defined default). But it's probably the only missing bit, so if anyone can help, the feature would be finished.

Co-authored-by: Álex Román Núñez <eirexe123@gmail.com>
@EIREXE
Copy link
Contributor Author

EIREXE commented Feb 5, 2024

Okay, I just realised I didn't actually get it to work, I think a redesign of canvas.glsl is needed because there's no space in the push constant to fit an instance ID, if it's fine i'll take a look at making it work like scene.glsl does.

@arkology
Copy link
Contributor

arkology commented Feb 5, 2024

there's no space in the push constant to fit an instance ID

I dont know much about rendering, but you are talking about this #80458, right?

@EIREXE
Copy link
Contributor Author

EIREXE commented Feb 5, 2024

there's no space in the push constant to fit an instance ID

I dont know much about rendering, but you are talking about this #80458, right?

Yes, exactly, lol, i'll just wait for that to get merged then

@clayjohn
Copy link
Member

This is a great first step towards adding support for instance shader parameters.

The missing piece is mapping the instance id to the global array. Here is what that looks like in the Forward+ renderer:

actions.instance_uniform_index_variable = "instances.data[instance_index_interp].instance_uniforms_ofs";

As you pointed out, there isn't room for that extra parameter in the current approach because push constants have such a limited size. That being said #80458 isn't really a full solution either as we will run into cache alignment issues if we start using a SSBO but then use 132 bytes for each instance

@Invertex
Copy link
Contributor

Invertex commented Sep 1, 2024

As you pointed out, there isn't room for that extra parameter in the current approach because push constants have such a limited size. That being said #80458 isn't really a full solution either as we will run into cache alignment issues if we start using a SSBO but then use 132 bytes for each instance

What about moving something less important from the push constant to the instance buffers?
In the case of canvas items, does specular_shininess need to be there?

struct PushConstant {
float world[6];
uint32_t flags;
uint32_t specular_shininess;
union {

That feels like something that should be part of shaders that have specular enabled, creating a shininess per-instance variable. (and can't imagine many people are using specular on their canvases in the first place...)
With that removed, there'd be room for the instance index, keeping the struct 128 bytes.

But I don't have much of a grasp on how this part of the engine works, just wondering!

@kakatoto-collab
Copy link

Hello, any news about that ? Instance uniforms are a must for anyone making a vampire survivor's like game.

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

Successfully merging this pull request may close these issues.

Instance uniforms are not implemented for 2D shaders
7 participants