From dc775a7bd54d28a9c369130e75e7559861da4ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tur=C3=A1nszki=20J=C3=A1nos?= Date: Thu, 8 Dec 2022 12:30:11 +0100 Subject: [PATCH] hdr image loading support; bc6h image loading fix; spherical envmap support; --- Editor/WeatherWindow.cpp | 4 +- WickedEngine/shaders/ShaderInterop_Renderer.h | 1 + WickedEngine/shaders/ddgi_raytraceCS.hlsl | 2 +- WickedEngine/shaders/envMap_skyPS_static.hlsl | 4 +- WickedEngine/shaders/globals.hlsli | 1 - WickedEngine/shaders/raytraceCS.hlsl | 2 +- WickedEngine/shaders/renderlightmapPS.hlsl | 2 +- WickedEngine/shaders/skyHF.hlsli | 10 +++++ WickedEngine/shaders/skyPS_static.hlsl | 2 +- WickedEngine/shaders/surfel_raytraceCS.hlsl | 2 +- WickedEngine/shaders/visibility_skyCS.hlsl | 2 +- WickedEngine/wiRenderer.cpp | 5 ++- WickedEngine/wiResourceManager.cpp | 38 +++++++++++++++++++ WickedEngine/wiVersion.cpp | 2 +- 14 files changed, 63 insertions(+), 14 deletions(-) diff --git a/Editor/WeatherWindow.cpp b/Editor/WeatherWindow.cpp index 1b4bd1602..649a68bd1 100644 --- a/Editor/WeatherWindow.cpp +++ b/Editor/WeatherWindow.cpp @@ -273,8 +273,8 @@ void WeatherWindow::Create(EditorComponent* _editor) { wi::helper::FileDialogParams params; params.type = wi::helper::FileDialogParams::OPEN; - params.description = "Cubemap texture"; - params.extensions.push_back("dds"); + params.description = "Image file (cube or spherical map)"; + params.extensions = wi::resourcemanager::GetSupportedImageExtensions(); wi::helper::FileDialog(params, [=](std::string fileName) { wi::eventhandler::Subscribe_Once(wi::eventhandler::EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) { auto& weather = GetWeather(); diff --git a/WickedEngine/shaders/ShaderInterop_Renderer.h b/WickedEngine/shaders/ShaderInterop_Renderer.h index 5e283d756..6ce1e2795 100644 --- a/WickedEngine/shaders/ShaderInterop_Renderer.h +++ b/WickedEngine/shaders/ShaderInterop_Renderer.h @@ -821,6 +821,7 @@ static const uint OPTION_BIT_DISABLE_ALBEDO_MAPS = 1 << 11; static const uint OPTION_BIT_FORCE_DIFFUSE_LIGHTING = 1 << 12; static const uint OPTION_BIT_VOLUMETRICCLOUDS_SHADOWS = 1 << 13; static const uint OPTION_BIT_OVERRIDE_FOG_COLOR = 1 << 14; +static const uint OPTION_BIT_STATIC_SKY_SPHEREMAP = 1 << 15; // ---------- Common Constant buffers: ----------------- diff --git a/WickedEngine/shaders/ddgi_raytraceCS.hlsl b/WickedEngine/shaders/ddgi_raytraceCS.hlsl index c3d8dcbb1..6d84ee613 100644 --- a/WickedEngine/shaders/ddgi_raytraceCS.hlsl +++ b/WickedEngine/shaders/ddgi_raytraceCS.hlsl @@ -68,7 +68,7 @@ void main(uint3 DTid : SV_DispatchThreadID, uint3 Gid : SV_GroupID, uint groupIn if (IsStaticSky()) { // We have envmap information in a texture: - envColor = texture_globalenvmap.SampleLevel(sampler_linear_clamp, ray.Direction, 0).rgb; + envColor = GetStaticSkyColor(ray.Direction); } else { diff --git a/WickedEngine/shaders/envMap_skyPS_static.hlsl b/WickedEngine/shaders/envMap_skyPS_static.hlsl index aedf3b9c8..4685b18ff 100644 --- a/WickedEngine/shaders/envMap_skyPS_static.hlsl +++ b/WickedEngine/shaders/envMap_skyPS_static.hlsl @@ -3,12 +3,10 @@ #include "objectHF.hlsli" #include "skyHF.hlsli" -TextureCube texture_sky : register(t0); - float4 main(PixelInput input) : SV_TARGET { float3 normal = normalize(input.nor); - float3 color = texture_sky.SampleLevel(sampler_linear_clamp, normal, 0).rgb; + float3 color = GetStaticSkyColor(normal); color = clamp(color, 0, 65000); return float4(color, 1); } diff --git a/WickedEngine/shaders/globals.hlsli b/WickedEngine/shaders/globals.hlsli index ae7230735..5346aab57 100644 --- a/WickedEngine/shaders/globals.hlsli +++ b/WickedEngine/shaders/globals.hlsli @@ -191,7 +191,6 @@ struct PrimitiveID } }; -#define texture_globalenvmap bindless_cubemaps[GetScene().globalenvmap] #define texture_envmaparray bindless_cubearrays[GetScene().envmaparray] #define texture_random64x64 bindless_textures[GetFrame().texture_random64x64_index] diff --git a/WickedEngine/shaders/raytraceCS.hlsl b/WickedEngine/shaders/raytraceCS.hlsl index f3a804fae..559f0ffe2 100644 --- a/WickedEngine/shaders/raytraceCS.hlsl +++ b/WickedEngine/shaders/raytraceCS.hlsl @@ -123,7 +123,7 @@ void main(uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex) if (IsStaticSky()) { // We have envmap information in a texture: - envColor = texture_globalenvmap.SampleLevel(sampler_linear_clamp, ray.Direction, 0).rgb; + envColor = GetStaticSkyColor(ray.Direction); } else { diff --git a/WickedEngine/shaders/renderlightmapPS.hlsl b/WickedEngine/shaders/renderlightmapPS.hlsl index 3142d9b82..eb5160439 100644 --- a/WickedEngine/shaders/renderlightmapPS.hlsl +++ b/WickedEngine/shaders/renderlightmapPS.hlsl @@ -232,7 +232,7 @@ float4 main(Input input) : SV_TARGET if (IsStaticSky()) { // We have envmap information in a texture: - envColor = texture_globalenvmap.SampleLevel(sampler_linear_clamp, ray.Direction, 0).rgb; + envColor = GetStaticSkyColor(ray.Direction); } else { diff --git a/WickedEngine/shaders/skyHF.hlsli b/WickedEngine/shaders/skyHF.hlsli index e4ee8ce52..f22e6e170 100644 --- a/WickedEngine/shaders/skyHF.hlsli +++ b/WickedEngine/shaders/skyHF.hlsli @@ -125,5 +125,15 @@ float3 GetDynamicSkyColor(in float3 V, bool sun_enabled = true, bool clouds_enab return sky; } +float3 GetStaticSkyColor(in float3 V) +{ + if (GetFrame().options & OPTION_BIT_STATIC_SKY_SPHEREMAP) + { + float2 uv = (float2(atan2(V.z, V.x) / PI, -V.y) + 1.0) * 0.5; + return bindless_textures[GetScene().globalenvmap].SampleLevel(sampler_linear_clamp, uv, 0).rgb; + } + return bindless_cubemaps[GetScene().globalenvmap].SampleLevel(sampler_linear_clamp, V, 0).rgb; +} + #endif // WI_SKY_HF diff --git a/WickedEngine/shaders/skyPS_static.hlsl b/WickedEngine/shaders/skyPS_static.hlsl index 4a06d9673..90619104f 100644 --- a/WickedEngine/shaders/skyPS_static.hlsl +++ b/WickedEngine/shaders/skyPS_static.hlsl @@ -8,7 +8,7 @@ float4 main(float4 pos : SV_POSITION, float2 clipspace : TEXCOORD) : SV_TARGET const float3 V = normalize(unprojected.xyz - GetCamera().position); - float4 color = float4(texture_globalenvmap.SampleLevel(sampler_linear_clamp, V, 0).rgb, 1); + float4 color = float4(GetStaticSkyColor(V), 1); float4 pos2DPrev = mul(GetCamera().previous_view_projection, float4(unprojected.xyz, 1)); float2 velocity = ((pos2DPrev.xy / pos2DPrev.w - GetCamera().temporalaa_jitter_prev) - (clipspace - GetCamera().temporalaa_jitter)) * float2(0.5f, -0.5f); diff --git a/WickedEngine/shaders/surfel_raytraceCS.hlsl b/WickedEngine/shaders/surfel_raytraceCS.hlsl index a0c88e663..03041c98d 100644 --- a/WickedEngine/shaders/surfel_raytraceCS.hlsl +++ b/WickedEngine/shaders/surfel_raytraceCS.hlsl @@ -66,7 +66,7 @@ void main(uint3 DTid : SV_DispatchThreadID) if (IsStaticSky()) { // We have envmap information in a texture: - envColor = texture_globalenvmap.SampleLevel(sampler_linear_clamp, ray.Direction, 0).rgb; + envColor = GetStaticSkyColor(ray.Direction); } else { diff --git a/WickedEngine/shaders/visibility_skyCS.hlsl b/WickedEngine/shaders/visibility_skyCS.hlsl index e47c5ff56..a6852026a 100644 --- a/WickedEngine/shaders/visibility_skyCS.hlsl +++ b/WickedEngine/shaders/visibility_skyCS.hlsl @@ -26,7 +26,7 @@ void main(uint Gid : SV_GroupID, uint groupIndex : SV_GroupIndex) if (IsStaticSky()) { // We have envmap information in a texture: - envColor = texture_globalenvmap.SampleLevel(sampler_linear_clamp, ray.Direction, 0).rgb; + envColor = GetStaticSkyColor(ray.Direction); } else { diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index cf12efc99..342d9d91f 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -3377,6 +3377,10 @@ void UpdatePerFrameData( { frameCB.options |= OPTION_BIT_VOLUMETRICCLOUDS_SHADOWS; } + if (vis.scene->weather.skyMap.IsValid() && !has_flag(vis.scene->weather.skyMap.GetTexture().desc.misc_flags, ResourceMiscFlag::TEXTURECUBE)) + { + frameCB.options |= OPTION_BIT_STATIC_SKY_SPHEREMAP; + } frameCB.scene = vis.scene->shaderscene; @@ -6798,7 +6802,6 @@ void RefreshEnvProbes(const Visibility& vis, CommandList cmd) if (vis.scene->weather.skyMap.IsValid()) { device->BindPipelineState(&PSO_sky[SKYRENDERING_ENVMAPCAPTURE_STATIC], cmd); - device->BindResource(&vis.scene->weather.skyMap.GetTexture(), 0, cmd, vis.scene->weather.skyMap.GetTextureSRGBSubresource()); } else { diff --git a/WickedEngine/wiResourceManager.cpp b/WickedEngine/wiResourceManager.cpp index 2688b97ed..e94f6aa88 100644 --- a/WickedEngine/wiResourceManager.cpp +++ b/WickedEngine/wiResourceManager.cpp @@ -132,6 +132,7 @@ namespace wi {"DDS", DataType::IMAGE}, {"TGA", DataType::IMAGE}, {"QOI", DataType::IMAGE}, + {"HDR", DataType::IMAGE}, {"WAV", DataType::SOUND}, {"OGG", DataType::SOUND}, {"LUA", DataType::SCRIPT}, @@ -566,6 +567,8 @@ namespace wi case tinyddsloader::DDSFile::DXGIFormat::BC4_SNorm: desc.format = Format::BC4_SNORM; break; case tinyddsloader::DDSFile::DXGIFormat::BC5_UNorm: desc.format = Format::BC5_UNORM; break; case tinyddsloader::DDSFile::DXGIFormat::BC5_SNorm: desc.format = Format::BC5_SNORM; break; + case tinyddsloader::DDSFile::DXGIFormat::BC6H_SF16: desc.format = Format::BC6H_SF16; break; + case tinyddsloader::DDSFile::DXGIFormat::BC6H_UF16: desc.format = Format::BC6H_UF16; break; case tinyddsloader::DDSFile::DXGIFormat::BC7_UNorm: desc.format = Format::BC7_UNORM; break; case tinyddsloader::DDSFile::DXGIFormat::BC7_UNorm_SRGB: desc.format = Format::BC7_UNORM_SRGB; break; default: @@ -634,6 +637,41 @@ namespace wi else assert(0); // failed to load DDS } + else if(!ext.compare("HDR")) + { + int height, width, channels; // stb_image + float* data = stbi_loadf_from_memory(filedata, (int)filesize, &width, &height, &channels, 0); + + if (data != nullptr) + { + TextureDesc desc; + desc.width = (uint32_t)width; + desc.height = (uint32_t)height; + switch (channels) + { + default: + case 4: + desc.format = Format::R32G32B32A32_FLOAT; + break; + case 3: + desc.format = Format::R32G32B32_FLOAT; + break; + case 2: + desc.format = Format::R32G32_FLOAT; + break; + case 1: + desc.format = Format::R32_FLOAT; + break; + } + desc.bind_flags = BindFlag::SHADER_RESOURCE; + desc.mip_levels = 1; + SubresourceData InitData; + InitData.data_ptr = data; + InitData.row_pitch = width * GetFormatStride(desc.format); + success = device->CreateTexture(&desc, &InitData, &resource->texture); + device->SetName(&resource->texture, name.c_str()); + } + } else { // qoi, png, tga, jpg, etc. loader: diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 99bb2882d..077408b34 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 71; // minor bug fixes, alterations, refactors, updates - const int revision = 111; + const int revision = 112; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);