Topic was automatically imported from the old Question2Answer platform.
Asked By
RuKeN
The awesome team of GDQuest have an awesome project with multiples shaders that can be found here:
On of their awesome shaders is named “SphereMask” a shader that is able to make a 3D object invisible and when a sphere collider enters in contact with that object reveals it:
The thing is that in my project, the object I want to hide have a texture with details and this shader is limited to display the object using a color and not it’s original texture
Can anyone help me to find a way to modify this shader to make it display the object in a normal way instead of show the object with a color? Shaders code is extremely different of what GDScript is
The ALBEDO variable in the fragment shader is the output color per pixel.
Right now it’s set to a mix of object_color and mask_color, which both seems to be fixed colors.
If the shader is running in a secondary pass, after the textured material, I believe you can do something like this to keep the existing color:
ALBEDO = mix(ALBEDO, mask_color.rgb, mask_value);
If you need to include a texture in the shader, add ‘uniform sampler2D texture;’ somewhere among the other uniform’s. This will add a texture shader parameter.
To read the texture, add ‘vec4 texture_color = texture(texture, UV);’ somwhere in the fragment shader, and finally change the ALBEDO to mix with the texture color.
Wow thanks for bring a solution and explaining it!
Just thinking in performance, I suppose that fragment() is similar to the process() function right? Is there a ready() function to get the texture just one time instead of in each loop?