#How do I make SubViewports render?

1 messages · Page 1 of 1 (latest)

zealous marsh
#

I'm trying to make a rearview mirror and have a ViewportTexture on it linking to a secondary camera, but all I'm getting it pink.

I see on the doc that subviewports only capture things below them in the hierarchy, is there a way to change this?

faint jungle
#

I think the way most would do that is have a shader that displays a VieportTexture, have a camera as child of the viewport that points backwards.

#

By "capture things below" it means cameras.
So that it doesn't try to capture stuff from your normal camera.

midnight sage
#

Hi! Try updating the viewport texture via a runtime script like this:

var viewport_texture = $SubViewport.get_texture()
$MeshInstance.material_override.albedo_texture = viewport_texture

Let me know if this solves the problem, i hope i have helped!

zealous marsh
zealous marsh
midnight sage
#

Mmmm.... Try to reorganize your hierarchy like this:

Root
├── SubViewport
│ ├── Camera
│ ├── MeshA
│ └── MeshB
└── OtherNodes

#

Im not 100% sure that will work,Just to try out

glad sorrel
#

I solved this by using a Node2D as a fake camera

faint jungle
#

Well I dunno what to tell you.
My game has a fake mirror using a camera and it displays the whole room just fine even though it's at the bottom.

glad sorrel
#

in _process on the SubViewport: canvas_transform = fake_cam.global_transform.affine_inverse()

zealous marsh
zealous marsh
faint jungle
#

Default settings on subviewport except for 512 x 512 size to make it perform a bit better.

glad sorrel
#

Maybe I'm wrong, but IIRC there was no way to make the Camera node ignore the hierarchy

faint jungle
#

And the mirror surface has a material with texture2D parameter. Then I click the parameter, select "new viewport texture" and it will ask me to pick a viewport. So I select the subviewport.

glad sorrel
#

Oh, I see, I missed the "3D"

#

Well, nice that it's easier in 3D, then

zealous marsh
nimble widget
zealous marsh
#

i tried just doing it manually before by getting the viewport's texture and setting the mesh's material to it.
it worked for capturing the root viewport, but still nothing for this one

nimble widget
#

Doesn't explain why your texture is pink, though.

faint jungle
#

Does the Subviewport show pink in the inspector too? Like on the panel with size settings etc.

nimble widget
#

Does it behave differently if you change the update mode (hidden inside "render target" in the properties) to always?

#

I have found that sometimes it doesn't always agree with me about whether the subviewport is visible.

zealous marsh
zealous marsh
faint jungle
#

If your mirror thing is a prefab you might need to right click, select "editable children" and add a new vieport texture to it.
Mine breaks sometimes

zealous marsh
faint jungle
#

Oooh? Extra weird...

midnight sage
#

True, I am not very familiar with godot 3d, but this should not happen.

zealous marsh
#

omg, i got it to work finally

#

i just set the ViewportTexture manually in code and it fixed it

midnight sage
#

Hahaha Im glad that the problem has been solved