Search Unity

Flat Lighting (FL)

Discussion in 'Assets and Asset Store' started by BogdanGochev, Jul 29, 2016.

  1. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    I'm not familiar with this building asset, but as you said anything is possible. Especially for the shadow shaders, as they are a bit more complex.
    I will make some experimental builds as well to test it.
     
  2. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852
    I've spent most of the day investigating this and I've got a little more info on the problem.

    Unity Editor - Windows PC (Unity 5.6.0p4):
    1) When I run Unity Editor with the "-force-opengl" command line, the shadow projector renders correctly (in the Editor).
    2) When I run the Unity Editor normally (DirectX11), the shadow projector always renders inverted (as per my prior screenshots).
    3) When I make Unity use DirectX9 (using this technique), the console displays several errors in the DX9 shader:

    Console Error Line 1.png
    Console Error Line 2.png
    Console Error Line 3.png

    Unity Editor - iMac (Unity 5.6.0p4):
    1) I haven't been able to import the Flat Lighting asset on my iMac. I created an empty project and tried to import the Flat Lighting asset. That was 6+ hours ago. Some of the other shader collections I have purchased on the asset store have a mechanism where you manually unpack, just the shaders you want, after you import the asset to your project. You might want to consider implementing something similar.

    OSX stuck importing asset.png

    Builds (via my PC):
    Windows
    - the shadow does not render
    UWP - the shadow does not render
    WebGL - the shadow does render
    iOS - On a new project, the shadow does render. On the project from yesterday, it does not. I will investigate further.

    Builds (via UCB):
    iOS
    - Failed. I changed some UCB settings and started a new build: Success! My new test project builds with UCB correctly. The UCB log still shows the same problems with the flat lighting shader. But the app launches and renders correctly!
    Android - Success! Renders properly on Samsung Note 4 and Google Tango Tablet. Will try other Android devices soon.
    OSX - Success! Renders properly on my 2009 iMac running OSX Sierra.

    iOS App Built with UCB:
    Built with UCB.png

    Conclusions:
    1) I think there might be a problem with your DX9 and DX11 shaders. I don't know anything about shader programming but I'm happy to help you explore this issue and test some workarounds if you don't have easy access to a PC.
     
    Last edited: May 10, 2017
  3. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    Thank you a lot for the detailed report !!!
    It's very helpful and it actually makes sense, as I mainly develop on OSX I haven't tested the asset on Windows for a while.

    I will do a test on Windows (Dx9 and Dx11) and try to fix it and will let you know what happens. As for DirectX9 from the errors that you posted, shader model 2 only has 32 constant registers and apparently I use quite a lot more. I will check it but probably I will have to make the shaders only shader model 3 compliant, which means that they will not be usable on DirectX9.
    I will probably make another version of the shader just with the basic features that compiles on DirectX9, but will probably have to cut the lights and shadows from that version.

    About the asset import time, it's something that is bugging me for a lot, but some of the shaders have a lot of variants (like 7000+) and the first time Unity compiles them takes a loooot of time. I haven't been able to came up with any solution but I'm very curious about "mechanism where you manually unpack" that you mention. I will definitely investigate on that too as it's one of the top priority things on my list.
     
  4. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852
    Hi @BogdanGochev,

    I just PM'd you an example of a shader asset where you manually unpack selected shaders after import.
     
  5. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
  6. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852
    Hi @BogdanGochev,

    Thank you very much for sending me an updated shader.

    The inverted shadow I was seeing in Unity Editor on my Windows PC is fixed.

    I'm very impressed with how quickly you were able to fix the shader once the issue was identified.

    Flat Lighting Shadow Fixed.png
     
  7. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    Big part of fixing a problem is first identify the issue, and I have to thank you for the detailed report and testing that you have done. That pointed me into the right direction.
    Glad is fixed now and I will continue working on the import times of the asset.
     
    schmosef likes this.
  8. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    852
    @BogdanGochev,

    Great job with the latest update!

    It imports very quickly on my PC and even my ancient iMac (which I gave up on after 24 hours trying to import the previous version).

    Shadows render correctly out of the box on my PC as well.
     
  9. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    Thank you!!!
    Yeah, now the surface shaders are packed so the import times are normal. That was a long standing problem that I'm happy is solved now.
     
    schmosef likes this.
  10. TaeHyeok-Lee

    TaeHyeok-Lee

    Joined:
    Jun 17, 2017
    Posts:
    2
    Hi @BogdanGochev,

    how to local gradient?

    i`m using unity 5.6.1f1.
     

    Attached Files:

  11. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    Hi @TaeHyeok-Lee ,
    Thanks for checking out my asset.
    Not sure that I understand your question. On the left side and right side you have a local gradient applied. in the middle you have a global gradient.
    The local gradient is applied to the local coordinate space of each object (in this case cubes) separately, different for each object.
    The global gradient is applied in the world space of the cubes, meaning that is the same for all.
    These two modes are controlled by the "Space" option.

    Hope that helps, if not, please explain a bit more what you are trying to achieve.
     
  12. TaeHyeok-Lee

    TaeHyeok-Lee

    Joined:
    Jun 17, 2017
    Posts:
    2
    left side is scene viewm and middle side is game view
    pictures are all the same option (local gradient option)
    One Object in game scene, it applies. but multiple object not applied

    I wonder why "scene view(left side)" and "game view(middle side)" are different.

    sorry... My English ability is poor.
     
  13. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    Scene View and Game View should definitely NOT be different.

    I have tried a similar setup that you have in the image but for me it was working fine.
    Screen Shot 2017-06-22 at 12.07.39 AM.png

    Maybe there is something in the setup of your scene or objects that I'm missing.
    I didn't understand that part : "One Object in game scene, it applies. but multiple object not applied"
    If you can, just send me your scene over email and I will have a look at it.
     
  14. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    @TaeHyeok-Lee On thing that could cause the problem that you have is if the objects are marked as "Static". When you run the game the meshes are combined into one object and the shader is applied to the whole object, instead to each cube individually.
    Try removing the "Static" or at least the "Baching Static" to disable the object merge at run time.
     
  15. 2stripe

    2stripe

    Joined:
    Mar 20, 2013
    Posts:
    3
    Hi! Just downloaded your asset and am really excited to start using it.

    After playing with it I see that only the Shadow Projector casts shadows. Is there any way to simulate the shadows cast by a point light? Or shadows that aren't directional?
     
  16. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    Hi 2stripe, thank you for the interest in my asset.

    There are two types of shader families, Flat Lighting and Flat Lighting Surface.
    The Flat Lighting Surface family of shaders do support shadows from different light sources, like point and spot. They use normal Unity light sources.
    In the demo scene there are couple of those examples. Also they are described in the documentation of the asset.
    One important note is that in order to use them you have to unpack them from the "FL" menu. This unpacking can take some time (around 20 minutes) because Unity has to pre-compile all their variants.

    If there is any other question feel free to post it here
     
  17. 2stripe

    2stripe

    Joined:
    Mar 20, 2013
    Posts:
    3
    Thank you for the quick reply and a point in the right direction.

    I found the interaction I wanted in your demo scene and was able to recreate it using FlatLighting/FlatLightingCelSurface. I am only able to get FlatLighting/FlightLightingSurface to to produce a 'gradient lighting'. Is there a way to produce flat lighting with FlightLightingSurface? Or is that only useful for its Light X/Y/Z options?

    FlatLightingCelSurfaceBasic produces a couple of cels (naturally), which isn't what I'd like (I'd want 1 color) but is closer. Is there a way to make that completely flat or am I looking in the wrong place?

    I looked around for documentation but the best I found was this thread. Is that on a website or in the Asset files somewhere? I'm new to Unity (but promise I looked for them).
     
  18. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    You are absolutely correct.
    FlightLightingSurface does produce 'gradient lighting' and it's main purpose is to integrate the flat Light X/Y/Z options with Unity lighting system.
    On the other hand FlatLightingCelSurface does produce more flat lighting similar to what you can achieve with my custom light sources but instead, using Unity light sources.

    You are not looking in the wrong place, the current state of that shader is that you cannot control the number of cels. I do understand you need thought and just made a slight modification to support it.
    Screen Shot 2017-09-10 at 12.02.53 PM.png
    I will include this options in a future update of the asset but if you want to use them now, please send me an email and I will send you a patch :)

    When you import the asset, in the top directory of the asset, there is a PDF file that explains the different parts and different lighting options. If you cannot find it, let me know and I will send you one copy of it.
     
  19. 2stripe

    2stripe

    Joined:
    Mar 20, 2013
    Posts:
    3
    Thank you thank you. Message sent.

    One final thing. My desired behavior is to be able to "combine" lights (like Light Source Blend: Multiple). Would that also be a quick patch or is that not possible when using Unity lights.

    I also plan to extend/modify this shader later on in my production if need be , so this is something I could possibly do if you point in the right direction.

    I must have missed that the first time. See it now, thanks!
     
    Last edited: Sep 10, 2017
  20. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    Hi 2stripe,
    I just send you the patch to your email.

    About what you mention to "combine"/ blend lights (like Light Source Blend: Multiple), it's going to be a tricky with Unity light sources, as we don't have that much control over them.
    What I do for my custom light sources is sort of average the light intensity and color. You can check the exact source in the file Shaders/cginc/FlatLightingSources.cginc , function name : blend_spot_into_point_lights (code is a bit cryptic)

    In any case, for the FlightLightingSurface family of shaders (and that includes FlatLightingCelSurface and the patch that I just send you), they are surface shaders and interact with Unity internal lighting calculations. Here is a good resource to learn more about them : https://docs.unity3d.com/Manual/SL-SurfaceShaders.html
    I created my own lighting model in the file Shaders/cginc/FlatLightingCommonSurface.cginc , function LightingToonRamp

    In any case I will try to research it a bit to see how it can be achieved.
     
  21. tomraegan

    tomraegan

    Joined:
    Mar 28, 2016
    Posts:
    137
    Hi there,

    I'm using a texture and I'm trying to use your shader to create a faceted look on the models using that texture.

    This CelSurfaceBasic achieves the facets, but can I get the texture to show at the same time?

    Thanks
     
  22. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    Hi tomraegan,
    You are right, I just tested it. It seem it's broken. I have a dirty way to fix it, but let me make a good fix and update the version (will release a new update this weekend).
    If you need a fix urgent, send me an email and I will send you back a patch.
     
  23. tomraegan

    tomraegan

    Joined:
    Mar 28, 2016
    Posts:
    137
    Cool. I am happy to wait.

    I appreciate the response.
     
  24. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    I just submitted the update (1.4.5). Should be available in a couple of days on the store, after the Unity team approves it.

    [Edit]
    It was just approved by unity asset store team, so it is available for you to try.
     
    Last edited: Sep 26, 2017
  25. _legolas_

    _legolas_

    Joined:
    Nov 10, 2014
    Posts:
    12
    Hello Bogdan,

    I am testing bake light by using MonuScene. My Unity version is Pro 2017 on macOS. Please check below picture:
    Screen Shot 2017-12-03 at 4.13.30 PM.png
    As you can see in the picture. the selected object doesn't have shadow on it. The same process is working on Cube object. Could you tell me what is the problem?
     
  26. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    Hi _legolas_,

    The baked lightmaps are generated by Unity itself. From what I see the object is marked as static and as such, should have lightmap generated. The other thing, is that the material must have the "Lightmpping" setting enabled and configured correctly in order to take into account the baked lightmaps from Unity.
    From what I see from the screenshot, that material (test-fl), doesn't have the "Lightmpping" setting enabled.

    If you still have problems, can you try selecting a standart unity material for that object, as it should receive lightmap and we can be more confident that is a bug with the shader.
     
  27. _legolas_

    _legolas_

    Joined:
    Nov 10, 2014
    Posts:
    12
    Hi Bogdan,
    Thank you for your response. I have follow your advises such as enable Lightmapping, Select Standard Material. There is no bug with the shader. After few tries in Unity, I found that the model doesn't have UV map.
     
  28. _legolas_

    _legolas_

    Joined:
    Nov 10, 2014
    Posts:
    12
    Hi Bogdan, another issue is when I add by script the prefab which contains the object use flat light to main scene. It lose the light mapping. Do you know about the solution?
     
  29. thestrandedmoose

    thestrandedmoose

    Joined:
    Jul 21, 2015
    Posts:
    70
    Hi- just curious,: will these shaders work in a HTML 5 WebGL build?
     
  30. _legolas_

    _legolas_

    Joined:
    Nov 10, 2014
    Posts:
    12
    Another question, Is Flat Lighting work with DOTween?
     
  31. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
  32. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    I can say that this does not solve the procedural lighting problem, nor does it play well at all with procedural games. It is very cool however, so I do not regret my purchase.
     
  33. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    Hi to all. Sorry I was away for so long.

    Sorry, but I don't think there should be a problem in the way of instantiating the prefab with the shaders. Maybe check your materials and scene setup.

    Part of the shaders does work (the basic flat shading and some other bits) In the history of this chat there is a demo in HTML5 with a showcase of the shaders running n the browser.

    Flat Lighting does work with DOTween in terms that you can animate the materials with it.
    It does NOT have a specific component, so you will have to make one yourself if you need to. But if you are unsure about some animation or effect you can always ask me and I will try my best to help.

    Not sure what procedural games you are referring to. If you provide a bit more context maybe I would be able to help you.
     
    Last edited: Jan 14, 2018
  34. _legolas_

    _legolas_

    Joined:
    Nov 10, 2014
    Posts:
    12
    Dear, Thank you for your advice. I can fix the first issue. Let say, I have two flat lighting materials, I want to change from material one to material two and vice versa. Could I point the way to do that?
     
  35. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    There is a blending component that I made a couple of months ago. It called "MaterialBlender" (you can find it in FlatLighting/Scripts/Behaviours)
    Basically you pass it a list of materials and you set the duration and it will blend or loop between them. There is a demo video of this component here :

    Hope that helps with your problem
     
  36. cleverleal

    cleverleal

    Joined:
    May 29, 2018
    Posts:
    4
    Does the shader supports the Unity Fog ? I would like to have a Y fog and also a Z fog based on camera....
     
  37. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    Hi, the surface shader option of the Flat Lighting does support Unity Fog so you can combine them both without a problem. Just use that variant as any other standard unity shader
     
  38. BigBoiii_Jones

    BigBoiii_Jones

    Joined:
    Aug 3, 2014
    Posts:
    40
    Does this light sprites pretty good? I'm making a old school FPS like DOOM, Wolfenstein, and Duke Nukem as a example and instead of it being pixelated sprites I'm gonna have it be very cartoony and the tone in general will be a cartoon feel. Right now I'm having troubles with sprites blending with environments due to lighting issues. From the looks of it this asset may fix that problem because the shading is very cartoony. However I'm not sure how well this will work with billboarded animated sprites. Also I'm a tad bit concerned with the lack of updates as of recent are future updates still planned?
     
  39. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    Hi, you can use this shaders for materials in sprites and they will be affected by the Flat Lighting light sources. Also you can use the surface shader option of the Flat Lighting, which will be affected by all unity light sources in a cartoony way.

    About the support, this asset is very much actively supported. There is an update coming in the next month or so. But keep in mind that I don't want to make it full of half-made features. My focus is to refine, polish and iterate on the core characteristics of flat lighting.
     
    schmosef likes this.
  40. Jesse_Pixelsmith

    Jesse_Pixelsmith

    Joined:
    Nov 22, 2009
    Posts:
    296
    Hi @BogdanGochev - I just bought your asset. Playing around with it I really like it. I'm confused on something though, is having "UseTexture" on supposed to ignore the light X/Y/Z? As soon as I turn it on, it seems to do so, but while still picking up ambient light.

    I do low poly games - I've traditionally done regular UV textures where the texture is basically a low res, color swatch, but I really like the concept of using Vertex colors, and if there are performance improvements, I might use them for most of my models those seem to work great with this package!

    However, decals and billboards I will actually need to represent with a normal UV texture. Is there a way that both of these methods can work together?
     

    Attached Files:

  41. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    Hi, using texture should ignore all X/Y/Z axis lighting, but it will still interact with the light sources and ambient light. If you just want to have a texture without anything else affecting it you can use one of Unity standard unlit texture shaders.

    I have received other requests for mixing the texture with axis colors, but also having the possibility to ignore the axis colors in some scenarios.
    The more I think about it the more it makes sense, so I will add another option to ignore or use the x/y/z lighting with textures.
    If you are in a hurry, send me an email and I will send you back an early patch with that feature.

    About using vertex colors, I do find it to be more performant because of the way modern GPUs work. They don't have to load additional assets like textures. They just load the mesh and it already has everything inside it.
    That is general case, there are always exceptions. For example with small textures, probably you wouldn't see much performance gain.

    Notice: This has been edited as I misunderstood the initial question.
     
    Last edited: Oct 13, 2018
  42. Jesse_Pixelsmith

    Jesse_Pixelsmith

    Joined:
    Nov 22, 2009
    Posts:
    296
    Awesome! Thank you. I'm not in a terrible hurry, but I'd love to see what the early patch looks like! I will probably heavily use this feature throughout the game (Unless it's changed the patch process for asset store assets takes a bit - maybe I could beta test / give feedback on the feature before an initial patch?) At any rate I'll shoot you an email. Thanks for your reply :D
     
  43. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    At the end didn't receive any email from you, but I have updated the asset with a small patch that includes "Texture Power". You can try it out and let me know what you thing about it.
     
  44. csims314

    csims314

    Joined:
    Oct 16, 2018
    Posts:
    2
    Hi Bogdan, I can't get the animated water to render on iOS. Is there a build setting I'm missing?

    Great Asset!
     
  45. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    Hi, thank you.
    What specific problems do you experience with that scene? Could you attach some screenshots of the problem? What device and OS version are you using ?
    The animated water requires some integrating OpenGL instructions (like ddx and ddy) and that could cause an issue. I do know of some Android phones that have problems rendering that because of their GPUs.
     
  46. csims314

    csims314

    Joined:
    Oct 16, 2018
    Posts:
    2
    IPhone X, OS 12.1. I'm just running the MaterialTestScene without any modifications. Unity 2018.3.0b6. The water just doesn't appear at all in the scene.
     
  47. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    That is weird, the problems that I had with that shader on mobile was that it didn't rendered properly, but still appears on the screen.
    Another possible problem is that for some reason the shader is not included in the build (Edit > Project Settings > Graphics ,make sure to include the animated water shader).

    If you still have problems with the shader, another way of achieving the same effect is to have an animated mesh, and just apply a Flat Lighting material to it. That is the way the flat water in Monument Valley game is done.
    I created the shader in order to avoid having to create and animate a mesh.
     
  48. reinfeldx

    reinfeldx

    Joined:
    Nov 23, 2013
    Posts:
    164
    Hi Bogdan, how do I go about fixing the shine-through of spot lights using your shaders?
     

    Attached Files:

  49. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    67
    Hi reinfeldx,
    One possible way to fix it is to trace a ray from your light source straight away until it hits a surface. You pass that normal in the shader and use it to color only the sides that are at most 90 degrees away from the normal generated in the raytrace.
    The code in the shader that does the lightsources is in "/Shaders/cginc/FlatLightingSources.cginc", probably for you the more interesting functions are : spot_light and point_light.

    I have to warn you that it's not a trivial thing to fix this and also it will have performance implications, especially the ray tracing.

    I have some ideas of how I can fix it just in the shader with some approximations so if you are not in a hurry I can send you a patch in a couple of days, just pm your email.
     
  50. gamezuv

    gamezuv

    Joined:
    Nov 6, 2013
    Posts:
    82
    hi there is a bug in unity 2018. I can bake shaders because the naming window of the bake shader is bugged out..