Terrain Virtual Texture (#422)

This commit is contained in:
Turánszki János
2022-05-02 10:34:27 +02:00
committed by GitHub
parent a055c80d1c
commit 18108223df
25 changed files with 491 additions and 864 deletions
+1 -3
View File
@@ -54,7 +54,6 @@ void AnimationWindow::Create(EditorComponent* editor)
else
{
animation->Play();
animation->amount = 0;
}
}
});
@@ -87,7 +86,7 @@ void AnimationWindow::Create(EditorComponent* editor)
timerSlider.SetTooltip("Set the animation timer by hand.");
AddWidget(&timerSlider);
amountSlider.Create(0, 1, 0, 100000, "Amount: ");
amountSlider.Create(0, 1, 1, 100000, "Amount: ");
amountSlider.SetSize(XMFLOAT2(250, hei));
amountSlider.SetPos(XMFLOAT2(x, y += step));
amountSlider.OnSlide([&](wi::gui::EventArgs args) {
@@ -169,7 +168,6 @@ void AnimationWindow::Update()
if (animation.IsPlaying())
{
playButton.SetText("Pause");
animation.amount = wi::math::Lerp(animation.amount, 1, 0.1f);
}
else
{
+3 -3
View File
@@ -374,9 +374,8 @@ void EditorComponent::Load()
if (terragen.terrainEntity == INVALID_ENTITY)
{
// Customize terrain generator before it's initialized:
terragen.material_Base.SetUseVertexColors(true);
terragen.material_Base.SetRoughness(1);
terragen.material_Slope.SetRoughness(0.5f);
terragen.material_Slope.SetRoughness(0.1f);
terragen.material_LowAltitude.SetRoughness(1);
terragen.material_HighAltitude.SetRoughness(1);
terragen.material_Base.textures[MaterialComponent::BASECOLORMAP].name = "terrain/base.jpg";
@@ -750,6 +749,7 @@ void EditorComponent::Load()
wi::resourcemanager::Mode embed_mode = (wi::resourcemanager::Mode)saveModeComboBox.GetItemUserData(saveModeComboBox.GetSelected());
wi::resourcemanager::SetMode(embed_mode);
terragen.BakeVirtualTexturesToFiles();
scene.Serialize(archive);
if (dump_to_header)
@@ -1902,7 +1902,7 @@ void EditorComponent::Update(float dt)
pathTraceStatisticsLabel.SetText(ss);
}
terragen.Generation_Update();
terragen.Generation_Update(camera);
wi::profiler::EndRange(profrange);
+22 -138
View File
@@ -14,21 +14,22 @@ using namespace wi::scene;
void MeshWindow::Create(EditorComponent* editor)
{
wi::gui::Window::Create("Mesh Window");
SetSize(XMFLOAT2(580, 600));
SetSize(XMFLOAT2(580, 580));
float x = 150;
float y = 0;
float hei = 18;
float step = hei + 2;
float infolabel_height = 190;
meshInfoLabel.Create("Mesh Info");
meshInfoLabel.SetPos(XMFLOAT2(x - 50, y += step));
meshInfoLabel.SetSize(XMFLOAT2(450, 190));
meshInfoLabel.SetSize(XMFLOAT2(450, infolabel_height));
meshInfoLabel.SetColor(wi::Color::Transparent());
AddWidget(&meshInfoLabel);
// Left side:
y = meshInfoLabel.GetScale().y + 5;
y = infolabel_height + 10;
subsetComboBox.Create("Selected subset: ");
subsetComboBox.SetSize(XMFLOAT2(40, hei));
@@ -49,35 +50,6 @@ void MeshWindow::Create(EditorComponent* editor)
subsetComboBox.SetTooltip("Select a subset. A subset can also be selected by picking it in the 3D scene.");
AddWidget(&subsetComboBox);
terrainCheckBox.Create("Terrain: ");
terrainCheckBox.SetTooltip("If enabled, the mesh will use multiple materials and blend between them based on vertex colors.");
terrainCheckBox.SetSize(XMFLOAT2(hei, hei));
terrainCheckBox.SetPos(XMFLOAT2(x, y += step));
terrainCheckBox.OnClick([&](wi::gui::EventArgs args) {
MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
if (mesh != nullptr)
{
mesh->SetTerrain(args.bValue);
if (args.bValue && mesh->vertex_colors.empty())
{
mesh->vertex_colors.resize(mesh->vertex_positions.size());
std::fill(mesh->vertex_colors.begin(), mesh->vertex_colors.end(), wi::Color::Red().rgba); // fill red (meaning only blend base material)
mesh->CreateRenderData();
for (auto& subset : mesh->subsets)
{
MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(subset.materialID);
if (material != nullptr)
{
material->SetUseVertexColors(true);
}
}
}
SetEntity(entity, subset); // refresh information label
}
});
AddWidget(&terrainCheckBox);
doubleSidedCheckBox.Create("Double Sided: ");
doubleSidedCheckBox.SetTooltip("If enabled, the inside of the mesh will be visible.");
doubleSidedCheckBox.SetSize(XMFLOAT2(hei, hei));
@@ -165,14 +137,14 @@ void MeshWindow::Create(EditorComponent* editor)
impostorCreateButton.SetSize(XMFLOAT2(200, hei));
impostorCreateButton.SetPos(XMFLOAT2(x - 50, y += step));
impostorCreateButton.OnClick([&](wi::gui::EventArgs args) {
Scene& scene = wi::scene::GetScene();
Scene& scene = wi::scene::GetScene();
ImpostorComponent* impostor = scene.impostors.GetComponent(entity);
if (impostor == nullptr)
if (impostor == nullptr)
{
impostorCreateButton.SetText("Delete Impostor");
impostorCreateButton.SetText("Delete Impostor");
scene.impostors.Create(entity).swapInDistance = impostorDistanceSlider.GetValue();
}
else
else
{
impostorCreateButton.SetText("Create Impostor");
scene.impostors.Remove(entity);
@@ -497,10 +469,12 @@ void MeshWindow::Create(EditorComponent* editor)
AddWidget(&optimizeButton);
// Right side:
// Right side:
x = 150;
y = meshInfoLabel.GetScale().y + 5;
y = infolabel_height + 10;
subsetMaterialComboBox.Create("Subset Material: ");
subsetMaterialComboBox.SetSize(XMFLOAT2(200, hei));
@@ -526,82 +500,16 @@ void MeshWindow::Create(EditorComponent* editor)
subsetMaterialComboBox.SetTooltip("Set the base material of the selected MeshSubset");
AddWidget(&subsetMaterialComboBox);
terrainMat1Combo.Create("Terrain Material 1: ");
terrainMat1Combo.SetSize(XMFLOAT2(200, hei));
terrainMat1Combo.SetPos(XMFLOAT2(x + 180, y += step));
terrainMat1Combo.SetEnabled(false);
terrainMat1Combo.OnSelect([&](wi::gui::EventArgs args) {
MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
if (mesh != nullptr)
{
if (args.iValue == 0)
{
mesh->terrain_material1 = INVALID_ENTITY;
}
else
{
Scene& scene = wi::scene::GetScene();
mesh->terrain_material1 = scene.materials.GetEntity(args.iValue - 1);
}
}
});
terrainMat1Combo.SetTooltip("Choose a sub terrain blend material. (GREEN vertex color mask)");
AddWidget(&terrainMat1Combo);
terrainMat2Combo.Create("Terrain Material 2: ");
terrainMat2Combo.SetSize(XMFLOAT2(200, hei));
terrainMat2Combo.SetPos(XMFLOAT2(x + 180, y += step));
terrainMat2Combo.SetEnabled(false);
terrainMat2Combo.OnSelect([&](wi::gui::EventArgs args) {
MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
if (mesh != nullptr)
{
if (args.iValue == 0)
{
mesh->terrain_material2 = INVALID_ENTITY;
}
else
{
Scene& scene = wi::scene::GetScene();
mesh->terrain_material2 = scene.materials.GetEntity(args.iValue - 1);
}
}
});
terrainMat2Combo.SetTooltip("Choose a sub terrain blend material. (BLUE vertex color mask)");
AddWidget(&terrainMat2Combo);
terrainMat3Combo.Create("Terrain Material 3: ");
terrainMat3Combo.SetSize(XMFLOAT2(200, hei));
terrainMat3Combo.SetPos(XMFLOAT2(x + 180, y += step));
terrainMat3Combo.SetEnabled(false);
terrainMat3Combo.OnSelect([&](wi::gui::EventArgs args) {
MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
if (mesh != nullptr)
{
if (args.iValue == 0)
{
mesh->terrain_material3 = INVALID_ENTITY;
}
else
{
Scene& scene = wi::scene::GetScene();
mesh->terrain_material3 = scene.materials.GetEntity(args.iValue - 1);
}
}
});
terrainMat3Combo.SetTooltip("Choose a sub terrain blend material. (ALPHA vertex color mask)");
AddWidget(&terrainMat3Combo);
morphTargetCombo.Create("Morph Target:");
morphTargetCombo.SetSize(XMFLOAT2(100, hei));
morphTargetCombo.SetPos(XMFLOAT2(x + 280, y += step));
morphTargetCombo.OnSelect([&](wi::gui::EventArgs args) {
MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
if (mesh != nullptr && args.iValue < (int)mesh->targets.size())
{
MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
if (mesh != nullptr && args.iValue < (int)mesh->targets.size())
{
morphTargetSlider.SetValue(mesh->targets[args.iValue].weight);
}
}
});
morphTargetCombo.SetTooltip("Choose a morph target to edit weight.");
AddWidget(&morphTargetCombo);
@@ -611,12 +519,12 @@ void MeshWindow::Create(EditorComponent* editor)
morphTargetSlider.SetSize(XMFLOAT2(100, hei));
morphTargetSlider.SetPos(XMFLOAT2(x + 280, y += step));
morphTargetSlider.OnSlide([&](wi::gui::EventArgs args) {
MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
if (mesh != nullptr && morphTargetCombo.GetSelected() < (int)mesh->targets.size())
{
MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
if (mesh != nullptr && morphTargetCombo.GetSelected() < (int)mesh->targets.size())
{
mesh->targets[morphTargetCombo.GetSelected()].weight = args.fValue;
mesh->dirty_morph = true;
}
}
});
AddWidget(&morphTargetSlider);
@@ -793,11 +701,8 @@ void MeshWindow::SetEntity(Entity entity, int subset)
if (mesh->vb_tan.IsValid()) ss += "tangent; ";
if (mesh->so_pos_nor_wind.IsValid()) ss += "streamout_position; ";
if (mesh->so_tan.IsValid()) ss += "streamout_tangents; ";
if (mesh->IsTerrain()) ss += "\n\nTerrain will use 4 blend materials and blend by vertex colors, the default one is always the subset material and uses RED vertex color channel mask, the other 3 are selectable below.";
meshInfoLabel.SetText(ss);
terrainCheckBox.SetCheck(mesh->IsTerrain());
subsetComboBox.ClearItems();
for (size_t i = 0; i < mesh->subsets.size(); ++i)
{
@@ -810,37 +715,16 @@ void MeshWindow::SetEntity(Entity entity, int subset)
subsetMaterialComboBox.ClearItems();
subsetMaterialComboBox.AddItem("NO MATERIAL");
terrainMat1Combo.ClearItems();
terrainMat1Combo.AddItem("OFF (Use subset)");
terrainMat2Combo.ClearItems();
terrainMat2Combo.AddItem("OFF (Use subset)");
terrainMat3Combo.ClearItems();
terrainMat3Combo.AddItem("OFF (Use subset)");
for (size_t i = 0; i < scene.materials.GetCount(); ++i)
{
Entity entity = scene.materials.GetEntity(i);
const NameComponent& name = *scene.names.GetComponent(entity);
subsetMaterialComboBox.AddItem(name.name);
terrainMat1Combo.AddItem(name.name);
terrainMat2Combo.AddItem(name.name);
terrainMat3Combo.AddItem(name.name);
if (subset >= 0 && subset < mesh->subsets.size() && mesh->subsets[subset].materialID == entity)
{
subsetMaterialComboBox.SetSelected((int)i + 1);
}
if (mesh->terrain_material1 == entity)
{
terrainMat1Combo.SetSelected((int)i + 1);
}
if (mesh->terrain_material2 == entity)
{
terrainMat2Combo.SetSelected((int)i + 1);
}
if (mesh->terrain_material3 == entity)
{
terrainMat3Combo.SetSelected((int)i + 1);
}
}
doubleSidedCheckBox.SetCheck(mesh->IsDoubleSided());
@@ -867,11 +751,11 @@ void MeshWindow::SetEntity(Entity entity, int subset)
morphTargetCombo.ClearItems();
for (size_t i = 0; i < mesh->targets.size(); i++)
{
morphTargetCombo.AddItem(std::to_string(i).c_str());
morphTargetCombo.AddItem(std::to_string(i).c_str());
}
if (selected < mesh->targets.size())
{
morphTargetCombo.SetSelected(selected);
morphTargetCombo.SetSelected(selected);
}
SetEnabled(true);
-6
View File
@@ -5,7 +5,6 @@ class EditorComponent;
class MeshWindow : public wi::gui::Window
{
bool terragen_initialized = false;
public:
void Create(EditorComponent* editor);
@@ -33,11 +32,6 @@ public:
wi::gui::Button mergeButton;
wi::gui::Button optimizeButton;
wi::gui::CheckBox terrainCheckBox;
wi::gui::ComboBox terrainMat1Combo;
wi::gui::ComboBox terrainMat2Combo;
wi::gui::ComboBox terrainMat3Combo;
wi::gui::ComboBox morphTargetCombo;
wi::gui::Slider morphTargetSlider;
File diff suppressed because it is too large Load Diff
+23 -11
View File
@@ -29,27 +29,28 @@ namespace std
};
}
inline static const int chunk_width = 64 + 3; // + 3: filler vertices for lod apron and grid perimeter
inline static const float chunk_half_width = (chunk_width - 1) * 0.5f;
inline static const float chunk_width_rcp = 1.0f / (chunk_width - 1);
inline static const uint32_t vertexCount = chunk_width * chunk_width;
inline static const int max_lod = (int)std::log2(chunk_width - 3) + 1;
struct ChunkData
{
wi::ecs::Entity entity = wi::ecs::INVALID_ENTITY;
wi::ecs::Entity grass_entity = wi::ecs::INVALID_ENTITY;
wi::HairParticleSystem grass;
bool grass_exists = false;
std::mt19937 prop_rand;
wi::Color region_weights[vertexCount] = {};
wi::graphics::Texture region_weights_texture;
uint32_t virtual_texture_resolution = 0;
wi::primitive::Sphere sphere;
};
struct TerrainGenerator : public wi::gui::Window
{
inline static const int chunk_width = 64 + 3; // + 3: filler vertices for lod apron and grid perimeter
inline static const float chunk_half_width = (chunk_width - 1) * 0.5f;
inline static const float chunk_width_rcp = 1.0f / (chunk_width - 1);
inline static const uint32_t vertexCount = chunk_width * chunk_width;
inline static const int max_lod = (int)std::log2(chunk_width - 3) + 1;
wi::scene::Scene* scene = &wi::scene::GetScene(); // by default it uses the global scene, but this can be changed
wi::ecs::Entity terrainEntity = wi::ecs::INVALID_ENTITY;
wi::ecs::Entity materialEntity_Base = wi::ecs::INVALID_ENTITY;
wi::ecs::Entity materialEntity_Slope = wi::ecs::INVALID_ENTITY;
wi::ecs::Entity materialEntity_LowAltitude = wi::ecs::INVALID_ENTITY;
wi::ecs::Entity materialEntity_HighAltitude = wi::ecs::INVALID_ENTITY;
wi::scene::Scene* scene = &wi::scene::GetScene(); // by default it uses the global scene, but this can be changed
wi::scene::MaterialComponent material_Base;
wi::scene::MaterialComponent material_Slope;
wi::scene::MaterialComponent material_LowAltitude;
@@ -99,9 +100,18 @@ struct TerrainGenerator : public wi::gui::Window
std::atomic_bool generation_cancelled;
float generation_time_budget_milliseconds = 12; // after this much time, the generation thread will exit. This can help avoid a very long running, resource consuming and slow cancellation generation
// Virtual texture updates will be batched like:
// 1) Execute all barriers (dst: UNORDERED_ACCESS)
// 2) Execute all compute shaders
// 3) Execute all barriers (dst: SHADER_RESOURCE)
wi::vector<Chunk> virtual_texture_updates;
wi::vector<wi::graphics::GPUBarrier> virtual_texture_barriers_begin;
wi::vector<wi::graphics::GPUBarrier> virtual_texture_barriers_end;
wi::gui::CheckBox centerToCamCheckBox;
wi::gui::CheckBox removalCheckBox;
wi::gui::Slider lodSlider;
wi::gui::Slider texlodSlider;
wi::gui::Slider generationSlider;
wi::gui::ComboBox presetCombo;
wi::gui::Slider seedSlider;
@@ -130,8 +140,10 @@ struct TerrainGenerator : public wi::gui::Window
// This will remove previously existing terrain
void Generation_Restart();
// This will run the actual generation tasks, call it once per frame
void Generation_Update();
void Generation_Update(const wi::scene::CameraComponent& camera);
// Tells the generation thread that it should be cancelled and blocks until that is confirmed
void Generation_Cancel();
// The virtual textures will be compressed and saved into resources. They can be serialized from there
void BakeVirtualTexturesToFiles();
};
+1 -1
View File
@@ -605,7 +605,7 @@ void WeatherWindow::Create(EditorComponent* editor)
ktxConvButton.Create("KTX2 Convert");
ktxConvButton.SetTooltip("All material textures in the scene will be cinverted to KTX2 format.\nTHIS MIGHT TAKE LONG, SO GET YOURSELF A COFFEE OR TEA!");
ktxConvButton.SetTooltip("All material textures in the scene will be converted to KTX2 format.\nTHIS MIGHT TAKE LONG, SO GET YOURSELF A COFFEE OR TEA!");
ktxConvButton.SetSize(XMFLOAT2(colorPicker.GetScale().x, hei));
ktxConvButton.SetPos(XMFLOAT2(x, y += step));
ktxConvButton.OnClick([=](wi::gui::EventArgs args) {
+1
View File
@@ -1,5 +1,6 @@
This file contains changelog of wi::Archive versions
79: removed terrain blend materials from mesh
78: serialized stars parameter in weather
77: serialized cloud shadow properties
76: serialized LOD parameters
+1 -3
View File
@@ -246,6 +246,7 @@ int main(int argc, char* argv[])
"ddgi_raytraceCS_rtapi.hlsl",
"ddgi_updateCS.hlsl",
"ddgi_updateCS_depth.hlsl",
"terrainVirtualTextureUpdateCS.hlsl",
};
shaders[static_cast<size_t>(ShaderStage::PS)] = {
@@ -275,12 +276,10 @@ int main(int argc, char* argv[])
"objectPS_transparent_pom.hlsl" ,
"objectPS_water.hlsl" ,
"objectPS_voxelizer.hlsl" ,
"objectPS_voxelizer_terrain.hlsl" ,
"objectPS_transparent.hlsl" ,
"objectPS_transparent_planarreflection.hlsl" ,
"objectPS_planarreflection.hlsl" ,
"objectPS_pom.hlsl" ,
"objectPS_terrain.hlsl" ,
"objectPS.hlsl" ,
"objectPS_hologram.hlsl" ,
"objectPS_paintradius.hlsl" ,
@@ -312,7 +311,6 @@ int main(int argc, char* argv[])
"envMap_skyPS_static.hlsl" ,
"envMap_skyPS_dynamic.hlsl" ,
"envMapPS.hlsl" ,
"envMapPS_terrain.hlsl" ,
"emittedparticlePS_soft_distortion.hlsl" ,
"downsampleDepthBuffer4xPS.hlsl" ,
"emittedparticlePS_simple.hlsl" ,
@@ -159,10 +159,8 @@ struct ShaderGeometry
int vb_atl;
int vb_pre;
uint3 padding;
uint materialIndex;
uint blendmaterial1;
uint blendmaterial2;
uint blendmaterial3;
float3 aabb_min;
uint flags;
@@ -182,9 +180,6 @@ struct ShaderGeometry
vb_pre = -1;
materialIndex = 0;
blendmaterial1 = 0;
blendmaterial2 = 0;
blendmaterial3 = 0;
aabb_min = float3(0, 0, 0);
flags = 0;
+4 -31
View File
@@ -1062,6 +1062,10 @@
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.0</ShaderModel>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)terrainVirtualTextureUpdateCS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.0</ShaderModel>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)underwaterCS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.0</ShaderModel>
@@ -1447,16 +1451,6 @@
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Pixel</ShaderType>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)envMapPS_terrain.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Pixel</ShaderType>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)envMapVS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
@@ -2205,17 +2199,6 @@
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Pixel</ShaderType>
<FileType>Document</FileType>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)objectPS_terrain.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Pixel</ShaderType>
<FileType>Document</FileType>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)objectPS_transparent.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
@@ -2270,16 +2253,6 @@
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Pixel</ShaderType>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)objectPS_voxelizer_terrain.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">Pixel</ShaderType>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)objectVS_common.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
@@ -551,9 +551,6 @@
<FxCompile Include="$(MSBuildThisFileDirectory)objectPS_voxelizer.hlsl">
<Filter>PS</Filter>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)objectPS_voxelizer_terrain.hlsl">
<Filter>PS</Filter>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)objectPS_hologram.hlsl">
<Filter>PS</Filter>
</FxCompile>
@@ -596,9 +593,6 @@
<FxCompile Include="$(MSBuildThisFileDirectory)envMapPS.hlsl">
<Filter>PS</Filter>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)envMapPS_terrain.hlsl">
<Filter>PS</Filter>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)emittedparticlePS_soft_distortion.hlsl">
<Filter>PS</Filter>
</FxCompile>
@@ -764,9 +758,6 @@
<FxCompile Include="$(MSBuildThisFileDirectory)objectPS_pom.hlsl">
<Filter>PS</Filter>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)objectPS_terrain.hlsl">
<Filter>PS</Filter>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)objectPS_transparent.hlsl">
<Filter>PS</Filter>
</FxCompile>
@@ -1052,6 +1043,9 @@
<FxCompile Include="$(MSBuildThisFileDirectory)underwaterCS.hlsl">
<Filter>CS</Filter>
</FxCompile>
<FxCompile Include="$(MSBuildThisFileDirectory)terrainVirtualTextureUpdateCS.hlsl">
<Filter>CS</Filter>
</FxCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)ShaderInterop.h">
@@ -1,2 +0,0 @@
#define TERRAIN
#include "envMapPS.hlsl"
-307
View File
@@ -40,18 +40,6 @@ inline ShaderMaterial GetMaterial()
{
return load_material(push.GetMaterialIndex());
}
inline ShaderMaterial GetMaterial1()
{
return load_material(GetMesh().blendmaterial1);
}
inline ShaderMaterial GetMaterial2()
{
return load_material(GetMesh().blendmaterial2);
}
inline ShaderMaterial GetMaterial3()
{
return load_material(GetMesh().blendmaterial3);
}
#define sampler_objectshader bindless_samplers[GetFrame().sampler_objectshader_index]
@@ -69,21 +57,6 @@ inline ShaderMaterial GetMaterial3()
#define texture_clearcoatnormalmap bindless_textures[GetMaterial().texture_clearcoatnormalmap_index]
#define texture_specularmap bindless_textures[GetMaterial().texture_specularmap_index]
#define texture_blend1_basecolormap bindless_textures[GetMaterial1().texture_basecolormap_index]
#define texture_blend1_normalmap bindless_textures[GetMaterial1().texture_normalmap_index]
#define texture_blend1_surfacemap bindless_textures[GetMaterial1().texture_surfacemap_index]
#define texture_blend1_emissivemap bindless_textures[GetMaterial1().texture_emissivemap_index]
#define texture_blend2_basecolormap bindless_textures[GetMaterial2().texture_basecolormap_index]
#define texture_blend2_normalmap bindless_textures[GetMaterial2().texture_normalmap_index]
#define texture_blend2_surfacemap bindless_textures[GetMaterial2().texture_surfacemap_index]
#define texture_blend2_emissivemap bindless_textures[GetMaterial2().texture_emissivemap_index]
#define texture_blend3_basecolormap bindless_textures[GetMaterial3().texture_basecolormap_index]
#define texture_blend3_normalmap bindless_textures[GetMaterial3().texture_normalmap_index]
#define texture_blend3_surfacemap bindless_textures[GetMaterial3().texture_surfacemap_index]
#define texture_blend3_emissivemap bindless_textures[GetMaterial3().texture_emissivemap_index]
uint load_entitytile(uint tileIndex)
{
#ifdef TRANSPARENT
@@ -1050,7 +1023,6 @@ PixelInput main(VertexInput input)
// PLANARREFLECTION - include planar reflection sampling
// POM - include parallax occlusion mapping computation
// WATER - include specialized water shader code
// TERRAIN - include specialized terrain material blending code
#ifdef DISABLE_ALPHATEST
[earlydepthstencil]
@@ -1212,285 +1184,6 @@ float4 main(PixelInput input, in bool is_frontface : SV_IsFrontFace) : SV_Target
#ifdef TERRAIN
color = 1;
surface.N = 0;
surface.albedo = 0;
surface.f0 = 0;
surface.roughness = 0;
surface.occlusion = 0;
surface.emissiveColor = 0;
surface.opacity = 1;
float4 sam;
float4 blend_weights = input.color;
blend_weights /= blend_weights.x + blend_weights.y + blend_weights.z + blend_weights.w;
float3 baseN = normalize(input.nor);
[branch]
if (blend_weights.x > 0)
{
float4 color2 = GetMaterial().baseColor;
#ifdef OBJECTSHADER_USE_UVSETS
[branch]
if (GetMaterial().uvset_baseColorMap >= 0 && (GetFrame().options & OPTION_BIT_DISABLE_ALBEDO_MAPS) == 0)
{
float2 uv = GetMaterial().uvset_baseColorMap == 0 ? uvsets.xy : uvsets.zw;
float4 basecolorMap = texture_basecolormap.Sample(sampler_objectshader, uv);
basecolorMap.rgb = DEGAMMA(basecolorMap.rgb);
color2 *= basecolorMap;
}
#endif // OBJECTSHADER_USE_UVSETS
float4 surfaceMap2 = 1;
#ifdef OBJECTSHADER_USE_UVSETS
[branch]
if (GetMaterial().uvset_surfaceMap >= 0)
{
float2 uv = GetMaterial().uvset_surfaceMap == 0 ? uvsets.xy : uvsets.zw;
surfaceMap2 = texture_surfacemap.Sample(sampler_objectshader, uv);
}
#endif // OBJECTSHADER_USE_UVSETS
Surface surface2;
surface2.N = baseN;
surface2.create(GetMaterial(), color2, surfaceMap2);
#ifdef OBJECTSHADER_USE_UVSETS
[branch]
if (GetMaterial().normalMapStrength > 0 && GetMaterial().uvset_normalMap >= 0)
{
float2 uv = GetMaterial().uvset_normalMap == 0 ? uvsets.xy : uvsets.zw;
sam.rgb = texture_normalmap.Sample(sampler_objectshader, uv).rgb;
sam.rgb = sam.rgb * 2 - 1;
surface2.N = lerp(baseN, mul(sam.rgb, TBN), GetMaterial().normalMapStrength);
}
#endif // OBJECTSHADER_USE_UVSETS
surface2.emissiveColor = GetMaterial().GetEmissive();
#ifdef OBJECTSHADER_USE_UVSETS
[branch]
if (GetMaterial().uvset_emissiveMap >= 0 && any(surface2.emissiveColor))
{
float2 uv = GetMaterial().uvset_emissiveMap == 0 ? uvsets.xy : uvsets.zw;
sam = texture_emissivemap.Sample(sampler_objectshader, uv);
sam.rgb = DEGAMMA(sam.rgb);
surface2.emissiveColor *= sam.rgb * sam.a;
}
#endif // OBJECTSHADER_USE_UVSETS
surface.N += surface2.N * blend_weights.x;
surface.albedo += surface2.albedo * blend_weights.x;
surface.f0 += surface2.f0 * blend_weights.x;
surface.roughness += surface2.roughness * blend_weights.x;
surface.occlusion += surface2.occlusion * blend_weights.x;
surface.emissiveColor += surface2.emissiveColor * blend_weights.x;
}
[branch]
if (blend_weights.y > 0)
{
float4 color2 = GetMaterial1().baseColor;
float4 uvsets = input.uvsets;
uvsets.xy = mad(uvsets.xy, GetMaterial1().texMulAdd.xy, GetMaterial1().texMulAdd.zw);
#ifdef OBJECTSHADER_USE_UVSETS
[branch]
if (GetMaterial1().uvset_baseColorMap >= 0 && (GetFrame().options & OPTION_BIT_DISABLE_ALBEDO_MAPS) == 0)
{
float2 uv = GetMaterial1().uvset_baseColorMap == 0 ? uvsets.xy : uvsets.zw;
float4 basecolorMap = texture_blend1_basecolormap.Sample(sampler_objectshader, uv);
basecolorMap.rgb = DEGAMMA(basecolorMap.rgb);
color2 *= basecolorMap;
}
#endif // OBJECTSHADER_USE_UVSETS
float4 surfaceMap2 = 1;
#ifdef OBJECTSHADER_USE_UVSETS
[branch]
if (GetMaterial1().uvset_surfaceMap >= 0)
{
float2 uv = GetMaterial1().uvset_surfaceMap == 0 ? uvsets.xy : uvsets.zw;
surfaceMap2 = texture_blend1_surfacemap.Sample(sampler_objectshader, uv);
}
#endif // OBJECTSHADER_USE_UVSETS
Surface surface2;
surface2.N = baseN;
surface2.create(GetMaterial1(), color2, surfaceMap2);
#ifdef OBJECTSHADER_USE_UVSETS
[branch]
if (GetMaterial1().normalMapStrength > 0 && GetMaterial1().uvset_normalMap >= 0)
{
float2 uv = GetMaterial1().uvset_normalMap == 0 ? uvsets.xy : uvsets.zw;
sam.rgb = texture_blend1_normalmap.Sample(sampler_objectshader, uv).rgb;
sam.rgb = sam.rgb * 2 - 1;
surface2.N = lerp(baseN, mul(sam.rgb, TBN), GetMaterial1().normalMapStrength);
}
#endif // OBJECTSHADER_USE_UVSETS
surface2.emissiveColor = GetMaterial1().GetEmissive();
#ifdef OBJECTSHADER_USE_UVSETS
[branch]
if (GetMaterial1().uvset_emissiveMap >= 0 && any(surface2.emissiveColor))
{
float2 uv = GetMaterial1().uvset_emissiveMap == 0 ? uvsets.xy : uvsets.zw;
sam = texture_blend1_emissivemap.Sample(sampler_objectshader, uv);
sam.rgb = DEGAMMA(sam.rgb);
surface2.emissiveColor *= sam.rgb * sam.a;
}
#endif // OBJECTSHADER_USE_UVSETS
surface.N += surface2.N * blend_weights.y;
surface.albedo += surface2.albedo * blend_weights.y;
surface.f0 += surface2.f0 * blend_weights.y;
surface.roughness += surface2.roughness * blend_weights.y;
surface.occlusion += surface2.occlusion * blend_weights.y;
surface.emissiveColor += surface2.emissiveColor * blend_weights.y;
}
[branch]
if (blend_weights.z > 0)
{
float4 color2 = GetMaterial2().baseColor;
float4 uvsets = input.uvsets;
uvsets.xy = mad(uvsets.xy, GetMaterial2().texMulAdd.xy, GetMaterial2().texMulAdd.zw);
#ifdef OBJECTSHADER_USE_UVSETS
[branch]
if (GetMaterial2().uvset_baseColorMap >= 0 && (GetFrame().options & OPTION_BIT_DISABLE_ALBEDO_MAPS) == 0)
{
float2 uv = GetMaterial2().uvset_baseColorMap == 0 ? uvsets.xy : uvsets.zw;
float4 basecolorMap = texture_blend2_basecolormap.Sample(sampler_objectshader, uv);
basecolorMap.rgb = DEGAMMA(basecolorMap.rgb);
color2 *= basecolorMap;
}
#endif // OBJECTSHADER_USE_UVSETS
float4 surfaceMap2 = 1;
#ifdef OBJECTSHADER_USE_UVSETS
[branch]
if (GetMaterial2().uvset_surfaceMap >= 0)
{
float2 uv = GetMaterial2().uvset_surfaceMap == 0 ? uvsets.xy : uvsets.zw;
surfaceMap2 = texture_blend2_surfacemap.Sample(sampler_objectshader, uv);
}
#endif // OBJECTSHADER_USE_UVSETS
Surface surface2;
surface2.N = baseN;
surface2.create(GetMaterial2(), color2, surfaceMap2);
#ifdef OBJECTSHADER_USE_UVSETS
[branch]
if (GetMaterial2().normalMapStrength > 0 && GetMaterial2().uvset_normalMap >= 0)
{
float2 uv = GetMaterial2().uvset_normalMap == 0 ? uvsets.xy : uvsets.zw;
sam.rgb = texture_blend2_normalmap.Sample(sampler_objectshader, uv).rgb;
sam.rgb = sam.rgb * 2 - 1;
surface2.N = lerp(baseN, mul(sam.rgb, TBN), GetMaterial2().normalMapStrength);
}
#endif // OBJECTSHADER_USE_UVSETS
surface2.emissiveColor = GetMaterial2().GetEmissive();
#ifdef OBJECTSHADER_USE_UVSETS
[branch]
if (GetMaterial2().uvset_emissiveMap >= 0 && any(surface2.emissiveColor))
{
float2 uv = GetMaterial2().uvset_emissiveMap == 0 ? uvsets.xy : uvsets.zw;
sam = texture_blend2_emissivemap.Sample(sampler_objectshader, uv);
sam.rgb = DEGAMMA(sam.rgb);
surface2.emissiveColor *= sam.rgb * sam.a;
}
#endif // OBJECTSHADER_USE_UVSETS
surface.N += surface2.N * blend_weights.z;
surface.albedo += surface2.albedo * blend_weights.z;
surface.f0 += surface2.f0 * blend_weights.z;
surface.roughness += surface2.roughness * blend_weights.z;
surface.occlusion += surface2.occlusion * blend_weights.z;
surface.emissiveColor += surface2.emissiveColor * blend_weights.z;
}
[branch]
if (blend_weights.w > 0)
{
float4 color2 = GetMaterial3().baseColor;
float4 uvsets = input.uvsets;
uvsets.xy = mad(uvsets.xy, GetMaterial3().texMulAdd.xy, GetMaterial3().texMulAdd.zw);
#ifdef OBJECTSHADER_USE_UVSETS
[branch]
if (GetMaterial3().uvset_baseColorMap >= 0 && (GetFrame().options & OPTION_BIT_DISABLE_ALBEDO_MAPS) == 0)
{
float2 uv = GetMaterial3().uvset_baseColorMap == 0 ? uvsets.xy : uvsets.zw;
float4 basecolorMap = texture_blend3_basecolormap.Sample(sampler_objectshader, uv);
basecolorMap.rgb = DEGAMMA(basecolorMap.rgb);
color2 *= basecolorMap;
}
#endif // OBJECTSHADER_USE_UVSETS
float4 surfaceMap2 = 1;
#ifdef OBJECTSHADER_USE_UVSETS
[branch]
if (GetMaterial3().uvset_surfaceMap >= 0)
{
float2 uv = GetMaterial3().uvset_surfaceMap == 0 ? uvsets.xy : uvsets.zw;
surfaceMap2 = texture_blend3_surfacemap.Sample(sampler_objectshader, uv);
}
#endif // OBJECTSHADER_USE_UVSETS
Surface surface2;
surface2.N = baseN;
surface2.create(GetMaterial3(), color2, surfaceMap2);
#ifdef OBJECTSHADER_USE_UVSETS
[branch]
if (GetMaterial3().normalMapStrength > 0 && GetMaterial3().uvset_normalMap >= 0)
{
float2 uv = GetMaterial3().uvset_normalMap == 0 ? uvsets.xy : uvsets.zw;
sam.rgb = texture_blend3_normalmap.Sample(sampler_objectshader, uv).rgb;
sam.rgb = sam.rgb * 2 - 1;
surface2.N = lerp(baseN, mul(sam.rgb, TBN), GetMaterial3().normalMapStrength);
}
#endif // OBJECTSHADER_USE_UVSETS
surface2.emissiveColor = GetMaterial3().GetEmissive();
#ifdef OBJECTSHADER_USE_UVSETS
[branch]
if (GetMaterial3().uvset_emissiveMap >= 0 && any(surface2.emissiveColor))
{
float2 uv = GetMaterial3().uvset_emissiveMap == 0 ? uvsets.xy : uvsets.zw;
sam = texture_blend3_emissivemap.Sample(sampler_objectshader, uv);
sam.rgb = DEGAMMA(sam.rgb);
surface2.emissiveColor *= sam.rgb * sam.a;
}
#endif // OBJECTSHADER_USE_UVSETS
surface.N += surface2.N * blend_weights.w;
surface.albedo += surface2.albedo * blend_weights.w;
surface.f0 += surface2.f0 * blend_weights.w;
surface.roughness += surface2.roughness * blend_weights.w;
surface.occlusion += surface2.occlusion * blend_weights.w;
surface.emissiveColor += surface2.emissiveColor * blend_weights.w;
}
surface.N = normalize(surface.N);
#endif // TERRAIN
#ifdef OBJECTSHADER_USE_EMISSIVE
surface.emissiveColor *= Unpack_R11G11B10_FLOAT(input.emissiveColor);
#endif // OBJECTSHADER_USE_EMISSIVE
@@ -1,8 +0,0 @@
#define OBJECTSHADER_COMPILE_PS
#define OBJECTSHADER_LAYOUT_COMMON
#define SHADOW_MASK_ENABLED
#define OUTPUT_GBUFFER
#define TILEDFORWARD
#define DISABLE_ALPHATEST
#define TERRAIN
#include "objectHF.hlsli"
@@ -51,122 +51,6 @@ void main(PSInput input)
emissiveColor *= emissiveMap.rgb * emissiveMap.a;
}
#ifdef TERRAIN
color = 0;
emissiveColor = 0;
float4 blend_weights = input.color;
blend_weights /= blend_weights.x + blend_weights.y + blend_weights.z + blend_weights.w;
float4 sam;
[branch]
if (blend_weights.x > 0)
{
[branch]
if (GetMaterial().uvset_baseColorMap >= 0 && (GetFrame().options & OPTION_BIT_DISABLE_ALBEDO_MAPS) == 0)
{
float2 uv = GetMaterial().uvset_baseColorMap == 0 ? input.uvsets.xy : input.uvsets.zw;
sam = texture_basecolormap.Sample(sampler_objectshader, uv);
sam.rgb = DEGAMMA(sam.rgb);
}
else
{
sam = 1;
}
color += sam * GetMaterial().baseColor * blend_weights.x;
[branch]
if (GetMaterial().uvset_emissiveMap >= 0 && any(GetMaterial().GetEmissive()))
{
float2 uv = GetMaterial().uvset_emissiveMap == 0 ? input.uvsets.xy : input.uvsets.zw;
sam = texture_emissivemap.Sample(sampler_objectshader, uv);
sam.rgb = DEGAMMA(sam.rgb);
emissiveColor += sam.rgb * sam.a * GetMaterial().GetEmissive() * blend_weights.x;
}
}
[branch]
if (blend_weights.y > 0)
{
[branch]
if (GetMaterial1().uvset_baseColorMap >= 0 && (GetFrame().options & OPTION_BIT_DISABLE_ALBEDO_MAPS) == 0)
{
float2 uv = GetMaterial1().uvset_baseColorMap == 0 ? input.uvsets.xy : input.uvsets.zw;
sam = texture_blend1_basecolormap.Sample(sampler_objectshader, uv);
sam.rgb = DEGAMMA(sam.rgb);
}
else
{
sam = 1;
}
color += sam * GetMaterial1().baseColor * blend_weights.y;
[branch]
if (GetMaterial1().uvset_emissiveMap >= 0 && any(GetMaterial1().GetEmissive()))
{
float2 uv = GetMaterial1().uvset_emissiveMap == 0 ? input.uvsets.xy : input.uvsets.zw;
sam = texture_blend1_emissivemap.Sample(sampler_objectshader, uv);
sam.rgb = DEGAMMA(sam.rgb);
emissiveColor += sam.rgb * sam.a * GetMaterial1().GetEmissive() * blend_weights.y;
}
}
[branch]
if (blend_weights.z > 0)
{
[branch]
if (GetMaterial2().uvset_baseColorMap >= 0 && (GetFrame().options & OPTION_BIT_DISABLE_ALBEDO_MAPS) == 0)
{
float2 uv = GetMaterial2().uvset_baseColorMap == 0 ? input.uvsets.xy : input.uvsets.zw;
sam = texture_blend2_basecolormap.Sample(sampler_objectshader, uv);
sam.rgb = DEGAMMA(sam.rgb);
}
else
{
sam = 1;
}
color += sam * GetMaterial2().baseColor * blend_weights.z;
[branch]
if (GetMaterial2().uvset_emissiveMap >= 0 && any(GetMaterial2().GetEmissive()))
{
float2 uv = GetMaterial2().uvset_emissiveMap == 0 ? input.uvsets.xy : input.uvsets.zw;
sam = texture_blend2_emissivemap.Sample(sampler_objectshader, uv);
sam.rgb = DEGAMMA(sam.rgb);
emissiveColor += sam.rgb * sam.a * GetMaterial2().GetEmissive() * blend_weights.z;
}
}
[branch]
if (blend_weights.w > 0)
{
[branch]
if (GetMaterial3().uvset_baseColorMap >= 0 && (GetFrame().options & OPTION_BIT_DISABLE_ALBEDO_MAPS) == 0)
{
float2 uv = GetMaterial3().uvset_baseColorMap == 0 ? input.uvsets.xy : input.uvsets.zw;
sam = texture_blend3_basecolormap.Sample(sampler_objectshader, uv);
sam.rgb = DEGAMMA(sam.rgb);
}
else
{
sam = 1;
}
color += sam * GetMaterial3().baseColor * blend_weights.w;
[branch]
if (GetMaterial3().uvset_emissiveMap >= 0 && any(GetMaterial3().GetEmissive()))
{
float2 uv = GetMaterial3().uvset_emissiveMap == 0 ? input.uvsets.xy : input.uvsets.zw;
sam = texture_blend3_emissivemap.Sample(sampler_objectshader, uv);
sam.rgb = DEGAMMA(sam.rgb);
emissiveColor += sam.rgb * sam.a * GetMaterial3().GetEmissive() * blend_weights.w;
}
}
color.a = 1;
#endif // TERRAIN
Lighting lighting;
lighting.create(0, 0, 0, 0);
@@ -1,2 +0,0 @@
#define TERRAIN
#include "objectPS_voxelizer.hlsl"
@@ -0,0 +1,87 @@
#include "globals.hlsli"
static const uint region_count = 4;
Texture2D<float4> region_weights_texture : register(t0);
struct Terrain
{
ShaderMaterial materials[region_count];
};
ConstantBuffer<Terrain> terrain : register(b10);
// These are expected to be in the same bind slots as corresponding MaterialComponent::TEXTURESLOT enums
RWTexture2D<unorm float4> output_baseColorMap : register(u0);
RWTexture2D<unorm float4> output_normalMap : register(u1);
RWTexture2D<unorm float4> output_surfaceMap : register(u2);
[numthreads(8, 8, 1)]
void main(uint3 DTid : SV_DispatchThreadID)
{
float2 output_dim = 0;
output_baseColorMap.GetDimensions(output_dim.x, output_dim.y);
const float2 uv = (DTid.xy + 0.5f) / output_dim;
float4 region_weights = region_weights_texture.SampleLevel(sampler_linear_clamp, uv, 0);
float weight_sum = 0;
float4 total_baseColor = 0;
float4 total_surface = 0;
float2 total_normal = 0;
for (uint i = 0; i < region_count; ++i)
{
float weight = region_weights[i];
ShaderMaterial material = terrain.materials[i];
float4 baseColor = material.baseColor;
[branch]
if (material.texture_basecolormap_index >= 0)
{
Texture2D tex = bindless_textures[material.texture_basecolormap_index];
float2 dim = 0;
tex.GetDimensions(dim.x, dim.y);
float2 diff = dim / output_dim;
float lod = log2(max(diff.x, diff.y));
float4 baseColorMap = tex.SampleLevel(sampler_linear_clamp, uv, lod);
baseColor *= baseColorMap;
}
total_baseColor += baseColor * weight;
float4 surface = float4(1, material.roughness, material.metalness, material.reflectance);
[branch]
if (material.texture_surfacemap_index >= 0)
{
Texture2D tex = bindless_textures[material.texture_surfacemap_index];
float2 dim = 0;
tex.GetDimensions(dim.x, dim.y);
float2 diff = dim / output_dim;
float lod = log2(max(diff.x, diff.y));
float4 surfaceMap = tex.SampleLevel(sampler_linear_clamp, uv, lod);
surface *= surfaceMap;
}
total_surface += surface * weight;
float2 normal = float2(0.5, 0.5);
[branch]
if (material.texture_normalmap_index >= 0)
{
Texture2D tex = bindless_textures[material.texture_normalmap_index];
float2 dim = 0;
tex.GetDimensions(dim.x, dim.y);
float2 diff = dim / output_dim;
float lod = log2(max(diff.x, diff.y));
float2 normalMap = tex.SampleLevel(sampler_linear_clamp, uv, lod).rg;
normal = normalMap;
}
total_normal += normal * weight;
weight_sum += weight;
}
total_baseColor /= weight_sum;
total_surface /= weight_sum;
total_normal /= weight_sum;
output_baseColorMap[DTid.xy] = total_baseColor;
output_surfaceMap[DTid.xy] = total_surface;
output_normalMap[DTid.xy] = float4(total_normal, 1, 1);
}
+1 -1
View File
@@ -5,7 +5,7 @@ namespace wi
{
// this should always be only INCREMENTED and only if a new serialization is implemeted somewhere!
static constexpr uint64_t __archiveVersion = 78;
static constexpr uint64_t __archiveVersion = 79;
// this is the version number of which below the archive is not compatible with the current version
static constexpr uint64_t __archiveVersionBarrier = 22;
+1 -3
View File
@@ -145,7 +145,6 @@ namespace wi::enums
PSTYPE_OBJECT_UNLIT,
PSTYPE_OBJECT_TRANSPARENT_UNLIT,
PSTYPE_OBJECT_WATER,
PSTYPE_OBJECT_TERRAIN,
PSTYPE_IMPOSTOR,
PSTYPE_OBJECT_HOLOGRAM,
@@ -172,7 +171,6 @@ namespace wi::enums
PSTYPE_SKY_DYNAMIC,
PSTYPE_SUN,
PSTYPE_ENVMAP,
PSTYPE_ENVMAP_TERRAIN,
PSTYPE_ENVMAP_SKY_STATIC,
PSTYPE_ENVMAP_SKY_DYNAMIC,
PSTYPE_CUBEMAP,
@@ -180,7 +178,6 @@ namespace wi::enums
PSTYPE_CAPTUREIMPOSTOR_NORMAL,
PSTYPE_CAPTUREIMPOSTOR_SURFACE,
PSTYPE_VOXELIZER,
PSTYPE_VOXELIZER_TERRAIN,
PSTYPE_VOXEL,
PSTYPE_FORCEFIELDVISUALIZER,
PSTYPE_RENDERLIGHTMAP,
@@ -359,6 +356,7 @@ namespace wi::enums
CSTYPE_DDGI_RAYTRACE,
CSTYPE_DDGI_UPDATE,
CSTYPE_DDGI_UPDATE_DEPTH,
CSTYPE_TERRAIN_VIRTUALTEXTURE_UPDATE,
// raytracing pipelines:
+1 -51
View File
@@ -285,7 +285,6 @@ PipelineState PSO_object
[OBJECTRENDERING_DOUBLESIDED_COUNT]
[OBJECTRENDERING_TESSELLATION_COUNT]
[OBJECTRENDERING_ALPHATEST_COUNT];
PipelineState PSO_object_terrain[RENDERPASS_COUNT];
PipelineState PSO_object_wire;
PipelineState PSO_object_wire_tessellation;
@@ -806,7 +805,6 @@ void LoadShaders()
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::PS, shaders[PSTYPE_OBJECT_UNLIT], "objectPS_unlit.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::PS, shaders[PSTYPE_OBJECT_TRANSPARENT_UNLIT], "objectPS_transparent_unlit.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::PS, shaders[PSTYPE_OBJECT_WATER], "objectPS_water.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::PS, shaders[PSTYPE_OBJECT_TERRAIN], "objectPS_terrain.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::PS, shaders[PSTYPE_IMPOSTOR], "impostorPS.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::PS, shaders[PSTYPE_OBJECT_HOLOGRAM], "objectPS_hologram.cso"); });
@@ -824,7 +822,6 @@ void LoadShaders()
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::PS, shaders[PSTYPE_VOLUMETRICLIGHT_POINT], "volumetricLight_PointPS.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::PS, shaders[PSTYPE_VOLUMETRICLIGHT_SPOT], "volumetricLight_SpotPS.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::PS, shaders[PSTYPE_ENVMAP], "envMapPS.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::PS, shaders[PSTYPE_ENVMAP_TERRAIN], "envMapPS_terrain.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::PS, shaders[PSTYPE_ENVMAP_SKY_STATIC], "envMap_skyPS_static.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::PS, shaders[PSTYPE_ENVMAP_SKY_DYNAMIC], "envMap_skyPS_dynamic.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::PS, shaders[PSTYPE_CAPTUREIMPOSTOR_ALBEDO], "captureImpostorPS_albedo.cso"); });
@@ -839,7 +836,6 @@ void LoadShaders()
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::PS, shaders[PSTYPE_SHADOW_TRANSPARENT], "shadowPS_transparent.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::PS, shaders[PSTYPE_SHADOW_WATER], "shadowPS_water.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::PS, shaders[PSTYPE_VOXELIZER], "objectPS_voxelizer.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::PS, shaders[PSTYPE_VOXELIZER_TERRAIN], "objectPS_voxelizer_terrain.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::PS, shaders[PSTYPE_VOXEL], "voxelPS.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::PS, shaders[PSTYPE_FORCEFIELDVISUALIZER], "forceFieldVisualizerPS.cso"); });
if (device->CheckCapability(GraphicsDeviceCapability::RAYTRACING))
@@ -1034,6 +1030,7 @@ void LoadShaders()
}
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::CS, shaders[CSTYPE_DDGI_UPDATE], "ddgi_updateCS.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::CS, shaders[CSTYPE_DDGI_UPDATE_DEPTH], "ddgi_updateCS_depth.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::CS, shaders[CSTYPE_TERRAIN_VIRTUALTEXTURE_UPDATE], "terrainVirtualTextureUpdateCS.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::HS, shaders[HSTYPE_OBJECT], "objectHS.cso"); });
wi::jobsystem::Execute(ctx, [](wi::jobsystem::JobArgs args) { LoadShader(ShaderStage::HS, shaders[HSTYPE_OBJECT_PREPASS], "objectHS_prepass.cso"); });
@@ -1189,48 +1186,6 @@ void LoadShaders()
}
});
wi::jobsystem::Dispatch(ctx, RENDERPASS_COUNT, 1, [](wi::jobsystem::JobArgs args) {
SHADERTYPE realVS = GetVSTYPE((RENDERPASS) args.jobIndex, false, false, false);
PipelineStateDesc desc;
desc.rs = &rasterizers[RSTYPE_FRONT];
desc.bs = &blendStates[BSTYPE_OPAQUE];
desc.dss = &depthStencils[DSSTYPE_DEFAULT];
desc.vs = &shaders[realVS];
switch (args.jobIndex)
{
case RENDERPASS_MAIN:
desc.dss = &depthStencils[DSSTYPE_DEPTHREADEQUAL];
desc.ps = &shaders[PSTYPE_OBJECT_TERRAIN];
break;
case RENDERPASS_PREPASS:
desc.ps = &shaders[PSTYPE_OBJECT_PREPASS];
break;
case RENDERPASS_VOXELIZE:
desc.dss = &depthStencils[DSSTYPE_DEPTHDISABLED];
desc.rs = &rasterizers[RSTYPE_VOXELIZE];
desc.vs = &shaders[VSTYPE_VOXELIZER];
desc.gs = &shaders[GSTYPE_VOXELIZER];
desc.ps = &shaders[PSTYPE_VOXELIZER_TERRAIN];
break;
case RENDERPASS_ENVMAPCAPTURE:
desc.ps = &shaders[PSTYPE_ENVMAP_TERRAIN];
break;
case RENDERPASS_SHADOW:
case RENDERPASS_SHADOWCUBE:
desc.dss = &depthStencils[DSSTYPE_SHADOW];
desc.rs = &rasterizers[RSTYPE_SHADOW_DOUBLESIDED];
desc.ps = nullptr;
break;
default:
return;
}
device->CreatePipelineState(&desc, &PSO_object_terrain[args.jobIndex]);
});
// Clear custom shaders (Custom shaders coming from user will need to be handled by the user in case of shader reload):
customShaders.clear();
@@ -2417,7 +2372,6 @@ void RenderMeshes(
const float tessF = mesh.GetTessellationFactor();
const bool tessellatorRequested = tessF > 0 && tessellation;
const bool terrain = mesh.IsTerrain();
if (forwardLightmaskRequest)
{
@@ -2462,10 +2416,6 @@ void RenderMeshes(
pso = tessellatorRequested ? &PSO_object_wire_tessellation : &PSO_object_wire;
}
}
else if (mesh.IsTerrain())
{
pso = &PSO_object_terrain[renderPass];
}
else if (material.customShaderID >= 0 && material.customShaderID < (int)customShaders.size())
{
const CustomShader& customShader = customShaders[material.customShaderID];
-7
View File
@@ -2997,10 +2997,6 @@ namespace wi::scene
mesh._flags &= ~MeshComponent::TLAS_FORCE_DOUBLE_SIDED;
mesh.terrain_material1_index = (uint32_t)materials.GetIndex(mesh.terrain_material1);
mesh.terrain_material2_index = (uint32_t)materials.GetIndex(mesh.terrain_material2);
mesh.terrain_material3_index = (uint32_t)materials.GetIndex(mesh.terrain_material3);
// Update morph targets if needed:
if (mesh.dirty_morph && !mesh.targets.empty())
{
@@ -3060,9 +3056,6 @@ namespace wi::scene
geometry.vb_uvs = mesh.vb_uvs.descriptor_srv;
geometry.vb_atl = mesh.vb_atl.descriptor_srv;
geometry.vb_pre = mesh.so_pre.descriptor_srv;
geometry.blendmaterial1 = mesh.terrain_material1_index;
geometry.blendmaterial2 = mesh.terrain_material2_index;
geometry.blendmaterial3 = mesh.terrain_material3_index;
geometry.aabb_min = mesh.aabb._min;
geometry.aabb_max = mesh.aabb._max;
geometry.tessellation_factor = mesh.tessellationFactor;
+1 -17
View File
@@ -314,7 +314,7 @@ namespace wi::scene
RENDERABLE = 1 << 0,
DOUBLE_SIDED = 1 << 1,
DYNAMIC = 1 << 2,
TERRAIN = 1 << 3,
_DEPRECATED_TERRAIN = 1 << 3,
_DEPRECATED_DIRTY_MORPH = 1 << 4,
_DEPRECATED_DIRTY_BINDLESS = 1 << 5,
TLAS_FORCE_DOUBLE_SIDED = 1 << 6,
@@ -347,15 +347,6 @@ namespace wi::scene
float tessellationFactor = 0.0f;
wi::ecs::Entity armatureID = wi::ecs::INVALID_ENTITY;
// Terrain blend materials:
// There are 4 blend materials, the first one (default) being the subset material
// Must have TERRAIN flag enabled
// Must have vertex colors to blend between materials
// extra materials that are not set will use the base subset material
wi::ecs::Entity terrain_material1 = wi::ecs::INVALID_ENTITY;
wi::ecs::Entity terrain_material2 = wi::ecs::INVALID_ENTITY;
wi::ecs::Entity terrain_material3 = wi::ecs::INVALID_ENTITY;
// Morph Targets
struct MeshMorphTarget
{
@@ -407,22 +398,15 @@ namespace wi::scene
};
mutable BLAS_STATE BLAS_state = BLAS_STATE_NEEDS_REBUILD;
// Only valid for 1 frame material component indices:
uint32_t terrain_material1_index = ~0u;
uint32_t terrain_material2_index = ~0u;
uint32_t terrain_material3_index = ~0u;
mutable bool dirty_morph = false;
inline void SetRenderable(bool value) { if (value) { _flags |= RENDERABLE; } else { _flags &= ~RENDERABLE; } }
inline void SetDoubleSided(bool value) { if (value) { _flags |= DOUBLE_SIDED; } else { _flags &= ~DOUBLE_SIDED; } }
inline void SetDynamic(bool value) { if (value) { _flags |= DYNAMIC; } else { _flags &= ~DYNAMIC; } }
inline void SetTerrain(bool value) { if (value) { _flags |= TERRAIN; } else { _flags &= ~TERRAIN; } }
inline bool IsRenderable() const { return _flags & RENDERABLE; }
inline bool IsDoubleSided() const { return _flags & DOUBLE_SIDED; }
inline bool IsDynamic() const { return _flags & DYNAMIC; }
inline bool IsTerrain() const { return _flags & TERRAIN; }
inline float GetTessellationFactor() const { return tessellationFactor; }
inline wi::graphics::IndexBufferFormat GetIndexFormat() const { return vertex_positions.size() > 65536 ? wi::graphics::IndexBufferFormat::UINT32 : wi::graphics::IndexBufferFormat::UINT16; }
+10 -2
View File
@@ -373,8 +373,12 @@ namespace wi::scene
archive >> vertex_uvset_1;
}
if (archive.GetVersion() >= 41)
if (archive.GetVersion() >= 41 && archive.GetVersion() < 79)
{
// These are no longer used:
Entity terrain_material1;
Entity terrain_material2;
Entity terrain_material3;
SerializeEntity(archive, terrain_material1, seri);
SerializeEntity(archive, terrain_material2, seri);
SerializeEntity(archive, terrain_material3, seri);
@@ -440,8 +444,12 @@ namespace wi::scene
archive << vertex_uvset_1;
}
if (archive.GetVersion() >= 41)
if (archive.GetVersion() >= 41 && archive.GetVersion() < 79)
{
// These are no longer used:
Entity terrain_material1;
Entity terrain_material2;
Entity terrain_material3;
SerializeEntity(archive, terrain_material1, seri);
SerializeEntity(archive, terrain_material2, seri);
SerializeEntity(archive, terrain_material3, seri);
+1 -1
View File
@@ -9,7 +9,7 @@ namespace wi::version
// minor features, major updates, breaking compatibility changes
const int minor = 60;
// minor bug fixes, alterations, refactors, updates
const int revision = 61;
const int revision = 62;
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);