Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Save data between passes in custom node

Discussion in 'Shader Graph' started by Marius_BB, Apr 12, 2022.

  1. Marius_BB

    Marius_BB

    Joined:
    Oct 18, 2021
    Posts:
    3
    Hi everyone,
    I've been trying for hours to create a custom node function that allows us to change parts of a texture according to an alpha mask (different uniform grey parts). Everything works quite well, but, as you imagine, some issues occured.
    As there's an unknown number of independent parts in this script, I wanted to choose the one to change with an ID (at least this works) and to keep modified values for ID that are not currently triggered in an array.
    That's where the issue occure, I have no clue on how to keep this array data between shader path to use it again and create the final texture as a result of all the modified pieces of the one in input.

    To go over that, I tried (without success) to keep the values as parameter of the Shader Graph, but obviously this solution seems to not be reliable at all.

    Here's the code I used, and of course, modif_col, the tab that I want to keep, is declared as static, out of every functions :

    void ourFct_float(float4 vecVal, float4 text_entree, float4 alphamask, float id ,out float4 Out){

    int i;
    float ran =0.05;
    float fuzziness =0.01;
    float mask;

    //init();
    float3 am= alphamask;
    float4 colorchanged;
    float4 lerped;
    int idint = id;
    modif_col[idint] = vecVal;
    float3 greycol = Greyval[idint];
    float4 total;

    for(i=0;i<3;i++){
    float3 greycol = Greyval[i];
    if(i==0){

    Unity_ColorspaceConversion_RGB_RGB_float(greycol,greycol);

    Unity_ColorMask_float(am, greycol, ran, mask ,fuzziness);
    Unity_Multiply_float4_float4(text_entree, modif_col[i], colorchanged);
    float4 lerp = float4(0,0,0,0);
    Unity_Lerp_float4(lerp,colorchanged,mask,lerped);
    Unity_Add_float4(text_entree ,lerped,total);
    }
    else{
    Unity_ColorspaceConversion_RGB_RGB_float(greycol,greycol);
    Unity_ColorMask_float(am, greycol, ran, mask ,fuzziness);
    Unity_Multiply_float4_float4(text_entree, modif_col[i], colorchanged);
    float4 lerp = float4(0,0,0,0);
    Unity_Lerp_float4(lerp,colorchanged,mask,lerped);
    Unity_Add_float4(total ,lerped,total);

    }



    PS : I've noticed that by commenting the init function, only the last greyValue used is stored in memory