@@ -427,6 +427,18 @@ struct PSOutput
427
427
}
428
428
429
429
static constexpr char EnvMapPSMain[] = R"(
430
+ void main(in float4 Pos : SV_Position,
431
+ in float4 ClipPos : CLIP_POS,
432
+ out float4 Color : SV_Target0,
433
+ out float4 MotionVec : SV_Target4)
434
+ {
435
+ SampleEnvMapOutput EnvMap = SampleEnvMap(ClipPos);
436
+ Color = EnvMap.Color;
437
+ MotionVec = float4(EnvMap.MotionVector, 0.0, 1.0);
438
+ }
439
+ )" ;
440
+
441
+ static constexpr char EnvMapPSMainGL[] = R"(
430
442
void main(in float4 Pos : SV_Position,
431
443
in float4 ClipPos : CLIP_POS,
432
444
out float4 Color : SV_Target0,
@@ -436,12 +448,12 @@ void main(in float4 Pos : SV_Position,
436
448
out float4 MotionVec : SV_Target4,
437
449
out float4 SpecularIBL : SV_Target5)
438
450
{
439
- Color = SampleEnvMap(ClipPos);
440
-
451
+ SampleEnvMapOutput EnvMap = SampleEnvMap(ClipPos);
452
+ Color = EnvMap.Color;
441
453
Normal = float4(0.0, 0.0, 0.0, 0.0);
442
454
BaseColor = float4(0.0, 0.0, 0.0, 0.0);
443
455
MaterialData = float4(0.0, 0.0, 0.0, 0.0);
444
- MotionVec = float4(0.0 , 0.0, 0.0, 0 .0);
456
+ MotionVec = float4(EnvMap.MotionVector , 0.0, 1 .0);
445
457
SpecularIBL = float4(0.0, 0.0, 0.0, 0.0);
446
458
}
447
459
)" ;
@@ -539,8 +551,12 @@ void GLTFViewer::CrateEnvMapRenderer()
539
551
540
552
if (m_pDevice->GetDeviceInfo ().IsGLDevice ())
541
553
{
542
- // Normally, environment map shader does not need to write to other targets .
554
+ // Normally, environment map shader only needs to write color and motion vector .
543
555
// However, on WebGL this results in errors.
556
+ EnvMapRendererCI.PSMainSource = EnvMapPSMainGL;
557
+ }
558
+ else
559
+ {
544
560
EnvMapRendererCI.PSMainSource = EnvMapPSMain;
545
561
}
546
562
}
@@ -1197,8 +1213,9 @@ void GLTFViewer::Render()
1197
1213
EnvMapAttribs.MipLevel = m_EnvMapMipLevel;
1198
1214
// It is essential to write zero alpha because we use alpha channel
1199
1215
// to attenuate SSR for transparent surfaces.
1200
- EnvMapAttribs.Alpha = 0.0 ;
1201
- EnvMapAttribs.ConvertOutputToSRGB = (m_RenderParams.Flags & GLTF_PBR_Renderer::PSO_FLAG_CONVERT_OUTPUT_TO_SRGB) != 0 ;
1216
+ EnvMapAttribs.Alpha = 0.0 ;
1217
+ EnvMapAttribs.ConvertOutputToSRGB = (m_RenderParams.Flags & GLTF_PBR_Renderer::PSO_FLAG_CONVERT_OUTPUT_TO_SRGB) != 0 ;
1218
+ EnvMapAttribs.ComputeMotionVectors = m_bEnablePostProcessing;
1202
1219
1203
1220
m_EnvMapRenderer->Render (EnvMapAttribs, TMAttribs);
1204
1221
}
@@ -1274,7 +1291,7 @@ void GLTFViewer::Render()
1274
1291
Attribs.pContext = m_pImmediateContext;
1275
1292
Attribs.GridSize = {SCDesc.Width / 20 , SCDesc.Height / 20 };
1276
1293
// Render motion vectors in the opposite direction
1277
- Attribs.Scale = float2{-0 .05f } / std::max (m_ElapsedTime, 0 .001f );
1294
+ Attribs.Scale = float2{-0 .01f } / std::max (m_ElapsedTime, 0 .001f );
1278
1295
Attribs.StartColor = float4{1 };
1279
1296
Attribs.EndColor = float4{0.5 , 0.5 , 0.5 , 1.0 };
1280
1297
Attribs.ConvertOutputToSRGB = (SCDesc.ColorBufferFormat == TEX_FORMAT_RGBA8_UNORM || SCDesc.ColorBufferFormat == TEX_FORMAT_BGRA8_UNORM);
0 commit comments