#Identical code not producing same result

1 messages · Page 1 of 1 (latest)

clever gazelle
#

I wrote this shader, and it doesn't produce the results I want, which is why I wrote an identical c# function and that does work indeed

#
This is the c# function
public void DispatchCpu()
    {
        UpdateData("points");
        Texture2D mainText = new Texture2D(256,256);
        Texture2D points = TData["points"];
        Texture2D indices = TData[indexerSilable + "points"];

        for(int y = 0;y<mainText.width;y++)
        {
            for(int x = 0;x<mainText.height;x++)
            {
                Vector2 myPos = new Vector2(x,y)/mainText.width;
                
               
                for(int i=0;i<points.width*points.height;i+=2)
                    {
                        int b0,b1,b2,b3;
                        b0 = i;          
                        b1 = i+1;
                        b2 = i+2;
                        b3 = i+3;

                        Vector2 point = new Vector2(points.GetPixel(b0 % points.w,(b0 / points.width) % points.height).r,                              points.GetPixel(b1 % points.width,(b1 / points.width) % points.height).r)*short.MaxValue;
                        Vector2 distance2 = myPos-point;
                        float dist = Vector2.Dot(distance2,distance2);
                        if(dist<0.001f)
                        {
                            mainText.SetPixel(x,y,new Color(0,0,0,1));
                        }
                        
                    }
                
            }
            
        }
        mainText.Apply();
        CpuMat.mainTexture = mainText;
        



    }
#
fixed4 frag(v2f i) : SV_Target
            {
                float2 range =  float2(i_PointText_TexelSize.z,i_PointText_TexelSize.w);
                float2 pointRange = float2(_PointText_TexelSize.z,_PointText_TexelSize.w);

                
                
                float a,b = 0;
                float2 myPos = i.uv;

                float4 col = float4(i.uv.x,i.uv.y,i.uv.x*0.5+i.uv.y*0.5,1);
                float4 awh = i_PointText_TexelSize;
                float4 bwh = _PointText_TexelSize;
                
                for(b = 0;b<bwh.z*bwh.w;b+=2)
                    {
                        float b1 = b+1;
                       
                        float x = tex2D(_PointText,float2((b % bwh.z)*bwh.x,((b / bwh.z) % bwh.w)*bwh.y))*32767;
                        float y = tex2D(_PointText,float2((b1 % bwh.z)*bwh.x,((b1 / bwh.z) % bwh.w)*bwh.y))*32767;
                        float2 pointA = float2(x,y);
                        float2 dist2 = pointA-myPos;
                        float dist = dot(dist2,dist2);
                        
                           
                        
                        if(dist<0.0005f)
                        {
                            col = float4(1,1,1,1);
                        }
                        
                       
                        
                    }
                
                
               
                return col;
            }

And this is my shader code