Download

Question about default lit/ unlit perfomance issue

Hi, I’m working on a GearVR game. In my scene the drawcalls don’t go over ~30, the triangle count is bellow 100k in any view (using multi view so it’s not 2x100k)
The problem is the framerate, it goes from 60 to 25 fps (around 30 most of the time).
The scene is made of lowpoly fbx meshes, all using the same default lit material, fully rough with only a single texture connected to the base color node. Because I need a very basic night/day cycle, the only light is a movable sunlight with shadows unchecked (I only need the dynamic shading). No postprocess, HDR off, etc.

So I tryied using “unlit” shading on this material and the framerate never goes bellow 60fps, which is good but makes everything looks flat and totaly break all the 3D effect and the possibility of night/day cycle.

Is there a compromise between this two options? Like using default lit without unnecessary fancy effects (My render style is lowpoly/cartoon) or unlit with fake shading calculated on sunlight intensity/rotation giving some depth to the scene?

Maybe you should consider forward shading.

I’m not sure that forward shading is supported on mobile.

On mobile default is forward shading. At Project settings in Rendering settings you can disable all features that you don’t need. Disable dynamic shadows, static shadows, dynamic points lights, vertex fog etc.

Then I don’t understand your first comment.

I have already disabled all shadows, I don’t have any pointlight, only one directionnal light, no fog, no post process, etc. I tryied disabling everything in the project settings but because they are disabled in my level, it doesn’t give me any framerate increase.
I’m bellow the Epic and Oculus recommandations about drawcalls/triangles and I don’t get 60 fps until I change my only one material from default lit to unlit so it looks like I have no choice and chose unlit but I need ideas to make it look less flat.
I can add a variable in my material to modify the emissive intensity in a night/day blueprint but is there something I can do to fake “self shadows”?

If you just have that one material it’s quite easy to make diffuse only directional light at material level.
Diffuse Light is simply:


 clamp(dot(directionToLight, worldNormal),0.0, 1.0)

Then you can multiply that with texture color.

I’m sorry, I don’t understand your code, should I copy this in my material blueprint?

Ok sorry, it works but the “fake self shadows” are pitch black. Is there some modification I can make to change the color of those black faces? Thanks for your help ! :slight_smile:

Famous half lambert from half life.
https://developer.valvesoftware.com/wiki/Half_Lambert



float lambert = dot(directionToLight, worldNormal) * 0.5 + 0.5;
lambert *= lambert;


You can also use hemisphere model for indirect portion. Just add this for sun light.



float3 indirectLight = lerp(groundColor, skyColor, (worldNormal.z * 0.5 + 0.5));


Look like i’m doing something wrong:
“Error [SM5] Material.usf(1282,14-20): error X3000: syntax error: unexpected token ‘lambert’”

Lambert is just local variable. You need to use it for sometbhing.

Oh ok.
Well, all your materials works and are very nice but unfortunatly it looks like it’s as heavy as using the “default lit” with a movable direction light without shadows. It gives me the same framerate.
I think that the problem is those calculations are done for every triangle rendered and that Epic and Oculus are too optimist about GearVR recommandations. They recommand to stay bellow 100k triangles per view but 90k (2x45k) with something else than full static precomputed light doesn’t look like possible on Galaxy s6 edge.

Hello Haoris.
I run in the same problem and just found a solution (for me).
I use the cell shading material (not the post process one) propose by AzzaMat here : https://forums.unrealengine.com/showthread.php?111096-Cell-Shading-in-Unreal&p=553333&viewfull=1#post553333

I make an unlit material and use only the emissive channel.
When he create the light “ramp” texture in photoshop, he choose to have black and white to obtain his cell shading effect.
But if you use a gradient, you can have fluid transition in your shadowing.

Personnaly, I upgrade his Template with a Fresnel node and some other stuff… But if you understand what he does in his cell shaded material, you can obtain a pretty good result with no light at all in your scene (you just need a vector for the direction of the simulated light ^^). I jump from 5 fps to 30 on my basic android phone with this trick :slight_smile:

Of course, there will be no shadow “projection” at all.

Thanks for your answer but the materials form Kalle-H are more simple and gives me low framerate. Oculus doesn’t accept apps running at less than constant 60fps so 30fps is far from enough :confused:

The 30 fps I speak of concern only my project, playing on a very low grade android phone, don’t take it as a precise measure of performance :slight_smile:
I don’t think we can even extrapolate this result as a x6 frame rate… It’s depending on so much other parameters.

But if you have a good solution, I’m happy for you ^^.

Edit : I read the Kalle-H solution carefully and laugh because my solution is just a practical application of “clamp(dot(directionToLight, worldNormal),0.0, 1.0)”. Kalle-H and I proposed almost the same thing ^^. By using the parameters collection to control your “directionToLight” vector and with a “multiply” bloc or two, you can add light intensity and light color to manage your day/night cycle.
My base material is somethibg like this :


clamp((dot(directionToLight, worldNormal)* lightStrength * lightColor),0.0, 1.0) 

With the 3 parameters (directionToLight, lightStrength, lightColor) in a parametersCollection. By changing them in the collection, you affect every instance of this material.

PS : I think you wanna say High framerate :wink:

You could try to move light calculation to vertex shader and send light amount using custom texture coordinate. This is bit cheaper.

Sorry, I was talking about my actual 30 fps like I mentionned in my first post :slight_smile:

No, I actualy have LOW framerate even with Kalle-H solution. Default lit = 30fps, Unlit with light calculation = 30 fps, Unlit with a texture directly connected to the emissive color pin = 60 fps

I’m really bad with materials, would you mind posting a screenshot of this please?
Thanks for you help