Code Monkey home page Code Monkey logo

gpu-spline-deformation's Introduction

Roy Theunissen License: MIT GitHub Follow Twitter

Sample for baking deformation to a texture then applying it to a mesh via a shader.

About the Project

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.

Video | Article

Example

Getting Started

  • Add the package to your Unity project (tips on how to install it are in the Installation section)
  • Create the mesh you will be deforming that's pointing in the forward Z axis. Samples are provided.
    • Make sure it has a material with the Deformation Lookup Shader shader.
    • If the mesh does not start at (0, 0, 0) and stop at (0, 0, 1), adjust the Z Start and Z End properties accordingly.
  • Implement the IDeformationProvider interface in the script that is responsible for the deformation that you want to bake or use the provided BezierSpline script.
  • Add a DeformationTextureRenderer script to the scene. I recommend adding it next to the mesh you'll be deforming.
  • Assign the script responsible for the deformation to the Deformation Provider field.
    • Assign the material for the mesh that will be deformed (this is necessary for assigning it dynamically created textures)
  • You should now see the mesh deform along whatever deformation is provided via the script.

Troubleshooting

  • If the mesh is not deforming, check that Amount is set to 1 in the material. This feature exists for quickly toggling the effect on and off to see what it does.
  • If the mesh is not deforming, check that it has the right material, shader and texture assigned
  • Make sure the correct texture asset and/or material are assigned in the Deformation Texture Renderer
  • If you are seeing artifacts or incorrect deformation:
    • Make sure the resolution is sufficiently large. Set the mode to Dynamic and try out larger resolutions until the artifacts disappear
    • Make sure Z Start and Z End are set correctly in the material
    • Make sure the texture's wrap mode is set to clamp. For looping meshes you may want the X-axis to be set to Repeat

Installation

Package Manager

Go 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:

  • Name: OpenUPM
  • URL: https://package.openupm.com

Then under 'Scope(s)' press the + button and add com.roytheunissen.

It should look something like this:
image


All of my packages will now be available to you in the Package Manager in the 'My Registries' section and can be installed from there.

Git Submodule

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

OpenUPM

The package is available on the openupm registry. It's recommended to install it via openupm-cli.

openupm add com.roytheunissen.gpusplinedeformation

Manifest

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"

Unity Package Manager

from Window->Package Manager, click on the + sign and Add from git: https://github.com/RoyTheunissen/GPU-Spline-Deformation.git

Contact

Roy Theunissen

[email protected]

Acknowledgements

gpu-spline-deformation's People

Contributors

brunomikoski avatar roytheunissen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

gpu-spline-deformation's Issues

Generated Mesh Not Showing at Some Camera Angles

Hi, thanks for making your work public and it's a great technique.

I'd just like to let you know that the generated mesh doesn't appear at some camera angles, if a part of its spline doesn't show in the Scene or Game view. If the whole spline appears in the Scene or Game view, the generated mesh becomes more stable.

I tested it with Unity 2019.2.1f1 and 2021.1.15f1. Here's what happened when I tilted the camera a little:

Seen_on_Cam
After_Cam_is_Tilted

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.