Announcement

Collapse
No announcement yet.

Transforming vertices into orthographic view space

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

    Transforming vertices into orthographic view space

    Hiya.

    I want to be able to render an object and use world position offset to effectively render it as a 2d orthographic object in 2d screen space.

    I've tried various combinations of transform nodes but the fact that the transform always has to be a world position offset means its pretty much always going to be in projection space. it there a way to have the matrices in a certain way that will render local space directly into the screen without a projection matrix?

    Cheers
    Dan
    Visual Effects Artist, Weta Digital, Wellington New Zealand
    BLOG www.danielelliott.co.uk
    @danielelliott3d https://twitter.com/danielelliott3d
    Unreal Engine and VFX Tutorials https://www.youtube.com/user/DokipenTechTutorials
    2015 Showreel: https://vimeo.com/116917817

    #2
    Here's what I have tried. I plug worldposition into a transform from world to local or from world to camera. then I subtract that result from world position to get the offset and plug that into world position offset. But think I'm missing something. is this possible with the current material capabilities? surely its just a matrix transform to draw into normalized device coordinates? the fact that its an offset though makes me think that its hard to do post projection transform.
    Visual Effects Artist, Weta Digital, Wellington New Zealand
    BLOG www.danielelliott.co.uk
    @danielelliott3d https://twitter.com/danielelliott3d
    Unreal Engine and VFX Tutorials https://www.youtube.com/user/DokipenTechTutorials
    2015 Showreel: https://vimeo.com/116917817

    Comment


      #3
      Think I've found the solution.

      I looked through the FViewUniformShaderParameters available and did the opposite of WorldToClip which is clipToTranslatedWorld.

      Click image for larger version

Name:	UE4Editor_2016-05-29_22-28-20.jpg
Views:	1
Size:	58.9 KB
ID:	1107294

      So now I have the sphere aligned to viewport in an orthographic way. It's streyched to match the viewport whicg I expected. Also moving the sphere in X and Y in the world transforms it vertically and horizontally in the viewport which is what I want. These are going to be parented to the camera so I'll need to add in extra offsets once they get in NDC space and to account for the aspect ratio.

      Click image for larger version

Name:	UE4Editor_2016-05-29_22-36-31.jpg
Views:	1
Size:	18.7 KB
ID:	1107295

      The reasons for all this is to investigate a new way of doing fog of war without having to do the whole sceneCapture2D stuff. I am going to render spheres that are parented to the camera and render them to custom depth. I'll also push them far into the distance using camera vector so that they render behind everything else. I can then use post processing to create the fog of war.

      The post processing stuff works as thats just a world XY UV lookup.

      Click image for larger version

Name:	UE4Editor_2016-05-29_22-40-21.jpg
Views:	1
Size:	35.8 KB
ID:	1107296

      I'll start another thread once I've figured it all out.
      Visual Effects Artist, Weta Digital, Wellington New Zealand
      BLOG www.danielelliott.co.uk
      @danielelliott3d https://twitter.com/danielelliott3d
      Unreal Engine and VFX Tutorials https://www.youtube.com/user/DokipenTechTutorials
      2015 Showreel: https://vimeo.com/116917817

      Comment


        #4
        So the issue I'm facing now is how to counter world space movement of the object. I'd like to have the object rendered in the middle of the viewport and control the horizontal and vertical offsets as well as scale separately. That to me suggests that the object should be in local space. However, the matrix does clip to 'TranslatedWorld' which has PreViewTranslation in it. (https://docs.unrealengine.com/latest...ordinateSpace/)

        Subtracting PreViewTranslation from the position before ClipToTranslated world does weird thing as well as subtracting after. I wish we could just have a Matrix Override Slot and create our own from the View.Params!
        Visual Effects Artist, Weta Digital, Wellington New Zealand
        BLOG www.danielelliott.co.uk
        @danielelliott3d https://twitter.com/danielelliott3d
        Unreal Engine and VFX Tutorials https://www.youtube.com/user/DokipenTechTutorials
        2015 Showreel: https://vimeo.com/116917817

        Comment


          #5
          Now using PrevInvViewProj which pretty much does what I want (some flickering here and there) but the issue is that it is the previous frame's inverse view projection. Is there a way to get the current frame's inverse view projection?
          Visual Effects Artist, Weta Digital, Wellington New Zealand
          BLOG www.danielelliott.co.uk
          @danielelliott3d https://twitter.com/danielelliott3d
          Unreal Engine and VFX Tutorials https://www.youtube.com/user/DokipenTechTutorials
          2015 Showreel: https://vimeo.com/116917817

          Comment


            #6
            Oh man you won't believe this. No one is listening but I don't care, I figured out the weirdest fix. Unreal doesn't expose the current inverse projection matrix directly! I was about to go through and compile the engine to add it to the FViewUniformShaderParameters from SceneRendering.cpp but as I was about to add it I noticed that ClipToPrevClip is provided. Guess what that is?

            Code:
            ViewUniformShaderParameters.ClipToPrevClip = InvViewProj * PrevViewProj;
            Well since we have InvPrevViewProj exposed we can just remult it to get the InvViewProj....

            Code:
            mul(View.ClipToPrevClip,View.PrevInvViewProj);
            So now I can render meshes to the screen orthographically. The normals are messed up but I'm not interested in them as I am rendering to custom depth anyway.

            Hope this can be of use to some people.
            Visual Effects Artist, Weta Digital, Wellington New Zealand
            BLOG www.danielelliott.co.uk
            @danielelliott3d https://twitter.com/danielelliott3d
            Unreal Engine and VFX Tutorials https://www.youtube.com/user/DokipenTechTutorials
            2015 Showreel: https://vimeo.com/116917817

            Comment


              #7
              I find it interesting. This could be THE way of creating a proper fog of war actually o.o .
              Fighting Game Template: PROJECT: Unreal Fighter 2D

              Comment


                #8
                Originally posted by Achilleon View Post
                I find it interesting. This could be THE way of creating a proper fog of war actually o.o .
                Proof of concept. It works.

                This is a sphere mesh rendered into custom depth and read in post process. I can now add as many spheres and with a little bit of extra work, I'll be able to control 2d screen position and scale (have scale kind of working).
                Click image for larger version

Name:	UE4Editor_2016-05-30_23-51-19.jpg
Views:	1
Size:	73.6 KB
ID:	1107397
                Visual Effects Artist, Weta Digital, Wellington New Zealand
                BLOG www.danielelliott.co.uk
                @danielelliott3d https://twitter.com/danielelliott3d
                Unreal Engine and VFX Tutorials https://www.youtube.com/user/DokipenTechTutorials
                2015 Showreel: https://vimeo.com/116917817

                Comment


                  #9
                  This is some really high end stuff that I probably wouldn't understand without a tutorial. Well done! Maybe you would like to share it when its polished! Total respect. ^-^
                  Fighting Game Template: PROJECT: Unreal Fighter 2D

                  Comment


                    #10
                    Ooh here I am using pixel depth offset with a radial gradient to push the pixels as they are written to the depth buffer. When this goes into the Post process, you can use the depth gradient as a falloff. no manual blurs in hlsl. nice and cheap this is!

                    Click image for larger version

Name:	UE4Editor_2016-05-31_00-05-35.jpg
Views:	1
Size:	62.7 KB
ID:	1107398
                    Visual Effects Artist, Weta Digital, Wellington New Zealand
                    BLOG www.danielelliott.co.uk
                    @danielelliott3d https://twitter.com/danielelliott3d
                    Unreal Engine and VFX Tutorials https://www.youtube.com/user/DokipenTechTutorials
                    2015 Showreel: https://vimeo.com/116917817

                    Comment


                      #11
                      Originally posted by dokipen View Post
                      Ooh here I am using pixel depth offset with a radial gradient to push the pixels as they are written to the depth buffer. When this goes into the Post process, you can use the depth gradient as a falloff. no manual blurs in hlsl. nice and cheap this is!

                      [ATTACH=CONFIG]95441[/ATTACH]
                      This is really a marketplace thing to sell. I am sure lots of RTS creators would be interested in this as this is the only thing that is not easy to do. ^_^
                      Fighting Game Template: PROJECT: Unreal Fighter 2D

                      Comment


                        #12
                        Originally posted by Achilleon View Post
                        This is really a marketplace thing to sell. I am sure lots of RTS creators would be interested in this as this is the only thing that is not easy to do. ^_^

                        I'll think about the marketplace but I'd be happy to do a tutorial too.

                        One small issue right now is that there seems to be some motion blur or slight lag on the world position offsets that causes the sphere to wobble a bit when the camera moves. I might have to try the custom compile option to see if that fixes it.
                        Visual Effects Artist, Weta Digital, Wellington New Zealand
                        BLOG www.danielelliott.co.uk
                        @danielelliott3d https://twitter.com/danielelliott3d
                        Unreal Engine and VFX Tutorials https://www.youtube.com/user/DokipenTechTutorials
                        2015 Showreel: https://vimeo.com/116917817

                        Comment


                          #13
                          So the only stumbling block now seems to be that the inverse view projection exposed to the material through the custom node has temporalAA offsets baked in. For this effect to work the raw inverse viewProjection matrix needs to be passed through.

                          I've submitted a pull request with that added in. Was only 2 files and 2 lines modification to pass it through.
                          https://github.com/EpicGames/UnrealEngine/pull/2450

                          I'd be grateful if one of the devs would review it and accept (pretty please)
                          Visual Effects Artist, Weta Digital, Wellington New Zealand
                          BLOG www.danielelliott.co.uk
                          @danielelliott3d https://twitter.com/danielelliott3d
                          Unreal Engine and VFX Tutorials https://www.youtube.com/user/DokipenTechTutorials
                          2015 Showreel: https://vimeo.com/116917817

                          Comment


                            #14
                            Very nice indeed!

                            This is probably a much nicer method than my volume-texture idea. One thing I would comment on, I know so many games that do a great fog-of-war, then they forget to mask out the audio. It becomes a game of echo-location to find the enemy base usually..

                            I assume the data for the fog is stored somewhere, so the CPU can access it? Or is this all GPU side?

                            Comment


                              #15
                              Yeah this is all completely on the gpu. I'll have to mirror the functionality in CPU. I'll get to that when I get to the networking side of things. This way there's no data going back and forth between cpu and gpu though which might be a good thing, although I'll still need to send accross material parameters to control the placement of the sphere by modifying the world position offset.

                              Yeah sound is gonna be fun to get into ( i did music tech at thames valley uni). love sound design.
                              Visual Effects Artist, Weta Digital, Wellington New Zealand
                              BLOG www.danielelliott.co.uk
                              @danielelliott3d https://twitter.com/danielelliott3d
                              Unreal Engine and VFX Tutorials https://www.youtube.com/user/DokipenTechTutorials
                              2015 Showreel: https://vimeo.com/116917817

                              Comment

                              Working...
                              X