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); }
bool MaterialBinder::Apply( RenderCore::Metal::DeviceContext& metalContext, RenderCore::Techniques::ParsingContext& parserContext, unsigned techniqueIndex, const RenderCore::Assets::ResolvedMaterial& mat, const SystemConstants& sysConstants, const ::Assets::DirectorySearchRules& searchRules, const RenderCore::Metal::InputLayout& geoInputLayout) { using namespace RenderCore; using namespace RenderCore::Techniques; ParameterBox materialParameters = RenderCore::Assets::TechParams_SetResHas(mat._matParams, mat._bindings, searchRules); TechniqueMaterial material(geoInputLayout, {}, materialParameters); auto variation = material.FindVariation(parserContext, techniqueIndex, _shaderTypeName.c_str()); if (variation._shader._shaderProgram == nullptr) { return false; // we can't render because we couldn't resolve a good shader variation } // we must bind the shader program & the bound layout // but we're not using the BoundUniforms in the ResolvedShader object metalContext.Bind(*variation._shader._shaderProgram); metalContext.Bind(*variation._shader._boundLayout); // Instead of using ResolvedShader::_boundUniforms, let's // look at the reflection information for the shader program // and assign each shader input to some reasonable value BindConstantsAndResources( metalContext, parserContext, mat, sysConstants, searchRules, *variation._shader._boundUniforms, *variation._cbLayout); return true; }
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); }
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); }
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); }
BinaryHighlight::BinaryHighlight(RenderCore::Metal::DeviceContext& metalContext) { _pimpl = std::make_unique<Pimpl>(metalContext); const auto& viewport = _pimpl->_savedTargets.GetViewports()[0]; using namespace RenderCore; auto& offscreen = RenderCore::Techniques::FindCachedBox<CommonOffscreenTarget>( CommonOffscreenTarget::Desc(unsigned(viewport.Width), unsigned(viewport.Height), Metal::NativeFormat::R8G8B8A8_UNORM)); const bool doDepthTest = true; if (constant_expression<doDepthTest>::result()) { metalContext.Bind(Techniques::CommonResources()._dssReadOnly); Metal::DepthStencilView dsv(_pimpl->_savedTargets.GetDepthStencilView()); metalContext.Bind(MakeResourceList(offscreen._rtv), &dsv); } else { metalContext.Bind(MakeResourceList(offscreen._rtv), nullptr); } metalContext.Clear(offscreen._rtv, Float4(0.f, 0.f, 0.f, 0.f)); _pimpl->_srv = offscreen._srv; }