Baking spline deformation to a texture then applying it to a mesh via a shader.
Sample for baking deformation to a texture then applying it to a mesh via a shader.
I saw Simon Trümpler's Tileable Liquid Mesh on Spline and I was wondering how the mesh was following the spline exactly. It gave me the idea of baking the deformation to a texture somehow, which actually turned out to be really simple.
Deformation Lookup Shader
shader.Z Start
and Z End
properties accordingly.IDeformationProvider
interface in the script that is responsible for the deformation that you want to bake or use the provided BezierSpline
script.DeformationTextureRenderer
script to the scene. I recommend adding it next to the mesh you'll be deforming.Amount
is set to 1 in the material. This feature exists for quickly toggling the effect on and off to see what it does.Z Start
and Z End
are set correctly in the materialGo to Edit > Project Settings > Package Manager
. Under 'Scoped Registries' make sure there is an OpenUPM entry.
If you don't have one: click the +
button and enter the following values:
OpenUPM
https://package.openupm.com
Then under 'Scope(s)' press the +
button and add com.roytheunissen
.
It should look something like this:
You can check out this repository as a submodule into your project's Assets folder. This is recommended if you intend to contribute to the repository yourself
The package is available on the openupm registry. It's recommended to install it via openupm-cli.
openupm add com.roytheunissen.gpusplinedeformation
You can also install via git URL by adding this entry in your manifest.json
"com.roytheunissen.gpusplinedeformation": "https://github.com/RoyTheunissen/GPU-Spline-Deformation.git"
from Window->Package Manager, click on the + sign and Add from git: https://github.com/RoyTheunissen/GPU-Spline-Deformation.git