Announcement

Collapse
No announcement yet.

Custom Lit Material

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

    Custom Lit Material

    I am trying to write a material that uses custom lighting in the Unreal Material Editor. For now I am just trying to learn how custom lighting works by replicating the phong lighting method.

    I am not sure how to get access to the surface normal information of whatever the material is supposed to be shading via a material expression, however. Furthermore, while there is a material expression for LightVector I am not sure if it is what i need for the lighting calc or if it is something else.

    Has anyone else messed around with custom lighting who could help me out?

    #2
    for the normals, you either use a TextureSample expression with the normal map assigned to it or a Constant3Vector expression with R=0.0, G=0.0, and B=1.0. Which to use depends on whether you are using a normal map or not.

    The LightVector should be the direction from the current pixel being calculated to the current light being calculated.

    Comment


      #3
      I am still having trouble with the LightVector material Expression. I created a material that I set to custom lit, and I just plugged the LightVector directly into the custom lighting node on it. Nothing else was hooked up. I expected to see a visual representation of the light vector applied painted on the surface, and the in-editor lighting approximation showed me just that:



      This is exactly what I expected to see: the various colors map to the light vector perfectly: redish where the vector is positive x, greenish where it is positive y, yellowish where it is both, and blackish where they are both negative. So this appeared to work fine. However, when I built the lighting (changing nothing else), this is what is saw:



      This looks totally messed up, the colors no longer map to the LightVector; instead they appear random. I am curious why this is and how I could fix it. This is making all my custom lit materials look fine with in-editor lighting, but completely bizarre in game.

      Comment


        #4
        My guess is that it has to do with light being generalized as coming from three directions (used for specularity) on lightmapped surfaces. You do not get a true specular reflection when using lightmaps. An approximation is used based on light coming from three general directions. It appears this same effect affecting the custom lighting model is what you are seeing here.

        I reserve the right to be wrong about all of this.

        Comment


          #5
          Interesting. I am trying to write a toon-shader, and my first thought was to do it as a custom lighting solution. However, if i can't get accurate light vectors i am not sure how i am going to deiced on the shading boundaries accurately. Maybe i should try and use phong shading for this? Or un-shaded? Any suggestions?

          Comment


            #6
            It should work fine if you set the surfaces and lights not to force lightmaps. The tradeoff is using dynamic lighting for everything would cause a performance hit.

            I've made a pretty complex customizable toon shader using custom lighting and I noticed the same thing you are running into. The second you use lightmapped surfaces, the effect breaks down somewhat.

            Comment


              #7
              I see. I suppose it is best to just use cartoon-y textures on anything that is going to be lightmapped, and reserve dynamic toon-shading for anything that is dynamically lit (like characters.) I was hoping that the light building process would bake my toon shading into the BSP and static meshes for me, but I guess I can do it manually.

              Comment

              Working...
              X