Shadder works in editor but not in runtime (double materials meshes)
Asked Answered
W

3

0

For some reason texture shadders like :

shader_type spatial;
render_mode unshaded;
uniform sampler2D refletion_tx;
void fragment() {
	ALBEDO = texture(refletion_tx,vec2(1.0-SCREEN_UV.x,SCREEN_UV.y)).rgb;
}

Dont work if:
1) The meshes is inside a node3d
2) In my case, if the mesh has more then 1 material ( and you want only one of it to have the shader )

editor
https://ibb.co/dbsvsYg

run
https://ibb.co/VLqkzV2

Is this a godot restriction ? I am doing anything wrong ? Its possible to workarround it ? Is this a bug ?

Worldbeater answered 9/5, 2023 at 14:6 Comment(0)
W
0

Worldbeater Just an observation: I did check "Local to scene" to all materials and mesh, no effect...

Worldbeater answered 9/5, 2023 at 14:7 Comment(0)
W
0

Just adding something else, that I am using as workaround, I am not sure why but using viewports as texture or shader only works if you use it in the override material.

Worldbeater answered 16/5, 2023 at 14:41 Comment(0)
W
0

I just notice that even using override materials, it dont work if you fully assign by code :

var mat_ret_r: ShaderMaterial = ShaderMaterial.new()
mat_ret_r.set_shader( preloadedshader )
var vpr: ViewportTexture = ViewportTexture.new()
vpr.set_local_to_scene(true)
vpr.set_viewport_path_in_scene( ret_r.get_node("SubViewport").get_path()  )
ret_r.set_surface_override_material( 0, mat_ret_r )

The code works, the material changes in screen, but for some reason is blank, as the video card dont support it or if there is some "update" function awaiting to be called ( I have the felling that the editor do something else after we assign everything ).

I am missing some magic "update" function at the end or something ?

Another thing, I notice even when we assign by the editor and it works all fine, when we test in another machines, it dont work, and show blank texture, is this normal ? Maybe some videocards dont support viewports or something ?

Worldbeater answered 16/5, 2023 at 15:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.