shader with viewport texture only work in editor
Asked Answered
M

5

0

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

Melano answered 10/7, 2021 at 2:23 Comment(0)
A
0

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.

Altair answered 11/7, 2021 at 2:25 Comment(0)
M
0

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.

Melano answered 18/7, 2021 at 7:22 Comment(0)
A
0

@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.

Altair answered 18/7, 2021 at 14:56 Comment(0)
M
0

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

Melano answered 20/7, 2021 at 8:12 Comment(0)
D
0

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.

Didymium answered 9/5, 2023 at 12:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.