Announcement

Collapse
No announcement yet.

How To Reverse Light Vector

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How To Reverse Light Vector

    Hello,

    I have the need to reverse a light vector.

    I have a scope on my weapon that when aimed, I want a streaking texture to appear when you look at the sun. I'm using a dot product between my normal map and a light vector and it works perfectly except that it's showing up only when I look directly away from the light. I need to flip it so that it happens when I look at the light instead.

    I tried a thousand combinations of appends, masks, one-minus, subtracts and multiply by -1 in every channel and it all seems to affect the preview on a sphere but doesn't change it in the game. I even tried 3 copies of the light vector, each masked to R, then G, then B and then appended them all together and again, multiplying any of those channels by -1 definitely seems to change the preview on the sphere, but in game it just appears to be making the effect stronger or weaker, not actually changing what angle I have to look at for it to show up. When looking directly at the sun, it's black.

    Light vector seems to be the only options since in 1p view, the scope is locked to the camera so reflection vectors and camera vectors never change when I'm mousing around.

    Again, the desired effect is working flawlessly, just at 180 from the light. I need to flip the yaw and pitch on that vector.

    Any clues? This is a little advanced for me.

    Here's a video of the issue.


    #2
    A vector in the reverse direction is a vector with all components facing in the opposite direction. Before doing your dot-product, normalise it and multiply it by -1.

    Comment


      #3
      Thanks Ambershee, that makes a lot of sense and actually much cleaner than what I attempted. Unfortunately this isn't solving the problem.

      See on all my attempts to correct this, and using your suggestion, everything is working correctly in the material preview window. The light actually reverses direction with all of these changes. It leads me to believe that it's solved. However, when I get into game, it makes no changes to what's happening on the scope at all. I think this is an issue with the fact that it's an overlay mesh that's attached to the camera. Perhaps this object isn't actually officially "in" the world and isn't updating its angles based on light or reflection vectors. I think I'm going to just ditch the concept and keep the scope clean.

      Comment


        #4
        I don't have a specific solution but just a thought. You mention that you have a mesh attached to the camera as an overlay to achieve the effect. Is it maybe very close?.. too close?.. maybe it's getting clipped?.

        Comment


          #5
          You can actually see what I'm talking about in the video. The 1st person weapon is attached and placed in the foreground layer. It's close, but it's not clipping.

          Comment


            #6
            It should still accept lighting. I suspect a light environment may perhaps be causing unexpected results.

            Comment


              #7
              Your shader is fine (although you could just multiply by a scalar -1, and you'll want to saturate the result of the dot product).

              I'm guessing that your objects are still casting shadows. The self-shadowing would prevent any light from being reflected on the new "front" side of your objects with the light direction reversed.

              Comment


                #8
                ^ That sounds very plausible.

                Comment

                Working...
                X