Announcement

Collapse
No announcement yet.

Moving light sources on mobile?

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

    Moving light sources on mobile?

    I've had a look at this: https://docs.unrealengine.com/latest...ing/index.html

    I'm thinking about doing a project involving simple indoor levels with the player carrying a torch (in 1st person), however it says that only Stationary and Static lighting is supported on mobile platforms.

    Is this a strict limitation in that a project won't build to Android at all with moving light sources, or will it build but be missing any moving lights? Or is it more of a 'soft-limitation' in that it may or may not work depending on the circumstances but it's not officially supported?

    If it is a strict limitation, are there any plans to support moving light sources on mobile at all in the near future?

    #2
    Mobile uses a different forward rendered pipeline so it is a hard limitation.

    The UE4 Trello roadmap has both dynamic lighting and shadows for mobile, but they are still in the "Wishlist/Backlog" category so there is no telling when they might be included in the engine.

    However, it doesn't mean it is entirely impossible to add your own torch light to a scene. You could use a Custom UV node (so it is calculated per vertex), and provide the location of your torch to your material . Then calculate the distance and add emissive light to the material. I haven't tried anything similar so I am not sure if that specifically would work, but it should be possible to get it working somehow. Worst-case scenario would be re-writing and customizing some of the mobile shaders assuming you have someone with the skills to do it.

    Comment


      #3
      Thanks for the info!

      That's a shame, hopefully it'll get implemented sooner rather than later though.

      Your alternative solution sounds interesting, but my plan with this idea was just going to be a quick side-project to spend just a few hours reimplementing something I'd made before, so it sounds a little complex for what I was hoping to do!

      Comment


        #4
        The basic material isn't too complicated to set up. Here's a quick example I put together:
        Click image for larger version

Name:	LightMaterial.png
Views:	1
Size:	120.2 KB
ID:	1053287

        You have a light position, light radius, and a light color as parameters. This just adds light based on distance--you could do better if you take into account the light angle as well, but this was just a quick proof of concept. This is being done in a custom UV so it is relatively cheap as the computer does it per-vertex and not per-pixel. You would need to have enough triangles in your geometry to get a good result. You might be able to use a per-pixel lighting calculations (i.e specular or normal mapping), but that would start getting expensive because this is all in addition to the standard UE4 material.

        Here's a screenshot of what it looks like in the mobile preview:
        Click image for larger version

Name:	LightScreenshot.png
Views:	1
Size:	355.2 KB
ID:	1053289

        Hopefully it will work the same on actual devices.

        Comment


          #5
          Awesome stuff there CaptainScience, I had thought custom UV was for tiling only!!

          Comment


            #6
            I still had the project open so I decided to add the dot product for the light angle on there as well to make a very simple vertex light. It should be pretty fast as long as your geometry isn't too crazy detailed, but you can see a few interpolation artefacts on the ground.

            Click image for larger version

Name:	VertexLight.jpg
Views:	1
Size:	95.3 KB
ID:	1053302

            Here's the changes I made to the material. Makes it a bit more useful for adding a very simple dynamic light to a mobile scene.

            Click image for larger version

Name:	VertxLightMaterial.jpg
Views:	1
Size:	106.2 KB
ID:	1053303

            Comment


              #7
              Very nice, thanks!

              I'll give it a try when I get back to doing that side-project

              Comment


                #8
                Just as a note to anyone who wants to try something like this: it seems like custom UVs only accept a float2 so the blue component will be cut off. You would need to use a component of one of the other custom UVs to pass through the blue component of the light.

                Or make due with yellow/red/green/monochromatic light.

                Comment


                  #9
                  I've been trying hard with no success to get this working with a texture instead of just a color as shown in the examples above for a mobile unlit texture.

                  Customized UVs do not seem to allow textures so I tried plugging it into the emissive color node however the texture does not show correctly.

                  If I plug the whole lot into the emissive color node it works - at least on the pc and mobile preview - on the android device the 'light radius effect' does not work

                  Any one able to get the above 'torch' effect to work with textures rather than just colors or at least can give hint were I'm going wrong?

                  Many thanks in advance!

                  Click image for larger version

Name:	uv_lighting_material_with_texture.JPG
Views:	1
Size:	162.7 KB
ID:	1064471
                  Headgear - VR/AR solutions

                  Mobile VR Game: We Come In Peace... Oculus GearVR | Google Play Daydream | Pico Goblin

                  Comment


                    #10
                    Your value coming through the customized UV isn't a UV at all--it's really an intensity value of your light--so you don't want to use it directly to sample from a texture. You want to use your regular object UVs to get the texture, and then multiply that by the value in the custom UV.

                    If your object doesn't have UVs, you can always do some type of UV projection (planar is simple: just use two components of your world position). It might be expensive per-pixel if you wanted to try a more complicated projection (like a spherical projection centred on the eye of your character) so you could store that in a second set of custom UVs and it will also be calculated at each vertex Though that will always introduce some interpolation artefacts.

                    Comment


                      #11
                      Hi CaptainScience thanks for the reply!

                      Unfortunately I'm still a bit of a noob with the material editor - so when you say:

                      Originally posted by CaptainScience View Post
                      You want to use your regular object UVs to get the texture, and then multiply that by the value in the custom UV.
                      How exactly do you do that?

                      I'm just using the default floor object from the starter kit so I assume the object has UVs ... would be interested to know how to do that simple planar UV projection as well though if also not complicated to demostrate
                      Headgear - VR/AR solutions

                      Mobile VR Game: We Come In Peace... Oculus GearVR | Google Play Daydream | Pico Goblin

                      Comment


                        #12
                        If you leave the "UVs" input empty, the texture should use the first set of UVs automatically. If the model has UV data, it will be loaded into UV0 automatically. However, if you use custom UVs, and put data into UV0 you will overwrite them. So if you have UV data from your mesh that you want to keep, you need to have extra custom UV slots in your material and don't use the first one or two. Models will frequently use UV0 for their main texture (possibly overlapping) and UV1 for their lightmap (guaranteed to be unique).

                        Here's a quick material I set up with a textured light. The important change is putting the data into UV1, and then multiplying that with the light color and texture to get the final value.
                        Click image for larger version

Name:	TexturedMobileLight.jpg
Views:	1
Size:	214.5 KB
ID:	1064607

                        And here's an example of a planar projection. You just take the world coordinates, scale them to a size that fits your texture, and use any two of them as UVs:
                        Click image for larger version

Name:	PlanarProjection.jpg
Views:	1
Size:	198.1 KB
ID:	1064608

                        Comment


                          #13
                          Many many thanks for these examples CaptainScience!! I think I have a slightly better understanding of UVs now

                          Will apply them to my demo project soon and post here when it's done
                          Headgear - VR/AR solutions

                          Mobile VR Game: We Come In Peace... Oculus GearVR | Google Play Daydream | Pico Goblin

                          Comment


                            #14
                            Thanks for sharing this. For a small performance hit, it works on Android! I tested out having pre-baked static lighting with a point light, and utilizing this vertex shader to provide dynamic lighting to some objects and it works very well for my older device! I'm not sure if there's a better way to modify intensity other than multiplying the final output once more by a constant (works well enough!) and it doesn't seem to light any vertices at all if the object is rather centered on the light source. But that can be avoided with level design...

                            Comment


                              #15
                              Thanks again for your nice material idea CaptainScience - as promised the link to the finished product

                              https://play.google.com/store/apps/d...es.aMazeBall3D

                              Great effect for a maze where I don't want to reveal too much area
                              Headgear - VR/AR solutions

                              Mobile VR Game: We Come In Peace... Oculus GearVR | Google Play Daydream | Pico Goblin

                              Comment

                              Working...
                              X