Next Pass Shaders Applying to All Instances
Asked Answered
D

6

0

Hey guys! I am new to Godot and have run into a bit of a pickle.

Just to give some background, I want to have interactables in my game. I am using to shaders to give feedback to the user, a highlight shader and outline shader. They can be found from the following URLs:

Item Highlight Shader: https://godotshaders.com/shader/collectable-item-shining-highlight/
Item Outline Shader: https://godotshaders.com/shader/pixel-perfect-outline-shader/

The highlight shader gets shown if the item is interactable, and is replaced with the outline shader when the user hovers their mouse over the item. The following image shows how I am changing the shader during runtime:


The issue I am having is that if I have many instances of an object in my scene (I have not duplicated with CNTRL+D, and instead dragged from file directory), they all share the same shader. For example, if I hover over once instance of an item, then all instances in that scene get the outline effect.

The item in question is a vent screw:

which is used multiple times in a vent cover scene:

The following image shows the shader being applied to all screws:

I have made sure to check the local to scene box for each shader, and the materials for the vent screws:

I have also attempted to make vent screw sub-resources unique:

I have also attempted to apply the "instance" word in my shader variables (I am not entirely sure how this works, I am new to shaders):

If you guys need any more information, I'd be happy to share more. If anyone would prefer to have access to the files then I can attempt to upload those as well. If I have not clarified by problem enough, I will try rephrase and explain it again. Thank you again for your time. I recently swapped from unity to Godot and I am having a lovely time.

Disprove answered 4/7, 2023 at 9:28 Comment(0)
D
0

Okay it appears I have found a solution with a little help from Reddit. I made an adjustment to my _ready() function and it is now the following:

The new line is:
meshInstance.mesh.surface_set_material(0, meshInstance.mesh.surface_get_material(0).duplicate())

I am not entirely sure what this means or why it works, but please reply with a reason if you do know so that future members can solve this issue.

Disprove answered 4/7, 2023 at 13:30 Comment(0)
G
0

All the best,
Paul.

Gleason answered 4/7, 2023 at 9:29 Comment(0)
E
0

Disprove Assign the material to material_override property of mesh instances instead directly to the mesh.

Etymology answered 4/7, 2023 at 9:31 Comment(0)
D
0

Etymology

I have applied the change with the following code update:

However, it did not fix my issue. Did I write the code correctly?

Disprove answered 4/7, 2023 at 9:39 Comment(0)
E
0

Disprove Your object instances must be scenes in order for local to scene to work.

Etymology answered 4/7, 2023 at 10:5 Comment(0)
D
0

Etymology

Apologies, but can you explain further please, as I am not fully understanding the statement. Are my current object instances not scenes?

Disprove answered 4/7, 2023 at 12:59 Comment(0)
D
0

Okay it appears I have found a solution with a little help from Reddit. I made an adjustment to my _ready() function and it is now the following:

The new line is:
meshInstance.mesh.surface_set_material(0, meshInstance.mesh.surface_get_material(0).duplicate())

I am not entirely sure what this means or why it works, but please reply with a reason if you do know so that future members can solve this issue.

Disprove answered 4/7, 2023 at 13:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.