Skip to content

JacobRThompson/UnityMeanCurvature

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mean Curvature Shader for Unity

Demonstration Image
Sample output. Max curvature mapped to (255,255,255); min curvature mapped to (0,0,0); exponent of 3.5 used.

A senior seminar project used to fulfill the requirements for a bachelor of mathematics degree. The accompanying paper can be found here, while a video demonstration can be downloaded here.

Description:

Once applied to a material, this shader leverages Unity's shader graph system and GPU differentiation to generate a heat map of game object's mean curvature everywhere along its surface. This robust tool works with most opaque models and prefabs out of the box. Target game objects do require valid Mesh.normals data, however. When working with procedurally-generated or broken meshes, the use of Mesh.RecalculateNormals() is recommended.

Use:

Place Mean Curvature.shadergraph and Sigmoid.shadersubgraph from this repo's Assets/Shaders folder into any project using Unity's High-Definition Render Pipeline (HDRP) or Lightweight Render Pipeline (LWRP). Apply the mean curvature shader to a target material. In its current form, this shader does not interact with Unity's lighting models. This can be remedied by copying the contents of Mean Curvature.shadergraph into a lit shader graph (guide).

For color selection, curvatures are mapped to values between 0 and 1 using a modified sigmoid curve:

where k is the value of Exponent Base within the shader. Higher values result in positive and negative curvatures getting mapped closer to MaxColor and MinColor respectively. When ApplyHighlight is enabled, curvatures (before sigmoid is applied) equal to or approaching HighlightValue are mapped to HighlightColor.

Limitations:

(See paper for more information)

  • Some amount of data is lost due to screen-space transformations. We advise against using this for numerical applications

  • The coloration of objects is dependent on camera position; moving the camera will slightly change the color of any target

  • Whenever multiple vertices of a game object lie on the same pixel, visual artifacts are introduced into the final render

  • The resolution of the user's monitor dramatically affects the behavior of this shader

Included Scenes:

  • DynamicMesh: When in play mode, this shader is applied to a continuously-deforming mesh. Standard WASD controls are used for player movement. Camera sensitivity and movement speed are controlled by the main camera game object.

  • Sandbox: A scene showing the shader applied to various standard test models and a collection of rocks that can be found here.

  • ScreenSpaceDistortion: Each object is colored according to its normal data, but half of the included objects are also sent to and from screen space. Moving the camera in edit mode reveals the loss of information and bizarre behavior that can occur when moving between spaces.