Hello everyone.

I am trying to reproduce the following tutorial to get a silouhette on my players whe they go behind things :

https://www.gdquest.com/tutorial/godot/shaders/silhouette-2d/

It works great in the editor but not in runtime, i join you a video so you can see by yourself what i mean :

I was thiking maybe the viewport doesnt pass the texture well but i think it does since the outline of the animation shape is correct. So i have no clue :)

If you have any leads, that would be amazing. Thanks

How are you setting the ViewportTexture in the shader? If you are doing it through the Godot editor, you may need to set it through script, as I found when working on the Viewport demos for Godot 3, back when it was just released, that setting the ViewportTexture through script fixed it not correctly working when running the project.

7 days later

I was setting it up via the editor.

Where should I set it in the script ?

I tried this : $mask.material.set_shader_param('texture', $Viewport.get_texture()) $Sprite.material.set_shader_param('texture', $Viewport.get_texture())

but it didnt changed anything.

@hjiul said: I was setting it up via the editor.

Where should I set it in the script ?

I tried this : $mask.material.set_shader_param('texture', $Viewport.get_texture()) $Sprite.material.set_shader_param('texture', $Viewport.get_texture())

but it didnt changed anything.

I think you can just set it straight to the texture property of the Sprite and then it should work:

$mask.texture = $Viewport.get_texture()
$Sprite.texture = $Viewport.get_texture()

That said, I'm assuming the shader is an exact copy of the shader on the GDQuest site, so if you made modifications to have the texture's passed in, instead of it using TEXTURE, then you'll need to set the shader param like you did in your post. If that is the case, then I would double check to make sure the names of the shader uniforms are exactly the same as the name passed in set_shader_param, as they have to be exact to work correctly.

So i tried to put : $mask.texture = $Viewport.get_texture() $Sprite.texture = $Viewport.get_texture()

in both the ready or process function.

Nothing changes.

And yes, I use exactly the same as the tutorial. The only part of the tutorial i didnt copied was the moving script but from what i see in it, there should be nothing there that would influence the shader.

Thanks for the help though

a year later
5 months later

I am having the same problem in a particular project. The same shadder works in similar situation for another project.
I suspect it has something to do with the mesh, some attribute that prevents the material to compile and work.