Skip to content

Commit

Permalink
Hydrogent: added axes rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Nov 7, 2023
1 parent f1c0260 commit fd165cd
Show file tree
Hide file tree
Showing 15 changed files with 519 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Hydrogent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set(SOURCE
src/Tasks/HnSetupRenderingTask.cpp
src/Tasks/HnRenderRprimsTask.cpp
src/Tasks/HnRenderEnvMapTask.cpp
src/Tasks/HnRenderAxesTask.cpp
src/Tasks/HnPostProcessTask.cpp
src/Tasks/HnSetupSelectionDepthTask.cpp
src/Tasks/HnProcessSelectionTask.cpp
Expand Down Expand Up @@ -52,6 +53,7 @@ set(INTERFACE
interface/Tasks/HnSetupRenderingTask.hpp
interface/Tasks/HnRenderRprimsTask.hpp
interface/Tasks/HnRenderEnvMapTask.hpp
interface/Tasks/HnRenderAxesTask.hpp
interface/Tasks/HnPostProcessTask.hpp
interface/Tasks/HnSetupSelectionDepthTask.hpp
interface/Tasks/HnProcessSelectionTask.hpp
Expand Down
7 changes: 7 additions & 0 deletions Hydrogent/include/HnShaderSourceFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,22 @@
namespace Diligent
{

namespace USD
{

class HnShaderSourceFactory final
{
public:
static IShaderSourceInputStreamFactory& GetInstance();

static RefCntAutoPtr<IShaderSourceInputStreamFactory> CreateHnFxCompoundFactory();

private:
HnShaderSourceFactory();

RefCntAutoPtr<IShaderSourceInputStreamFactory> m_pFactory;
};

} // namespace USD

} // namespace Diligent
108 changes: 108 additions & 0 deletions Hydrogent/interface/Tasks/HnRenderAxesTask.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright 2023 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* In no event and under no legal theory, whether in tort (including negligence),
* contract, or otherwise, unless required by applicable law (such as deliberate
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
* liable for any damages, including any direct, indirect, special, incidental,
* or consequential damages of any character arising as a result of this License or
* out of the use or inability to use the software (including but not limited to damages
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
* all other commercial damages or losses), even if such Contributor has been advised
* of the possibility of such damages.
*/

#pragma once

#include "HnTask.hpp"

#include "../../../../DiligentCore/Graphics/GraphicsEngine/interface/PipelineState.h"
#include "../../../../DiligentCore/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h"
#include "../../../../DiligentCore/Graphics/GraphicsEngine/interface/Buffer.h"
#include "../../../../DiligentCore/Common/interface/RefCntAutoPtr.hpp"
#include "../../../../DiligentCore/Common/interface/BasicMath.hpp"

namespace Diligent
{

namespace USD
{

class HnRenderPassState;

struct HnRenderAxesTaskParams
{
float4x4 Transform = float4x4::Identity();

float4 PositiveXColor{1.0f, 0.0f, 0.0f, 1.0f};
float4 PositiveYColor{0.0f, 1.0f, 0.0f, 1.0f};
float4 PositiveZColor{0.0f, 0.0f, 1.0f, 1.0f};
float4 NegativeXColor{0.5f, 0.3f, 0.3f, 1.0f};
float4 NegativeYColor{0.3f, 0.5f, 0.3f, 1.0f};
float4 NegativeZColor{0.3f, 0.3f, 0.5f, 1.0f};

constexpr bool operator==(const HnRenderAxesTaskParams& rhs) const
{

return Transform == rhs.Transform &&
PositiveXColor == rhs.PositiveXColor &&
PositiveYColor == rhs.PositiveYColor &&
PositiveZColor == rhs.PositiveZColor &&
NegativeXColor == rhs.NegativeXColor &&
NegativeYColor == rhs.NegativeYColor &&
NegativeZColor == rhs.NegativeZColor;
}

constexpr bool operator!=(const HnRenderAxesTaskParams& rhs) const
{
return !(*this == rhs);
}
};

/// Renders coordinate axes.
class HnRenderAxesTask final : public HnTask
{
public:
HnRenderAxesTask(pxr::HdSceneDelegate* ParamsDelegate, const pxr::SdfPath& Id);
~HnRenderAxesTask();

virtual void Sync(pxr::HdSceneDelegate* Delegate,
pxr::HdTaskContext* TaskCtx,
pxr::HdDirtyBits* DirtyBits) override final;

virtual void Prepare(pxr::HdTaskContext* TaskCtx,
pxr::HdRenderIndex* RenderIndex) override final;


virtual void Execute(pxr::HdTaskContext* TaskCtx) override final;

private:
void PreparePSO(const HnRenderPassState& RPState);

private:
pxr::HdRenderIndex* m_RenderIndex = nullptr;

HnRenderAxesTaskParams m_Params;

bool m_ParamsAreDirty = true;

RefCntAutoPtr<IPipelineState> m_PSO;
RefCntAutoPtr<IShaderResourceBinding> m_SRB;
RefCntAutoPtr<IBuffer> m_ConstantsCB;
};

} // namespace USD

} // namespace Diligent
6 changes: 6 additions & 0 deletions Hydrogent/interface/Tasks/HnTaskManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct HnRenderRprimsTaskParams;
struct HnPostProcessTaskParams;
struct HnRenderPassParams;
struct HnReadRprimIdTaskParams;
struct HnRenderAxesTaskParams;

/// Task manager implementation in Hydrogent.
class HnTaskManager
Expand All @@ -62,6 +63,7 @@ class HnTaskManager
static constexpr TaskUID TaskUID_RenderRprimsAdditiveSelected = 0x2cb8a35254ec46da;
static constexpr TaskUID TaskUID_RenderRprimsTranslucentSelected = 0x50a786394d834b4f;
static constexpr TaskUID TaskUID_RenderEnvMap = 0xf646122e1dc74bab;
static constexpr TaskUID TaskUID_RenderAxes = 0x4cbc5eb258b407b;
static constexpr TaskUID TaskUID_ReadRprimId = 0x199572fe7ff144ef;
static constexpr TaskUID TaskUID_ProcessSelection = 0x87ef181ec6d4cf8;
static constexpr TaskUID TaskUID_PostProcess = 0x1f5367e65d034500;
Expand Down Expand Up @@ -94,6 +96,7 @@ class HnTaskManager
/// - RenderRprimsMaskedUnselected
/// * Renders only unselected Rprims with the masked material tag
/// - RenderEnvMap
/// - RenderAxes
/// - RenderRprimsAdditive
/// * Renders all Rprims with additive material tag
/// - RenderRprimsTranslucent
Expand All @@ -118,6 +121,7 @@ class HnTaskManager
/// | RenderRprimsDefaultUnselected | | V | V | V | | V |
/// | RenderRprimsMaskedUnselected | | V | V | V | | V |
/// | RenderEnvMap | | | V | | | |
/// | RenderAxes | | | V | | | |
/// | RenderRprimsAdditive | V | V | V | V | | V |
/// | RenderRprimsTranslucent | V | V | V | V | | V |
/// | SetupSelectionDepth | | | | | bind | |
Expand Down Expand Up @@ -178,6 +182,7 @@ class HnTaskManager
void SetRenderRprimParams(const HnRenderRprimsTaskParams& Params);
void SetPostProcessParams(const HnPostProcessTaskParams& Params);
void SetReadRprimIdParams(const HnReadRprimIdTaskParams& Params);
void SetRenderAxesParams(const HnRenderAxesTaskParams& Params);

void EnableTask(TaskUID UID, bool Enable);
bool IsTaskEnabled(TaskUID UID) const;
Expand All @@ -204,6 +209,7 @@ class HnTaskManager
void CreateSetupRenderingTask();
void CreateRenderRprimsTask(const pxr::TfToken& MaterialTag, TaskUID UID, const HnRenderPassParams& RenderPassParams);
void CreateRenderEnvMapTask();
void CreateRenderAxesTask();
void CreateReadRprimIdTask();
void CreateCopySelectionDepthTask();
void CreateSetupSelectionDepthTask();
Expand Down
13 changes: 13 additions & 0 deletions Hydrogent/shaders/HnAxes.psh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
struct PSInput
{
float4 Pos : SV_POSITION;
float4 Color : COLOR;
};

void main(in PSInput PSIn,
out float4 Color : SV_Target0,
out float4 MeshId : SV_Target1)
{
Color = PSIn.Color;
MeshId = float4(0.0, 0.0, 0.0, 0.0);
}
46 changes: 46 additions & 0 deletions Hydrogent/shaders/HnAxes.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "HnAxesStructures.fxh"
#include "BasicStructures.fxh"

struct PSInput
{
float4 Pos : SV_POSITION;
float4 Color : COLOR;
};

cbuffer cbCameraAttribs
{
CameraAttribs g_CameraAttribs;
}

cbuffer cbConstants
{
AxesConstants g_Constants;
}

void main(in uint VertID : SV_VertexID,
out PSInput PSIn)
{
//float3 Pos[12];
//Pos[0] = float3(-1.0, 0.0, 0.0);
//Pos[1] = float3( 0.0, 0.0, 0.0);
//Pos[2] = float3( 0.0, 0.0, 0.0);
//Pos[3] = float3(+1.0, 0.0, 0.0);

//Pos[4] = float3(0.0, -1.0, 0.0);
//Pos[5] = float3(0.0, 0.0, 0.0);
//Pos[6] = float3(0.0, 0.0, 0.0);
//Pos[7] = float3(0.0, +1.0, 0.0);

//Pos[ 8] = float3(0.0, 0.0, -1.0);
//Pos[ 9] = float3(0.0, 0.0, 0.0);
//Pos[10] = float3(0.0, 0.0, 0.0);
//Pos[11] = float3(0.0, 0.0, +1.0);
float3 Pos;
Pos.x = (VertID == 0) ? -1.0 : ((VertID == 3) ? +1.0 : 0.0);
Pos.y = (VertID == 4) ? -1.0 : ((VertID == 7) ? +1.0 : 0.0);
Pos.z = (VertID == 8) ? -1.0 : ((VertID == 11) ? +1.0 : 0.0);

PSIn.Pos = mul(mul(float4(Pos, 1.0), g_Constants.Transform), g_CameraAttribs.mViewProj);
PSIn.Color = g_Constants.AxesColors[VertID/2];
PSIn.Color.a *= 1 - length(Pos);
}
10 changes: 10 additions & 0 deletions Hydrogent/shaders/HnAxesStructures.fxh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef _HN_AXES_STRUCTURES_FXH_
#define _HN_AXES_STRUCTURES_FXH_

struct AxesConstants
{
float4x4 Transform;
float4 AxesColors[6]; // -X, +X, -Y, +Y, -Z, +Z
};

#endif // _HN_AXES_STRUCTURES_FXH_
13 changes: 13 additions & 0 deletions Hydrogent/shaders_inc/HnAxes.psh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"struct PSInput\n"
"{\n"
" float4 Pos : SV_POSITION;\n"
" float4 Color : COLOR;\n"
"};\n"
"\n"
"void main(in PSInput PSIn,\n"
" out float4 Color : SV_Target0,\n"
" out float4 MeshId : SV_Target1)\n"
"{\n"
" Color = PSIn.Color;\n"
" MeshId = float4(0.0, 0.0, 0.0, 0.0);\n"
"}\n"
46 changes: 46 additions & 0 deletions Hydrogent/shaders_inc/HnAxes.vsh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"#include \"HnAxesStructures.fxh\"\n"
"#include \"BasicStructures.fxh\"\n"
"\n"
"struct PSInput\n"
"{\n"
" float4 Pos : SV_POSITION;\n"
" float4 Color : COLOR;\n"
"};\n"
"\n"
"cbuffer cbCameraAttribs\n"
"{\n"
" CameraAttribs g_CameraAttribs;\n"
"}\n"
"\n"
"cbuffer cbConstants\n"
"{\n"
" AxesConstants g_Constants;\n"
"}\n"
"\n"
"void main(in uint VertID : SV_VertexID,\n"
" out PSInput PSIn)\n"
"{\n"
" //float3 Pos[12];\n"
" //Pos[0] = float3(-1.0, 0.0, 0.0);\n"
" //Pos[1] = float3( 0.0, 0.0, 0.0);\n"
" //Pos[2] = float3( 0.0, 0.0, 0.0);\n"
" //Pos[3] = float3(+1.0, 0.0, 0.0);\n"
"\n"
" //Pos[4] = float3(0.0, -1.0, 0.0);\n"
" //Pos[5] = float3(0.0, 0.0, 0.0);\n"
" //Pos[6] = float3(0.0, 0.0, 0.0);\n"
" //Pos[7] = float3(0.0, +1.0, 0.0);\n"
"\n"
" //Pos[ 8] = float3(0.0, 0.0, -1.0);\n"
" //Pos[ 9] = float3(0.0, 0.0, 0.0);\n"
" //Pos[10] = float3(0.0, 0.0, 0.0);\n"
" //Pos[11] = float3(0.0, 0.0, +1.0);\n"
" float3 Pos;\n"
" Pos.x = (VertID == 0) ? -1.0 : ((VertID == 3) ? +1.0 : 0.0);\n"
" Pos.y = (VertID == 4) ? -1.0 : ((VertID == 7) ? +1.0 : 0.0);\n"
" Pos.z = (VertID == 8) ? -1.0 : ((VertID == 11) ? +1.0 : 0.0);\n"
"\n"
" PSIn.Pos = mul(mul(float4(Pos, 1.0), g_Constants.Transform), g_CameraAttribs.mViewProj);\n"
" PSIn.Color = g_Constants.AxesColors[VertID/2];\n"
" PSIn.Color.a *= 1 - length(Pos);\n"
"}\n"
10 changes: 10 additions & 0 deletions Hydrogent/shaders_inc/HnAxesStructures.fxh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"#ifndef _HN_AXES_STRUCTURES_FXH_\n"
"#define _HN_AXES_STRUCTURES_FXH_\n"
"\n"
"struct AxesConstants\n"
"{\n"
" float4x4 Transform;\n"
" float4 AxesColors[6]; // -X, +X, -Y, +Y, -Z, +Z\n"
"};\n"
"\n"
"#endif // _HN_AXES_STRUCTURES_FXH_\n"
12 changes: 12 additions & 0 deletions Hydrogent/shaders_inc/shaders_list.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
static const MemoryShaderSourceFileInfo g_Shaders[] =
{
{
"HnAxes.psh",
#include "HnAxes.psh.h"
},
{
"HnAxes.vsh",
#include "HnAxes.vsh.h"
},
{
"HnAxesStructures.fxh",
#include "HnAxesStructures.fxh.h"
},
{
"HnClosestSelectedLocation.fxh",
#include "HnClosestSelectedLocation.fxh.h"
Expand Down
21 changes: 21 additions & 0 deletions Hydrogent/src/HnShaderSourceFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@
#include "HnShaderSourceFactory.hpp"
#include "ShaderSourceFactoryUtils.h"

#include "../../../Utilities/include/DiligentFXShaderSourceStreamFactory.hpp"
#include "ShaderSourceFactoryUtils.h"

namespace Diligent
{

namespace USD
{

#include "../shaders_inc/shaders_list.h"

HnShaderSourceFactory::HnShaderSourceFactory()
Expand All @@ -45,4 +51,19 @@ IShaderSourceInputStreamFactory& HnShaderSourceFactory::GetInstance()
return *TheFactory.m_pFactory;
}

RefCntAutoPtr<IShaderSourceInputStreamFactory> HnShaderSourceFactory::CreateHnFxCompoundFactory()
{
IShaderSourceInputStreamFactory* ppShaderSourceFactories[] =
{
&HnShaderSourceFactory::GetInstance(),
&DiligentFXShaderSourceStreamFactory::GetInstance(),
};
CompoundShaderSourceFactoryCreateInfo CompoundSourceFactoryCI{ppShaderSourceFactories, _countof(ppShaderSourceFactories)};
RefCntAutoPtr<IShaderSourceInputStreamFactory> pHnFxCompoundSourceFactory;
CreateCompoundShaderSourceFactory(CompoundSourceFactoryCI, &pHnFxCompoundSourceFactory);
return pHnFxCompoundSourceFactory;
}

} // namespace USD

} // namespace Diligent
Loading

0 comments on commit fd165cd

Please sign in to comment.