Search Unity

How to exposed SDF and Pointcache Parameter?

Discussion in 'Visual Effect Graph' started by kkrg001, Apr 18, 2020.

  1. kkrg001

    kkrg001

    Joined:
    Mar 6, 2019
    Posts:
    35
    hi.Let me ask a simple question.
    I don't want to create a new VFX Graph for each SDF.
    How to exposed SDF and Pointcache Parameter?
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    @kkrg001

    SDF:
    1. Make a Texture3D block
    2. Convert it to an Exposed Property
    3. Name the property, check that the green dot is lit, which means it shows in UI.
    4. Check your Visual Effect in Inspector, and you see your exposed Texture3D there.

    Point cache:
    As far as I know, point cache can't be exposed to UI (I'm on 7.1.6) but maybe it's been already changed in later versions.
     
  3. kkrg001

    kkrg001

    Joined:
    Mar 6, 2019
    Posts:
    35
    @Olmi
    Thank you for your polite answer!
    It's a pity that we can't parameterize the point cache, but SDF worked well.
     
  4. owen_planchart

    owen_planchart

    Joined:
    Aug 11, 2016
    Posts:
    11
    This is very useful, thank you.

    Once you have the Texture3D exposed do you know how one could change between different SDF's dynamically (say by pressing the mouse)? Can this be done in VFX graph or does it have to be done with script? I am very new to Csharp, so i'd be grateful for any guidance.
     
  5. kkrg001

    kkrg001

    Joined:
    Mar 6, 2019
    Posts:
    35
    Probably, I don't think you can change parameters dynamically without using csharp...
    I think that it is possible to prepare multiple SDFs in a graph and switch them with parameters.
     
  6. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    @kkrg001 you could use switch to do the SDF selection, which would just use an int/uint as the parameter, then expose that to UI. But the thing with switch is that it does not accept Texture3D as an input, so you would have to sample the Texture3D using Sample Texture3D node and then pass that Vector3 to the switch. And that means also that you would need to generate UVs yourself for that sampling... at least I haven't figured out any other way. And it might not be usable for all cases, conform to SDF wouldn't work I think etc.

    i.e. something like this:
    texture3d_switch.PNG

    So maybe some custom solution would be easier/better to set the SDF texture.

    But it's not that difficult to access the VFX component's public field, I think something like this would work (find the string name of the exposed parameter you have on your blackboard or whatever it's officially called.):

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.VFX;
    3.  
    4. public class VisualEffectChangeTexture3D : MonoBehaviour
    5. {
    6.  
    7.     public VisualEffect vfx;
    8.     public RenderTexture texture3D;
    9.  
    10.     void Start()
    11.     {
    12.  
    13.         if (vfx != null && vfx.HasTexture("SDF 3D Texture"))
    14.         {
    15.             vfx.SetTexture("SDF 3D Texture", texture3D);
    16.         }
    17.     }
    18.  
    19. }
    In this example I just used RenderTexture, instead of Texture3D but both should function.
     
    Last edited: Apr 19, 2020
    florianhanke likes this.
  7. kkrg001

    kkrg001

    Joined:
    Mar 6, 2019
    Posts:
    35
    @Olmi
    Thank you very much for your polite answer.
    The replacement of SDF also worked well!

    ..Designers including myself are generally not good at scripting.
    As for me, in UE4 i can make a single game with BluePrint.
    But I don't like to see C# ...

    sorry to complain.
    Thank you very much!
     
  8. owen_planchart

    owen_planchart

    Joined:
    Aug 11, 2016
    Posts:
    11
    Thank you, I will give this a go.
     
  9. Vaspra

    Vaspra

    Joined:
    Apr 15, 2018
    Posts:
    34
    I had a VFX graph I wanted to use with many different point caches, so I turned the core effect into a subgraph and exposed the 2D map as a texture rather than the cache (was only caring about the 2D map from the pointcache anyway). Then I could make a new VFX graph for as many models as I wanted, which simply contain a pointcache block and the subgraph with a texture 2D input :)

    upload_2020-5-24_16-7-33.png
     
    bunnybreaker likes this.
  10. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,091