Subviewport exhibiting aberrant alpha behaviour on _draw()

Godot Version

4.3

Question

Drawing to Subviewport, alpha levels change for no reason on last draw. Is it a bug?

Here is a quick test of a mini program.

  • As you slide the mouse and press the left button, it draws a set of faded rectangles, each is a different colour and alpha.
  • When you let go of the mouse button, it stops drawing. (But keep moving the mouse)
  • It is set by boolean value to stop drawing, so no further draws occur
  • The last Draw is always done many times over, this should not happen.

Mouse Slide Test

For example, when the subviewport is used for faint, permanent, tyre skidding it creates odd termination points when the skid is realeased. Always on the last frame of the skid draw, it repeats, many times over, making the (faint black rectangle) turn out full black. I guesstimate the redraw of the last frame occurs about 4 to 8 times, judging by some alpha-level testing. But it may be higher.

Hard-blocking the _draw() function does not solve this issue. Ie: Making draws occur say every half second (using delta). This makes it worse(!), it’s nothing but flat, matte black. It recognizes each single draw as the last(!).

For the Mouse test.

Scene Setup

Set the subviewport to never clear

Subviewport Clear Settings

Code for mini test.

NOTE: Code is attached to control node.

extends Control
# Allow the user to draw (Hard Stop Draw)
var Allow_Draw: bool = false
	
func _draw():
	# Do not draw the screen unless allowed to
	if Allow_Draw == true:
		# Get the Mouse position
		var MousePos: Vector2 = Vector2(get_global_mouse_position())
		# Draw 3 different squares of varying alpha
		draw_rect(Rect2(MousePos,Vector2(10,10)),Color(1,1,0,.05),true)
		draw_rect(Rect2(MousePos+Vector2(0,10),Vector2(10,10)),Color(1,1,1,.1),true)
		draw_rect(Rect2(MousePos+Vector2(0,20),Vector2(10,10)),Color(0,1,0,.2),true)
		# Do not allow it to draw again
		Allow_Draw = false

func _process(_delta):
	# On Mouse press
	if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
		# Allow the Subviewport to allow drawing
		Allow_Draw = true
		# Run the draw process
		queue_redraw()

I’m closing this off as I’ve added it as an engine bug on github.com. It can be searched for under the same heading. [ Subviewport exhibiting aberrant alpha behaviour on _draw() #96151 ]

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.