Search Unity

Problem with point lights, they are squared

Discussion in 'Shaders' started by vegenarie, Sep 29, 2014.

  1. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    I have made a cg shader and all lights work fine, included the spot lights, but point lights are seen as a square, it happens the same if you use a spot light without the unity cookie attenuation. Seems to be any problem with getting the unity cubemap for the point light.
     
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,791
    I'm afraid I don't really understand. A screenshot would help.
     
  3. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    I am not in the same computer now but imagine a spot light looking to the ground, like a lantern light focused, it would be a nice circle illuminating the ground just in that area, without spot light cookie attenuation it would be just an ugly square. The same happens with point light cookie attenuation, but they use a cubemap instead of just a texture2D, so when i use point lights its just an square illuminating the ground, so that is why i say something wrong happens with the cubemap given by unity that doesnt work properly.
     
  4. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    I have an image of t
    I am using the tutorial in http://en.wikibooks.org/wiki/Cg_Programming/Unity/Cookies
    I am following the codes shown but point lights are shown wrong

    pointlight.png
     
  5. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
  6. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    still cannot see your screenshot btw.
     
  7. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    That screen shot is tiny. It's really hard to see anything in the picture, let alone isolate the issue.
     
  8. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    Ok, here the image bigger
     

    Attached Files:

  9. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    So that rectangle is always screen space axis-aligned? My guess would be that attenuation is being done incorrectly, and the shape is a result of the light pre pass clipping for the light.

    Can you post the shader in question?
     
  10. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    I dont see it screen space aligned but world aligned, when i move i can see as new squares are enlighted in the terrain.

    I am using a code very similar to http://en.wikibooks.org/wiki/Cg_Programming/Unity/Cookies

    The attenuation i follow is

    Code (CSharp):
    1.             #if defined (DIRECTIONAL) || defined (DIRECTIONAL_COOKIE)
    2.                lightDirection = normalize(_WorldSpaceLightPos0.xyz);
    3.             #elif defined (POINT_NOATT)
    4.                lightDirection = normalize(
    5.                   _WorldSpaceLightPos0 - input.posWorld.xyz);
    6.             #elif defined(POINT)||defined(POINT_COOKIE)||defined(SPOT)
    7.                float3 vertexToLightSource =
    8.                   _WorldSpaceLightPos0.xyz - input.posWorld.xyz;
    9.                float distance = length(vertexToLightSource);
    10.                attenuation = 1.0 / distance; // linear attenuation
    11.                lightDirection = normalize(vertexToLightSource);
    12.             #endif
    Cookie attenuation

    Code (CSharp):
    1.             float cookieAttenuation = 1.0;
    2.                // by default no cookie attenuation
    3.             #if defined (DIRECTIONAL_COOKIE)
    4.                cookieAttenuation = tex2D(_LightTexture0,
    5.                   input.posLight.xy).a;
    6.             #elif defined (POINT_COOKIE)
    7.                cookieAttenuation = texCUBE(_LightTexture0,
    8.                   input.posLight.xyz).a;
    9.             #elif defined (SPOT)
    10.                cookieAttenuation = tex2D(_LightTexture0,
    11.                   input.posLight.xy / input.posLight.w
    12.                   + float2(0.5, 0.5)).a;
    13.             #endif
     
  11. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    That's some impressive alignment in your screen shot, then.

    The whole shader is useful because then someone trying to solve your problem can test it.
     
  12. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Lol.....really sorry but i can't helped it, for some reason this one crack me up :D