219 const int integrationSteps,
220 const float stepSize,
221 const float animationPhase,
222 const float contrastLo,
223 const float contrastHi,
225 const std::shared_ptr<RenderTarget>& renderTarget,
226 const std::vector<std::shared_ptr<MetalBindGroupFormat>>& bindGroupFormats,
227 MTL::SamplerState* defaultSampler,
228 MTL::DepthStencilState* defaultDepthStencilState)
230 if (!encoder || !velocityTexture || !noiseTexture) {
235 if (!_shader || !_composePass->vertexBuffer() || !_composePass->vertexFormat() ||
236 !_blendState || !_depthState) {
237 spdlog::warn(
"[MetalLICPass] missing resources");
247 auto pipelineState = pipeline->
get(primitive, _composePass->vertexFormat(),
nullptr, -1,
248 _shader, renderTarget, bindGroupFormats, _blendState, _depthState,
250 if (!pipelineState) {
251 spdlog::warn(
"[MetalLICPass] failed to get pipeline state");
256 if (!vb || !vb->raw()) {
257 spdlog::warn(
"[MetalLICPass] missing vertex buffer");
261 encoder->setRenderPipelineState(pipelineState);
262 encoder->setCullMode(MTL::CullModeNone);
263 encoder->setDepthStencilState(
264 _depthStencilState ? _depthStencilState : defaultDepthStencilState);
265 encoder->setVertexBuffer(vb->raw(), 0, 0);
271 encoder->setFragmentTexture(velHw ? velHw->raw() :
nullptr, 0);
272 encoder->setFragmentTexture(noiseHw ? noiseHw->raw() :
nullptr, 1);
273 if (defaultSampler) {
274 encoder->setFragmentSamplerState(defaultSampler, 0);
278 struct alignas(16) LICUniforms
280 simd::float2 textureSize;
281 simd::float2 noiseSize;
283 float animationPhase;
284 int32_t integrationSteps;
290 uniforms.textureSize = simd::float2{
291 static_cast<float>(std::max(velocityTexture->
width(), 1u)),
292 static_cast<float>(std::max(velocityTexture->
height(), 1u))
294 uniforms.noiseSize = simd::float2{
295 static_cast<float>(std::max(noiseTexture->
width(), 1u)),
296 static_cast<float>(std::max(noiseTexture->
height(), 1u))
298 uniforms.stepSize = stepSize;
299 uniforms.animationPhase = animationPhase;
300 uniforms.integrationSteps = integrationSteps;
301 uniforms.contrastLo = contrastLo;
302 uniforms.contrastHi = contrastHi;
303 uniforms.minVelocity = 1.0e-6f;
305 encoder->setFragmentBytes(&uniforms,
sizeof(LICUniforms), 5);
307 encoder->drawPrimitives(MTL::PrimitiveTypeTriangle,
308 static_cast<NS::UInteger
>(0),
static_cast<NS::UInteger
>(3));
309 _device->recordDrawCall();
GPU texture resource supporting 2D, cubemap, volume, and array formats with mipmap management.
gpu::HardwareTexture * impl() const