Search Unity

Weird gap between lights

Discussion in 'Shaders' started by Waseemmongdol, Dec 28, 2021.

  1. Waseemmongdol

    Waseemmongdol

    Joined:
    Dec 28, 2021
    Posts:
    1
    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):
    1. struct Light{
    2.    float4 position;
    3.    float size;
    4. };
    5.  
    6. //appdata and v2f
    7.  
    8. StructuredBuffer<Light> _LightData;
    9. fixed4 frag (v2f i) : SV_Target{
    10.    float _distance = 0;
    11.    fixed4 color = tex2D(_MainTex, i.uv);
    12.    for(int a = 0; a < _LightArraySize;a++){
    13.        if(_distance>0){
    14.            if(_distance > distance(i.worldSpacePos, _LightData[a].position+0.5)/_LightData[a].size){
    15.                _distance = distance(i.worldSpacePos, _LightData[a].position+0.5)/_LightData[a].size;
    16.            }
    17.        }else{
    18.            _distance = distance(i.worldSpacePos, _LightData[a].position+0.5)/_LightData[a].size;
    19.        }
    20.    }
    21.    return fixed4(color.x - _distance, color.y - _distance, color.z - _distance, color.w);
    22. }
     
    Last edited: Jan 1, 2022
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,566
    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.