I have started learning to code shaders a couple of weeks ago. I wanted to create a basic shader for my 2D project. But while doing it, I was faced with the problem shown here Here is my code(part of it): Code Code (CSharp): struct Light{ float4 position; float size; }; //appdata and v2f StructuredBuffer<Light> _LightData; fixed4 frag (v2f i) : SV_Target{ float _distance = 0; fixed4 color = tex2D(_MainTex, i.uv); for(int a = 0; a < _LightArraySize;a++){ if(_distance>0){ if(_distance > distance(i.worldSpacePos, _LightData[a].position+0.5)/_LightData[a].size){ _distance = distance(i.worldSpacePos, _LightData[a].position+0.5)/_LightData[a].size; } }else{ _distance = distance(i.worldSpacePos, _LightData[a].position+0.5)/_LightData[a].size; } } return fixed4(color.x - _distance, color.y - _distance, color.z - _distance, color.w); }
You forgot to tell what your problem, what effect you tried to achieve, did provide a screenshot of it and so on. Also subtracting distance from color is not how you blend color based on distance.