Git Product home page Git Product logo

unity-technologies / com.unity.demoteam.mesh-to-sdf Goto Github PK

View Code? Open in Web Editor NEW
552.0 14.0 33.0 7.94 MB

A light and fast real-time SDF generator, primarily for animated characters. The dynamic SDF can be used for all sorts of VFX. Also enables hair-to-character collisions in the new hair package.

License: Other

C# 81.55% ShaderLab 2.88% HLSL 15.57%
billing-3020 owner-unity-demo-team

com.unity.demoteam.mesh-to-sdf's Introduction

Package: com.unity.demoteam.mesh-to-sdf

A real-time Signed Distance Field generator. Use a Mesh or a dynamically deforming SkinnedMesh as input to generate a 3D SDF texture every frame.

The SDF can be used by the VFX Graph, the Hair system, and other effects relying on SDFs.


mesh-to-sdf

The generator is real-time - to achieve better performance, it sacrifices robustness and the ability to handle large meshes. Typical resolutions would be a 5-8k triangle mesh in a 16^3-64^3 voxel volume. If your mesh is much larger or messy (holes, spiky shapes, etc.), it's best to use a cleaner low-res proxy mesh instead. Note that the SDF generator shipping with the VFX Graph has a more robust handling of larger or messy meshes, but it's slower.

The generator works by first splatting distances into voxels in a small area around each triangle, then using either a linear flood or jump flood to fill the rest of the volume.

Performance

Tested with a 32^3 voxel volume, 5k triangle mesh

  • jump flood: RTX3090 0.22ms
  • linear flood, 8 iterations: RTX3090 0.18ms, RTX2080Super 0.21ms

Requirements

  • Unity 2021.2+ (mesh buffer access in compute shaders)
  • Compute shaders supported on target platform

Installation

Use Add package from git URL (in the Package Manager):

https://github.com/Unity-Technologies/com.unity.demoteam.mesh-to-sdf.git

or

Declare the package as a git dependency in Packages/manifest.json:

"dependencies": {
    "com.unity.demoteam.mesh-to-sdf": "https://github.com/Unity-Technologies/com.unity.demoteam.mesh-to-sdf.git",
    ...
}

Documentation

Quickstart

Examples

Samples included with the package show basic setup and are described in the doc above.

The mesh-to-sdf examples project is a vfx demo, with the dynamic SDFs driving VFX Graph effects and a raymarching shader:

mesh-to-sdf.mov

Acknowledgements

The core functionality of the generator (initial splatting of distances around mesh faces) uses the implementation from TressFX published by AMD under the MIT license. Thank you!

Known issues

Limitations and known issues

com.unity.demoteam.mesh-to-sdf's People

Contributors

mikko-alaluusua-unity avatar repodb[bot] avatar robcupisz 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

com.unity.demoteam.mesh-to-sdf's Issues

only takes mesh, should take models

i mean if you want to do a composite object like a robot arm (totally random example)
it's made of dozens of parts that you then want to control programmatically, for example add IK to the hydraulic
well with the current baking tool you have to do each part one by one
a bit much
if instead this could take all mesh within a model it would be better,
even better would be batch multiple models.

Weird performance behavior

Hi,

i observed that in some cases, a higher poly mesh gives much better performance than a lower poly one. I compared 3000 vs 6000 poly mesh with roughly same layout, the 6000 poly mesh generates the SDF more than twice as fast.
How can this be?

error pink area on sdf texture

image

I used a mesh with 2568 tris and got pink are on sdf texture as the image shows.

This error cause error when I use vfx sample position and collide with sdf:
image

is this package still available ?

Hi, I get an error, when I try to install the package - within the package manager, as well as when putting the url in dependencies and also when opening the demo-project with appropriate editor.
In the last case is says "com.unity.demoteam.mesh-to-sdf: Error when executing git command. fatal: not in a git directory'

does it mean it is not there anymore ? Or do I do something wrong ?

thanks,

Please make Explicit Update mode available

Hi,

great library! Works great with out of the box component.

However, i am trying to integrate this into a custom pipeline, and for this need to control when SDF should be updated. I saw in code that this is already foreseen, but not fully implemented (not exposed in editor, needs internal access for command buffer name, and no garbage collection / vertex buffer disposal integrated). Would be great to have the option to explicitly call update.

URP?

Is this asset work with URP RP?

Some meshes seem to cause artifacts (sometimes)

Seems that meshes with e.g. holes in the mesh seem to create artifacts in created SDF. Strangely, this only seems to happen sometimes. With exact same setup, I get different behavior. Sometimes these artifacts are created, and if they get created, they seem to stay. Sometimes they are not created at all, and in that case also don't start appearing in same run.
Here are some images of the good case, and two images of the artifacts created in bad case (artifacts vary during the run of application). I also saw artifacts being created if the bounding box of SDF does not cover the full mesh, probably same cause, as this then naturally creates "holes" in the processed part of the mesh.

SDF_Good
SDF_Bad2
SDF_Bad1

Metal: SDF Tracer shader error

Shader error in 'Unlit/SDFTracer': HLSLcc: Metal shading language does not support buffer size query from shader. Pass the size to shader as const instead.
 (on metal)

Compiling Subshader: 0, Pass: <Unnamed Pass 0>, Fragment program with <no keywords>
Platform defines: SHADER_API_MOBILE UNITY_ENABLE_REFLECTION_BUFFERS UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_LIGHTMAP_DLDR_ENCODING UNITY_NO_DXT5nm UNITY_NO_RGBM UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2
Disabled keywords: SHADER_API_GLES30 UNITY_ASTC_NORMALMAP_ENCODING UNITY_COLORSPACE_GAMMA UNITY_ENABLE_DETAIL_NORMALMAP UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_HARDWARE_TIER1 UNITY_HARDWARE_TIER2 UNITY_HARDWARE_TIER3 UNITY_LIGHTMAP_FULL_HDR UNITY_LIGHTMAP_RGBM_ENCODING UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_NO_FULL_STANDARD_SHADER UNITY_PBS_USE_BRDF1 UNITY_PBS_USE_BRDF3 UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_SPECCUBE_BLENDING UNITY_SPECCUBE_BOX_PROJECTION UNITY_UNIFIED_SHADER_PRECISION_MODEL UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_VIRTUAL_TEXTURING

Adding MeshToSDF in runtime

Hi, everything works fine when the script added in the editor,
but if I add it in runtime, I get an error in line 149 in function Init()

m_InitializeKernel = m_Compute.FindKernel(Labels.Initialize);

in this case, m_Compute is null, and I have no idea how to initialize it.
Tried to call OnEnable() using reflection after adding it to GameObject, but no luck.
I would appreciate a hint.

Jump Flood Algorithm iteration numbers

Hi, I don't quite understand why the number of iterations in JFA is \log_{2}{maxDim} - 1 (MeshtoSDF.cs line 332). In Guodong Rong's paper of JFA, the jump rood is at least \log_{2}{maxDim}.

Causing Access Violation When Used with Dx12 / DXR

This package works great out of the box once I got my head around how to use it, however as soon as I enabled DX12/DXR in the scene to use ray tracing for environments it crashed and kept crashing on launch until force starting it with DX11 and turning off all raytracing settings in project.

The Debug results show it was an access violation, Error Code: 0xc0000005
Module name: Unity

For the time being its fine as my project is still in early stages and doesn't need raytracing immediately but it would be awesome to get it working with Raytracing.

Methods to get the SDF value

Hey I am a new learner. Appreciate your excellent work for the package.

I am wondering how we can get the SDF value by sampling the sdf texture?
To be more specific, now we have SDFTexture.sdf(RenderTexture) and SDFTexture. worldToSDFTexCoords(Matrix4*4),
Below is what I thought:

          // Transform the vertex using the provided matrix
           var transformedVertex = m_worldToSDFTexCoords * new Vector4(vertex.x, vertex.y, vertex.z, 1.0f);
           var textureCoords = new Vector3(transformedVertex.x, transformedVertex.y, transformedVertex.z);
           // Ensure the texture coordinates are within the texture bounds
           textureCoords.x = Mathf.Clamp01(textureCoords.x);
           textureCoords.y = Mathf.Clamp01(textureCoords.y);
           textureCoords.z = Mathf.Clamp01(textureCoords.z);

           // How to read the SDF value from the texture at the specified texture coordinates? Like below?
           var sdfValue = m_sdf.GetPixel(textureCoords.x, textureCoords.y, textureCoords.z);

Is this truncated sdf?

Hi, thank you for your great package. It also works well with complex mesh objects.

Since I had to use the sdf values directly, I took out the values of render texture using the code at HERE.

However, I found that the sdf values are clamped into [0, 1], called truncated sdf (tsdf), that is, the sdf values written in render texture inside the object were not negative but 0, and if the sdf is bigger than 1, the values written in render texture are 1.
(I think there may be a problem with the code in the link above..)

I need the real sdf, so I want to know the parts where to clamp the sdf values and how to modify it.

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.