Search Unity

Question Adding result of subshader A + B sometimes differs from B + A

Discussion in 'Shader Graph' started by Bovine, Jul 31, 2022.

  1. Bovine

    Bovine

    Joined:
    Oct 13, 2010
    Posts:
    195
    Hi There

    So I have a shader that picks which light to use and then calls a subshader to get back the light's colour and effectively the brightness, baked into that colour value.

    During the course of rendering a plane it will pick light A and light B and add them for the the resulting light calculation. However, at a point across the plane it will pick light B and light A and the at the point at which the differing order occurs I can get a shimmering artefact that I don't understand.

    Yes, it could be something else, but this is my best understanding of what is going on, looking at the data being produced and consumed and using some debug nodes in the shader.

    See this image here, scene left, game right.

    upload_2022-7-31_9-1-9.png

    The artefacts do shimmer depending on the view position, i.e. while zooming/rotating, but they represent a place across the plane where I am adding result of lighting A to result of lighting B but in some cases it will be A + B and in others B + A.

    I've checked the order and inputs a million times and it does not seem to matter. It seems that I occasionally get a different result of getting the light value for A, then B and adding them as when I get the light value for B then A and adding them :/ I have one other test I may try somehow. :D

    Should I expect these results to be stables regardless of the order? I was generally taught that A + B = B + A :D

    Any hep would be appreciated.

    Thanks
    Bovine
     
  2. Bovine

    Bovine

    Joined:
    Oct 13, 2010
    Posts:
    195
    SOLVED: so it was mip-mapping. In my lighting sub shader I sample a small lighting texture, but the texture was set to still include mip-maps. This meant I was not necessarily getting the same pixel depending on the view. Given the texture was like 16 pixels or so across, this seemed a bit excessive :D