Jump to content

SaveTexture saves only black texture (Cubemap)


klepto2
 Share

Go to solution Solved by Josh,

Recommended Posts

I am working on a small tool to generate the specular and diffuse maps based on an input cubemap:

image.thumb.png.c1004e865c095500c471009bff72830b.png

While the generation itself works flawlessly, I can't get the SaveTexture feature to work with cubemaps. 

I download the image data from the gpu and if i save the pixmaps (each face and mipmap) seperately this works. But with a mipchain i only get a black cube texture. (Tried it with various viewers, renderdoc, nvidia texture tools).

Then i tried the sample you provided here:

and followed the same workflow as you. The result is the same, the code in this blog also results in a black texture :(

  • Like 1
  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

I know if you look at any cubemaps texture in the Asset Browser it's also black despite it working in the world renderer. Did you try Setting the background to your generated cubemap?

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

The reason why cubemaps are not shown in the asset browser is, that the pbr shaders don't support cubemaps as diffuse texture. You can try it yourself and create a material and try  to assign a cubemap to the diffuse slot.  In this case SaveTexture just saves black color instead of the actual pixel values. I know that it worked some time ago as i have tried the code mentioned in the blog before. Maybe Josh just hasn't applied some internal changes which were made lately.

Btw: yes i tried them in the Editor as well ;)

  • Like 1
  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

This might be useful to you:
https://github.com/UltraEngine/IBLSampler

My copy of the cli.exe program compiled from this project was compressed with UPX and now Windows is aggressively deleting the EXE. I was not able to recompile it...it requires a lot of external libraries and I don't think this project is actively maintained. So I wrote the program linked to above to do the same thing, although it is not very polished:
https://github.com/KhronosGroup/glTF-IBL-Sampler

I used this to generate the new default skybox / reflection maps.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

3 hours ago, klepto2 said:

The reason why cubemaps are not shown in the asset browser is, that the pbr shaders don't support cubemaps as diffuse texture. You can try it yourself and create a material and try  to assign a cubemap to the diffuse slot.  In this case SaveTexture just saves black color instead of the actual pixel values. I know that it worked some time ago as i have tried the code mentioned in the blog before. Maybe Josh just hasn't applied some internal changes which were made lately.

Btw: yes i tried them in the Editor as well ;)

The asset browser actually does not use Vulkan for rendering. Rather, it loads the texture as a pixmap and converts the pixel format to BGRA, then displays it on a panel as a pixmap.

It would be helpful to get the cubemap you saved, because otherwise I am not sure what I am looking for. There are several possible points of failure:

  • The saved cubemap might really be black
  • Loading a pixmap from a cubemap might not be working
  • Converting the cubemaps's pixel format to BGRA might not be working

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

8 minutes ago, Josh said:

This might be useful to you:
https://github.com/UltraEngine/IBLSampler

My copy of the cli.exe program compiled from this project was compressed with UPX and now Windows is aggressively deleting the EXE. I was not able to recompile it...it requires a lot of external libraries and I don't think this project is actively maintained. So I wrote the program linked to above to do the same thing, although it is not very polished:
https://github.com/KhronosGroup/glTF-IBL-Sampler

I used this to generate the new default skybox / reflection maps.

It seems to me with a little elbow grease, this can be converted into a tool in which an extension can be written to use to generate hdr cubemaps.

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

30 minutes ago, reepblue said:

It seems to me with a little elbow grease, this can be converted into a tool in which an extension can be written to use to generate hdr cubemaps.

Yeah, I thought about that. There is a Pixmap::Sample command which will accept texcoords and return a sample with bilinear filtering. So I think the program would be something like this (might have errors):

for (int n = 0; n < 6)
	for (int x = 0; x < w)
  		for (int y = 0; y < w)
  			Vec3 dir = figure out vector for this pixel
  			float v = ACos(dir.y) / 90.0f
  			float u = ATan(dir.z, dir.x) / 360.0f
  			color = hdri->Sample(u,v)
  			cubeface[n]->WritePixel(u, v, color)

Then you could just input single HDRIs like this and spit out the specular and diffuse cubemaps:
https://polyhaven.com/hdris

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

2 hours ago, Josh said:

The asset browser actually does not use Vulkan for rendering. Rather, it loads the texture as a pixmap and converts the pixel format to BGRA, then displays it on a panel as a pixmap.

It would be helpful to get the cubemap you saved, because otherwise I am not sure what I am looking for. There are several possible points of failure:

  • The saved cubemap might really be black
  • Loading a pixmap from a cubemap might not be working
  • Converting the cubemaps's pixel format to BGRA might not be working

The saved cubemap is black, the pixmaps in the mipchain passed to the save texture function are valid. They are saved correctly, when the pixmap save method is used. Just the provided way in the blog sample and the sample itself is not working. If you still need some data i will provide it later.

The cubemap data is calculated in a computeshader and the result is mapped back to the host. For the later atmosphere shader I just need the calculations, but for the engine I thought I could provide a small tool which also saves the generated cubemaps. I know iblsampler, and I use some shader code from it.

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

  • Solution

I put together a working example for you.

savecubemap.zip

It seems to work, but maybe there is something small you and I are doing that is throwing it off.

Some guesses:

  • Maybe the pixmap format you are using isn't getting saved.
  • Maybe a pixmap format conversion isn't working as expected.
  • Maybe your order of mipmaps isn't correct.

It could also be that the save routine is encountering a situation it can't handle correctly, and I just haven't noticed it yet.

Hopefully this will help you!

Untitled.thumb.jpg.b52355cad5a64c6f3421322fbf11eb21.jpg

vs.thumb.jpg.b7eadc39cc902413f12109832ff74c57.jpg

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Okay, I am adding this check in the routine:

			if (mipchain[0]->blocksize > 0)
			{
				for (auto mipmap : mipchain)
				{
					if (mipmap->size.x < mipchain[0]->blocksize or mipmap->size.y < mipchain[0]->blocksize)
					{
						Print("Error: Mipchain contains mipmaps with dimensoins smaller than the format's block size.");
						return false;
					}
				}
			}

Thank you for pointing this out.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Looks good. How are you generating the specular mipmaps? It looks like the mipmaps in my specular cubemaps are a lot blurrier, if you look at Materials/Environment/Default/specular.dds in Visual Studio.

mip1.png.8a4077e0c1c30b67fd782c83802b652b.png

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

this might be due the type of host synchronization i do. I currently use vkCmdCopyImage which doesn't support linaer filtering for the download. I will later try to change it to staging buffers, which might be better in this case.

  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

It's not just downsampling, though. The IBL filter I got from the Khronos project takes a lot of samples to blur make each mipmap blurrier. If you don't do that, then rough surfaces will look kind of blocky instead of rough.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Fixed the blurriness:

 image.png.d774f6b7658bc01ef90232fa6b8dc892.png

The color is not as bright as the one from the ibl sampler as it uses dds or tex files to gnerate the filtered cubemap, which is different to the hdr format. Maybe i can find a soltuin for that as well.

  • Like 1
  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

8 hours ago, klepto2 said:

The color is not as bright as the one from the ibl sampler as it uses dds or tex files to gnerate the filtered cubemap, which is different to the hdr format. Maybe i can find a soltuin for that as well.

DDS supports some HDR formats. BC6 is the compressed RGB HDR format.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...