Announcement

Collapse
No announcement yet.

[SOLVED]Object Screen Position Within Material Editor

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

    [SOLVED]Object Screen Position Within Material Editor

    Does anyone know if there is some easy way to obtain an object's screen position from within the material editor(without using a blueprint to MPC to solve)? Currently, the transform position node only transforms to world space.

    For example, if the object were in the top left, it's whole color would be 0,0
    If it were in the middle, it would be 0.5,0.5
    Bottom right, 1,1
    And so on...

    Right now, I've been trying to use all kinds of trig to solve it by taking the object position, the camera position, camera forward vector, FOV, etc, to triangulate it all, but it's becoming a mess and I'm apparently a bit rusty on it all.

    #2
    TranslatedWorldToClip will get you there.

    Comment


      #3
      why don't your transform from World Position to View Space or Camera Space?

      Comment


        #4
        Originally posted by Raildex_ View Post
        why don't your transform from World Position to View Space or Camera Space?
        I don't want a gradient. I want an exact value that can be used with other operations that I need(it's sort of a "tracking" effect).
        Originally posted by Deathrey View Post
        TranslatedWorldToClip will get you there.
        I've tried it a few different ways, but I'm not managing to get it to work. Do you have an example of it working?

        Comment


          #5
          You could try something like this:

          Code:
          float4 Clip = mul(float4(In.xyz,1),View.WorldToClip);
          float2 ClipXY = Clip.xy / Clip.a;
          float2 ScreenXY = (ClipXY * 0.5 + 0.5);
          return saturate(float2(ScreenXY.x, 1 - ScreenXY.y));

          Comment


            #6
            Originally posted by stororokw View Post
            You could try something like this:

            Code:
            float4 Clip = mul(float4(In.xyz,1),View.WorldToClip);
            float2 ClipXY = Clip.xy / Clip.a;
            float2 ScreenXY = (ClipXY * 0.5 + 0.5);
            return saturate(float2(ScreenXY.x, 1 - ScreenXY.y));
            Turned out to be something ridiculously simple: When biasing, I had a dyslexia moment where I was adding the 0.5 before multiplying by 0.5. It was giving me weird issues when zooming and that would probably explain why. stororokw, I ended up coming up with an almost identical solution (minus the goofing on biasing and I did some of it with nodes). I caught my mistake looking at your code and resolved it.

            Thanks for the help guys. Marking this one as solved!
            Last edited by IronicParadox; 07-12-2018, 09:09 PM.

            Comment

            Working...
            X