Skip to content

Commit

Permalink
Import .hdr textures and cubemaps
Browse files Browse the repository at this point in the history
  • Loading branch information
Benualdo committed Nov 9, 2024
1 parent 42308a4 commit a2c52d0
Show file tree
Hide file tree
Showing 25 changed files with 65 additions and 56 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@ The following assets are provided under permissive licenses. Please follow the p
| [Traffic Cone]( https://www.cgtrader.com/free-3d-models/exterior/street-exterior/traffic-cone-5849a434-2331-4a90-9b87-087ccc16cd0c ) | hinndia
| [Soccergoal]( https://www.turbosquid.com/3d-models/soccergoal-3d-model-1840894 ) | NorbertVarga

### Environment maps

| Name<img width=140/> | Info<img width=200/>
| --------------------------------------------------------------------------------------------------------- | -------------------
| [Free HDR Map 779]( https://hdri-skies.com/free-hdris/hdr-map-779/ ) | [hdri-skies.com](hdri-skies.com)


### Sounds

| Name<img width=140/> | Info<img width=200/>
Expand All @@ -319,6 +326,7 @@ The following assets are provided under permissive licenses. Please follow the p
| [Tally Dub]( https://pixabay.com/fr/music/reggae-tally-dub-brotheration-records-2016-140287/ ) | Brotheration Records



# Misc

These tools are not mandatory but can be useful for development.
Expand Down
12 changes: 6 additions & 6 deletions data/Scenes/PBR.scene
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@
<Property type="Uint32" name="m_uid" flags="" value="2193914723"/>
<Property type="Uint32" name="m_originalUID" flags="" value="0"/>
<Property type="EnumFlagsU32" name="m_objectFlags" flags="" value=""/>
<Property type="String" name="m_resourcePath" flags="NotVisible" value="data/Textures/EnvMaps/hilly_terrain_01_1k.tga"/>
<Property type="String" name="m_resourcePath" flags="NotVisible" value="data/Textures/EnvMaps/779-hdri-skies-com.hdr"/>
</Object>
</Property>
<Property type="Float" name="m_irradiance" flags="HasRange" value="1"/>
<Property type="Float" name="m_specularReflection" flags="HasRange" value="1"/>
<Property type="Float" name="m_irradiance" flags="HasRange" value="0.5"/>
<Property type="Float" name="m_specularReflection" flags="HasRange" value="0.5"/>
</Object>
</Property>
<Property type="ObjectPtrVector" name="m_children" flags="NotVisible">
Expand All @@ -83,14 +83,14 @@
<Property type="EnumFlagsU32" name="m_objectFlags" flags="" value=""/>
<Property type="EnumFlagsU32" name="m_flags" flags="Bitfield" value="Enabled"/>
<Property type="Float4" name="m_color" flags="Color" x="1" y="1" z="1" w="1"/>
<Property type="Float4x4" name="m_local" flags="Flatten" Ix="0.92090529" Iy="-0.074080594" Iz="0.38268369" Iw="0" Jx="-0.12128442" Jy="0.87858117" Jz="0.46194068" Jw="0" Kx="-0.37043908" Ky="-0.4718169" Kz="0.80010468" Kw="0" Tx="0" Ty="0" Tz="2" Tw="1"/>
<Property type="Float4x4" name="m_local" flags="Flatten" Ix="0.77756" Iy="0.060900792" Iz="0.62585479" Iw="0" Jx="0.26460093" Jy="0.87120998" Jz="-0.41351587" Jw="0" Kx="-0.57043129" Ky="0.48713475" Kz="0.66130227" Kw="0" Tx="0" Ty="0" Tz="4.5" Tw="1"/>
<Property type="EnumFlagsU64" name="m_tags" flags="Bitfield" value=""/>
<Property type="ObjectPtrVector" name="m_components">
<Object class="LightComponent">
<Property type="String" name="m_name" flags="NotVisible" value="New LightComponent"/>
<Property type="Uint32" name="m_uid" flags="" value="1800330117"/>
<Property type="Uint32" name="m_originalUID" flags="" value="0"/>
<Property type="EnumFlagsU32" name="m_objectFlags" flags="" value=""/>
<Property type="EnumFlagsU32" name="m_objectFlags" flags="" value="Opened"/>
<Property type="EnumFlagsU32" name="m_flags" flags="Bitfield" value="Enabled"/>
<Property type="EnumU8" name="m_lightType" value="Directional"/>
<Property type="ObjectPtr" name="m_lightDesc" flags="Flatten">
Expand All @@ -106,7 +106,7 @@
<Property type="Uint2" name="m_shadowResolution" x="2048" y="2048"/>
<Property type="Float" name="m_shadowIntensity" flags="HasRange" value="1"/>
<Property type="Float4" name="m_color" flags="" x="1" y="1" z="1" w="1"/>
<Property type="Float" name="m_intensity" flags="HasRange" value="1"/>
<Property type="Float" name="m_intensity" flags="HasRange" value="3"/>
</Object>
</Property>
</Object>
Expand Down
Binary file added data/Textures/EnvMaps/779-hdri-skies-com.hdr
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Root>
<Object class="TextureResourceMeta">
<Property type="String" name="m_name" flags="NotVisible" value="_MGL8969.tga.meta"/>
<Property type="String" name="m_name" flags="NotVisible" value="779-hdri-skies-com.hdr.meta"/>
<Property type="EnumU8" name="m_importSettings.m_importerType" value="Cubemap"/>
<Property type="EnumU8" name="m_importSettings.m_importerFormat" value="Automatic"/>
<Property type="Bool" name="m_importSettings.m_sRGB" value="false"/>
Expand Down
Binary file removed data/Textures/EnvMaps/EnvMap.max
Binary file not shown.
Binary file removed data/Textures/EnvMaps/Siggraph_env.tga
Binary file not shown.
Binary file removed data/Textures/EnvMaps/_MGL8969.tga
Binary file not shown.
Binary file removed data/Textures/EnvMaps/blouberg_sunrise_2.tga
Binary file not shown.
10 changes: 0 additions & 10 deletions data/Textures/EnvMaps/blouberg_sunrise_2.tga.meta

This file was deleted.

Binary file removed data/Textures/EnvMaps/evening_road_01_puresky_1k.hdr
Binary file not shown.
Binary file not shown.
10 changes: 0 additions & 10 deletions data/Textures/EnvMaps/evening_road_01_puresky_1k.tga.meta

This file was deleted.

Binary file removed data/Textures/EnvMaps/hilly_terrain_01_1k.exr
Binary file not shown.
Binary file removed data/Textures/EnvMaps/hilly_terrain_01_1k.tga
Binary file not shown.
10 changes: 0 additions & 10 deletions data/Textures/EnvMaps/hilly_terrain_01_1k.tga.meta

This file was deleted.

Binary file removed data/Textures/EnvMaps/the_sky_is_on_fire_1K.hdr
Binary file not shown.
Binary file not shown.
Binary file removed data/Textures/EnvMaps/the_sky_is_on_fire_2k.hdr
Binary file not shown.
Binary file removed data/Textures/EnvMaps/the_sky_is_on_fire_2k.png
Binary file not shown.
10 changes: 0 additions & 10 deletions data/Textures/EnvMaps/the_sky_is_on_fire_2k.png.meta

This file was deleted.

5 changes: 5 additions & 0 deletions src/editor/ImGui/Window/About/ImGuiAbout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ namespace vg::editor

drawLibraryDescriptionList("Models", models, (uint)countof(models));

LibraryDescription environmentMaps[] =
{
{ "Free HDR Map 779", "hdri-skies.com", "https://hdri-skies.com/free-hdris/hdr-map-779/" }
};

LibraryDescription sound[] =
{
{ "FX - Swoosh - normal", "bolkmar", "https://freesound.org/people/bolkmar/sounds/451127/" },
Expand Down
5 changes: 3 additions & 2 deletions src/engine/Resource/Texture/TextureResource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ namespace vg::engine
const vector<string> TextureResource::GetExtensions() const
{
vector<string> ext;
ext.push_back(".psd");
ext.push_back(".tga");
ext.push_back(".hdr");
ext.push_back(".jpg");
ext.push_back(".png");
ext.push_back(".psd");
ext.push_back(".tga");
return ext;
}

Expand Down
45 changes: 40 additions & 5 deletions src/gfx/Importer/TextureImporter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace vg::gfx
TextureImporterFormat srcFormat, dstFormat;
if (isHDR)
{
data = (u8 *)stbi_loadf(_path.c_str(), &srcWidth, &srcHeight, &srcChannels, 4);
data = (float *)stbi_loadf(_path.c_str(), &srcWidth, &srcHeight, &srcChannels, 4);
srcFormat = TextureImporterFormat::RGBA32f;
}
else if (is16bits)
Expand Down Expand Up @@ -231,6 +231,20 @@ namespace vg::gfx
vector<float4> tempBuffer;
switch (dstFormat)
{
case TextureImporterFormat::RGBA8:
{
success |= generateMipmaps<float4>((float4 *)data, _desc, tempBuffer);
success |= convert<float4, UByte4>(_desc, tempBuffer, _finalBuffer);
}
break;

case TextureImporterFormat::RGBA16:
{
success |= generateMipmaps<float4>((float4 *)data, _desc, tempBuffer);
success |= convert<float4, UShort4>(_desc, tempBuffer, _finalBuffer);
}
break;

case TextureImporterFormat::RGBA32f:
{
success |= generateMipmaps<float4>((float4 *)data, _desc, tempBuffer);
Expand Down Expand Up @@ -310,6 +324,13 @@ namespace vg::gfx
return totalSize;
}

//--------------------------------------------------------------------------------------
template <typename SourceFormat> bool isHDR(const SourceFormat & _value);

template <> bool isHDR(const UByte4 & _value) { return false; }
template <> bool isHDR(const UShort4 & _value) { return false; }
template <> bool isHDR(const float4 & _value) { return any(_value > 1.0f); }

//--------------------------------------------------------------------------------------
template <typename SourceFormat> bool TextureImporter::generateMipmaps(const SourceFormat * _src, const TextureDesc & _desc, core::vector<SourceFormat> & _buffer)
{
Expand All @@ -324,6 +345,8 @@ namespace vg::gfx

SourceFormat * dst = _buffer.data();

bool hdrValuesFound = false;

for (uint s = 0; s < _desc.slices; ++s)
{
uint mipWidth = width;
Expand Down Expand Up @@ -406,10 +429,22 @@ namespace vg::gfx
break;
}

out[dstX + dstY * mipWidth].r = in[i + faceOffsetX * mipWidth + (j + faceOffsetY * mipHeight) * mipWidth * 4].r; // * 4 because we're using a 4x3 cross pattern
out[dstX + dstY * mipWidth].g = in[i + faceOffsetX * mipWidth + (j + faceOffsetY * mipHeight) * mipWidth * 4].g; // * 4 because we're using a 4x3 cross pattern
out[dstX + dstY * mipWidth].b = in[i + faceOffsetX * mipWidth + (j + faceOffsetY * mipHeight) * mipWidth * 4].b; // * 4 because we're using a 4x3 cross pattern
out[dstX + dstY * mipWidth].a = in[i + faceOffsetX * mipWidth + (j + faceOffsetY * mipHeight) * mipWidth * 4].a; // * 4 because we're using a 4x3 cross pattern
const auto & srcTexel = in[i + faceOffsetX * mipWidth + (j + faceOffsetY * mipHeight) * mipWidth * 4]; // * 4 because we're using a 4x3 cross pattern
auto & dstTexel = out[dstX + dstY * mipWidth];

if (!hdrValuesFound)
{
if (isHDR(srcTexel))
{
VG_WARNING("[Import] At least one HDR value has been found importing cubemap file");
hdrValuesFound = true;
}
}

dstTexel.r = srcTexel.r;
dstTexel.g = srcTexel.g;
dstTexel.b = srcTexel.b;
dstTexel.a = srcTexel.a;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/Importer/TextureImporterData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace vg::renderer
{
static const u32 TextureImporterDataVersion = 3;
static const u32 TextureImporterDataVersion = 4;

//--------------------------------------------------------------------------------------
bool TextureImporterData::load(const core::string & _file)
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#define VG_FRAMEWORK_VERSION_MAJOR 0
#define VG_FRAMEWORK_VERSION_MINOR 41
#define VG_FRAMEWORK_VERSION_PATCH 0
#define VG_FRAMEWORK_VERSION_PATCH 1

0 comments on commit a2c52d0

Please sign in to comment.