Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating 3DImageTexture using Noise.get_seamless_image_3d causes errors, invalid texture #82046

Closed
Andicraft opened this issue Sep 21, 2023 · 1 comment
Labels

Comments

@Andicraft
Copy link

Godot version

4.2dev5 [e3e2528]

System information

Godot v4.2.dev5.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3060 Ti (NVIDIA; 31.0.15.3623) - AMD Ryzen 9 5950X 16-Core Processor (32 Threads)

Issue description

I'm using a script to combine several FastNoiseLite textures into one, using get_seamless_image - however, it's throwing lots of errors at me and while it seems to generate a valid image, the output file is small and turns into an invalid 1x1x1 image after restarting Godot (or rightclicking and choosing Make Unique).

The error thrown (once for each image slice) is:

Missing Images
Attempting to use an uninitialized RID
servers/rendering/renderer_rd/storage_rd/texture_storage.cpp:767 - Condition "!t" is true.

The image generated is at first glance seemingly valid, even after saving as an asset in the project:
image

But after restarting the editor or rightclicking and hitting Make Unique it turns invalid:
image

Steps to reproduce

Attach this script to a Node3D and tick the Generate box to run the code. Save the image and restart the editor. Also attached a reproduction project where this is already setup.

@tool
extends Node3D

@export var generate : bool = true:
	set(input):
		generate_noise()
		
@export var test : bool = true:
	set(input):
		pass
		
@export var noise_size : int = 64
@export var skirt : float = 0.25
		
@export var cellnoise_red : FastNoiseLite
@export var simplexnoise_red : FastNoiseLite

@export var cellnoise_green : FastNoiseLite

@export var cellnoise_blue : FastNoiseLite
		
@export var cellnoise_alpha : FastNoiseLite

@export var final_texture : ImageTexture3D
		
func generate_noise() -> void:
	
	var s = noise_size
	var imgs : Array[Image] = []
	var imgs_cell_r : Array[Image] = cellnoise_red.get_seamless_image_3d(s, s, s, true, skirt)
	var imgs_spx_r : Array[Image] = simplexnoise_red.get_seamless_image_3d(s, s, s, false, skirt)
	var imgs_cell_g : Array[Image] = cellnoise_green.get_seamless_image_3d(s, s, s, true, skirt)
	var imgs_cell_b : Array[Image] = cellnoise_blue.get_seamless_image_3d(s, s, s, true, skirt)
	var imgs_cell_a : Array[Image] = cellnoise_alpha.get_seamless_image_3d(s, s, s, true, skirt)
	
	for slice in range(noise_size):
		var img = Image.create(noise_size, noise_size, false, Image.FORMAT_RGBA8)
		imgs.append(img)
		for x in range(noise_size):
			for y in range(noise_size):
				
				var cr = imgs_cell_r[slice].get_pixel(x, y)
				var sr = imgs_spx_r[slice].get_pixel(x, y)
				var red = cr.lerp(sr, 0.5)
				
				var cg = imgs_cell_g[slice].get_pixel(x, y)
				var green = cg
				
				var cb = imgs_cell_b[slice].get_pixel(x, y)
				var blue = cb
				
				var ca = imgs_cell_a[slice].get_pixel(x, y)
				var alpha = ca
				
				imgs[slice].set_pixel(x, y, Color(red.r, green.r, blue.r, alpha.r))
	
		var noise_tex = ImageTexture3D.new()
		noise_tex.create(Image.FORMAT_RGBA8, noise_size, noise_size, noise_size, false, imgs)
		final_texture = noise_tex

Minimal reproduction project

3DTextureGen.zip

@bitsawer
Copy link
Member

Thanks for the report. Seems like a duplicate of #80866, so closing to keep discussion in one place. If you think this is a separate issue, feel free to comment or re-open the issue.

There is also a PR linked to the other issue (#82055), although it seems to still need some work.

@bitsawer bitsawer closed this as not planned Won't fix, can't repro, duplicate, stale Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants