VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
metalLICPass.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2025-2026 Arnis Lektauers
3//
4// Surface LIC (Line Integral Convolution) post-processing pass.
5//
6// Renders flow direction as a dense texture-based visualization by
7// convolving noise along screen-space velocity vectors.
8//
9// Pipeline (single full-screen fragment pass):
10// 1. Read velocity texture (RG16Float — screen-space velocity per pixel)
11// 2. Read tiled noise texture (R8Unorm — 200×200 white noise)
12// 3. For each pixel, trace forward/backward through velocity field,
13// accumulate noise values → grayscale LIC output
14// 4. Apply contrast enhancement
15// 5. Output as R8Unorm or modulate with scene color
16//
17// Follows the MetalTaaPass decomposition pattern:
18// - Embedded MSL source as string literal
19// - Full-screen triangle from MetalComposePass
20// - Lazy resource creation
21// - Uniforms via setFragmentBytes
22//
23// References:
24// - Cabral & Leedom, SIGGRAPH 1993 (original LIC)
25// - Laramee et al. 2003 (image-space LIC)
26// - VTK vtkSurfaceLICInterface (production reference)
27//
28#pragma once
29
30#include <memory>
31#include <Metal/Metal.hpp>
32
33namespace visutwin::canvas
34{
35 class BlendState;
36 class DepthState;
38 class MetalComposePass;
41 class RenderTarget;
42 class Shader;
43 class Texture;
44
50 {
51 public:
54
70 void execute(MTL::RenderCommandEncoder* encoder,
71 Texture* velocityTexture,
72 Texture* noiseTexture,
73 int integrationSteps,
74 float stepSize,
75 float animationPhase,
76 float contrastLo,
77 float contrastHi,
78 MetalRenderPipeline* pipeline,
79 const std::shared_ptr<RenderTarget>& renderTarget,
80 const std::vector<std::shared_ptr<MetalBindGroupFormat>>& bindGroupFormats,
81 MTL::SamplerState* defaultSampler,
82 MTL::DepthStencilState* defaultDepthStencilState);
83
84 private:
85 void ensureResources();
86
87 MetalGraphicsDevice* _device;
88 MetalComposePass* _composePass;
89
90 std::shared_ptr<Shader> _shader;
91 std::shared_ptr<BlendState> _blendState;
92 std::shared_ptr<DepthState> _depthState;
93 MTL::DepthStencilState* _depthStencilState = nullptr;
94 };
95}
void execute(MTL::RenderCommandEncoder *encoder, Texture *velocityTexture, Texture *noiseTexture, int integrationSteps, float stepSize, float animationPhase, float contrastLo, float contrastHi, MetalRenderPipeline *pipeline, const std::shared_ptr< RenderTarget > &renderTarget, const std::vector< std::shared_ptr< MetalBindGroupFormat > > &bindGroupFormats, MTL::SamplerState *defaultSampler, MTL::DepthStencilState *defaultDepthStencilState)
MetalLICPass(MetalGraphicsDevice *device, MetalComposePass *composePass)
GPU texture resource supporting 2D, cubemap, volume, and array formats with mipmap management.
Definition texture.h:57