Search Unity

uFlex - NVidia FLEX for Unity3D - Unified Visual FX [RELEASED]

Discussion in 'Assets and Asset Store' started by korzen303, Apr 15, 2016.

  1. chanddu

    chanddu

    Joined:
    Jun 13, 2016
    Posts:
    7
    Hi @korzen303.
    Can you please tell me how to use different meshes in uFlex other than the default one.
    With Regards,
    Chanddu.
     
  2. iliaVIS

    iliaVIS

    Joined:
    May 16, 2016
    Posts:
    1
    hi there,
    i would like to use uflex with the current usecase:
    a pool of rigidbodies with many rigidbodies.
    rigidbodies should be textured specifically, not colored with a general color. is there a way to do this ?

    also , can i speed up the framerate of the simulation . the bodies and gravity works abit slow..
     
  3. kawon

    kawon

    Joined:
    Nov 1, 2016
    Posts:
    3
    Hi, @korzen303
    When do you plan to release a new version? (approx.) Thank you.
     
  4. korzen303

    korzen303

    Joined:
    Oct 2, 2012
    Posts:
    223
    Anyone has standard unity shader with improvments from minute 29?

    I wrote something like this, from video, maybe sombody can make it work:
    Code (CSharp):
    1. Shader "Custom/shaderflexmoj" {
    2. Properties {
    3.         _Color ("Color", Color) = (1,1,1,1)
    4.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
    5.         _Glossiness ("Smoothness", Range(0,1)) = 0.5
    6.         _Metallic ("Metallic", Range(0,1)) = 0.0
    7.     }
    8.     SubShader {
    9.         Tags { "RenderType"="Opaque" }
    10.         LOD 200
    11.    
    12.         CGPROGRAM
    13.         #pragma multi_compile _ _DYNAMIC_VERTICES
    14.         #pragma vertex vertForwardBaseDynamic
    15.  
    16.         // Physically based Standard lighting model, and enable shadows on all light types
    17.         #pragma surface surf Standard fullforwardshadows
    18.         #pragma target 3.0
    19.  
    20.         #ifdef _DYNAMIC_VERTICES
    21.           #include "../dodatki/DynamicVertices.cginc"
    22.             VertexOutputForwardBase vertForwardBaseDynamic(VertexInput v, uint vertexId :SV_VertexID){
    23.             TransferStandardDynamicData(v, vertexId);
    24.             return vertForwardBase(v);
    25.             }
    26.             #else
    27.             VertexOutputForwardBase vertForwardBaseDynamic(VertexInput v){
    28.             return vertForwardBase(v);
    29.             }
    30.             #endif
    31.         // Use shader model 3.0 target, to get nicer looking lighting
    32.  
    33.  
    34.         sampler2D _MainTex;
    35.  
    36.         struct Input {
    37.             float2 uv_MainTex;
    38.         };
    39.  
    40.  
    41.         half _Glossiness;
    42.         half _Metallic;
    43.         fixed4 _Color;
    44.  
    45.         void surf (Input IN, inout SurfaceOutputStandard o) {
    46.             // Albedo comes from a texture tinted by color
    47.             fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
    48.             o.Albedo = c.rgb;
    49.             // Metallic and smoothness come from slider variables
    50.             o.Metallic = _Metallic;
    51.             o.Smoothness = _Glossiness;
    52.             o.Alpha = c.a;
    53.         }
    54.         ENDCG
    55.  
    56.     }
    57.     FallBack "Diffuse"
    58. }
    also made made txt file changed to cginc
    Code (CSharp):
    1.      int _firstVertex;
    2.          StructuredBuffer<float3>POSITIONS;
    3.          StructuredBuffer<float3>NORMALS;
    4.          StructuredBuffer<float4>TANGENTS;
    5.  
    6.          void TransferStandardDynamicData(inout VertexInput v, int vertexId)
    7.          {
    8. vertexId += _firstVertex;
    9.          v.vertex.xyz=POSITIONS[vertexId];
    10.          v.normal=NORMALS[vertexId];
    11.              #ifdef _TANGENT_TO_WORLD
    12.              v.tangent.xyz=TANGENTS[vertexId];
    13.              #endif}

    As you might guess it does not compile.

    Also on the video at 31min Flex particles are asigned to the nearest skinned mesh vertexes, therfore He can animate main model with cloths(maybe he has made only an empty shel made from flex particles), then these Flex particles might have zero invere mass which is important for uflex Cloth settings...
    It would be pretty nice if uflex got a function like that,of creating uflex particle for skinned mesh characters where uflex particles are asigned to movig mesh vertexes with 0 mass.[/QUOTE]

    @pan-master Hi, have you managed to get this to work eventually? Thanks
     
  5. Nepif168

    Nepif168

    Joined:
    Dec 9, 2016
    Posts:
    1
    Hi @korzen303.
    Im Japanese.
    Thank you for beautiful asset.

    I have a question.
    Can I create more than one particle?

    Thank you.
     
  6. nsfnotthrowingaway

    nsfnotthrowingaway

    Joined:
    Feb 18, 2016
    Posts:
    48
    Any updates on the AMD situation? Also, how about XBox One, PS4, and Switch?
     
  7. MultivariousDev01

    MultivariousDev01

    Joined:
    May 22, 2014
    Posts:
    28
    Hey @korzen303, I started a private conversation with you where I provided my e-mail address. If you'd like to correspond about the issue I've found, I'd love to hear from you!
     
  8. BrineyDepths

    BrineyDepths

    Joined:
    May 24, 2017
    Posts:
    6
    I stumbled into a solution for this and another problem with additional UV sets. To fix the normal mapping issue I added this in FlexWindow.cs at line 817 where uFlex creates the mesh. It makes uFlex import the model's tangents.

    mesh.tangents = this.inputMesh.tangents;

    Plus, if you are using a mesh with multiple UV sets then put in this line.

    mesh.uv2 = this.inputMesh.uv2;

    Do this for mesh.uv3 and 4 if needed.
     
  9. AntonioMaurino

    AntonioMaurino

    Joined:
    Nov 16, 2017
    Posts:
    1
    Please, I have this problem. I needed to reduce the particle to real sizes to put the liquid inside a glass of water, that is, a reduction of approximately 100 times. The liquid leaks through the mesh. How to solve this?

    fluid.jpg
     
  10. ccc7861

    ccc7861

    Joined:
    Jan 19, 2016
    Posts:
    16
    glass create as Rigbody used uflex tool
     
  11. TechnicalArtist

    TechnicalArtist

    Joined:
    Jul 9, 2012
    Posts:
    736
    Any roadmap for android?
     
  12. Tejaswini_yarra

    Tejaswini_yarra

    Joined:
    Dec 13, 2017
    Posts:
    1
    Hi,
    @ccc7861 - I am trying to cut a uflex softbody using your code in #138 , I see that you are using CutTool in it with a default plane.

    So,should I create a class cut tool with a game object that has a property Deafault Plane or is there another way.

    Anyone else who used the code ??

    Thanks for the Help!.
     
    rasheedfareeha, steel and mozkid like this.
  13. alexbdillon

    alexbdillon

    Joined:
    Aug 30, 2017
    Posts:
    3
    Hi, I'm receive 12 or so warnings about "MaxParticles" and was wondering if there was any code I need to fix or update to resolve these issues. Please see the attached screenshot for more info.
     

    Attached Files:

  14. alexbdillon

    alexbdillon

    Joined:
    Aug 30, 2017
    Posts:
    3
    @ccc7861 Thank for sharing this code! Do you have anything like it for writing a function to cut flex tearing cloths via script?


     
  15. mlsptn

    mlsptn

    Joined:
    Jul 27, 2016
    Posts:
    7
    Hi @korzen303,

    Great plugin!

    I'm having an issue with softbodies and I'm wondering if you can help. When I create a softbody from my model, there are jagged artifacts along the UV seams of the model as you can see here:



    I exported my model again but this time with no UV map, and the artifacts go away in the created softbody:



    Do you have any idea why this is happening? The non-softbody version of the model that has the UV map looks smooth as well.
     
  16. mlsptn

    mlsptn

    Joined:
    Jul 27, 2016
    Posts:
    7
    Hi Everyone,

    I wrote a script that lets you bind softbodies to rigidbodies. This is equivalent to the "attach to rigids" feature in the Flex build of UE4, if you're familiar with that. To use the script, attach it to your uFlex softbody and assign the colliders that you wish to bind the softbody to using the "colliders to bind to" field.

    Hope this helps someone!

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. namespace uFlex
    6.  
    7. {
    8.     public class LockedParticle
    9.     {
    10.         public int particleIndex;
    11.         public Vector3 localPos;
    12.         public Transform rigidBoundTo;
    13.  
    14.         public LockedParticle(int idx, Vector3 pos, Transform rigid) {
    15.             particleIndex = idx;
    16.             localPos = pos;
    17.             rigidBoundTo = rigid;
    18.         }
    19.     }
    20.  
    21.     public class BindToRigids : FlexProcessor
    22.     {
    23.         List<LockedParticle> lockedParticles = new List<LockedParticle> ();
    24.  
    25.         public Collider[] collidersToBindTo;
    26.  
    27.         private FlexParticles m_flexParticles;
    28.  
    29.         float particleRadius;
    30.  
    31.         Vector3 localToGlobal(Vector3 point) {
    32.             return transform.localToWorldMatrix.MultiplyPoint (point);
    33.         }
    34.  
    35.         public override void FlexStart(FlexSolver solver, FlexContainer cntr, FlexParameters parameters)
    36.         {
    37.             particleRadius = parameters.m_radius;
    38.             m_flexParticles = GetComponent<FlexParticles>();
    39.  
    40.             int indexOffset = m_flexParticles.m_particlesIndex;
    41.  
    42.             for (int i = 0; i < m_flexParticles.m_particlesCount; i++) {
    43.                 Vector3 particlePos = localToGlobal(m_flexParticles.m_particles [i].pos);
    44.  
    45.                 for (int j = 0; j < collidersToBindTo.Length; j++) {
    46.  
    47.                     if (collidersToBindTo [j].bounds.Contains (particlePos)) {
    48.  
    49.                         Transform colliderTransform = collidersToBindTo [j].gameObject.transform;
    50.  
    51.                         // get particle pos relative to object transform
    52.                         Vector3 localPos = colliderTransform.worldToLocalMatrix.MultiplyPoint(particlePos);
    53.  
    54.                         LockedParticle particleToLock = new LockedParticle (i + indexOffset, localPos, colliderTransform);
    55.  
    56.                         // add to list of particles to constrain
    57.                         lockedParticles.Add (particleToLock);
    58.                     }
    59.                 }
    60.             }
    61.         }
    62.  
    63.         public override void PostContainerUpdate(FlexSolver solver, FlexContainer cntr, FlexParameters parameters)
    64.         {
    65.             // update locked particles
    66.             print(lockedParticles.Count);
    67.             for (int i = 0; i < lockedParticles.Count; i++) {
    68.                 LockedParticle p = lockedParticles [i];
    69.  
    70.                 int idx = p.particleIndex;
    71.  
    72.                 Vector3 newPos = p.rigidBoundTo.transform.localToWorldMatrix.MultiplyPoint (p.localPos);
    73.  
    74.                 cntr.m_particles [idx].pos = newPos;
    75.                 cntr.m_particles [idx].invMass = 0.0f;
    76.             }
    77.         }
    78.     }
    79. }
     
    My5x6 likes this.
  17. Ascensi

    Ascensi

    Joined:
    Sep 7, 2013
    Posts:
    579

    hey thanks! i tried but get this error
    UnityException: get_value is not allowed to be called from a ScriptableObject constructor (or instance field initializer), call it in OnEnable instead. Called from ScriptableObject 'FlexWindow'.
    See "Script Serialization" page in the Unity Manual for further details.
    uFlex.FlexWindow..ctor () (at Assets/uFlex/Editor/FlexWindow.cs:74)

    I don't write code so I'm not sure how to fix.

    @korzen303 I'd like to use the rope system to make a suspension bridge. I've tested your ropes and no matter how I stretch them out it doesn't go crazy and fail.

    The only thing I'm missing is how to connect my rigid body meshes to your rope? This is the bridge I made in the past but like I said I need it to be more stable and faster on the GPU.



    Also you should be asking Partel Lang - developer of Final IK about your shader problem, he apparently wrote that GPU cloth in the video.
     
    Last edited: Feb 27, 2018
  18. mozkid

    mozkid

    Joined:
    Jan 10, 2018
    Posts:
    3
    Hi Tejaswini!! did you got an answer for your question?
     
  19. mozkid

    mozkid

    Joined:
    Jan 10, 2018
    Posts:
    3
    Can you please add a tutorial for this code?
     
  20. mozkid

    mozkid

    Joined:
    Jan 10, 2018
    Posts:
    3
    I've Got this error:
    An object reference is required for the non-static field, method, or property 'CutTool.DefaultPlane'
    Can someone help me with this script?
     
    freenut likes this.
  21. pan-master

    pan-master

    Joined:
    Nov 11, 2013
    Posts:
    127
    1. At default particles are distributed with value of influacne that equls=1,
    Could it be possibe to asign different infualce values to particles depending on the distantce of particles to the closest vertex?
    I mean, the closer particle is is to mesh vertex the more Invluecne that particle it should have, It would create bone like particle structure, with hard interior influacnes and jigle inluacne at outer possitions.
    2.Could it be possible to override part of meshRenderer of soft body with custom vertex positions?
     
  22. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,502
    Sounds like nvidia have something up their sleeves:

    https://developer.nvidia.com/gdc18-show-guide-nvidia
     
  23. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    417
  24. s903101

    s903101

    Joined:
    Jun 22, 2015
    Posts:
    1
    hi @mlsptn

    i had same issue with jagged
    i think this issue occur becasue the UV Border

    it can fix by add one line to theFlexWindows.cs

    in the function of
    private void GenerateFromMesh(GameObject go)

    add this
    "mesh.normals = this.inputMesh.normals;"

    below this line
    mesh.RecalculateNormals();

    like below

    private void GenerateFromMesh(GameObject go)
    {
    .
    .

    mesh.RecalculateNormals();
    mesh.normals = this.inputMesh.normals;//add this then it will use inputMesh normal to create normal
    .
    .
    }

    and remake softbody again i will no jagged
    but in game the softbody collide and change shape
    the jagged will appear
    i do not know how to fix it


    sorry with my poor english
     
    Last edited: Mar 17, 2018
  25. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,502
    As expected from the wording in the nvidia GDC show guide, an official Unity FleX plugin got announced, even before the talk/demo on the subject which takes place tomorrow. And 'Unity (Coming Soon)' got added to the GameWorks FleX page engine section. I am not at GDC myself so am reliant on others for news on this, and my own fevered refreshing of key pages on the net :D

    https://developer.nvidia.com/flex
     
  26. korzen303

    korzen303

    Joined:
    Oct 2, 2012
    Posts:
    223
    NVidia showed this GameWorks/Flex plugin already at Unite Europe in June last year. Hence, the lack of updates to uFlex since then. Upgrading uFlex to Flex 1.1 or 1.2 would require a major rewrite.

    I am really happy that I provided the Unity Community with such a great technology as NVidia Flex more than two years ago!
     
    Ascensi, yonghang and elbows like this.
  27. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    Hello @korzen303 , it seems the SmallScale sample scene does only work for the fluid, but not for creating e.g. a sphere and having the particles interact with it (with a MeshCollider). They just ignore it. Also, the fluid particles mostly ignore the armadillos in your sample scene; there seems to be a tiny bit of interaction going on, but really not much.

    Could you please check that you sample scene is working as intended?

    Steps to reproduce:
    - create a small sphere (e.g. radius 0.5)
    - add MeshCollider instead of SphereCollider
    - change MeshCollider cooking to "Inflate"
    - Play.
    - move sphere through fluid

    Expected: sphere affects fluid particles.
    Actual: nothing happens.
     
    zhaowei418 likes this.
  28. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,502
    I found the GDC Nvidia session video on GDCvault, I dont seem to be able to link directly to that sessions video though, so you have to find it on the following page:

    https://www.gdcvault.com/browse/gdc-18#page-9

    (its called NVIDIA GameWorks: New Features)

    Anyway the Unity FleX bit starts a bit after the 28 minute mark, and is basically a brief demo of the plugin in use. The only thing said about timescale is that a slide says 'coming shortly after GDC'.
     
    mlsptn likes this.
  29. caoyuxi

    caoyuxi

    Joined:
    Jul 9, 2015
    Posts:
    10
    guys i have question for uflex liquid section.
    i was trying to use particle system to emit liquid into a mesh container with mesh colider. the issue is when liquid hit the edge of the vertical plane and flat plane , the liquid wont bounce back and start to accumulate water inside of the container with mesh colider. it just leak out of the box.
    did i create the colider box in a wrong way ?
    InkedUnity_2018-05-19_17-26-35_LI.jpg
    James
     
  30. korzen303

    korzen303

    Joined:
    Oct 2, 2012
    Posts:
    223
    @pan-master try reinstalling the GeForce drivers with clean option marked. Sometimes WindowsUpdates brake things
     
  31. pan-master

    pan-master

    Joined:
    Nov 11, 2013
    Posts:
    127
    Iam trying to use uFlex fluid with DynamicMesh Colliders,
    It looks like FlexCollider.cs script Reads MeshFilter.mesh and MeshCollider of Collision Object,to Pass CollisionMeshData into Solver

    To read Updated MeshCollider I change FlexColliders.cs at 51 line
    from GetComponent<MeshFilter>().mesh;
    to
    GetComponent<MeshFilter>().sharedMesh;

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class DynamicCOllider : MonoBehaviour {
    6.     [Range(0.005f,1)]
    7.     public float RateOfUpdate = 0;
    8.     MeshCollider meshColider;
    9.     SkinnedMeshRenderer skinnedMeshRenderer;
    10.     Mesh bakedMesh;
    11.     MeshFilter meshFilter;
    12.     // Use this for initialization
    13.     void Start () {
    14.         skinnedMeshRenderer = GetComponent<SkinnedMeshRenderer>();
    15.         meshFilter = GetComponent<MeshFilter>();
    16.         meshColider = GetComponent<MeshCollider>();
    17.        
    18.         ///Initialisation of Dynamic Collider///
    19.         bakedMesh = new Mesh();
    20.         skinnedMeshRenderer.BakeMesh(bakedMesh);
    21.         meshFilter.sharedMesh = bakedMesh;
    22.         meshColider.sharedMesh = bakedMesh;
    23.  
    24.         //Updateing Collider
    25.         InvokeRepeating("UpdateShapeOfMeshCollider", 0.1f, RateOfUpdate);
    26.     }
    27.  
    28.     void UpdateShapeOfMeshCollider() {
    29.         skinnedMeshRenderer.BakeMesh(bakedMesh);
    30.      
    31.         meshFilter.sharedMesh = bakedMesh;
    32.         meshFilter.sharedMesh.RecalculateBounds();
    33.  
    34.          meshColider.sharedMesh = bakedMesh;
    35.          meshColider.sharedMesh.RecalculateBounds();
    36.  
    37.     }
    38.  
    39. }
    40.  
    However it looks like flexCollider.cs Script isnt Updating the shape of the collider
    Maybe it is becuase "ProcessColliders" of FlexCollider.cs updates only on Collider Translation?

     
    Last edited: Jul 8, 2018
  32. steel

    steel

    Joined:
    Nov 20, 2012
    Posts:
    8
    did you get answer for this?
     
  33. My5x6

    My5x6

    Joined:
    Sep 8, 2018
    Posts:
    1
    Last edited: Dec 20, 2018
  34. Sumardani

    Sumardani

    Joined:
    Mar 5, 2019
    Posts:
    1
    Hi, I have a problem with my uFlex. i just want this granular touch each other in theor surface, not their core. anyone can help me? please

    upload_2019-3-13_11-45-26.png
     
  35. yyxymlove

    yyxymlove

    Joined:
    Jul 14, 2014
    Posts:
    5
    Wowowowow! Almost can not believe that! Is there anyway can we get the source code for unity?
     
  36. Stickeyd

    Stickeyd

    Joined:
    Mar 26, 2017
    Posts:
    174
    Does it work on AMD? Does scaling work fine?
     
  37. johnson281

    johnson281

    Joined:
    Aug 10, 2019
    Posts:
    2
    Go to package manager search for nvidia , import the package and try again . It worked for me
     
    vjblind likes this.
  38. hinalk

    hinalk

    Joined:
    Apr 5, 2018
    Posts:
    2
    Hi @korzen303
    Can this asset be used to achieve glue gun like effect?
    I mean solidification and minor colour change of the fluid overtime.

    Also, would it be possible to achieve the welding gun effect through this?
    Would require a highly viscous liquid property with an option to add incandescence.

    I hope I am making my question clear :)
     
  39. korzen303

    korzen303

    Joined:
    Oct 2, 2012
    Posts:
    223
    Hi @hinalk I am afraid that it would be difficult to achieve very viscous liquid with Flex. It is due to Jacobi solver used for PBD implementation on the GPU. It simply does not converge that great compared to Gauss-Seidel or direct methods. But try maybe first with the free NVidia Flex integration and let us know
     
  40. hinalk

    hinalk

    Joined:
    Apr 5, 2018
    Posts:
    2
    @korzen303 thank you for the response.
    will try and post the progress on forum
     
  41. wechat_os_Qy00joB7YnFwoyJGIJFz204aw

    wechat_os_Qy00joB7YnFwoyJGIJFz204aw

    Joined:
    Oct 12, 2020
    Posts:
    1
    Hello! I have the same problem with you, I'd like to know if you'solved it, if you do, how?
     
  42. Slight0

    Slight0

    Joined:
    Dec 6, 2013
    Posts:
    28
    Hey, does this support plastic deformation that flex provides?
     
  43. BYALA

    BYALA

    Joined:
    May 23, 2021
    Posts:
    2
    @korzen303
    Hi Korzen!
    uFlex is a great plugin, but I have a question about how to make a particle in the soft body not physically simulated, I want some particles to be completely detached from the original object, in other words, I want to be able to delete it. I have tried changing the m_Phase in the FlexContainer to 0, but it doesn't work. Another question is whether there is a way to render separate particles as different colors independently.
    I hope you can still answer my questions, thank you!
     
  44. BYALA

    BYALA

    Joined:
    May 23, 2021
    Posts:
    2
    I have implemented this function.THX.
     
  45. cdev1

    cdev1

    Joined:
    Oct 19, 2021
    Posts:
    9
    where can i get this asset package? not found on store.
     
  46. korzen303

    korzen303

    Joined:
    Oct 2, 2012
    Posts:
    223
  47. NidhiParayil97

    NidhiParayil97

    Joined:
    Apr 6, 2023
    Posts:
    2
    Hi,
    I just downloaded the uFlex V0.55 and I could get the
    softdragon prefab to work. However I was wondering how to make custom soft bodies. The quickstart guide says Tools-> uflex and choose rigid or soft bodies (in the uflex.Flexwind window), but in my case the uflex.Flexwind window does not pop up.

    When I select tools -> uflex, the Flex comes under the SampleScene and that's it. I probably might me missing something, please do guide me on what to do.
     
  48. korzen303

    korzen303

    Joined:
    Oct 2, 2012
    Posts:
    223
  49. NidhiParayil97

    NidhiParayil97

    Joined:
    Apr 6, 2023
    Posts:
    2
  50. manurocker95

    manurocker95

    Joined:
    Jun 14, 2016
    Posts:
    210
    Hey, I saw all pages to check if softbodies could be cut. There was a cutting code somewhere around page 2 but it basically cuts it in half. Is it possible to tear the softbody in chunks without planes or "dissolve" part of the softbodies?

    Thanks in advance <3