LWRP questions

Hi,

I am trying to understand better how LWRP works, especially the stuff that I shouldn’t care about because it’s supposed to work as it is (but it doesn’t in my case).

some clarification first:

#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS

in the documentation I read what _ is about, but the documentation actually specify that it should be __. Is it the same thing?

When is _ADDITIONAL_LIGHTS chose over _ADDITIONAL_LIGHTS_VERTEX ?

And now my question: I can’t understand how to read the ambient light (the new one with the three terms). My shaders do not take ambient light in consideration and I can’t figure out why.

I am using LightweightFragmentPBR, forward rendering, NO GI, NO LM, NO probles, only one directional light atm.

There are 3 variants in this line the _ represents off, or no additional lights, _ADDITIONAL_LIGHTS_VERTEX is if you have the pipeline asset set to have additional lights but their type is vertex lit only, and finally _ADDITIONAL_LIGHTS if for per pixel additional lights.

Take a look here for some of the GI lighting functions, depending if you want to sample it per vertex or per pixel will decide which of the functions you choose.

If you still have issues, feel free to post up your shader code here that is giving you trouble if you are still stuck.

I am trying to figure it out with the minimum amount of process involved, so no GI, no lightmaps, no probes and no mixed lighting. At the moment what I can’t understand is how I get the ambient light as input in a shader (or even where it’s processed in your code).

The ambient light is the code I linked above, ambient light in Unity(built in/LWRP/URP/HDRP) is provided by SphericalHarmonics(SH) probes, even when you are not using Light Probes in the scene, there is a single SH probe generated based off the lighting settings window, this is what you need to read to get the ambient lighting.

1 Like

ok thanks, I couldn’t have figured it out on my own (now I have to understand why it doesn’t work)

1 Like

found the mistake, I commented out too many lines (and in this case
OUTPUT_SH(lwWNormal, o.lightmapUVOrVertexSH.xyz):wink:

1 Like

Do you recognise this code and in case tell me what it is (wondering why there is a loop)?

loop
  ige r2.y, r1.w, r0.x
  breakc_nz r2.y
  itof r2.y, r1.w
  lt r2.w, r2.y, l(2.000000)
  movc r7.xy, r2.wwww, cb1[11].xyxx, cb1[11].zwzz
  add r3.w, r2.y, l(-2.000000)
  movc r2.y, r2.w, r2.y, r3.w
  lt r2.y, r2.y, l(1.000000)
  movc r2.y, r2.y, r7.x, r7.y
  ftoi r2.y, r2.y
  add r7.xyz, -r3.xyzx, cb0[r2.y + 10].xyzx
  dp3 r2.w, r7.xyzx, r7.xyzx
  max r2.w, r2.w, l(0.000061)
  rsq r3.w, r2.w
  mul r7.xyz, r3.wwww, r7.xyzx
  rcp r3.w, r2.w
  mul r2.w, r2.w, cb0[r2.y + 42].x
  mad r2.w, -r2.w, r2.w, l(1.000000)
  max r2.w, r2.w, l(0.000000)
  mul r2.w, r2.w, r2.w
  mul r2.w, r2.w, r3.w
  dp3 r3.w, cb0[r2.y + 58].xyzx, r7.xyzx
  mad_sat r3.w, r3.w, cb0[r2.y + 42].z, cb0[r2.y + 42].w
  mul r3.w, r3.w, r3.w
  mul r2.w, r2.w, r3.w
  mul r8.xyz, r2.wwww, cb0[r2.y + 26].xyzx
  dp3_sat r2.y, r0.yzwy, r7.xyzx
  mad r4.xyz, r8.xyzx, r2.yyyy, r4.xyzx
  iadd r1.w, r1.w, l(1)
endloop

This is the raw compiled code so a bit hard to tell what it is off the bat, but my guess is that it might be the additional light loop.

1 Like