Light Function material and Cubemaps

Hello,

I’m trying to get fake shadows from a lamp using a material light function. I’m already using simple light functions with spotlights and 2D textures, but I would like to push that more, using point lights and cubemaps.

I baked a cubemap in Max around a lamp prop, and I’m trying to make it work with a light function material, but I’m stuck at that point. Here is what I have:

I’ve only found one thread about this topic [here][2], but it didn’t really helped me. I’ve tried 2 types of cubemaps, DDS generated with ATI Cubemapgen and HDR spherical. So far the light function seems to be totally ignored by my light actor. Other light material function we have in bank are working fine, but they all use 2D textures.

It seems the best way is to use several Spots with LightFunctions. In this discussion, you will surely find the answer to your question [UE4] Learning Lighting Art - Page 2 — polycount .

Hey! I have found a workaround in the end, thanks :slight_smile: Turns out the LightFunction projection is already using a spherical map out of the box, so nothing was required shader-wise, I just had to find the correct coordinate when baking a shadow and that was it!

Can you show an example? I’m trying to get a similar effect. In UE3 I used the Light Vector for coordinates but it doesn’t seem to work correctly in UE4. Thanks!

Hi,

I don’t have an example that I can show because of NDAs. But it’s quite simple, I have found this documentation for Unity : https://docs.unity3d.com/uploads/ExpertGuides/Create_High-Quality_Light_Fixtures_in_Unity.pdf

I took a lot of inspiration from it, and it’s actually easier to do in Unreal, since you don’t need to render on 6 textures to create a cubemap. You only need to render your shadows on a sphere from a 360 camera.

Here is how I would do it:

• In your 3D software, place your lamp mesh and whatever lights you need inside it.

• Create a sphere around your lamp.

• Set your lamp mesh to be invisible to cameras (still needs to cast shadows, easily done with VRay or Arnold properties).

• Create a 360 camera at the center of your lamp mesh.

• Hit render, use a square resolution.

• Use that render as a texture in a light function material. Might require some tweaks in Photoshop to look the way you expect.

• Done! You may need to adjust the axis of your texture, since UE will not necessarily project it in the way you expect. To edit that quickly I simply created flip X & flip Y parameters in my master material, so I can tweak shadow projection easily in material instances.

Thanks so much for your fast & detailed reply!
Great documentation on it as well. I feel inspired by the caustics part.

If I’m understanding correctly then you aren’t using a cubemap in UE4? Even for point lights you use a normal texture?

I had a cube map already, and it kinda works if I hook a light vector into the coordinates but tends to flicker off weirdly and apparently “Light Vector” coordinates are depreciated. I was hoping to find out what coordinates I should plugin to use a cube map. I might change to a spherical map though if that seems to work for you?

I’m not using a cubemap indeed, just the raw texture in a point light. I think the point light already has a built-in spherical projection for light functions. Just like you I started with cubemaps & complicated maths for UVs, but the solution was really that simple. I have not tried with spots though, IES are doing a good enough job for me, but I think they would totally work with light functions too, the projection is probably a simple plane at that point. And I tried caustics in one of my tests, it works beautifully :slight_smile: The only thing that refrains me from using that everywhere is that UE’s documentation specifies that light functions are heavy rendering-wise. I have not been able to profile them in a stress test yet, it’s something I look forward to do.

Little tip, you might need to do your mipmaps by hand. You don’t need a big resolution for your light function textures, but they tend to look wonky or even totally disappear in the distance when higher mip levels kick in. I would recommend to disable mipmaps to begin with.