-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1c0260
commit fd165cd
Showing
15 changed files
with
519 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.