Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to use 3D Object in 2D game with 2D Pipeline

Discussion in 'Scripting' started by Mashimaro7, Aug 16, 2020.

  1. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    Is there a way to bring 3D objects into a 2D project that is using the 2D Universal pipeline for rendering? I have some 3D objects I want to bring in to the project I'm working on, but they just get imported as pure white.
    upload_2020-8-17_1-51-43.png
    Is there a way to import 3D models into a 3D game, and keep the 2D pipeline for lighting? I'l tried a few different shaders, but if they're not pure white they're pink. I would like them to have shading as a 3D object, and still interact with light and rotate on all axis if possible. If it's impossible to use a 3D object, if there was a way to at least have a 2D sprite taken from a 3D object, but still react to light in a 3D way, that'd work too I suppose.

    Thanks in advance.
     
    jugbandb likes this.
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,888
    You just need to pick an appropriate shader for your materials. Currently you are using "Sprite-Lit" which obviously is not going to work on a non-sprite object. Try "Universal Render Pipeline/SimpleLit" or "Universal Render Pipeline/Lit". Those are the basic lit ones. All of the standard shaders are going to show up pink in URP.
     
    Bunny83 likes this.
  3. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    I have tried this, the sphere is still white with no shading. Like I said, I've tried multiple different materials. Here's what it looks like on simple lit
    upload_2020-8-17_16-26-46.png
    It doesn't receive light no matter what. I cranked the lighting down to 0, here's what it looks like, on a Lit material
    upload_2020-8-17_16-29-10.png
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,888
    Do you have any lights in the scene?
     
  5. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    Yes, there's a global light, the second picture is after I turned the global light's intensity to 0
     
  6. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,888
    Global light is only for 2d sprites. Try adding a 3d light such as directional light or point light.
     
  7. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    Okay, I added a directional light and a point light, still no luck.
    upload_2020-8-17_18-10-56.png
     
  8. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
  9. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    Can somebody help please?
     
  10. johnedvard

    johnedvard

    Joined:
    Jan 25, 2013
    Posts:
    4
    I am encountering the same problem. I have created a new 2D project, I am using the 2D Renderer Data with UniversalRenderPipeline, but my 3D cube is white.
     
  11. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    I wasn't able to completely solve this, I can't get shading in. But I was able to change the colour by changing the shader of the object.
     
  12. Geogalion

    Geogalion

    Joined:
    Jan 20, 2016
    Posts:
    2
    Hello,
    Did you solved the problem? I'm interested on it!
    Thanks a lot!
     
  13. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    No sorry, ↑ see previous reply :p

    I made a new shader which was just a basic shader. No shading, but I was able to change colour.
     
  14. ayyshush

    ayyshush

    Joined:
    Dec 28, 2020
    Posts:
    1
  15. eb3000

    eb3000

    Joined:
    Apr 5, 2015
    Posts:
    1
    Just add a Directional Light to the scene
     
  16. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    Yes, I've tried this and it doesn't work. See previous comment lol

    I just saw this, I tried some of the things in there, unfortunately my issue is kinda the opposite lol. They want a 2D sprite affected by 3D lights, I wanted a 3D mesh affected by light in a 2D renderer.

    I still haven't been able to solve this, I made a basic shader for a voronoi texture so it at least doesn't look completely white, but it still doesn't receive shadows.
    This is what it looks like with a URP lit shader, directional light in scene.
    upload_2021-2-16_17-22-0.png

    Ay, my client put this game on hold for a few months so I'm still not in a rush to fix this, but maybe one day I'll get it fixed XD
     
  17. Blakiemon

    Blakiemon

    Joined:
    Aug 19, 2019
    Posts:
    1
    Hi, this is something I am curious about too! Would it perhaps be possible to light a 3D object as if it were 2D? E.g render the 3d objects as a sprite per say, so that it lights up as if it were a flat image. I hope that the solution isn't to convert the lighting system to 3D. Because 3D lighting takes up lots of processing.
     
  18. Mashimaro7

    Mashimaro7

    Joined:
    Apr 10, 2020
    Posts:
    727
    It's not free, but there's a plugin that converts 3D models to sprites. This might be what you're looking for?
    https://assetstore.unity.com/packages/tools/sprite-management/animation-baking-studio-3d-to-2d-31247
    I could swear there was a free one somewhere, but I can't find it, maybe it's gone.
     
  19. gzckrg1

    gzckrg1

    Joined:
    Jun 24, 2020
    Posts:
    14
  20. nerseus

    nerseus

    Joined:
    Sep 6, 2017
    Posts:
    3
    I can confirm that the solution posted by gzckrg1 works (2 cameras, one is overlay, etc.)
     
  21. MTTHKL

    MTTHKL

    Joined:
    Aug 12, 2018
    Posts:
    5
    @nerseus, @gzckrg1 I tried to follow the steps explained behind the link, but didn't succeed. Could you explain the steps you took to have 3D object to receive light correctly with URP 2D renderer?
     
  22. HofiOne

    HofiOne

    Joined:
    Apr 19, 2021
    Posts:
    68
    URP documentation says the following (https://docs.unity3d.com/Packages/c...es.universal@12.1/manual/Lights-2D-intro.html)

    "No interoperability with 3D Lights and 3D Renderers

    Currently both 3D and 2D Lights can only affect 3D and 2D Renderers respectively. 2D Lighting does not work on or effect 3D Renderers such as the Mesh Renderer, while 3D Lighting will similarly have no effect on 2D Renderers such as the Sprite Renderer. While interoperability between the respective Lights and Renderers may be developed in the future, currently a combination of 2D and 3D Lights and 2D and 3D Renderers in a single Scene can be achieved by using the camera stacking technique."

    just a side note, seems it is a bit outdated as one exception is surely not true currently (at least in v 2021.1.28f1), the 3d renderer has effect on 2d sprites with e.g. Sprite-lit-default material, maybe an unwanted side-effect but those sprites are lit always (no matter if there's a light or not)
     
    Last edited: Apr 27, 2022
  23. HofiOne

    HofiOne

    Joined:
    Apr 19, 2021
    Posts:
    68
  24. rossirrs

    rossirrs

    Joined:
    Jan 13, 2021
    Posts:
    7
    only use light2D from unity
     
  25. JustPataki

    JustPataki

    Joined:
    Feb 19, 2022
    Posts:
    1
    the trick is to add one of the 3d object in hierarchy window, then change it's mesh
     

    Attached Files:

  26. TopGunDropOuts

    TopGunDropOuts

    Joined:
    Jan 21, 2021
    Posts:
    1
    I dunno if this problem ever got fixed, but I noticed that the z axis on the tree transform position in the OP is set to 0. I had a similar problem with a project of mine and the fix was to set the axis greater than 0 (try 1). You might try and see if it'll work. I suspect it has something to do with unity's lighting system requiring a depth component to have the ability to render light reflections on 3D objects.
     
  27. JulianRice

    JulianRice

    Joined:
    Oct 5, 2017
    Posts:
    13
    Another note, if you drag and drop a texture into the `Base Map`, then the sprite will appear in the model. I'd recommend making a copy of the material for that though!