Skip to content

Commit 6530fc7

Browse files
Hydrogent: don't write all render targets in bound box and env map tasks on GL
1 parent 6de5e52 commit 6530fc7

File tree

2 files changed

+6
-55
lines changed

2 files changed

+6
-55
lines changed

Hydrogent/src/Tasks/HnRenderBoundBoxTask.cpp

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void HnRenderBoundBoxTask::Sync(pxr::HdSceneDelegate* Delegate,
7272
*DirtyBits = pxr::HdChangeTracker::Clean;
7373
}
7474

75-
static std::string GetBoundBoxPSMain(bool IsGL)
75+
static std::string GetBoundBoxPSMain()
7676
{
7777
static_assert(HnFrameRenderTargets::GBUFFER_TARGET_COUNT == 7, "Did you change the number of G-buffer targets? You may need to update the code below.");
7878

@@ -83,21 +83,6 @@ void main(in BoundBoxVSOutput VSOut,
8383
ss << " out float4 Color : SV_Target" << HnFrameRenderTargets::GBUFFER_TARGET_SCENE_COLOR << ',' << std::endl
8484
<< " out float4 MotionVec : SV_Target" << HnFrameRenderTargets::GBUFFER_TARGET_MOTION_VECTOR;
8585

86-
if (IsGL)
87-
{
88-
// Normally, bound box shader does not need to write to anything but
89-
// color and motion vector targets.
90-
// However, in OpenGL this somehow results in color output also being
91-
// written to the MeshID target. To work around this issue, we use a
92-
// custom shader that writes 0.
93-
ss << ',' << std::endl
94-
<< " out float4 MeshId : SV_Target" << HnFrameRenderTargets::GBUFFER_TARGET_MESH_ID << ',' << std::endl
95-
<< " out float4 Normal : SV_Target" << HnFrameRenderTargets::GBUFFER_TARGET_NORMAL << ',' << std::endl
96-
<< " out float4 BaseColor : SV_Target" << HnFrameRenderTargets::GBUFFER_TARGET_BASE_COLOR << ',' << std::endl
97-
<< " out float4 Material : SV_Target" << HnFrameRenderTargets::GBUFFER_TARGET_MATERIAL << ',' << std::endl
98-
<< " out float4 IBL : SV_Target" << HnFrameRenderTargets::GBUFFER_TARGET_IBL;
99-
}
100-
10186
ss << R"()
10287
{
10388
BoundBoxOutput BoundBox = GetBoundBoxOutput(VSOut);
@@ -107,21 +92,9 @@ void main(in BoundBoxVSOutput VSOut,
10792
Color = float4(BoundBox.Color.rgb, 0.0);
10893
10994
MotionVec = float4(BoundBox.MotionVector, 0.0, 1.0);
95+
}
11096
)";
11197

112-
if (IsGL)
113-
{
114-
ss << R"(
115-
MeshId = float4(0.0, 0.0, 0.0, 1.0);
116-
Normal = float4(0.0, 0.0, 1.0, 1.0);
117-
BaseColor = float4(0.0, 0.0, 0.0, 0.0);
118-
Material = float4(0.0, 0.0, 0.0, 0.0);
119-
IBL = float4(0.0, 0.0, 0.0, 0.0);
120-
)";
121-
}
122-
123-
ss << "}\n";
124-
12598
return ss.str();
12699
}
127100

@@ -185,7 +158,7 @@ void HnRenderBoundBoxTask::Prepare(pxr::HdTaskContext* TaskCtx,
185158
BoundBoxRndrCI.RenderTargetMask = ((1u << HnFrameRenderTargets::GBUFFER_TARGET_SCENE_COLOR) |
186159
(1u << HnFrameRenderTargets::GBUFFER_TARGET_MOTION_VECTOR));
187160

188-
const std::string PSMain = GetBoundBoxPSMain(BoundBoxRndrCI.pDevice->GetDeviceInfo().IsGLDevice());
161+
const std::string PSMain = GetBoundBoxPSMain();
189162

190163
BoundBoxRndrCI.PSMainSource = PSMain.c_str();
191164

Hydrogent/src/Tasks/HnRenderEnvMapTask.cpp

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void HnRenderEnvMapTask::Sync(pxr::HdSceneDelegate* Delegate,
8181
*DirtyBits = pxr::HdChangeTracker::Clean;
8282
}
8383

84-
static std::string GetEnvMapPSMain(bool WriteAllTargets)
84+
static std::string GetEnvMapPSMain()
8585
{
8686
static_assert(HnFrameRenderTargets::GBUFFER_TARGET_COUNT == 7, "Did you change the number of G-buffer targets? You may need to update the code below.");
8787

@@ -93,37 +93,15 @@ void main(in float4 Pos : SV_Position,
9393
ss << " out float4 Color : SV_Target" << HnFrameRenderTargets::GBUFFER_TARGET_SCENE_COLOR << ',' << std::endl
9494
<< " out float4 MotionVec : SV_Target" << HnFrameRenderTargets::GBUFFER_TARGET_MOTION_VECTOR;
9595

96-
if (WriteAllTargets)
97-
{
98-
ss << ',' << std::endl
99-
<< " out float4 MeshId : SV_Target" << HnFrameRenderTargets::GBUFFER_TARGET_MESH_ID << ',' << std::endl
100-
<< " out float4 Normal : SV_Target" << HnFrameRenderTargets::GBUFFER_TARGET_NORMAL << ',' << std::endl
101-
<< " out float4 BaseColor : SV_Target" << HnFrameRenderTargets::GBUFFER_TARGET_BASE_COLOR << ',' << std::endl
102-
<< " out float4 Material : SV_Target" << HnFrameRenderTargets::GBUFFER_TARGET_MATERIAL << ',' << std::endl
103-
<< " out float4 IBL : SV_Target" << HnFrameRenderTargets::GBUFFER_TARGET_IBL;
104-
}
105-
10696
ss << R"()
10797
{
10898
SampleEnvMapOutput EnvMap = SampleEnvMap(ClipPos);
10999
110100
Color = EnvMap.Color;
111101
MotionVec = float4(EnvMap.MotionVector, 0.0, 1.0);
102+
}
112103
)";
113104

114-
if (WriteAllTargets)
115-
{
116-
ss << R"(
117-
MeshId = float4(0.0, 0.0, 0.0, 1.0);
118-
Normal = float4(0.0, 0.0, 0.0, 0.0);
119-
BaseColor = float4(0.0, 0.0, 0.0, 0.0);
120-
Material = float4(0.0, 0.0, 0.0, 0.0);
121-
IBL = float4(0.0, 0.0, 0.0, 0.0);
122-
)";
123-
}
124-
125-
ss << "}\n";
126-
127105
return ss.str();
128106
}
129107

@@ -156,7 +134,7 @@ void HnRenderEnvMapTask::Prepare(pxr::HdTaskContext* TaskCtx,
156134
EnvMapRndrCI.RenderTargetMask = ((1u << HnFrameRenderTargets::GBUFFER_TARGET_SCENE_COLOR) |
157135
(1u << HnFrameRenderTargets::GBUFFER_TARGET_MOTION_VECTOR));
158136

159-
const std::string PSMain = GetEnvMapPSMain(EnvMapRndrCI.pDevice->GetDeviceInfo().IsGLDevice());
137+
const std::string PSMain = GetEnvMapPSMain();
160138

161139
EnvMapRndrCI.PSMainSource = PSMain.c_str();
162140

0 commit comments

Comments
 (0)