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 Can't do loop in custom function node

Discussion in 'Shader Graph' started by segant, Jan 29, 2020.

  1. segant

    segant

    Joined:
    May 3, 2017
    Posts:
    196
    I created a texture(16x1) and just change their rgba with setpixel or pixels but the problem is the loop doesn't add uvs as i expected. It shows the last loop value . I just want to keep old waves. I change a pixel when raycast hit and upload it to shader. But keeping old values. I think it deletes calculations when i use graphics blit or set texture from material. I'm not experienced with shaders.
    Code (CSharp):
    1. int i=0;
    2. float2 uv=float2(0.0,0.0);
    3. while(i<16){
    4.     float4 col=waves.SampleLevel(SS,int2(i,0),0); //waves is Texture2D RGBA32 Float
    5.      //somecalculation here with float2
    6.          uv+=calculation;
    7.  
    8.  
    9. i++;
    10.        
    11.            }
    12. outcolor=uv.x/16.0;
     
    Last edited: Jan 30, 2020