Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Flat Lighting (FL)

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

  1. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    50
    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:
    786
    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:
    50
    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:
    786
    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:
    50
  6. schmosef

    schmosef

    Joined:
    Mar 6, 2012
    Posts:
    786
    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:
    50
    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:
    786
    @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:
    50
    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:
    50
    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:
    50
    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:
    50
    @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:
    50
    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:
    50
    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:
    50
    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:
    91
    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:
    50
    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:
    91
    Cool. I am happy to wait.

    I appreciate the response.
     
  24. BogdanGochev

    BogdanGochev

    Joined:
    Sep 17, 2015
    Posts:
    50
    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:
    9
    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:
    50
    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:
    9
    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:
    9
    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:
    62
    Hi- just curious,: will these shaders work in a HTML 5 WebGL build?
     
  30. _legolas_

    _legolas_

    Joined:
    Nov 10, 2014
    Posts:
    9
    Another question, Is Flat Lighting work with DOTween?
     
  31. The-Britain

    The-Britain

    Joined:
    Mar 31, 2015
    Posts:
    702
  32. The-Britain

    The-Britain

    Joined:
    Mar 31, 2015
    Posts:
    702
    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:
    50
    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:
    9
    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:
    50
    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:
    50
    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. EHEBrandon

    EHEBrandon

    Joined:
    Aug 3, 2014
    Posts:
    32
    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:
    50
    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.