diff --git a/Editor/CameraComponentWindow.cpp b/Editor/CameraComponentWindow.cpp index ce1ff2c42..b5c4eb460 100644 --- a/Editor/CameraComponentWindow.cpp +++ b/Editor/CameraComponentWindow.cpp @@ -242,6 +242,13 @@ void CameraComponentWindow::Create(EditorComponent* _editor) })); AddWidget(&samplecountSlider); + crtCheckbox.Create("CRT: "); + crtCheckbox.SetTooltip("Toggle CRT TV mode for this camera (when render to texture is enabled)"); + crtCheckbox.OnClick(forEachSelectedCameraComponent([](auto camera, auto args) { + camera->SetCRT(args.bValue); + })); + AddWidget(&crtCheckbox); + AddWidget(&preview); @@ -275,6 +282,7 @@ void CameraComponentWindow::SetEntity(Entity entity) resolutionXSlider.SetValue((int)camera->render_to_texture.resolution.x); resolutionYSlider.SetValue((int)camera->render_to_texture.resolution.y); samplecountSlider.SetValue((int)camera->render_to_texture.sample_count); + crtCheckbox.SetCheck(camera->IsCRT()); preview.entity = entity; preview.renderpath.scene = &scene; @@ -311,16 +319,19 @@ void CameraComponentWindow::ResizeLayout() resolutionXSlider.SetVisible(true); resolutionYSlider.SetVisible(true); samplecountSlider.SetVisible(true); + crtCheckbox.SetVisible(true); layout.add(resolutionXSlider); layout.add(resolutionYSlider); layout.add(samplecountSlider); + layout.add_right(crtCheckbox); } else { resolutionXSlider.SetVisible(false); resolutionYSlider.SetVisible(false); samplecountSlider.SetVisible(false); + crtCheckbox.SetVisible(false); } layout.jump(); diff --git a/Editor/CameraComponentWindow.h b/Editor/CameraComponentWindow.h index b46c98302..8d8d3c915 100644 --- a/Editor/CameraComponentWindow.h +++ b/Editor/CameraComponentWindow.h @@ -34,6 +34,7 @@ public: wi::gui::Slider resolutionXSlider; wi::gui::Slider resolutionYSlider; wi::gui::Slider samplecountSlider; + wi::gui::CheckBox crtCheckbox; CameraPreview preview; diff --git a/WickedEngine/shaders/crt_screenCS.hlsl b/WickedEngine/shaders/crt_screenCS.hlsl index cfb95ff6f..fdade2c12 100644 --- a/WickedEngine/shaders/crt_screenCS.hlsl +++ b/WickedEngine/shaders/crt_screenCS.hlsl @@ -157,6 +157,7 @@ void main(uint3 DTid : SV_DispatchThreadID) float2 uv = (DTid.xy + 0.5) * postprocess.resolution_rcp.xy; //uv = Warp(uv); color.rgb=Tri(uv)*Mask(DTid.xy); + color.rgb *= 1 + sin(GetTime() * 100) * postprocess.params0.x; color.rgb=ToSrgb(color.rgb); output[DTid.xy] = color; diff --git a/WickedEngine/wiRenderPath3D.cpp b/WickedEngine/wiRenderPath3D.cpp index a81a2081f..040a38475 100644 --- a/WickedEngine/wiRenderPath3D.cpp +++ b/WickedEngine/wiRenderPath3D.cpp @@ -2642,7 +2642,7 @@ namespace wi wi::jobsystem::Execute(ctx, [this, cmd, i](wi::jobsystem::JobArgs args) { GraphicsDevice* device = GetDevice(); - const wi::scene::CameraComponent& camera = scene->cameras[i]; // reload, not captured in lambda (alloc) + wi::scene::CameraComponent& camera = scene->cameras[i]; // reload, not captured in lambda (alloc) wi::renderer::Visibility& visibility = *(wi::renderer::Visibility*)camera.render_to_texture.visibility.get(); visibility.layerMask = getLayerMask(); visibility.scene = scene; @@ -2728,6 +2728,12 @@ namespace wi wi::renderer::DrawLightVisualizers(visibility, cmd); device->RenderPassEnd(cmd); + if (camera.IsCRT() && getSceneUpdateEnabled()) + { + wi::renderer::Postprocess_CRT(camera.render_to_texture.rendertarget_render, camera.render_to_texture.rendertarget_display, cmd, 0.2f); + std::swap(camera.render_to_texture.rendertarget_render, camera.render_to_texture.rendertarget_display); + } + wi::renderer::GenerateMipChain(camera.render_to_texture.rendertarget_render, wi::renderer::MIPGENFILTER_LINEAR, cmd); } device->EventEnd(cmd); diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 062a1496a..50f73bd29 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -16850,7 +16850,8 @@ void Postprocess_Sharpen( void Postprocess_CRT( const Texture& input, const Texture& output, - CommandList cmd + CommandList cmd, + float flicker ) { ScopedGPUProfiling("Postprocess_CRT", cmd); @@ -16867,6 +16868,7 @@ void Postprocess_CRT( postprocess.resolution.y = desc.height; postprocess.resolution_rcp.x = 1.0f / postprocess.resolution.x; postprocess.resolution_rcp.y = 1.0f / postprocess.resolution.y; + postprocess.params0.x = flicker; device->PushConstants(&postprocess, sizeof(postprocess), cmd); const GPUResource* uavs[] = { diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index ab3d50134..74b249987 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -848,7 +848,8 @@ namespace wi::renderer void Postprocess_CRT( const wi::graphics::Texture& input, const wi::graphics::Texture& output, - wi::graphics::CommandList cmd + wi::graphics::CommandList cmd, + float flicker = 0 ); enum class Tonemap { diff --git a/WickedEngine/wiScene_Components.h b/WickedEngine/wiScene_Components.h index 99b41aabe..4cad99b8e 100644 --- a/WickedEngine/wiScene_Components.h +++ b/WickedEngine/wiScene_Components.h @@ -1408,6 +1408,7 @@ namespace wi::scene DIRTY = 1 << 0, CUSTOM_PROJECTION = 1 << 1, ORTHO = 1 << 2, + CRT_FILTER = 1 << 3, }; uint32_t _flags = EMPTY; @@ -1496,9 +1497,11 @@ namespace wi::scene constexpr void SetDirty(bool value = true) { if (value) { _flags |= DIRTY; } else { _flags &= ~DIRTY; } } constexpr void SetCustomProjectionEnabled(bool value = true) { if (value) { _flags |= CUSTOM_PROJECTION; } else { _flags &= ~CUSTOM_PROJECTION; } } constexpr void SetOrtho(bool value = true) { if (value) { _flags |= ORTHO; } else { _flags &= ~ORTHO; } SetDirty(); } + constexpr void SetCRT(bool value = true) { if (value) { _flags |= CRT_FILTER; } else { _flags &= ~CRT_FILTER; } SetDirty(); } constexpr bool IsDirty() const { return _flags & DIRTY; } constexpr bool IsCustomProjectionEnabled() const { return _flags & CUSTOM_PROJECTION; } constexpr bool IsOrtho() const { return _flags & ORTHO; } + constexpr bool IsCRT() const { return _flags & CRT_FILTER; } void Lerp(const CameraComponent& a, const CameraComponent& b, float t); diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 00e2ba762..d2cef64f8 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 71; // minor bug fixes, alterations, refactors, updates - const int revision = 826; + const int revision = 827; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);