Additional lighting issue when switch to Android platform?

Engine version: 2021.2.0f1
URP version: 12.1

In Android platform:

One point Light, seems right:

Two point lights, seems the first point light lighting twice:

How to reproduce:

  1. Use Windows machine to create a empty project with Unity version 2021.2.0f1, and use URP 12.1.
  2. Use [UniversalRP-HighQuality] render pipeline asset, and change [Additional Lights - Per Object Limit] to 8.
  3. Switch to Android playform in Build Settins.
  4. Create a new scene, a camera, a plane, a direction light, a point light. Looks shading is right.
  5. Create another additional light, [Lit] Shader cannot get the second light information correctly.

Can someone tell me how to fix it? Many thanks in advance!

More testing:
When light index comes to 5, [Lit] shader can get another light information:


When light numbers increasing, the second light becomes brighter…

Debugging:
In [ForwardLights.cs] file [SetupAdditionalLightConstants] function, I can see to position/colors of additional lights are correct.
(BTW, when I switch to Android platform, the max visible light number should be 32 or 16, however, [m_AdditionalLightPositions] is 256 length. The next screenshot shows UnityEditor - Android plateform is not mobile platform. Therefore, [maxVisibleAdditionalLights] is 265.)

Let’s assume all lights information is correct in Pipeline side. I start debug shader side.
When I tried to change [RealtimeLights.hlsl] file [GetPerObjectLightIndex] function, let it return 1 directly.


The RED LIGHT can influence the plane now.


++
Keep changing [GetPerObjectLightIndex] function, I moved light index mapping code to [!defined(SHADER_API_GLES)] branch, I can see upto 4 lights. (This code can only mapping 4 lighti index)


Therefore, I guass, in the engine side, the mapping of object light index to word light index is running in [!defined(SHADER_API_GLES)] branch.

If anyone has idea to fix it or any workaround ways, please tell me. Thanks in advanced!

++missing screenshot
7622275--948049--upload_2021-11-2_18-15-10.jpg

Anyone helps?

That doesn’t look right. Can I get you to report an issue? Then we can take a look and fix it :slight_smile:

Hi Peter,
Thanks for your reply. I had reported this issue, case id is [1378103].
https://fogbugz.unity3d.com/default.asp?1378103_492seh95aal7oor1

Please help to follow it. :slight_smile:
Much thanks.

2 Likes

“Fix In Review for 14.x.x”
OMG…
I Baked Lightmap in andriod platform with dLdr encoding,so it can not switch to pc platform.And this issue was totally a disaster for me.

Solution I found:
change the following line

int perObjectLightIndex = unity_LightIndices[lightIndex / 4][lightIndex % 4];

to

float4 temp = unity_LightIndices[lightIndex / 4];
int perObjectLightIndex = temp[lightIndex % 4];

The Key is use float4 for temp, not half4

2 Likes

Thanks bro, that works!!! It’s been bothering me for a long time.

Add more information for guys might trapped into this bug:

  1. Go to “RealtimeLights.hlsl” file
  2. find “GetPerObjectLightIndex(uint index)” function
  3. in [#elif !defined(SHADER_API_GLES)] branch
  4. change the code follow Jack’s post.
1 Like

BTW. Why change half4 to float4 will works? It seems the precision is enough to get light index…

Fury_Sven_ You are super persistent.
super thank you. your persistence has helped me a lot.

but i can’t modify RealtimeLights.hlsl.
if i will fix it, it will return to original state soon

i got it. it’s package auto make file. so i can’t modify this file
so i will upgrade unity version. thank you

Hi, just copy the whole [com.unity.render-pipelines.universal@12.xx] folder from Unity Library PackageCache to your project local package folder (i.e. [YourProject/Packages] which is in the same level with [Assets] folder). No need to upgrade unity version. :slight_smile:

=============== UPDATE ====================
URP 12.1.4 Seems fixed this issure. @programmer119 @peterbay @jacketjlzUnity

Fury_Sven_ thank you for your help.
i tried add to library/pachage other version render-pipelines.universal@12.xx. but just deleted on unity import package time. and have modifed library/packagemanager, but not worked. i think way to use other version render-pipelines.universal@12.xx is unity upgrade

Yes, upgrade Unity version is the best way to use URP 12.4.
In my case, it’s hard to let all my colleagues to upgrade Unity version. Therefore, I copied [com.unity.render-pipelines.core], [com.unity.render-pipelines.universal], [com.unity.shadergraph] from library package cache into project’s package folder, make them as local package. It works fine.