0

enter image description here

I set spotlight angle to 150 degree. But it is not doing what I hope for in this unusual situation.

It's simple.

If I set spot light angle to 150 degree, then it has to lighten 150 degree area. but as you can see above, light reaches only small area in the center(maybe like 24 degree area??)

Why is this happening? and How can I fix it?

I know I can make range something big like 5000 to solve problem. But I have to make spotlight reach until maximum range. And on maximum range, light should be spread out exactly along with angle. Light must be SPREAD ON MAXIMUM RANGE.

Distance between spot light and plane is 50. and spotlight range is 51. I overrided default shader to modify light attenuation to be very low so that light will be reached until almost maximum range.

Thanks.


Added purpose of my application and shader


OK. First of all, Thank you all for your time to help me. Really.. I really appreciate of everyone.

I am pretty experienced full-stack programmer but really new in 3D graphics and shader things.. So I don't think I can make projector by my own in short time without long term study of shader programming.

Anyway,

  1. Purpose of my application

    • I'm simulating CCTV placement and I have to visualize exact CCTV coverage area. That's why I need something like unity standard asset projector. BUT! UNITY PROJECTOR can't make shadow and it even lighten back side of mesh which doesn't make sense totally and can't be used for my purpose. As mentioned in answers, I know that I'm making something very unrealistic. To visualize exact CCTV coverage area, I need some light which goes only until certain range. So, to clarify what I'm trying, I will list the properties my projector needs to satisfy.

    • Possible to control vertical and horizontal angle. (Unity projector can)

    • Rectangular shape as CCTV cameras see (I think cookie can solve)
    • Possible to control maximum range (light or cameras always has range option)
    • Light should reach until maximum range and it has to evenly distributed in maximum range. (This is the beginning of this thread)
    • Projector should make hard shadow (because purpose is showing exact coverage area)

I was planning to make this kind of projector putting spot light inside of box with a rectangular hole. I was going to dynamically make exact coordinated box according to properties of CCTV above : range. vertical and horizontal angle. But if spot light is like this, I can't do this.

  1. My shader (I don't want to call it MY shader beacause I just added a line to default shader as I mentioned)

    • I changed light mode to deferred in player setting
    • Changed DEFERRED default shader to my custom shader in resources folder(Internal-DeferredShading.shader). But I didn't change any code in this file.
    • Copy UnityDeferredLibrary.cginc file in my resources and added a line

This is the shader code

    // spot light case
    #if defined (SPOT)  
    float3 tolight = _LightPos.xyz - wpos;
    half3 lightDir = normalize (tolight);

    float4 uvCookie = mul (_LightMatrix0, float4(wpos,1));
    float atten = tex2Dproj(_LightTexture0, UNITY_PROJ_COORD(uvCookie)).w;
    atten *= uvCookie.w < 0;
    float att = dot(tolight, tolight) * _LightPos.w;
    // as you can notice, this is A line I added
    att = att *att *att *att*att *att *att *att*att *att *att *att * att *att *att *att*att *att *att *att*att *att *att *att * att *att *att *att*att *att *att *att*att *att *att *att;
    atten *= tex2D (_LightTextureB0, att.rr).UNITY_ATTEN_CHANNEL;

    atten *= UnityDeferredComputeShadow (wpos, fadeDist, uv);

I'm now really desperate and hurry now. I really need help. I am even willing to pay if someone makes this kind of projector...

Thank you again to all. I really appreciate.

reference images

enter image description here enter image description here

Myeong-jae Kim
  • 133
  • 3
  • 11
  • Can try do it without your shader? If the light range will be good then the problem is in your shader. – Jerry Switalski Jan 25 '16 at 09:43
  • 1
    Of course that you will have this effect if you set your range to 51. Imagine baloon touching a wall. In your example baloon just barely touches a wall, but make it bigger and the touch area will grow. Same with your light, change it to like 200 and it should be ok. – Łukasz Motyczka Jan 25 '16 at 10:03
  • Thanks for good explanation using baloon. But it doesnt make sense that spot light is supposed to spread out along specific angle. I admit that light intensity decreases by distance but why does spot light shape look like baloon? It is not point light. – Myeong-jae Kim Jan 25 '16 at 11:32

1 Answers1

3

To fix this you need to have greater range of the spot light.

  1. Range meets the plane. 1

  2. Higher range 2

This is due to the shader has really low test for color in outer areas, as the Spotlight type of light has a gradient light from the center to the outer rim.

Jerry Switalski
  • 2,690
  • 1
  • 18
  • 36
  • Thanks for your time but I suggest you to read my post carefully. – Myeong-jae Kim Jan 25 '16 at 11:34
  • Sorry, I see now your point. But the answer remains unless you show the shader, as if it should show full intensity on outer rim then its just not working. Anyway I see gradient shading in your spotlight shader too. My suggestion is not to use spotlight i this case but any other projector. Unless you need is as spotlight. – Jerry Switalski Jan 25 '16 at 12:17
  • Thank you Jerry. I googled a lot but I think I can't find answer for my problem. I want to make real-world projector with shadow casting. I will put this spot light in a box with hole. My shader is not specific to this spot light. I overrided default light shader to control attenuation of spot light. I just added a line. I don't think my shader code is related to my problem. – Myeong-jae Kim Jan 25 '16 at 12:25
  • I know there is projector prefab in standard asset. This asset projector has problem that it can't shadow cast. And it lights back side of mesh as well. This isn't right. What I am doing is to show CCTV coverage area exactly with camera vertical, horizontal angle and range. That's why spot light should not go more than maximum range and light must spread out until maximum range. – Myeong-jae Kim Jan 25 '16 at 12:29
  • Okay I get it, but I still think the problem is in the shader. I see it works very similar to the standard, as we can see gradient. In this case it will work very similar to the standard shader a d wont draw with this range outer areas. Try to remove completly grading in this light. – Jerry Switalski Jan 25 '16 at 12:34
  • "What I am doing is to show CCTV coverage area exactly with camera vertical, horizontal angle and range." you WILL NOT be able to do this with a spotlight, Kim. The spotlight is a very carefully engineered system that is **MEANT TO WORK -- LIKE A SPOTLIGHT (!)**. Note carefully that IN REAL LIFE you COULD NOT do this with a spotlight. You'll need some custom coding at some level. – Fattie Jan 25 '16 at 15:10