Deferred lightning impossible on Orthographic Camera?

I just stumble upon an interesting fact that seems to be noted nowhere in the documentation.

I have a point light inside a Lantern that cast shadow on the ground. When I switch the camera (or the scene preview) to orthographic, the shadow disapear!

When I go check the setting of my light, there is a little warning that have appear on my light that say that in forward rendering, only directional light can cast shadow. But I just change the projection, everything is still set on deferred!

Is this an intended behaviour or a bug? Because orthographic is just a different projection amtrix, so it shouldn’t mess up neither with shadow map nor deferred rendering, no?

hmmm… check the rendering path on your orthographic camera… Is it set to Deferred?

1 Like

Yes of course, I’ve checked in my Player Setting and ON my camera, each are set to Deferred.

And I’ve the shadow drawn when in perspective (and only deferred have shadow for point light) and when I switch to orthographic the Shadow disappear. Both in game view (so throught a camera set on ortho) and on the Scene Preview (so by right clicking on the little cube and unchecking “Perspective”).

So it would seems its a limitation : orthographic camera cannot be on a deferred path, but I find this strange since it’s just a switch of projection matrix…

Note to anyone having the same problem I did: Directional Lights should work in Orthographic. If they’re not, you probably baked a lightmap that you need to clear.

Yeah I tested it with a scene here… Seems to work just fine …

I’ve run into the exact same issue in 3.5 beta, did you ever find out what was wrong Sirithang?

Toggling the camera between Perspective and Orthographic disables shadows on points lights and gives a “only directional lights can have shadows in forward rendering” warning. This happens in a fresh project, with an empty scene except for a camera and a point light.

I’ve checked with the 3.5 beta and same issus as with 3.4 and 3.4.2f*…

It work only with directional light, they give shadow, but point/spot don’t give shadow with an ortho camera. Would it be an engine restriction? as shader can’t transform from a perspective shadowmap to an ortho camera point of view? Why does it work with directional light then? Because the shadow map being already in orthographic the conversion is possible?

Would lvoe to hear an official response on that, is there a mean to submit this to the Unity team, or should I send a mail?

I have seen a few threads mentioning this now, but never an official response confirming whether or not it is working as intended… I submitted a bug about it anyway, can’t hurt. :slight_smile:

It was confirmed that realtime shadows don’t work on orthographic cameras by Aras back on 3.0 or 3.1 already and was also mentioned to be by design.

Ah ok, thanks for clearing that up.

Ouch, this is so bad. Anybody found a solution to this bug (because this is a bug, right?)?

Ok, found the fullforwardshadows options for Shaders :slight_smile:

Yes, it’s an unfortunate performance choice we had to do - deferred does not work with orthographic cameras. The reason was that we did not want to slow down perspective+deferred case just to make it possible to use orthographic projection.

Thanks for the explanation Aras :slight_smile:

OLD “Is there a work around?”

EDIT ahh sorry found this it works :smile:

Shader “0Diffuse1” {
Properties {
_Color (“Main Color”, Color) = (1,1,1,1)
_MainTex (“Base (RGB)”, 2D) = “white” {}
}
SubShader {
Tags { “RenderType”=“Opaque” }
LOD 200
CGPROGRAM
#pragma surface surf Lambert fullforwardshadows
sampler2D _MainTex;
fixed4 _Color;
struct Input {float2 uv_MainTex;};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
Fallback “VertexLit”
}

a perspective one with a very small view angle. Its not perfectly orthogonal that way but depending on your explicit need might be enough.

If it isn’t, then you are out of luck unluckily

I needed the data from the deferred render pipeline but wanted an orthographic view so i putting an orthographic projection matrix in to a perspective camera projection matrix to trick the pipeline and it works :slight_smile:

1 Like

Hey Pete I’m looking for the same thing, would you mind sharing the script you made?

I’m also very interested by this solution!
I’m trying to have both dynamic shadows and pixel perfect rendering.

Does it also applies to a perspective camera using an orthographic projection matrix?

Here is an test project where I use a little script to apply an orthographic projection matrix to a perspective camera with deferred lighting enabled.
The scene contains a point light that should produce dynamic shadows.

https://dl.dropboxusercontent.com/u/24322340/Unity3D/orthoprojmatrix_vs_deferredlighting.unitypackage

Here is the script I use:

using UnityEngine;
using System.Collections;

public class OrthoProjMatrix : MonoBehaviour
{
	[SerializeField] float orthographicSize = 10f;

	void Update()
	{
		float aspect = (float) Screen.width / (float) Screen.height;
		camera.projectionMatrix = Matrix4x4.Ortho(-orthographicSize * aspect, orthographicSize * aspect, -orthographicSize, orthographicSize, camera.nearClipPlane, camera.farClipPlane);
	}
}

The lighting and shadows both appear perfectly when the script is not running


:sunglasses:

but don’t when it is.


:frowning:

But here is what is even more wierd: when I increase the near clipping plane or move the camera forward, a halo appears when near the point light


:face_with_spiral_eyes:

and shadows when near the background plane.


:shock:

Does it make any sense to you guys?
Reminder: I’m trying to get both dynamic shadows and pixel perfect rendering.