klepto2 Posted October 18, 2023 Share Posted October 18, 2023 I am working on a small tool to generate the specular and diffuse maps based on an input cubemap: 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 1 Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
reepblue Posted October 18, 2023 Share Posted October 18, 2023 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? Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
klepto2 Posted October 18, 2023 Author Share Posted October 18, 2023 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 1 Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Josh Posted October 18, 2023 Share Posted October 18, 2023 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. Quote 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 More sharing options...
Josh Posted October 18, 2023 Share Posted October 18, 2023 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 Quote 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 More sharing options...
reepblue Posted October 18, 2023 Share Posted October 18, 2023 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. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted October 18, 2023 Share Posted October 18, 2023 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 Quote 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 More sharing options...
Josh Posted October 18, 2023 Share Posted October 18, 2023 Also, I have been unable to find any simple code that converts a BC6 image back to RGBA. There are two libraries that are both pretty big: https://github.com/hglm/detex https://github.com/hglm/texgenpack Quote 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 More sharing options...
klepto2 Posted October 18, 2023 Author Share Posted October 18, 2023 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. Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Solution Josh Posted October 18, 2023 Solution Share Posted October 18, 2023 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! Quote 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 More sharing options...
klepto2 Posted October 19, 2023 Author Share Posted October 19, 2023 Ok, found the error. I generated to many mipmaps. BCH6 has a blocksize of 4 which i missed, which means the lowest mipmap size is also 4 and not 1. Thanks for the point in the right direction. Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Josh Posted October 19, 2023 Share Posted October 19, 2023 Hmmm, I think the routine should still provide an error if the mipmaps are wrong. Are you sure SaveTexture is saving a bad file or is it returning false? Quote 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 More sharing options...
klepto2 Posted October 19, 2023 Author Share Posted October 19, 2023 It is saving the dds file with the wrong mipmap count, but it will not load in ultraEngine, while other tools load it, but display a black screen. Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Josh Posted October 19, 2023 Share Posted October 19, 2023 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. Quote 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 More sharing options...
klepto2 Posted October 19, 2023 Author Share Posted October 19, 2023 The Zone-map with the provided zone-sky only. the generated specular and diffuse maps in action this is a current screen of the tool with the settings used: textures_generated.zip Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Josh Posted October 19, 2023 Share Posted October 19, 2023 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. Quote 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 More sharing options...
klepto2 Posted October 19, 2023 Author Share Posted October 19, 2023 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. Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Josh Posted October 19, 2023 Share Posted October 19, 2023 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. Quote 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 More sharing options...
klepto2 Posted October 19, 2023 Author Share Posted October 19, 2023 The code is the same as the one from Khronos. What might be, is that I have one step missed. But the mipmaps are generated the same way. And before downloading they look smooth. But will take a closer look. 1 Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
klepto2 Posted October 20, 2023 Author Share Posted October 20, 2023 Fixed the blurriness: 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. 1 Quote Windows 10 Pro 64-Bit-Version NVIDIA Geforce 1080 TI Link to comment Share on other sites More sharing options...
Josh Posted October 20, 2023 Share Posted October 20, 2023 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. Quote 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 More sharing options...
Recommended Posts
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.