Coder Social home page Coder Social logo

vertexpaint's Introduction

Vertex Painter for Unity
©2015 Jason Booth
Tested with Unity 5.6.6

Example Video:

quick tutorial:
https://www.youtube.com/watch?v=mtbCtwgI440&feature=youtu.be
water and refraction:
https://www.youtube.com/watch?v=V70GQjOH8_Y&feature=youtu.be
distance based UV scaling:
https://www.youtube.com/watch?v=ESfTK4TYFQ4
custom brushes:
https://www.youtube.com/watch?v=UtfpgzvrLUI

Love that I'm giving away this professional quality software instead of selling it on the asset store? You can donate here:
https://pledgie.com/campaigns/31113

Warning: This package can take a long time to import into Unity due to a large number of shader variants; if you do not need the shaders and only want the vertex painter, I suggest removing them from the project before importing. They are fantastic shaders though..

A note on the license:

I have been asked by several people if I mind them reselling parts or all of this
package in the Unity Asset Store. I have amended the license to prohibit this
use case. I have given this package away for free and put considerable work into
it, if you find that your product is enhanced by it’s use, then please point your
users towards my repository. Thank you.

Additional Vertex Streams

	This package allows you to paint information onto the vertices of a mesh in the Unity editor as well as modify any attribute of the mesh. It uses the new 'additionalVertexStream' system of Unity5, which allows you to override per-instance data on meshes without paying the cost of duplicating a full mesh. This makes it ideal for painting vertex information across many instances of a mesh. The tool also allows you to easily bake that information back to mesh assets if you'd prefer to make a modified mesh and store that in disk, instead of with the instance in the scene. 

Features
	The toolset contains several different painting modes as well as a few tools that come in handy when doing this type of work.You can modify the positions, normals, UVs and colors of a mesh, painting colors, values, or direction vectors taken from the stroke. You can bake lighting or ambient occlusion data into the vertices, or bake any of the changes you’ve made into a new mesh asset on disk. 


Precision

	Different channels of mesh data support different levels of precision. For instance, the color channel stores a color in 8888 format, which means you can only store 0 to 1 values with 256 possible values in each component of the color channel. The 4 UV channels, however, provide 4 32-bit floats each. It is important to understand these limitations when working with vertex data. 

Interface


Paint
	This tool allows you to paint information directly onto the vertices Color or UV channels. Data can be viewed as either color information or greyscale information if you are working on individual channels. You can even extend the system with custom brushes that you define for your project, so if you want to paint onto the color and UV channels in one stroke, you can! This is really useful if you want to pack various sub-material values into vertices to save on sampler ops. 

Deform
	This tool allows you to modify the vertices positions, properly recalculating normals and tangents. 

Flow

	This tool allows you to paint directional vectors into the color or UV channels, which can be used to create flowing effects in shaders. Note that the tool currently computes direction with a dot product of the tangent and bitangent of your mesh- this means that if your tangents are not in the expected space, the flow direction may be computed wrong.

Bake
	This tab contains a number of utilities, such as the ability to bake AO and lighting into the mesh data. You can also bake information from a texture into your vertices, bake pivot points into the UV channels of the mesh (allowing you to combine many objects and animate them individually in the shader). Finally, you can save meshes as disk assets from this tab.

Custom
   This tab allows you to work with custom brushes, which can be written to do just about anything you can imagine. An example custom brush is included which paints simplex noise onto a model, but the system allows you to write your own custom brushes, apply arbitrary transformations to the vertex data as you paint, as well as provide an interface for your brush.

Shaders

	Included with the package is a ‘SplatBlend’ shader. The SplatBlend shader closely mirrors Unity’s Standard Shader, but allows you to blend up to 5 different textures together per vertex. The blending is handled via a hight map stored in the alpha channel of the diffuse map, to produce a natural looking blend that allows sand to appear in the cracks of the stone before covering the stone, etc. Values painted into the color channels of the vertices control how much of each texture appears at each vertex. The Specular, Emissive, Metallic, and Normal data is handled in the same manner as with the Standard Shader. 

	Each layer has controls for texture scaling, parallax height, and a contrast which controls the width of the blending area between each layer. 

	The shader also allows you to designate one layer of the shader to flow mode. This distorts the texture along directional vectors painted into the third UV set (The first UV set is used for your UV mapping, and Unity uses the second UV set for enlighten data). This is useful to create flowing water, lava, or other effects. The flow layer contains controls for speed and intensity, allowing you to modify the effect globally across the material. The flow layer can optionally use alpha and refraction to distort the layers below it. The normal map will be used as the refraction direction.  

	There is also an option for Distance UV blending- this is mostly useful for terrain type features. What this does is generate a scaled set of UVs and blend between two samples based on the distance from the camera. 

	The performance of this shader is highly variable based on how many layers you use and which features you enable. Features which are not used in any layers are compiled out; while a feature used on any layer is computed for every layer. In other words, if you don’t use emissive textures on any layer you won’t pay for the feature, but if you use it on one layer an emissive value will be sampled for every layer.

	To understand performance characteristics, here is the number of samples taken for various options on a 5 layer shader with a flow map on one layer:

	Diffuse Only         = 4 texture samples + 2 flow texture samples
	With Normal Map      = 8 texture samples + 4 flow texture samples
	With Specular Map    = 12 texture samples + 4 flow texture samples
	With Parallax        = 16 texture samples + 4 flow texture samples
	With Distance Blend  = 32 texture samples + 4 flow texture samples

	As you can see, the complexity of the shader can grow very fast as features are enabled. 

	Because these features are compiled out when not in use, what the shader compiler is actually doing is compiling a shader for each option and picking the correct shader. This means that importing the shaders actually produces many thousands of shader variants, which makes import time very, very long. Before shipping, you may want to use Unity’s ShaderVariantCollection feature to remove the shaders your game does not use; this will make your app much smaller, as it will remove unused variants.

	Pivot Example:

    The pivot example contains a small tutorial that will show you how to bake the pivot of many objects into the vertices, then combine the object into one object and still rotate them all around their own pivots in the shader. This can be very useful for a number of effects, such as rotating asteroids, objects which shatter into pieces, etc, and is often many times cheaper than animating these effects any other way. 

vertexpaint's People

Contributors

invertex avatar kenamis avatar siccity avatar slipster216 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  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

vertexpaint's Issues

Painted Static Mesh error on play

I'm getting error when going into play mode with painted static meshes.
Mesh are static and lightmapped, tested with 2 layer splat shaders, vertex color painted, uv flow painted.
Using refractivewater sample material.
The flow are broken when going into play mode,
Lightmap UV also sometimes broken (could it be related with UV2 are used as flowdir uv?)
also spammed with this error msg below.

Not allowed to access vertices on mesh 'Combined Mesh (root: scene)' UnityEngine.Mesh:get_vertices() JBooth.VertexPainterPro.VertexInstanceStream:Apply(Boolean) (at Assets/Painter/VertexInstanceStream.cs:371) JBooth.VertexPainterPro.VertexInstanceStream:Start() (at Assets/Painter/VertexInstanceStream.cs:104)
Not allowed to access triangles/indices on mesh 'Combined Mesh (root: scene)' UnityEngine.Mesh:get_triangles() JBooth.VertexPainterPro.VertexInstanceStream:Apply(Boolean) (at Assets/Painter/VertexInstanceStream.cs:376) JBooth.VertexPainterPro.VertexInstanceStream:Start() (at Assets/Painter/VertexInstanceStream.cs:104)
Not allowed to access colors on mesh 'Combined Mesh (root: scene)' UnityEngine.Mesh:get_colors() JBooth.VertexPainterPro.VertexInstanceStream:EnforceOriginalMeshHasColors(Mesh) (at Assets/Painter/VertexInstanceStream.cs:124) JBooth.VertexPainterPro.VertexInstanceStream:Apply(Boolean) (at Assets/Painter/VertexInstanceStream.cs:397) JBooth.VertexPainterPro.VertexInstanceStream:Start() (at Assets/Painter/VertexInstanceStream.cs:104)

Color pick dialogue closes/crashes unity.

When choosing a tint colour in the splat shader (does not effect any default unity shader colour pickers) the Colour Dialogue will open and immediately close. Attempting to open it multiple times will crash Unity.

Using Unity 2017.3.1f1 on OSX High Sierra

Assets/VertexPaint-master/VertexInstanceStream.cs(457,33): error CS0103: The name `meshStream' does not exist in the current context

"private Mesh meshStream;" must be outside of #if UNITY_EDITOR construct for iOS or Android Build:

// hack around unity bugs in the editor..
private Mesh meshStream;

if UNITY_EDITOR

    public Mesh GetModifierMesh() {
        return meshStream;
    }

    void Update() {
        if (!Application.isPlaying) {
            MeshRenderer r = GetComponent<MeshRenderer>();
            r.additionalVertexStreams = meshStream;
        }
    }

endif

Resources leak

Hi
I have spot two resources leaks. Leaks are issuing message in the editor log. They are not a big issue but could be annoying by spamming the log.

Both could be solved by using hideFlags member (see http://answers.unity3d.com/questions/643942/how-does-setting-the-hideflags-resolves-leaking-is.html).

  1. The Mesh created in VertexInstanceStream.Apply is leaking. To solve this, after its instanciation, add the following line
    m.hideFlags = HideFlags.DontSave;

  2. The Material created in VertexPainterWindow.UpdateDisplayMode is leaking. To solve this, after its instanciation, add the following line
    vertexShaderMat.hideFlags = HideFlags.DontSave;

Best regards.

[Unity 5.4] Brush Cursor Position Error

VertexPainterWindow_Painting.cs

>>>>>>>>>>>>>>> 2076
			float mult = 2;
			if (Application.unityVersion.StartsWith("5.3") )
			{
				mult = 1;
			}
===============
#if UNITY_5_3_OR_NEWER
			float mult = 1;
#else
			float mult = 2;
#endif
<<<<<<<<<<<<<<<

Mesh.optimize is obsolete in 2018.3

Just a head's up that I just tried to add Vertex Painter to a 2018.3b2 project and it's taking ages to load. I'm seeing this error:

VertexPaint/Editor/VertexPainterUtilities.cs(29,10):error CS0619: 'Mesh.Optimize()' is : 'This method is no longer supported (UnityUpgradable)'

Exception when deleting selected object

When deleting selected object that was painted, an exception can occurs :

MissingReferenceException: The object of type 'MeshRenderer' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
JBooth.VertexPainterWindow.InitMeshes () (at Assets/Third party/VertexPaint/Editor/VertexPainterWindow_Painting.cs:95)
JBooth.VertexPainterWindow.OnSelectionChange () (at Assets/Third party/VertexPaint/Editor/VertexPainterWindow_GUI.cs:276)

A possible fix would be in VertexPainterWindow_Painting.cs, in method void InitMeshes(), to test that jobs[i].renderer isn't null :

void InitMeshes()
{
         // revert old
         for (int i = 0; i < jobs.Length; ++i)
         {
             if ( jobs[i].renderer != null )
                jobs[i].renderer.sharedMaterial = jobs[i].originalMat;
         }
         ...

Question: Possible to generate this at runtime?

This looks really great, especially the video with the water effects, would it be possible to do this via scripts at runtime? Your example with the rocks and water got me wondering, for example a scene where it starts to rain, to generate water puddles and so on.

On and a second question, did you ever try this on a mobile device? ;)

Examples cause import to hang

Great asset! I am submoduling it into my own game's repository so I can fetch updates with ease. But it hangs at a certain shader.
image
I'm on Unity 2017.1.0f3.

Edit: While the examples are great, I would be interested in an alternative branch without them included. Just to keep a clean project. For now I'm gonna go with the manual approach downloading and extracting the .zip inside my project

Deform Brush Argument Exception error with Z-Up Mesh

Alright new one, right now it's the deform brush.
When i'm trying to paint using the deform brush on a mesh that using z as up axis i'm getting this error.
ArgumentException: Destination array was not long enough. Check destIndex and length, and the array's lower bounds. System.Array.CopyTo (System.Array array, Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Array.cs:1830) JBooth.VertexPainterPro.VertexPainterWindow.EndStroke () (at Assets/Painter/Editor/VertexPainterWindow_Painting.cs:1484) JBooth.VertexPainterPro.VertexPainterWindow.OnSceneGUI (UnityEditor.SceneView sceneView) (at Assets/Painter/Editor/VertexPainterWindow_Painting.cs:1824) UnityEditor.SceneView.CallOnSceneGUI () (at C:/buildslave/unity/build/Editor/Mono/SceneView/SceneView.cs:2043) UnityEditor.SceneView.HandleSelectionAndOnSceneGUI () (at C:/buildslave/unity/build/Editor/Mono/SceneView/SceneView.cs:1383) UnityEditor.SceneView.OnGUI () (at C:/buildslave/unity/build/Editor/Mono/SceneView/SceneView.cs:1220) System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
and unity scene view are locked, i have to restart unity fix the scene view.

VertexInstanceStream Decals causing artifacts on Linear+Deferred+HDR+VR Single/Multi Pass rendering

Hi,

I was building up a scene with some complex PostFX and was banging my head to understand the reason some of the splat decals on the floor of a well known Unity3D AAA asset disappeared in game.

I then realized that all the VertexInstanced entities were affected.

but ONLY AT BUILD time! In the editor they work just fine, but when you try to build, all the vertexes are messed up and cause all kind of issues.

I also removed all PostFX from the scene, updated the VertexPaint libraries to the latest version, but I keep getting the issue. even not plugging the VR headset seems to create such issues.

Again it all works perfectly in the editor and in play mode.

I'm using Unity5.5.3f1 on an Asus ROG 32GB RAM, 8GB VRAM (1070)

Shader Init & Scale transform on Paint

Negative transforms on the mesh breaks PaintMesh method.
Quick Hack:
-- float scale = 1.0f / j.renderer.transform.lossyScale.x;
++ float scale = 1.0f / Mathf.Abs(j.renderer.transform.lossyScale.x);

Uninitialized variable errors in shader VertexPainterPro_Preview using latest beta of unity.
Added: UNITY_INITIALIZE_OUTPUT(v2f, o);
to vert function.

Awesome tool btw!

Baking GI is giving artifacts for any mesh with VertexInstanceStream.cs

@slipster216 Amazing tool, thank you very much.

Using Unity 5.4.0 - 5.4.2,
Actively using VertexPaint (VP) with 3 layers + specular,
Accidentally clicking on meshes with Standard Shader material while VP is active. VP is adding VertexInstanceStream.cs to these meshes,
Baking GI with any texel units from 0.001 to 1,
Every mesh with VertexInstaceStream.cs script on it is baked with artifacts like old colored tv

Rebaking meshes using Standard Shader material without VertexInstanceStream.cs gives expected results without artifacts.

Have you ever encounter this kind of behavior?

Removing component VertexInstanceStream do not remove additionnal mesh data

When removing the component VertexInstanceStream, the change on MeshRenderer is not reverted.
To fix this, you could add this code to the VertexInstanceStream component :

void OnDestroy ()
{
       if ( ! Application.isPlaying )
       {
           MeshRenderer mr = GetComponent<MeshRenderer> ();
           if ( mr != null )
               mr.additionalVertexStreams = null;
       }
}

vertex painter break outline selection in unity 5.6+

when Vertex painter are active the object selection outline in scene view are gone, and i cannot bring it back.
is there any workaround for this? for unity 5.6+ might be better to remove show wireframe toggle since we don't need that anymore right?

internal error shader

in 5.6.0f3
painter works perfect but none of the custom shaders works! could you update this awesome asset?

VertexInstanceStream added on every meshes !

While the tool window is opened, the tool is automatically adding component VertexInstanceStream to any selected GameObject and all its hierarchy !

In class VertexPainterWindow :
property public VertexInstanceStream stream { get {
...
_stream = meshFilter.gameObject.AddComponent();
...
} }

This is madness...

2 Layer SplatBlend Specular NormalMap not flowing

In SplatMap example for the refractiveWater sample if you change the material from metallic into specular the uv flow are not working on the normal map, only the refraction that flowing.
Weirdly this is only happen with 2 layer, with another layer the flow are fine

Very slow compile time for SplatBlend_5Layer shaders

We have some SplatBlend_5Layer shaders in a project, which when opened by a user for the first time take a very long time to compile when the project is opened (to the Library/ShaderCache directory).

It can take over half an hour to do this for a small number of such shaders. I'm curious if we are doing something wrong, or if this is expected behaviour?

SplatBlend_5Layer issues

Hello!

First off I want to thank you for releasing this awesome code for free!

Secondly I seem to have problems when using 5 Layers. The last layer seems to ignore all Colors and just shows all the time. (no matter what color I use as fill)

Can you confirm this as a bug or am I using 5 Layers in a wrong way ?

'EditorGUILayout.ColorField `is ambiguous` error on import

Unity 2019.4.15 getting the following error on import:

The call is ambiguous between the following methods or properties: 'EditorGUILayout.ColorField(GUIContent, Color, bool, bool, bool, ColorPickerHDRConfig, params GUILayoutOption[])' and 'EditorGUILayout.ColorField(GUIContent, Color, bool, bool, bool, params GUILayoutOption[])'

Fixed, I think? by making an explicit reference to what type 'null' is.

VertexPainterWindow_GUI.cs line 464:
orig:
brushColor = EditorGUILayout.ColorField(new GUIContent("Brush Color"), brushColor, true, showAlpha, false, null);

change to:
GUILayoutOption[] options = null; brushColor = EditorGUILayout.ColorField(new GUIContent("Brush Color"), brushColor, true, showAlpha, false, options);

The name 'mult' does not exist in current context

After dragging files into the project asset folder, error shows up:
"Assets/Editor/VertexPainterWindow_Painting.cs(2083,77): error CS0103: The name `mult' does not exist in the current context"
Tested on 5.4.1f1 and 5.3.1f1 versions of Unity Editor.
Tested Vertex Painter package has been downloaded at 10am(LA), November 5, 2016.

ashampoo_snap_2016 11 05_20h43m03s_004_

Just tested on 5.3.2f1. Same thing! Am I doing something wrong...?((

Baked mesh lose existing data

I'm getting this error when i'm trying to use baked mesh

Mesh doesn't have albedo UVs. Please create them in your modelling package

And maybe this case help you to investigate the problem.
So i'm using 2 layer specular blend material, and painting the mask using vertex color and paint the flow direction for 2nd layer.
Now in the the vertex painter window i can see that now the mesh have edited data in Colors and UV2.
So i bake the mesh so i can use it as static mesh. and replace the mesh filter with baked mesh then i get that error.
Still an assumption, but it seems when the mesh are baked it lose the existing unedited mesh data like UV0 and UV1.
Can i request to add an option "Keep Existing Data" just beside the Save Mesh button? or maybe you can just make the existing data transferred into baked mesh by default when baking without using an option. i'm still unsure do we need a toggle for that or not.

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.