godotengine / godot

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

Transparent color become different when inside sub viewport #32615

Open sriedi7 opened 5 years ago

sriedi7 commented 5 years ago

Godot version: Godot 3.1.1 stable (GLES2 & GLES3) Godot 3.2 a1 (GLES2 & GLES3)

OS/device including version: Windows 10 pro

Issue description: I have ColorRect with the same color (it's a duplicate, so they should have the same color). But when I move 1 of them to sub viewport (with transparent_bg = on, and the subviewport inside viewport container). The color become different like this: image The duplicated color rect is the transparent white rect and 1 above it (become slightly darker).

Steps to reproduce: Open project below and open Coba.tscn

Minimal reproduction project: viewporttransparent.zip

Zylann commented 5 years ago

I believe this is due to a problem in the way this rectangle is blended (kinda similar to https://github.com/godotengine/godot/issues/31124 but at renderer level).

In this situation, you could fix the blending by adding a material on your ViewportContainer and setting its blend mode to Premult Alpha: image Although the fact this is 99% of times what you'd expect that's not very intuitive.

KoBeWi commented 4 years ago

Still valid in c3964b6

DmitriySalnikov commented 2 years ago

v3.4.2.stable.custom_build [45eaa2daf] Still need to use the Premult Alpha

Calinou commented 2 years ago

This seems like expected behavior to me. Setting the default CanvasItemMaterial blend mode to Premult Alpha may not be a good idea as it can break expectations (and it will look broken with most sprites).

More information on why you need to use premultiplied alpha when performing any kind of compositing (which includes transparent viewports).

matthewperiut commented 1 year ago

Confirmed identical behavior in Godot 4.1,

image

example project also converts perfectly to godot 4.

RichMakeGame commented 3 months ago

I believe that pre-multiplied rgb values are incorrect in forward+ render textures- in compatibility however the values do come out as expected. this is a forward+ test showing the rgb result of grey+alpha premult_off