Beispiel #1
0
    void ExecuteHighlightByStencil(
        RenderCore::Metal::DeviceContext& metalContext,
        RenderCore::Metal::ShaderResourceView& inputStencil,
        const HighlightByStencilSettings& settings,
        bool onlyHighlighted)
    {
        using namespace RenderCore;

        metalContext.BindPS(MakeResourceList(Metal::ConstantBuffer(&settings, sizeof(settings))));
        metalContext.BindPS(MakeResourceList(inputStencil));
        metalContext.Bind(Techniques::CommonResources()._dssDisable);
        metalContext.Bind(Techniques::CommonResources()._blendAlphaPremultiplied);
        metalContext.Bind(Metal::Topology::TriangleStrip);
        metalContext.Unbind<Metal::BoundInputLayout>();

        auto desc = BufferUploads::ExtractDesc(*inputStencil.GetResource());
        if (desc._type != BufferUploads::BufferDesc::Type::Texture) return;

        bool stencilInput = 
            Metal::AsTypelessFormat((Metal::NativeFormat::Enum)desc._textureDesc._nativePixelFormat) 
            == Metal::NativeFormat::R24G8_TYPELESS;
                
        StringMeld<64, ::Assets::ResChar> params;
        params << "ONLY_HIGHLIGHTED=" << unsigned(onlyHighlighted);
        params << ";INPUT_MODE=" << (stencilInput?0:1);

        {
            auto& shader = ::Assets::GetAssetDep<Metal::ShaderProgram>(
                "game/xleres/basic2D.vsh:fullscreen:vs_*", 
                "game/xleres/Vis/HighlightVis.psh:HighlightByStencil:ps_*",
                (const ::Assets::ResChar*)params);
                
            metalContext.Bind(shader);
            metalContext.Draw(4);
        }

        {
            auto& shader = ::Assets::GetAssetDep<Metal::ShaderProgram>(
                "game/xleres/basic2D.vsh:fullscreen:vs_*", 
                "game/xleres/Vis/HighlightVis.psh:OutlineByStencil:ps_*",
                (const ::Assets::ResChar*)params);
                
            metalContext.Bind(shader);
            metalContext.Draw(4);
        }

        metalContext.UnbindPS<Metal::ShaderResourceView>(0, 1);
    }
Beispiel #2
0
    void DeepOceanSim::DrawDebugging(   
        RenderCore::Metal::DeviceContext& context, 
        LightingParserContext& parserContext,
        const DeepOceanSimSettings& oceanSettings)
    {
        using namespace RenderCore;

        const unsigned dimensions       = oceanSettings._gridDimensions;
        const Float2 physicalDimensions = Float2(oceanSettings._physicalDimensions, oceanSettings._physicalDimensions);
        const Float2 calmWindVector     = oceanSettings._windVelocity[0] * Float2(XlCos(oceanSettings._windAngle[0]), XlSin(oceanSettings._windAngle[0]));
        const Float2 strongWindVector   = oceanSettings._windVelocity[1] * Float2(XlCos(oceanSettings._windAngle[1]), XlSin(oceanSettings._windAngle[1]));

        auto& calmSpectrum = Techniques::FindCachedBox<StartingSpectrumBox>(
            StartingSpectrumBox::Desc(  dimensions,dimensions, physicalDimensions, calmWindVector, 
                                        oceanSettings._scaleAgainstWind[0], oceanSettings._suppressionFactor[0]));
        auto& strongSpectrum = Techniques::FindCachedBox<StartingSpectrumBox>(
            StartingSpectrumBox::Desc(  dimensions,dimensions, physicalDimensions, strongWindVector, 
                                        oceanSettings._scaleAgainstWind[1], oceanSettings._suppressionFactor[1]));

        SetupVertexGeneratorShader(context);
        context.Bind(Techniques::CommonResources()._blendStraightAlpha);
        context.Bind(::Assets::GetAssetDep<Metal::ShaderProgram>(
            "game/xleres/basic2D.vsh:fullscreen:vs_*", "game/xleres/Ocean/FFTDebugging.psh:main:ps_*"));
        context.BindPS(MakeResourceList(
            _workingTextureRealSRV, _workingTextureImaginarySRV,
            calmSpectrum._inputRealShaderResource, calmSpectrum._inputImaginaryShaderResource,
            strongSpectrum._inputRealShaderResource, strongSpectrum._inputImaginaryShaderResource));
        context.Draw(4);
    }
Beispiel #3
0
    void BinaryHighlight::FinishWithOutline(RenderCore::Metal::DeviceContext& metalContext, Float3 outlineColor)
    {
        using namespace RenderCore;
        _pimpl->_savedTargets.ResetToOldTargets(metalContext);

            //  now we can render these objects over the main image, 
            //  using some filtering

        metalContext.BindPS(MakeResourceList(_pimpl->_srv));

        struct Constants
        {
            Float3 _color; unsigned _dummy;
        } constants = { outlineColor, 0 };
        RenderCore::SharedPkt pkts[] = { MakeSharedPkt(constants) };

        auto& shaders = Techniques::FindCachedBoxDep<HighlightShaders>(HighlightShaders::Desc());
        shaders._drawHighlightUniforms.Apply(
            metalContext, 
            RenderCore::Metal::UniformsStream(), 
            RenderCore::Metal::UniformsStream(pkts, nullptr, dimof(pkts)));
        metalContext.Bind(*shaders._drawHighlight);
        metalContext.Bind(Techniques::CommonResources()._blendAlphaPremultiplied);
        metalContext.Bind(Techniques::CommonResources()._dssDisable);
        metalContext.Bind(Metal::Topology::TriangleStrip);
        metalContext.Draw(4);
    }
Beispiel #4
0
    void RTShadows_DrawMetrics(
        RenderCore::Metal::DeviceContext& context, 
        LightingParserContext& parserContext, MainTargetsBox& mainTargets)
    {
        SavedTargets savedTargets(context);
        auto restoreMarker = savedTargets.MakeResetMarker(context);

        context.GetUnderlying()->OMSetRenderTargets(1, savedTargets.GetRenderTargets(), nullptr); // (unbind depth)

        context.BindPS(MakeResourceList(5, mainTargets._gbufferRTVsSRV[0], mainTargets._gbufferRTVsSRV[1], mainTargets._gbufferRTVsSRV[2], mainTargets._msaaDepthBufferSRV));
        const bool useMsaaSamplers = mainTargets._desc._sampling._sampleCount > 1;

        StringMeld<256> defines;
        defines << "SHADOW_CASCADE_MODE=2";
        if (useMsaaSamplers) defines << ";MSAA_SAMPLERS=1";

        auto& debuggingShader = ::Assets::GetAssetDep<Metal::ShaderProgram>(
            "game/xleres/basic2D.vsh:fullscreen:vs_*", 
            "game/xleres/shadowgen/rtshadmetrics.sh:ps_main:ps_*",
            defines.get());
        Metal::BoundUniforms uniforms(debuggingShader);
        Techniques::TechniqueContext::BindGlobalUniforms(uniforms);
        uniforms.BindShaderResources(1, {"RTSListsHead", "RTSLinkedLists", "RTSTriangles", "DepthTexture"});
        uniforms.BindConstantBuffers(1, {"OrthogonalShadowProjection", "ScreenToShadowProjection"});

        context.Bind(debuggingShader);
        context.Bind(Techniques::CommonResources()._blendStraightAlpha);
        SetupVertexGeneratorShader(context);

        for (const auto& p:parserContext._preparedRTShadows) {
            const Metal::ShaderResourceView* srvs[] = 
                { &p.second._listHeadSRV, &p.second._linkedListsSRV, &p.second._trianglesSRV, &mainTargets._msaaDepthBufferSRV };

            SharedPkt constants[2];
            const Metal::ConstantBuffer* prebuiltConstants[2] = {nullptr, nullptr};
            prebuiltConstants[0] = &p.second._orthoCB;
            constants[1] = BuildScreenToShadowConstants(
                p.second, parserContext.GetProjectionDesc()._cameraToWorld,
                parserContext.GetProjectionDesc()._cameraToProjection);

            uniforms.Apply(
                context, parserContext.GetGlobalUniformsStream(), 
                Metal::UniformsStream(constants, prebuiltConstants, dimof(constants), srvs, dimof(srvs)));
        }

        context.Draw(4);
    }