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:
    2
    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:
    175
    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:
    45
    Any updates on the AMD situation? Also, how about XBox One, PS4, and Switch?
     
  7. MultivariousDev01

    MultivariousDev01

    Joined:
    May 22, 2014
    Posts:
    21
    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. KlutoTek

    KlutoTek

    Joined:
    May 24, 2017
    Posts:
    5
    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. 3d_Artist1987

    3d_Artist1987

    Joined:
    Jul 9, 2012
    Posts:
    719
    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:
    577

    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:
    123
    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,414
    Sounds like nvidia have something up their sleeves:

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

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    393
  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,414
    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:
    175
    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:
    431
    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,414
    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:
    175
    @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:
    123
    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:
    1
    Wowowowow! Almost can not believe that! Is there anyway can we get the source code for unity?
     
unityunity