Announcement

Collapse
No announcement yet.

Front Facing Alpha Only?

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

    Front Facing Alpha Only?

    Hey Guys!

    While waiting for 4.5.0 to be officially released I had been spending some time in Unity.
    And I had been learning CG script. (To a lesser degree)

    One of things I found you could do is write 2 separate passes.
    One that calculated with full alpha, and then the visible pass which has fresnel alpha, etc.

    This meant that the first front faces would cull all other front and back faces of the same object.
    Much like how a ghost would appear.

    I can't for the life of me figure out how to do it.

    I have an image that gives the idea of what I'm after.


    If anyone could help it would be massively appreciated!

    Thanks guys!

    -Peace
    Attached Files
    For all and any info on our game in progress: SleepStep: Nightfall
    Go to our site: GearDrop Games


    Check out my tutorials/code snippets!

    #2
    Have you tried disabling Two-sided material rendering for your translucent material? If you do, UE should render nothing for backfaces, so the only visible elements of the material would be the outside (i.e. translucency should not let you see through the outside of the left half of the mesh to the inside of the right half, since the inside of the right half isn't rendered at all.

    Comment


      #3
      @Loken01 - Have a look at TheBeej's answer to my similar issue here: https://forums.unrealengine.com/showthread.php?45945-Translucent-Water-Material-Displacement-Banding-Issue

      My issue was an ocean, but using the same method you should be able to get your setup working as well.
      Last edited by DotCam; 10-20-2014, 11:12 AM. Reason: Replaced link, was highlighting words on the page...
      Free Community Ocean & Sky Project || Join us on Discord! || Trello Roadmap

      Comment


        #4
        Hey Guys!

        RhythmScript:
        Everything you saw in the top image is actually all front faces. Two-sided is off.
        Thanks for the reply though!

        DotCam:
        That looks like a perfect answer as to what I'm trying to achieve, however in terms of optimisation, I'm a bit worried.
        I was going to be using this on a skeletal mesh, so would I have to duplicate the entire moving mesh component?
        (Would like to avoid basically doubling the vert and bone count for a simple Ghoul/Ghost)

        Thanks so much!

        -Peace
        For all and any info on our game in progress: SleepStep: Nightfall
        Go to our site: GearDrop Games


        Check out my tutorials/code snippets!

        Comment


          #5
          Originally posted by Loken01 View Post
          [SIZE=3][COLOR=#0000cd]Hey Guys!
          DotCam:
          That looks like a perfect answer as to what I'm trying to achieve, however in terms of optimisation, I'm a bit worried.
          I was going to be using this on a skeletal mesh, so would I have to duplicate the entire moving mesh component?
          (Would like to avoid basically doubling the vert and bone count for a simple Ghoul/Ghost)

          -Peace
          Well You've come accross a fundamental problem in realtime rendering, especially in deferred renderers such as UE4.
          If you have nested or partially overlapping meshes you can try and set the transparency drawing order manually to resolve the issue, but in a skeletal mesh where you can probably see all of its sides while it moves you're gonna have to use a dynamic method such as the one alreday linked by DotCam.
          True OIT (order independent transparency) is not implemented right now in UE4, and as every solution out there has drawbacks of some sorts, i think it will take some time until the epic guys figure out how to do it in an elegant way.
          In the meantime you're gonna have to use hacks.

          Comment


            #6
            Take a look at this to have a clearer understanding of the issue:
            http://en.wikipedia.org/wiki/Order-i...t_transparency

            Comment


              #7
              Hey Max!

              Thanks so much for the info!
              It seems like I'm going to have to create my own implementation for this then.

              Would there be any way to create my own shader for Unreal?

              The method I'm used to is like so:
              1. Draw to the z/depth-Buffer (as if it was Opaque), but don't draw the mesh,
              2. then draw the mesh with required alpha,
              3. thus avoiding ordering issues, and technically... (I think) only drawing once.


              I'm not even sure if this is possible, however I don't yet know how Unreal handles shaders.

              For instance:
              1. If I made one, would it be used in every material?
              2. If not, how would I tell that one material to use a specific shader?
              3. Can they have more than one pass?


              Sorry for the bombardment of questions!
              I'm just really eager to learn! (However delving into PBR sounds scary)

              Thanks!

              -Peace
              For all and any info on our game in progress: SleepStep: Nightfall
              Go to our site: GearDrop Games


              Check out my tutorials/code snippets!

              Comment


                #8
                Originally posted by Loken01 View Post
                Hey Max!

                Thanks so much for the info!
                It seems like I'm going to have to create my own implementation for this then.

                Would there be any way to create my own shader for Unreal?

                The method I'm used to is like so:
                1. Draw to the z/depth-Buffer (as if it was Opaque), but don't draw the mesh,
                2. then draw the mesh with required alpha,
                3. thus avoiding ordering issues, and technically... (I think) only drawing once.


                I'm not even sure if this is possible, however I don't yet know how Unreal handles shaders.
                To get this to work with using the link I added earlier, you will have to create a blueprint with 2 of the same skel meshes with both at the same location (they will do this by default when added), for the first one in the list apply your material as you have been, and for the second one, you will be applying a material that has no inputs (just a new blank opaque material, will default to totally black).

                Now in the blueprint, with the second mesh selected, go down into the properties and change the settings to look like this:


                - Turn ON "Render Custom Depth"
                - Turn OFF "Render in Main Pass"

                Now the mesh and material applied to it will not be rendered, but instead input data to the depth buffer.

                For your original material, you must now add the nodes shown here, attach your original opacity calculations and plug it into the Opacity slot:




                And that's it, it should now work properly. Since it is a blueprint, you can simply drag and drop these into your scene. I would keep a copy of your original material and do some performance testing, for example place 10 of them in a scene, profile it, delete them, then place 10 of the blueprints into the scene and profile again. I am not sure how big of an impact there will be, but since the mesh is not actually rendered, it shouldn't be too much (performance difference on mine was very minimal, maybe 1-2fps for a 2km square ocean plane with approx 40,000 tri's).

                For instance:
                1. If I made one, would it be used in every material?
                Yes, every material that has this issue would need to be modified in the same way unfortunately.

                Hope that helps!
                Attached Files
                Last edited by DotCam; 10-20-2014, 11:39 AM.
                Free Community Ocean & Sky Project || Join us on Discord! || Trello Roadmap

                Comment


                  #9
                  Originally posted by Loken01 View Post
                  The method I'm used to is like so:
                  1. Draw to the z/depth-Buffer (as if it was Opaque), but don't draw the mesh,
                  2. then draw the mesh with required alpha,
                  3. thus avoiding ordering issues, and technically... (I think) only drawing once.
                  A depth prepass for an object is still drawing twice, but usually the whole object is drawn with the minimal amount of texture/material features as possible to reduce the load in the first pass as much as possible. So, the object you're using to write depth should have a really simple material (you wont see it anyway) and then you only have the cost of rendering the geometry, not the textures. In your case it looks to be pretty low-poly, so it shouldn't have a noticeable impact on performance.

                  Comment

                  Working...
                  X