3737#include " ShaderMacroHelper.hpp"
3838#include " FileSystem.hpp"
3939#include " imgui.h"
40- #include " imGuIZMO.h"
40+ #include " ../imGuIZMO.quat/ imGuIZMO.h"
4141#include " ImGuiUtils.hpp"
4242#include " CallbackWrapper.hpp"
4343#include " CommandLineParser.hpp"
@@ -427,6 +427,18 @@ struct PSOutput
427427}
428428
429429static 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"(
430442void main(in float4 Pos : SV_Position,
431443 in float4 ClipPos : CLIP_POS,
432444 out float4 Color : SV_Target0,
@@ -436,12 +448,12 @@ void main(in float4 Pos : SV_Position,
436448 out float4 MotionVec : SV_Target4,
437449 out float4 SpecularIBL : SV_Target5)
438450{
439- Color = SampleEnvMap(ClipPos);
440-
451+ SampleEnvMapOutput EnvMap = SampleEnvMap(ClipPos);
452+ Color = EnvMap.Color;
441453 Normal = float4(0.0, 0.0, 0.0, 0.0);
442454 BaseColor = float4(0.0, 0.0, 0.0, 0.0);
443455 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);
445457 SpecularIBL = float4(0.0, 0.0, 0.0, 0.0);
446458}
447459)" ;
@@ -539,8 +551,12 @@ void GLTFViewer::CrateEnvMapRenderer()
539551
540552 if (m_pDevice->GetDeviceInfo ().IsGLDevice ())
541553 {
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 .
543555 // However, on WebGL this results in errors.
556+ EnvMapRendererCI.PSMainSource = EnvMapPSMainGL;
557+ }
558+ else
559+ {
544560 EnvMapRendererCI.PSMainSource = EnvMapPSMain;
545561 }
546562 }
@@ -1197,8 +1213,9 @@ void GLTFViewer::Render()
11971213 EnvMapAttribs.MipLevel = m_EnvMapMipLevel;
11981214 // It is essential to write zero alpha because we use alpha channel
11991215 // 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;
12021219
12031220 m_EnvMapRenderer->Render (EnvMapAttribs, TMAttribs);
12041221 }
@@ -1274,7 +1291,7 @@ void GLTFViewer::Render()
12741291 Attribs.pContext = m_pImmediateContext;
12751292 Attribs.GridSize = {SCDesc.Width / 20 , SCDesc.Height / 20 };
12761293 // 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 );
12781295 Attribs.StartColor = float4{1 };
12791296 Attribs.EndColor = float4{0.5 , 0.5 , 0.5 , 1.0 };
12801297 Attribs.ConvertOutputToSRGB = (SCDesc.ColorBufferFormat == TEX_FORMAT_RGBA8_UNORM || SCDesc.ColorBufferFormat == TEX_FORMAT_BGRA8_UNORM);
0 commit comments