Cubemap and Godot4 (lack of docs)
Asked Answered
R

5

0

I've been trying for quite some time to create a Cubemap for my custom VisualShader, but cannot make it work.

I've read that Cubemaps are kinda "obsolete" in this version (in benefit of panoramas or skies o whatever), so you can't create them in 4.x, at least from editor directly. So I've made a CustomEditor with 6 slots to drag textures inside, to generate the 6 required images for a cubemap.
I'm using cubemap.create_from_images (that expects an Array[Image]), so I convert them using texture.get_image() before.

Then I create the .res using ResourceSaver.save passing the generated cubemap var, and it creates as a valid resource, I even can use it inside the Visual Shader editor, but is completely white, ignoring the images I passed by parameter in the "create_from_images" method.

Even more frustrating, is the fact that there is NO documentation about cubemaps at all. The docs only mention it briefly and describes a "create_placeholder" method that seems useless. Of course there is no tutorial about how to use a cubemap inside VisualShader editor, or even WHY you should use it, being cubemaps something that is been there for very long time in game engines, even in Godot 3.x.

In my case, I'm trying to create a very lightweight and low-detail reflection effect, and I do not want to use Panoramas or whatever high-end HDRi alternatives there may be. I just want a simple cubemap to do the trick, with a reflection that has NOTHING to do with the current scene environment. I just want to add some artistic touch to my custom shader without hitting the performance.

Does anyone has ever tried to use them successfully?

Repulse answered 9/10, 2023 at 17:56 Comment(0)
E
0

Repulse Do you have a working shader that samples from a samplerCube uniform?

Eyewash answered 9/10, 2023 at 18:55 Comment(0)
R
0

Eyewash a... what? 😆

I'm a shader newby, only made some basic stuff with texture2D and some UV warping/tiling some time ago. This is what I have now:

A cubemap that does not display anything inside preview:

And a very basic shader that tries to use a cubemap:

As I said, there is no documentation about this, so all I can do is guessing.

Repulse answered 9/10, 2023 at 19:26 Comment(0)
R
0

And this is the code I use to create the cubemap inside editor:
`
#Read user dropped textures
for cms in cubemapSlots:
if cms.textureRect.texture == null:
print("Missing textures 🙁")
return

#Create array for feeding cubemap sides
var imgs : Array[Image]
for cms in cubemapSlots:
	var img = Image.new()
	img.copy_from(cms.textureRect.texture.get_image())
	img.convert(Image.FORMAT_RGBA8)
	imgs.append(img)

#create the cubemap
var cubemap = Cubemap.new()
cubemap.create_from_images(imgs)
#Save to resources so can be selected inside visualShader editor
ResourceSaver.save(cubemap, "res://myCubemap.res")

`

Repulse answered 9/10, 2023 at 19:39 Comment(0)
E
0

Repulse create_from_images() returns an error code. Check what it returns.

Eyewash answered 9/10, 2023 at 19:40 Comment(0)
R
0

Eyewash It returns 0 (zero)

Repulse answered 9/10, 2023 at 20:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.