Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

VertExmotion [Released]

Discussion in 'Assets and Asset Store' started by kalagaan, Oct 30, 2014.

  1. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,644
    Thanks fo the reply. Unluckily i missed the discount. Next time. Because i will buy the two products.
     
  2. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    1,749
    Hi,

    As you outline above "vertex Motion uses the gpu so it's fast."

    I need this system for large volume deformations, hundreds of jellyfish.

    however when jacking your demo up to just 250 jellyfish, some vast cpu side overhead penalty kicks in. For incredibly simple animations like that ones I intend to use, seems like this would be slower than the built-in?. (I removed all the "are we next to another jellyfish" spawner noise, with a cheaper, partitioned, random and checked for other extraneous overheads )

    250InstancesNotVeryMany.JPG

    What is the best practice for using this "in volume"?

    Obviously a 65 ms frametime for just 250 instances is a complete order of magnitude away from where I would hope, and on the cpu side I would hope more like "two orders of magnitude" off of the mark.

    Seems to be a lot of cpu side work being done. any clues?

    here is 30 Jellyfish.

    With a deeper dig into where the time is going.
    just30JellyFish.JPG
     
    Last edited: Jan 18, 2015
  3. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    Hi, VertExmotion 1.1.0 sends sensors' data to shader with 'Material.SetVector' and 'Material.SetColor' functions.
    Next version (1.2.0 ) use 'Renderer.SetPropertyblock' function, it's much faster :)
    250 jellyfishes -> 5.56ms
    Capture_25jelly.PNG Capture_250jelly_profiler.PNG
     
  4. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    1,749
    ah happy days. Nice one. Materials access was never going to be fast.
    Yeah, if you are going to update the demos, a "Here is how you do the absolute maximum for the absolute minimum resources" would be excellent. For example if it would be possible to "stagger" sensor data over a few frames, or logically group the entire bunch of requests together, and then spread them over the available frames. Or do presumptive Lerping and just veer back toward the actual values, which would be scraped in a less granular manner.

    Both HerdSim and Suimono 2.0 have both just gone over to such a "load smearing" system after seeing the performance gains it offered. On all platforms.

    I wish more publishers were upfront about the actual bottlenecks, saves a boatload of time for your end users.

    Very happy, looking forward to shoving a thousand jellies in my sea.
    The less time I spend on the CPU on that? the better. I would take jerky distant motion over crippling frame stutter any day.

    MarskeByTheSea.JPG

    Also, if there is a way to trigger a large batch of say 20 jellyfish (so one combined mesh), and animate the entire blob as one thing, then do 50 of them and intersperse those with individual jellies nearer the camera. That would be sexy.

    Thanks.
     
    Last edited: Jan 18, 2015
    chelnok likes this.
  5. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    I love optimization, so I'll do my best for VertExmotion :)
    I'll do a LOD system, it will disable unnecessary computation ,and will switch to an alternative shader when gameobject is too far or out of view.
    I did an optimized code for sensors update (753 calls->2.4ms), but maybe I could do a sort of smoothing system with a delayed computation of sensors data with multithreading.
    I did this kind of code for a custom particule system.
     
    chelnok, twobob and hopeful like this.
  6. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    1,749
    awesome.


    I did some totting up on your 250 jellyfish example above and with; The Overhead (from servicing all the monobehaviour updates); The Jellyfish.Update's themselves; The sensor Update; The vertexMotion.Update; Plus the other tiny fixed costs; the total cost is actually approaching a full 60FPS count on it's own again, ( or thereabouts).

    So /anything/ you can do to make nearer 1000 jellyfish take nearer half that time I would be eternally grateful. Let me also point out I am not saying "GIVE ME THE MOON ON A STICK RIGHT NOW, A BLUE ONE!!!!" simply stating my project goals, I recognise that, beyond a certain point, no amount of clever wangling, wheedling, begging or optimisation can make a system work faster. nor it's creator. So... that said:
    I, honestly, think that you are /probably/ approaching the "diminishing returns" on greater internal optimisation with regard to CPU-> GPU shader interactions, looking at the numbers you are posting there, looks pretty tidy. That leaves me with the other option I mentioned (and any I haven't yet considered):

    "Lump animations" containing bigger blocks to be used far from the camera.
    Suppose I will have to play with combining a few meshes and see what falls out.
    Have you ever tried the system on combined blocks in this manner?
    Some "logically constrained" noise data shoved into such a block might effect decent enough "Randomness" to make the concept viable for other scenarios also: Fly swarms, Brownian effects, Sea anemone motions, fake weather, et cetera.
    All "value adding" to the product for sure. That type of "Usefulness" is studio-level helpful.

    Final thoughts:
    I am cognisant that "Feature-creep" is the very last thing you want in an asset-store project, what with all the "new version supporting" and the sheer longevity of the endeavor.

    So, just a video demonstrating how one might achieve such an effect with your current codebase, rather than me requesting any new code, would possibly have more actual value, since using a product creatively (with other simple solutions) is the best way to get more out of a product than adjusting the product itself (thank you Richard Matthew Stallman for that little nugget of thought-food).

    Additionally, I'm not 100% sure what the sensors "do", (sense stuff, at a wild guess, and pass it to the shader) however any options to reduce the actual quality/rate of data would be very helpful (or even remove it entirely, if required). I suspect I would be happy with a very low rate of "Actual real world" interaction for props like these invertebrates, and certainly for "far away" ones. Spending a few cycles on logical INITIAL placement via rays, and limiting subsequent motion would /probably/ be cheaper overall than constant checks and at-distance would be /probably/ adequate. I have stutter-stepped such sweeps, in other systems, at over 10 times the initial settings and got reasonable results via simple, cheap predictive Lerping, or even just "going anyway, checked or not". At distance it rarely matters.

    To be able to spawn say - 10 thousand - inert ones randomly placed over 40 square kilometers and have them trigger on proximity with the "Player" object would be the ideal. However that sort of thing requires a "Player-side" protocol, since obviously 10000 checks per frame would be stupid. Anyways. I would really like that. I may work on something like that myself in the absence of it's existence towards the end of this project. it would be a helpful addition to any game-writers arsenal.

    Much obliged.
    Very excited to see your LOD solution. Big respect for stepping up.
     
    Last edited: Jan 18, 2015
  7. gshape

    gshape

    Joined:
    Aug 8, 2012
    Posts:
    93
    Hi Kalagaan,

    Great news and looking forward to your coming update.
    I have sent an email regarding a problem on custom shader to you. Could you please kindly check?
    Thanks.
    gshape
     
  8. gshape

    gshape

    Joined:
    Aug 8, 2012
    Posts:
    93
    Hi, problem fixed! Thanks for your prompt reply! Looking forward to next update. ;)
     
  9. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    Nice :)
    Don't hesitate to show me your work with VertExmotion!
    I'm very curious about what you'll do with it :)
     
    gshape likes this.
  10. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    VertExmotion 1.2.0 has been submitted to the assetstore. :)
    It should be available soon.

    new : Unity5 (b18) standard shader compatibility
    new : multimaterial support
    new : gravity, local offset and world offset parameters available
    new : demo for gravity
    fix : scale issue
    fix : speed optimisation
    fix : Unity5 collision system works
    fix : Unity5 GUI
     
    punk, gshape, hopeful and 1 other person like this.
  11. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    1,749
    Doh. I foolishly went and looked for it.

    heh, available soon, noted
     
    Last edited: Jan 22, 2015
  12. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    VertExmotion 1.2.0 available on the assetstore :)
     
    twobob likes this.
  13. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,644
    VertExmotion 1.2.0 available on the assetstore :)

    ^^ this is better. Or add the link in your signature, because every time we have to go to your first post for this. Just a tip.. :p
     
    kalagaan and twobob like this.
  14. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    1,749
    Might i ask if you added any "performance limiting" options on the client side?
    (I note you smeared the period, et cetera internally)

    I am looking. or - if not - what could be used to limit the cpu side load.

    50 jellyfish are costing circa 17ms

    even with the load additionally partitioned thusly:
    Code (csharp):
    1.  
    2. void Start()
    3. {
    4. // smear
    5. m_bodyPeriod *= Random.Range (.9f, 1.1f);
    6. m_initialProceduralsensorPos = m_tentaclesProceduralSensor.transform.localPosition;
    7.  
    8. // init lottery to /roughly/ halve the load using randoms' Even Distribution curve
    9. if (Random.value < 0.5f)
    10. {
    11. thisFrame = true;
    12. } }
    13.  
    14. bool thisFrame;
    15.  
    16. void Update () {
    17. // service lottery
    18. if (thisFrame)
    19. { thisFrame = !thisFrame;
    20. return;
    21. }
    22. else
    23. {
    24. thisFrame = !thisFrame;
    25. }
    26. ...
    27.  
    60fps50Jellyfish.JPG

    I suppose 50 groups of 20 might be okay.

    What would be the best/cheapest way of performing animations on bundles of objects please.

    Thanks.

    The materialPropertyBlock was much faster as you said. under 4 ms, very impressive.

    possible gains:
    PossibleGain.JPG

    scale caching and a faster lookup for the dictionary.

    Would have been nice to have had some native "quality" stepping, but I can always weld some in.

    I will try spawning a few 1000 next in a huge sphere to test the LOD :)


    Okay so I tried:

    Code (csharp):
    1.  
    2. for (int i=0; i< m_jellySpawned.Count; ++i)
    3. {
    4.  
    5. go.transform.position = Random.insideUnitSphere * 300;
    6.  
    and just a few hundred

    LOD.JPG

    I didn't note any "disabling", is there a trick to enabling the LOD? thanks :)
     
    Last edited: Jan 24, 2015
  15. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    1,749
    In the absence of anything else:

    Code (csharp):
    1.  
    2. private Transform MainCamera;
    3.  
    4. void Start() {
    5.  
    6. MainCamera = FindObjectOfType<Camera>().transform;
    7. }
    8.  
    9. private float _distanceDisable = 100f;
    10.  
    11. void Update ()
    12. {
    13. // dump them all in.
    14. if( Time.time - m_lastSpawnTime > m_spawnRate && m_jellySpawned.Count < m_maxJelly )
    15. {
    16.  
    17. while (m_jellySpawned.Count < m_maxJelly)
    18. {
    19.  
    20. Vector3 point = MainCamera.position + Random.insideUnitSphere * _distanceDisable*4;
    21.  
    22. GameObject go = Instantiate(m_jellyfishPrefab, point, Quaternion.identity) as GameObject;
    23.  
    24. m_jellySpawned.Add(go);
    25.  
    26. go.transform.parent = m_spawnRoot;
    27. go.transform.localScale *= Random.Range(.1f, 1.2f);
    28. go.SendMessage("CheckDistance", SendMessageOptions.DontRequireReceiver);
    29.  
    30. }
    31.  
    32. m_lastSpawnTime = Time.time;
    33. }
    34.  
    35.  
    36. int idToDestroy = -1;
    37. for (int i=0; i< m_jellySpawned.Count; ++i)
    38. if (m_jellySpawned [i].transform.position.y > m_destroyYLimit ||
    39. ((m_jellySpawned [i].transform.position - MainCamera.position).sqrMagnitude > _distanceDisable * _distanceDisable))
    40.  
    41. idToDestroy = i;
    42.  
    43. if( idToDestroy != -1 )
    44. {
    45. Destroy(m_jellySpawned [idToDestroy]);
    46. m_jellySpawned.RemoveAt(idToDestroy);
    47. }
    48. }
    49.  
    50.  
    Roughly does what I want. And manages 2000 objects is a useful way, with a reasonable overhead.

    I have attached a DisableByDistance script to the prefab and removed the seemingly redundant animator (this saved many ms on 2000 objects)

    2000 objects:
    2000At60FPS.JPG

    the effect of the disableByDistance script

    DisablingByDistance.JPG

    Great stuff.

    If you do make any notes on the new LOD stuff I would be much obliged.
     
    Last edited: Jan 24, 2015
  16. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    Nice job, :)
    LOD is not yet included in 1.2.0, I need to work on it :p
    My LOD system will disable sensor update and will switch the shader to a 'classic' one.
    So this kind of LOD is based on the gameobject itself, not on a scalable number of instances.

    But for your project, the best thing to do is to use a pool of jellyfishes instances, instead of intanciate a lot of them.
    If you think that 50 jellyfishes could be visible at the same time, intantiate 50 jellyfishes in a List, then disable them.
    When you need to draw one, get the first disable in the list and enable it on the position.
    When one of the jellyfishes is out of view, set it as disable in the list.
    Use a dot product between camera direction and jellyfish delta position from the camera to disable not visible ones, and a max distance.
     
    Last edited: Jan 24, 2015
  17. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    1,749
    Are there any hidden "InvokeRepeating"s I should be aware of during the disabling stage?

    And thanks for getting back to me.
     
  18. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    I don't use InvokeRepeating, and there's no memory allocation in Update functions.
    You can check it in profiler, GC alloc have to be 0B, if some scripts allocate memory, you'll have big spikes on garbage collector cleaning.
     
  19. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    1,749
    Thanks. Yeah, cleaning up garbage has been a full time job lately.
    Good to know this isn't on the Naughty List :)
     
  20. Dandolittle

    Dandolittle

    Joined:
    Jul 2, 2013
    Posts:
    17
    Hey

    So been playing with the asset and having a lot of fun with the shaders however I'm coming across a problem with a toon shader i want to use. I tried following the guide in the PDF but not having a lot of luck. was wondering if you could give me a hand on this on how i could possibly get my shader working with your asset?

    Currently when i had the lines

    pragma surface surf Lambert alpha vertex:vert addshadow
    #include "Assets/VertExmotion/Shaders/VertExmotion.cginc"
    void vert (inout appdata_full v) {VertExmotion( v );}

    i get errors everywhere such as...

    Material doesnt have a float or range property "_color"

    basically i get this error for each property in my shader script

    Any help will be greatly appreciated :)


    Code (CSharp):
    1. Shader "Toon/Hair"
    2. {
    3.     Properties
    4.     {
    5.         _Color("Color(RGBA)", Color) = (1,1,1,1)
    6.         _MainTex("Texture", 2D) = "white" {}
    7.         _SphereAddTex("Texture(Sphere)", 2D) = "black" {}
    8.         _Shininess ("Shininess(0.0:)", Float) = 1.0
    9.  
    10.         _ShadowThreshold ("Shadow Threshold(0.0:1.0)", Float) = 0.5
    11.         _ShadowColor ("Shadow Color(RGBA)", Color) = (0,0,0,0.5)
    12.         _ShadowSharpness ("Shadow Sharpness(0.0:)", Float) = 100
    13.     }
    14.  
    15.     SubShader
    16.     {
    17.         // Settings
    18.         Tags {"Queue" = "Transparent" "IgnoreProjector"="True" "RenderType" = "Transparent"}
    19.         //Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
    20.  
    21.         // Surface Shader Pass ( Front )
    22.         Cull Off
    23.         ZWrite On
    24.         Blend SrcAlpha OneMinusSrcAlpha
    25.         CGPROGRAM
    26.         //#pragma surface surfHair ToonHair vertex:vert
    27.         #pragma surface surfHair ToonHair vertex:vert
    28.         //    Toon Hair Surface Shader for Unity
    29.         //    File        :    ToonSurfaceHair.cginc
    30.         //    Title        :    Toon Surface Shader with Alpha
    31.         //    Language    :    Cg Language
    32.         //    Include        :    ToonSurfaceHair.cginc
    33.         /*
    34.             How To Use    :
    35.            
    36.             CGPROGRAM
    37.             #pragma surface surfHair ToonHair vertex:vert
    38.             ENDCG
    39.         */
    40.  
    41.         float4 _Color;
    42.         sampler2D _MainTex;
    43.         float    _ShadowThreshold;
    44.         float4    _ShadowColor;
    45.         float    _ShadowSharpness;
    46.         float    _Shininess;
    47.         sampler2D _SphereAddTex;
    48.  
    49.  
    50.  
    51.         struct ToonSurfaceOutput
    52.         {
    53.             half3 Albedo;
    54.             half3 Normal;
    55.             half3 Emission;
    56.             half3 Gloss;
    57.             half Specular;
    58.             half Alpha;
    59.             half4 Color;
    60.         };
    61.  
    62.         inline half4 LightingToonHair (ToonSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
    63.         {
    64.             //Lighting paramater
    65.             float4    lightColor = _LightColor0 * atten;
    66.             float    lightStrength = dot(lightDir, s.Normal) * 0.5 + 0.5;
    67.                
    68.             //ToonMapping
    69.             half shadowRate = abs( max( -1, ( min( lightStrength, _ShadowThreshold ) -_ShadowThreshold)*_ShadowSharpness ) )*_ShadowColor.a;
    70.             float4 toon = float4(1,1,1,1) * (1-shadowRate) +  _ShadowColor *shadowRate;
    71.            
    72.             //Output
    73.             //float4 color = saturate( _Color * lightColor*2 ) * s.Color;
    74.             float4 color = _Color * (lightColor) * s.Color * (atten*2) * _Shininess;
    75.             color *= toon;
    76.             color.a = s.Alpha;
    77.             return color;
    78.         }
    79.  
    80.  
    81.         struct Input
    82.         {
    83.             float2 uv_MainTex;
    84.             float3 customColor;
    85.         };
    86.  
    87.         void vert (inout appdata_full v, out Input o) {
    88.             UNITY_INITIALIZE_OUTPUT(Input,o);
    89.             //o.customColor = abs(v.normal);
    90.             o.customColor = v.normal;
    91.         }
    92.  
    93.         void surfHair (Input IN, inout ToonSurfaceOutput o)
    94.         {
    95.  
    96.             // Defaults
    97.             o.Albedo = 0.0;
    98.             o.Emission = 0.0;
    99.             o.Gloss = 0.0;
    100.             o.Specular = 0.0;
    101.            
    102.            
    103.             // Sphere Map
    104.             float3 viewNormal = normalize( IN.customColor );
    105.             float3 viewNormal2 = normalize( mul( UNITY_MATRIX_MV, float4(normalize(o.Normal), 0.0) ).xyz );
    106.            
    107.             viewNormal = normalize(viewNormal*0.7 + viewNormal2*0.3);
    108.            
    109.             float2 sphereUv = viewNormal.xz * 0.5 + 0.5;
    110.            
    111.             float4 sphereAdd = tex2D( _SphereAddTex, sphereUv );
    112.            
    113.            
    114.             half4 c        = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    115.             o.Color        = c;
    116.             o.Color        += sphereAdd*0.2 * step(0,viewNormal.y); // SphereAddTex
    117.             o.Alpha        = c.a;
    118.         }
    119.  
    120.         ENDCG
    121.    
    122.     }
    123.  
    124.     // Other Environment
    125.     Fallback "Transparent/Diffuse"
    126. }
     
  21. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    Hi,
    your shader has already a vertex function, add VertExmotion in it. ;)

    void vert (inout appdata_full v, out Input o) {
    UNITY_INITIALIZE_OUTPUT(Input,o);
    //o.customColor = abs(v.normal);
    o.customColor = v.normal;
    VertExmotion( v );
    }

    Code (CSharp):
    1. Shader "VertExmotion/Toon/Hair"[/I]
    2. [I]{[/I]
    3. [I]    Properties[/I]
    4. [I]    {[/I]
    5. [I]        _Color("Color(RGBA)", Color) = (1,1,1,1)[/I]
    6. [I]        _MainTex("Texture", 2D) = "white" {}[/I]
    7. [I]        _SphereAddTex("Texture(Sphere)", 2D) = "black" {}[/I]
    8. [I]        _Shininess ("Shininess(0.0:)", Float) = 1.0[/I]
    9. [I]        _ShadowThreshold ("Shadow Threshold(0.0:1.0)", Float) = 0.5[/I]
    10. [I]        _ShadowColor ("Shadow Color(RGBA)", Color) = (0,0,0,0.5)[/I]
    11. [I]        _ShadowSharpness ("Shadow Sharpness(0.0:)", Float) = 100[/I]
    12. [I]    }[/I]
    13. [I]    SubShader[/I]
    14. [I]    {[/I]
    15. [I]        // Settings[/I]
    16. [I]        Tags {"Queue" = "Transparent" "IgnoreProjector"="True" "RenderType" = "Transparent"}[/I]
    17. [I]        //Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}[/I]
    18. [I]        // Surface Shader Pass ( Front )[/I]
    19. [I]        Cull Off[/I]
    20. [I]        ZWrite On[/I]
    21. [I]        Blend SrcAlpha OneMinusSrcAlpha[/I]
    22. [I]      [/I]
    23. [I]        CGPROGRAM[/I]
    24. [I]        #include "Assets/VertExmotion/Shaders/VertExmotion.cginc"[/I]
    25. [I]        //#pragma surface surfHair ToonHair vertex:vert[/I]
    26. [I]        #pragma surface surfHair ToonHair vertex:vert[/I]
    27. [I]        //    Toon Hair Surface Shader for Unity[/I]
    28. [I]        //    File        :    ToonSurfaceHair.cginc[/I]
    29. [I]        //    Title        :    Toon Surface Shader with Alpha[/I]
    30. [I]        //    Language    :    Cg Language[/I]
    31. [I]        //    Include        :    ToonSurfaceHair.cginc[/I]
    32. [I]        /*[/I]
    33. [I]            How To Use    :[/I]
    34. [I]         [/I]
    35. [I]            CGPROGRAM[/I]
    36. [I]            #pragma surface surfHair ToonHair vertex:vert[/I]
    37. [I]            ENDCG[/I]
    38. [I]        */[/I]
    39. [I]        float4 _Color;[/I]
    40. [I]        sampler2D _MainTex;[/I]
    41. [I]        float    _ShadowThreshold;[/I]
    42. [I]        float4    _ShadowColor;[/I]
    43. [I]        float    _ShadowSharpness;[/I]
    44. [I]        float    _Shininess;[/I]
    45. [I]        sampler2D _SphereAddTex;[/I]
    46. [I]        struct ToonSurfaceOutput[/I]
    47. [I]        {[/I]
    48. [I]            half3 Albedo;[/I]
    49. [I]            half3 Normal;[/I]
    50. [I]            half3 Emission;[/I]
    51. [I]            half3 Gloss;[/I]
    52. [I]            half Specular;[/I]
    53. [I]            half Alpha;[/I]
    54. [I]            half4 Color;[/I]
    55. [I]        };[/I]
    56. [I]        inline half4 LightingToonHair (ToonSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)[/I]
    57. [I]        {[/I]
    58. [I]            //Lighting paramater[/I]
    59. [I]            float4    lightColor = _LightColor0 * atten;[/I]
    60. [I]            float    lightStrength = dot(lightDir, s.Normal) * 0.5 + 0.5;[/I]
    61. [I]             [/I]
    62. [I]            //ToonMapping[/I]
    63. [I]            half shadowRate = abs( max( -1, ( min( lightStrength, _ShadowThreshold ) -_ShadowThreshold)*_ShadowSharpness ) )*_ShadowColor.a;[/I]
    64. [I]            float4 toon = float4(1,1,1,1) * (1-shadowRate) +  _ShadowColor *shadowRate;[/I]
    65. [I]         [/I]
    66. [I]            //Output[/I]
    67. [I]            //float4 color = saturate( _Color * lightColor*2 ) * s.Color;[/I]
    68. [I]            float4 color = _Color * (lightColor) * s.Color * (atten*2) * _Shininess;[/I]
    69. [I]            color *= toon;[/I]
    70. [I]            color.a = s.Alpha;[/I]
    71. [I]            return color;[/I]
    72. [I]        }[/I]
    73. [I]        struct Input[/I]
    74. [I]        {[/I]
    75. [I]            float2 uv_MainTex;[/I]
    76. [I]            float3 customColor;[/I]
    77. [I]        };[/I]
    78. [I]        void vert (inout appdata_full v, out Input o) {[/I]
    79. [I]            UNITY_INITIALIZE_OUTPUT(Input,o);[/I]
    80. [I]            //o.customColor = abs(v.normal);[/I]
    81. [I]            o.customColor = v.normal;[/I]
    82. [I]            VertExmotion( v );[/I]
    83. [I]        }[/I]
    84. [I]        void surfHair (Input IN, inout ToonSurfaceOutput o)[/I]
    85. [I]        {[/I]
    86. [I]            // Defaults[/I]
    87. [I]            o.Albedo = 0.0;[/I]
    88. [I]            o.Emission = 0.0;[/I]
    89. [I]            o.Gloss = 0.0;[/I]
    90. [I]            o.Specular = 0.0;[/I]
    91. [I]         [/I]
    92. [I]         [/I]
    93. [I]            // Sphere Map[/I]
    94. [I]            float3 viewNormal = normalize( IN.customColor );[/I]
    95. [I]            float3 viewNormal2 = normalize( mul( UNITY_MATRIX_MV, float4(normalize(o.Normal), 0.0) ).xyz );[/I]
    96. [I]         [/I]
    97. [I]            viewNormal = normalize(viewNormal*0.7 + viewNormal2*0.3);[/I]
    98. [I]         [/I]
    99. [I]            float2 sphereUv = viewNormal.xz * 0.5 + 0.5;[/I]
    100. [I]         [/I]
    101. [I]            float4 sphereAdd = tex2D( _SphereAddTex, sphereUv );[/I]
    102. [I]         [/I]
    103. [I]         [/I]
    104. [I]            half4 c        = tex2D(_MainTex, IN.uv_MainTex) * _Color;[/I]
    105. [I]            o.Color        = c;[/I]
    106. [I]            o.Color        += sphereAdd*0.2 * step(0,viewNormal.y); // SphereAddTex[/I]
    107. [I]            o.Alpha        = c.a;[/I]
    108. [I]        }[/I]
    109. [I]        ENDCG[/I]
    110. [I][/I]
    111. [I]    }[/I]
    112. [I]    // Other Environment[/I]
    113. [I]    Fallback "Transparent/Diffuse"[/I]
    114. [I]}

     
    Last edited: Jan 25, 2015
  22. ThunderTruck

    ThunderTruck

    Joined:
    Sep 25, 2013
    Posts:
    61
    Hi,
    in the new update v1.2.1 the standard shader for Unity 5b21 report that the _Cutoff parameter is missing
     
  23. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    Hi, I've included shaders for the b18 (full tested release) in VertExmotion 1.2.1,
    Here a fix for b21 ;)
     
  24. ThunderTruck

    ThunderTruck

    Joined:
    Sep 25, 2013
    Posts:
    61
    1000 thanks, you are one of the best! ... :)
     
    kalagaan likes this.
  25. ilesonen

    ilesonen

    Joined:
    Sep 11, 2012
    Posts:
    47
    Hi kalagaan,

    I'm trying to modify JMO's Toony Colors shader working with Vertexmotion. I don't get how to do this properly. Could you please help me with this code?

    Also, when I've setup Vertexmotion to work with one shader and then trying to change to another it forces the shader back to first one when hitting play?

    Thanks!

    (and thanks for fixing that scale issue, it works great now!)

    Here's the code.

    //ToonyColorsPro+MobileShaders
    // (c) 2013,2014JeanMoreno

    Shader"VertExmotion/Mobile/ToonyColorsPro/Basic"
    {
    Properties
    {
    _MainTex ("Base (RGB)", 2D) = "white" {}
    _Ramp ("ToonRamp (RGB)", 2D) = "gray" {}

    //COLORS
    _Color ("HighlightColor", Color) = (0.8,0.8,0.8,1)
    _SColor ("ShadowColor", Color) = (0.0,0.0,0.0,1)

    }

    SubShader
    {
    Tags { "RenderType"="Opaque" }
    LOD200

    CGPROGRAM

    #include "TGP_Include.cginc"

    #include "Assets/VertExmotion/Shaders/VertExmotion.cginc"

    //nolightmapnodirlightmapLIGHTMAP
    //noforwardaddONLY1DIRLIGHT (OTHERLIGHTSASVERTEX-LIT)
    #pragmasurfacesurfToonyColorsnolightmapnodirlightmapnoforwardadd

    #pragmasurfacesurfLambertalphavertex:vertaddshadow


    sampler2D_MainTex;

    structInput
    {
    half2uv_MainTex : TEXCOORD0;
    };


    voidvert (inoutappdata_fullv) {VertExmotion( v );}


    voidsurf (InputIN, inoutSurfaceOutputo)
    {
    half4c = tex2D(_MainTex, IN.uv_MainTex);

    o.Albedo = c.rgb;
    }
    ENDCG
    }

    Fallback"VertexLit"
    }
     
  26. bDubya

    bDubya

    Joined:
    Jan 29, 2015
    Posts:
    3
    Love the asset, only one minor quirk with creature/character animations is that using the shader to create a soft fat belly near the ribs of a character bounces up and down okay when moving slowly, but when it is running the belly gets sunken into the mesh around the ribs in a way that is kind of unsightly. Is there any workaround for this? I tried different sensor placements and directions and values but they all resulted in the same effect, or diminished the effect I wanted to achieve. Wish there was a way to control up and down as well as in and out. But maybe I'm doing something wrong? Thanks!
     
  27. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680

    Hi, I can't test your shader because I don't have Toony color.
    try this line :
    #pragma surface surfToonyColors vertex:vert nolightmap nodirlightmap noforwardadd

    instead of :
    #pragmasurfacesurfToonyColorsnolightmapnodirlightmapnoforwardadd
    #pragmasurfacesurfLambertalphavertex:vertaddshadow


    it should work ;)
     
  28. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    Thank you for your feedback!
    "Inner max distance = 0" should fix this...
    But it don't work properly, I'm really sorry for this... :(
    I'll do a fix ASAP. ;)
    Could you send me a sample? It would be easier to check the result.
     
    Last edited: Jan 29, 2015
  29. bDubya

    bDubya

    Joined:
    Jan 29, 2015
    Posts:
    3
    No problem; thanks for responding. Here's basically what I'm looking at. The left is the normal looking belly with vertexmotion all set up and the right is just after a quick start movement. I have Inner max distance set to 0 but still the belly caves in when he moves forward quickly, but looks good when walking at a slower pace. I noticed that when the character leans forward such as with running the sensor does not move with the mesh. I tried stabilizing it by attaching its parent as a bone in the inspector; this stabilized the location in relation to the belly but I still had traces of the same problem no mater where I put the sensor.

    Hope this is helpful. Thanks (and again keep up the good work!)
     

    Attached Files:

  30. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    1,749
    a screenshot might not hurt. "Weird results" is of limited helpfulness.

    A general expansion of the documentation to encompass more custom shader integration clues might be appropriate in the future?
     
  31. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    Yes, I have to include other examples in the documentation.
     
  32. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    I'm working on sensors' limits, this will fix this kind of problems. ;)
    I'll do an advanced mode, for more control on each axis.
     
    Last edited: Feb 3, 2015
    twobob likes this.
  33. bDubya

    bDubya

    Joined:
    Jan 29, 2015
    Posts:
    3
    Thanks for the fast update! Everything is working well now. Also really like the updated sensor. Setup was already simple, now it's even easier because I can see the sensor limits graphically. Helps eliminate the guesswork. Great job

    brian
     
    kalagaan and twobob like this.
  34. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    VertExmotion 1.2.2 available on the assetstore!
    • Limit system improved
    • new gizmos for limits settings
    • enable/disable brush settings in scene view
    • UI improved
    assetstore links : BASIC - PRO

    sensor_limits.PNG
     
    punk and twobob like this.
  35. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    386
    Hi! Thank you very much for your great asset which I have just purchased.
    Do you think you can support Pre-Integrated Skin shader? https://www.assetstore.unity3d.com/en/#!/content/7238
    The author of this shader is just about to release a new version for Unity5, but when this is done, could you support it?
    I love it so much.
     
  36. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    Thank you :)
    I can't buy all the shaders in the assetstore :p
    You should be able to make it compatible with the documentation.
    I'm thinking about an automated way to convert shaders :)

    Anyway if you have issue, send me an email, and I'll help you :)
     
    chelnok likes this.
  37. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    I've found a solution for FPS and timeScale issues, I'll update a new version soon!
    You'll have a perfect control of motion on all platforms. :)
     
    Last edited: Feb 13, 2015
    chelnok, hopeful and Byulbram like this.
  38. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    Version 1.2.3 will include a time control for each VertExmotion instance.
    So you'll be able to control sensor's time scale like a standard animation.
    demo here
     
    punk and hopeful like this.
  39. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    VertExmotion 1.2.3 available on the assetstore!
    • Fix : timescale and FPS issues
    • New : local timescale by instance ( VertExmotion.SetTimeScale(float timescale) )
    assetstore links : BASIC - PRO
     
  40. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    Last edited: Mar 6, 2015
    chelnok and punk like this.
  41. Licarell

    Licarell

    Joined:
    Sep 5, 2012
    Posts:
    434
    Is there any way to add an influence map. Painting on a surface is great but I would really love to use this with hair and when you have layered hair trying to paint underneath different layers is problematic.

    Thanks.
     
  42. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    I will create a tool for painting in UV space, it will be much better for hair :)
    an influence map is a good idea, I'll do it asap ;)
    I'll also add more features, like smooth brush, masking...
    If you have the source of the mesh, you should be able to paint vertex color in your favorite 3D software :)
     
    chelnok, punk, hopeful and 2 others like this.
  43. Licarell

    Licarell

    Joined:
    Sep 5, 2012
    Posts:
    434
    Dude your awesome!

    Thanks!
     
  44. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
  45. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    Version 1.2.4 comming soon
    include painting map
    paint_data_from_map.PNG
     
    ThunderTruck and punk like this.
  46. Licarell

    Licarell

    Joined:
    Sep 5, 2012
    Posts:
    434
    Rock on!!!
     
    kalagaan likes this.
  47. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    VertExmotion 1.2.4 available on the assetstore!
    • Fix : unity5 Demos and standard shader
    • New : paint map
    • New : Export painting data in new mesh (enable mesh sharing and compatibility unity4->unity5)
    assetstore links : BASIC - PRO
     
    chelnok and punk like this.
  48. arcmohudragon

    arcmohudragon

    Joined:
    Oct 15, 2012
    Posts:
    114
  49. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    680
    Hi,
    here the UnityChan shaders ;)
    These shaders are simple to convert, look at the .CG files, only 2 lines added and 1 modification :)

    Code (CSharp):
    1. //top of .cg file
    2. #include "Assets/VertExmotion/Shaders/VertExmotion.cginc"
    3.  
    4. v2f vert( appdata_full v )//here I've changed appdata_tan by appdata_full
    5. {
    6.     VertExmotion( v );//here the VertExmotion function
    I've duplicated the shader files only to change their name to "VertExmotion/..."


    UnityChan is a complex character, because the body is splitted in many gameobjects.

    here a way for an easy integration:
    - add VertExmotion script on all the meshes
    - create sensors on one of them (ex: skin)
    - share sensors on the other VertExmotion instances
    -> to do this : Drag&drop sensor in "Add existing sensor" field and add it
    -That's all :D


    Note : Don't forget to add a bone in the sensors' parent field.
     
    Last edited: Mar 21, 2015
  50. arcmohudragon

    arcmohudragon

    Joined:
    Oct 15, 2012
    Posts:
    114
    Wow! Fantastic easy solution! very very thanks!
     
    kalagaan likes this.