- Home /
Problem with custom depth map
Hello everyone,
I'm working on a simple simulation for activities of daily living. One part of this simulation is the generation of depth maps which we use for deep learning evaluations a.s.o.. A problem is that we use the fisheye projection approach from Bourke et al. (http://paulbourke.net/dome/unity3d/) and a limit is that we can't use the depth maps created for each camera. Long story short, I've written a simple shader that seems to work except the case if some character is laying in the bed. For an unknown reason, the person in the bed is closer to the ground than the surface of the bed in the depth map. See screenshot below:
# Shader Code
float4x4 _fisheyeView;
inline float CustomDepth(float3 vertex) {
float4x4 mat = mul(_fisheyeView, UNITY_MATRIX_M);
float3 v = mul(mat, vertex);
return 1 - (v.z / _fisheyeView._m13);
}
Has someone an explanation for this?
Answer by Namey5 · Mar 04, 2020 at 11:51 AM
Try the following;
inline float CustomDepth (float3 vertex)
{
float3 v = mul (_fisheyeView, float4 (mul (unity_ObjectToWorld, float4 (vertex, 1)).xyz, 1));
return 1 - (v.z / _fisheyeView._m13);
}
UNITY_MATRIX_M can sometimes be undefined, whereas unity_ObjectToWorld should always work.
You were multiplying a float3 by a float4x4, meaning the matrix would have been truncated to a float3x3 and the vertex would have been interpreted as a vector rather than a position.
It should be faster to multiply a point by a matrix than it is to multiply two matrices.
Not certain it will fix the problem, but if i had to guess why it was happening, points 1 and 2 would be my first thoughts.
Thank you! As you guess point 1 and 2 are the solutions to my problem.
Your answer
![](https://koobas.hobune.stream/wayback/20220612224349im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is it possible to create a depth render of scene using a replacement shader? 0 Answers
Increasing the level of detail with a depth render 0 Answers
Shader based camera compositing. 2 Answers
Wrong Depth texture being passed into the shader. 0 Answers
Distance from pixel to camera in shader 0 Answers