0
\$\begingroup\$

I am creating 1 scene in my game that would use a 3D asset - a cube, that I would like to rotate to show its different faces. My game is set up for URP 2D, and the game uses an orthographic camera.

First, is this possible to do - or would I have to use a perspective camera?

Here is what I have tried:

  • Using a perspective camera. But everytime I add a cube to the scene, it's showing as one big blob when rotated around, and is grey, probably because I don't know where/if I can add 2D directional light - I don't think that'll work with a 3D cube? When I add 3D directional light, it doesn't seem to work.
  • Changed the material of the cube.

Here is what I have currently tried:

This is my cube, using an orthographic camera, but without any directional light. So this makes sense to me.

enter image description here

This is now a perspective camera set-up with a nice directional light hitting it directly.

enter image description here

However, it looks like this.

enter image description here

I would like for it to look like a standard cube with shadows, etc. It looks like a grey blob at the moment. How do I fix this, and also is it possible to show that it is a cube using an orthographic camera?

EDIT:

Using the URP "lit" material and directional light, this is still how it looks: enter image description here

And on the camera: enter image description here

2D URP Pipeline Steps

I was asked to recreate the steps in a new scene, so here we go:

This is my scene camera after I created a brand new 2D URP project. It is orthographic and these are the settings: enter image description here

Note the camera settings/size/etc. It's a skybox, but it still shows up as a blue background on the camera.

As you can see here, directional light has been added, facing the cube. The global light 2D is also in this scene.

enter image description here

Nothing seems to change the flatness and blue background? Toggling 2D on and off does not work either.

This may be pertinent. Here's what my URP textures look like. One is red, another pink. I feel like this might be a problem with the materials or how they're being handled? enter image description here

This is what my cube material looks like. enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ I've updated the answer below with a workaround you can use with a 2D renderer. \$\endgroup\$
    – DMGregory
    Nov 3, 2022 at 0:27

1 Answer 1

1
\$\begingroup\$

It looks like the "Renderer 2D" URP pipeline definition does not process 3D lighting at all.

If you just want lighting for the sake of distinguishing cube faces, you can fake it with a shader. Here I've created a new unlit shader graph, and configured it like so:

Shader graph

This is just the math of Lambertian diffuse "n dot l" lighting plus an ambient term, written out as shader nodes, and using a vector parameter as your light direction (so you don't actually need a "light" object in your scene).

Slap this shader on your cube and you'll get shading dependent on the faces' direction and rotation of the cube:

Unity scene with shaded cube

\$\endgroup\$
3
  • \$\begingroup\$ Is it possible to apply different textures to each cube face using this approach? \$\endgroup\$ Nov 3, 2022 at 16:05
  • \$\begingroup\$ Sure. Though I'd recommend packing your six textures into a single texture or a texture array, then making a cube mesh with the six faces unwrapped to distinct texture coordinates. That makes things easiest (and most efficient for rendering). \$\endgroup\$
    – DMGregory
    Nov 3, 2022 at 16:22
  • \$\begingroup\$ Awesome, thank you. Just tried it and it worked like a charm! \$\endgroup\$ Nov 3, 2022 at 16:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .