godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.31k stars 20.23k forks source link

ViewportTexture with mipmaps enabled becomes translucent and disappears #39273

Closed amonroejj closed 3 years ago

amonroejj commented 4 years ago

(I didn't see any other issues with keywords ViewportTexture and mipmaps that described this.)

Godot 3.2.1.stable.official Windows 7, Geforce GTX 460M 391.35

Issue description: Expected: Apply a ViewportTexture to a Sprite3D, enable mipmaps, and view it from any distance or angle. (Actual goal is a card game in the mold of Chronicle: Runescape Legends where the card text needs to be readable at small sizes)

Observed: This Sprite3D when viewed from a glancing angle or if you move too far away from it (either in the editor or during gameplay)--where mipmaps would come into play--gets more and more translucent and eventually disappears altogether.

Disabling mipmaps fixes the disappearing, but effectively makes small text unreadable.

Screen capture: https://imgur.com/a/WMYNgfM

Steps to reproduce: Spatial ....Viewport ........(anything) ....Sprite3D with ViewportTexture referencing above viewport, with mipmaps enabled.

Minimal reproduction project: ViewportTextureGlitch.zip

EDIT 1: Doing it in code triggers the same translucency glitch:

$Sprite3D.texture = $Viewport.get_texture()
$Sprite3D.texture.flags = 7
danilw commented 4 years ago

Actual goal is a card game in the mold of Chronicle: Runescape Legends where the card text needs to be readable at small sizes

to do that you need to make your own font as texture and print its text from a shader in your "text mesh" if you need dynamic text

example shader that prints text from texture https://www.shadertoy.com/view/tsdGzN

if you do not need dynamic text, then you need to prerender all "cards with text on it" or text as textures and use it on your mesh as textures

using viewport to do this job is very much "overkill" and not end well at all

amonroejj commented 4 years ago

Needs to be dynamic, yes. A stock "Text3D" object would be a welcome addition. The link given is valuable, but isn't it limited to monospaced fonts? You also forfeit the convenient font outline setting that normal labels can use.

The defect is still valid though because the reproduction project does not use text.

Calinou commented 4 years ago

You could enable anisotropic filtering on the ViewportTexture to improve the texture appearance at grazing angles. You can increase the anisotropic filtering level in the Project Settings (by default, it's 4x).

PS: To improve performance, consider using MeshInstance with a PlaneMesh or a QuadMesh instead of Sprite3D.

akien-mga commented 3 years ago

Seems confirmed in 3.3-stable, see this thread: https://twitter.com/Firepal3D/status/1385188174973046787

Calinou commented 3 years ago

Mipmaps aren't generated for ViewportTexture, so I think this is expected. Generating mipmaps in real-time is very demanding and can likely only be done for 4.0 with a fast filtering implementation. It would be feasible to generate mipmaps for a ViewportTexture whose update mode is set to Once, but this may still introduce some stuttering if you decide to update the texture occasionally.

Also, the MRP uses GLES2 but this appears to be working in GLES3 only right now (at least according to https://github.com/godotengine/godot/issues/23417#issuecomment-703780891). This workaround might work too, as long as you don't need to update the texture often: https://github.com/godotengine/godot/issues/23417#issuecomment-434848308

Duplicate of https://github.com/godotengine/godot/issues/23417 (same cause).