Skip to content

Commit

Permalink
merged instances window with objects editor; added "Custom properties…
Browse files Browse the repository at this point in the history
…" tab for object editor
  • Loading branch information
steaklive committed Nov 14, 2023
1 parent ddccef0 commit 65b3424
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 65 deletions.
116 changes: 55 additions & 61 deletions source/EveryRay_Core/ER_RenderingObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace EveryRay_Core
{
static int currentSplatChannnel = (int)TerrainSplatChannels::NONE;
static const int maxInstancesHeightUI = 5;

ER_RenderingObject::ER_RenderingObject(const std::string& pName, int index, ER_Core& pCore, ER_Camera& pCamera, const std::string& pModelPath, bool availableInEditor, bool isInstanced)
:
Expand Down Expand Up @@ -855,6 +856,7 @@ namespace EveryRay_Core

if (isCurrentlyEditable && mIsInstanced)
{
mEditorSelectedInstancedObjectIndex = mEditorSelectedInstancedObjectIndexNextFrame;
// load current selected instance's transform to temp transform (for UI)
ER_MatrixHelper::SetFloatArray(mInstanceData[0][mEditorSelectedInstancedObjectIndex].World, mCurrentObjectTransformMatrix);
}
Expand Down Expand Up @@ -904,8 +906,7 @@ namespace EveryRay_Core

if (isCurrentlyEditable)
{
UpdateGizmos();
ShowInstancesListWindow();
UpdateGizmosAndUI();
if (mIsAABBDebugEnabled)
mDebugGizmoAABB->Update(mGlobalAABB);
}
Expand Down Expand Up @@ -949,7 +950,7 @@ namespace EveryRay_Core
aabb = ER_AABB(minVertex, maxVertex);
}

void ER_RenderingObject::UpdateGizmos()
void ER_RenderingObject::UpdateGizmosAndUI()
{
if (!(mIsAvailableInEditorMode && mIsSelected))
return;
Expand Down Expand Up @@ -1067,9 +1068,8 @@ namespace EveryRay_Core

if (ER_Utility::IsEditorMode)
{
ER_Utility::IsSunLightEditor = false;
ER_Utility::IsFoliageEditor = false;
ER_Utility::IsPostEffectsVolumeEditor = false;
ER_Utility::DisableAllEditors();
ER_Utility::IsEditorMode = true;

ImGui::Begin("Object Editor");
std::string name = mName;
Expand Down Expand Up @@ -1105,27 +1105,26 @@ namespace EveryRay_Core

std::string instanceCountText = "* Instance count: " + std::to_string(GetInstanceCount());
ImGui::Text(instanceCountText.c_str());
if (mIsIndirectlyRendered)
{
std::string info = "GPU indirect drawcall";
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1), info.c_str());
info = "Instances can't be transformed in editor";
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1), info.c_str());
}
ImGui::Separator();

std::string shadingModeName = "* Shaded in: ";
std::string shadingModeName = "Shaded in: ";
if (mIsForwardShading)
shadingModeName += "Forward";
else
shadingModeName += "Deferred";
ImGui::Text(shadingModeName.c_str());

if (mIsIndirectlyRendered)
{
std::string info = "* GPU indirect drawcall";
ImGui::Text(info.c_str());
info = "Can't be transformed in editor";
ImGui::Text(info.c_str());
}

ImGui::Separator();
ImGui::Checkbox("Rendered", &mIsRendered);
ImGui::Checkbox("Show AABB", &mIsAABBDebugEnabled);
ImGui::Checkbox("Skip indirect spec.", &mIsSkippedIndirectSpecular);
//ImGui::Checkbox("Skip indirect dif.", &mIsSkippedIndirectDiffuse);

if (ImGui::Button("Move camera to"))
{
XMFLOAT3 newCameraPos;
Expand All @@ -1136,6 +1135,18 @@ namespace EveryRay_Core
camera->SetPosition(newCameraPos);
}

if (mIsAvailableInEditorMode && mIsSelected && mIsInstanced && !mIsIndirectlyRendered)
{
// Shows a list of instances.
// You can select an instance, read some useful info about it and edit it via "Objects Editor".
// We do not need to edit per LOD (LODs share same transforms, AABBs, names).
// Note: does not work for objects rendered indirectly on the GPU!

ImGui::Text("Instances (dynamic):");
ImGui::PushItemWidth(-1);
ImGui::ListBox("##empty", &mEditorSelectedInstancedObjectIndexNextFrame, mInstancedNamesUI, static_cast<int>(mInstanceData[0].size()), maxInstancesHeightUI);
}

//terrain
//{
// ImGui::Combo("Terrain splat channel", &currentSplatChannnel, DisplayedSplatChannnelNames, 5);
Expand All @@ -1155,26 +1166,32 @@ namespace EveryRay_Core
// }
//}

ImGui::SliderFloat("Custom roughness", &mCustomRoughness, -1.0f, 1.0f);
ImGui::SliderFloat("Custom metalness", &mCustomMetalness, -1.0f, 1.0f);
ImGui::SliderFloat("Custom alpha discard", &mCustomAlphaDiscard, 0.0f, 1.0f);
if (mIsTransparent)
ImGui::SliderFloat("IOR", &mIOR, -5.0f, 5.0f);
if (mFurLayersCount > 0)
if (ImGui::CollapsingHeader("Custom properties"))
{
ImGui::ColorEdit3("Fur Color", mFurColor);
ImGui::SliderFloat("Fur Interpolation with albedo", &mFurColorInterpolation, 0.0, 1.0);
ImGui::SliderFloat("Fur Length", &mFurLength, 0.01f, 25.0f);
ImGui::SliderFloat("Fur Cutoff", &mFurCutoff, 0.01f, 1.0f);
ImGui::SliderFloat("Fur Cutoff End", &mFurCutoffEnd, 0.01f, 1.0f);
ImGui::SliderFloat("Fur UV Scale", &mFurUVScale, 0.01f, 15.0f);
ImGui::SliderFloat3("Fur Gravity Dir", &mFurGravityDirection[0], -1.0, 1.0);
ImGui::SliderFloat("Fur Gravity Strength", &mFurGravityStrength, 0.0, 10.0);
ImGui::SliderFloat("Fur Wind Frequency", &mFurWindFrequency, 0.0, 10.0);
ImGui::SliderFloat("Custom roughness", &mCustomRoughness, -1.0f, 1.0f);
ImGui::SliderFloat("Custom metalness", &mCustomMetalness, -1.0f, 1.0f);
ImGui::SliderFloat("Custom alpha discard", &mCustomAlphaDiscard, 0.0f, 1.0f);
if (mIsTransparent)
ImGui::SliderFloat("IOR", &mIOR, -5.0f, 5.0f);
if (mFurLayersCount > 0)
{
ImGui::ColorEdit3("Fur Color", mFurColor);
ImGui::SliderFloat("Fur Interpolation with albedo", &mFurColorInterpolation, 0.0, 1.0);
ImGui::SliderFloat("Fur Length", &mFurLength, 0.01f, 25.0f);
ImGui::SliderFloat("Fur Cutoff", &mFurCutoff, 0.01f, 1.0f);
ImGui::SliderFloat("Fur Cutoff End", &mFurCutoffEnd, 0.01f, 1.0f);
ImGui::SliderFloat("Fur UV Scale", &mFurUVScale, 0.01f, 15.0f);
ImGui::SliderFloat3("Fur Gravity Dir", &mFurGravityDirection[0], -1.0, 1.0);
ImGui::SliderFloat("Fur Gravity Strength", &mFurGravityStrength, 0.0, 10.0);
ImGui::SliderFloat("Fur Wind Frequency", &mFurWindFrequency, 0.0, 10.0);
}
ImGui::Checkbox("Triplanar mapping", &mIsTriplanarMapped);
//f (mIsTriplanarMapped)
// ImGui::SliderFloat("Triplanar mapping - sharpness", &mTriplanarMappingSharpness, 0.01, 50.0f);

ImGui::Checkbox("DEBUG - Skip indirect spec.", &mIsSkippedIndirectSpecular);
ImGui::Checkbox("DEBUG - Skip indirect dif.", &mIsSkippedIndirectDiffuse);
}
ImGui::Checkbox("Triplanar mapping", &mIsTriplanarMapped);
//f (mIsTriplanarMapped)
// ImGui::SliderFloat("Triplanar mapping - sharpness", &mTriplanarMappingSharpness, 0.01, 50.0f);

//Transforms
if (!mIsIndirectlyRendered)
Expand Down Expand Up @@ -1209,32 +1226,7 @@ namespace EveryRay_Core
ImGuizmo::Manipulate(cameraView, cameraProjection, mCurrentGizmoOperation, mCurrentGizmoMode, matrix, NULL, useSnap ? &snap[0] : NULL, boundSizing ? bounds : NULL, boundSizingSnap ? boundsSnap : NULL);
}
}

// Shows an ImGui window for the list of instances.
// You can select an instance, read some useful info about it and edit it via "Objects Editor".
// We do not need to edit per LOD (LODs share same transforms, AABBs, names).
// Note: does not work for objects rendered indirectly on the GPU!
void ER_RenderingObject::ShowInstancesListWindow()
{
if (!(mIsAvailableInEditorMode && mIsSelected && mIsInstanced) || mIsIndirectlyRendered)
return;

assert(mInstanceCount != 0);
assert(mInstanceData[0].size() != 0 && mInstanceData[0].size() == mInstanceCount);
assert(mInstancesNames.size() == mInstanceCount);

std::string title = mName + " instances:";
ImGui::Begin(title.c_str());

for (int i = 0; i < mInstanceData[0].size(); i++) {
mInstancedNamesUI[i] = mInstancesNames[i].c_str();
}

ImGui::PushItemWidth(-1);
ImGui::ListBox("##empty", &mEditorSelectedInstancedObjectIndex, mInstancedNamesUI, static_cast<int>(mInstanceData[0].size()), 15);
ImGui::End();
}


ER_RHI_GPUBuffer* ER_RenderingObject::GetIndirectMeshConstantBuffer()
{
if (!mIsIndirectlyRendered || !mIsLoaded)
Expand Down Expand Up @@ -1373,6 +1365,8 @@ namespace EveryRay_Core
{
std::string instanceName = mName + " #" + std::to_string(i);
mInstancesNames.push_back(instanceName);
mInstancedNamesUI[i] = strdup(instanceName.c_str());

mInstanceAABBs.push_back(mLocalAABB);
mInstanceCullingFlags.push_back(false);
}
Expand Down
9 changes: 5 additions & 4 deletions source/EveryRay_Core/ER_RenderingObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,9 @@ namespace EveryRay_Core
void LoadTexture(ER_RHI_GPUTexture** aTexture, bool* loadStat, const std::wstring& path, int meshIndex, bool isPlaceholder = false);
void CreateInstanceBuffer(InstancedData* instanceData, UINT instanceCount, ER_RHI_GPUBuffer* instanceBuffer);

void UpdateGizmos();
void UpdateGizmosAndUI();
void UpdateBitmaskFlags();
void ShowInstancesListWindow();

void ShowObjectsEditorWindow(const float *cameraView, float *cameraProjection, float* matrix);

ER_Core* mCore = nullptr;
Expand Down Expand Up @@ -462,10 +462,11 @@ namespace EveryRay_Core
ER_RenderableAABB* mDebugGizmoAABB = nullptr;

std::string mName;
const char* mInstancedNamesUI[MAX_DIRECT_INSTANCE_COUNT];
const char* mInstancedNamesUI[MAX_DIRECT_INSTANCE_COUNT] = { nullptr };
int mIndexInScene = -1;
int mCurrentLODIndex = 0; //only used for non-instanced object
int mEditorSelectedInstancedObjectIndex = 0;
int mEditorSelectedInstancedObjectIndex = 0; //only for direct instances and not GPU-driven/indirect
int mEditorSelectedInstancedObjectIndexNextFrame = 0; //only for direct instances and not GPU-driven/indirect
bool mIsAABBDebugEnabled = true;
bool mIsAvailableInEditorMode = false;
bool mIsSelected = false;
Expand Down

0 comments on commit 65b3424

Please sign in to comment.