Page 1 of 1

Z Depth Shader?

Posted: Fri Jun 29, 2018 3:36 pm
by Bulwerk
Does anyone have a clever solution for making a Z depth shader usable in the node graph?

Seems like something OSL could handle fairly easily. I'm terrible at coding so I thought I would ask the community for some input

Thanks!

Re: Z Depth Shader?

Posted: Fri Jun 29, 2018 6:46 pm
by Phantom107
Absolutely I need this to. I have an insane amount of work to do but I'm going to get into OSL and then program this -- if someone else hasn't done it in the meantime

Re: Z Depth Shader?

Posted: Fri Jun 29, 2018 7:49 pm
by aoktar
I think you need somethings like this. You can improve if you need.

Code: Select all

shader zdepth
(
    float dmax=10[[float min=0, float max=100]],
    output color col = 0
)
{
		point CamPos = point("camera", 0, 0, 0);
		float d = 1-clamp(distance(CamPos,P)/dmax,0,1);
		col = d;
}

Re: Z Depth Shader?

Posted: Fri Jun 29, 2018 7:57 pm
by Bulwerk
Exactly what I was looking for!

Thanks!

Re: Z Depth Shader?

Posted: Sat Jun 30, 2018 8:48 pm
by Phantom107
Thanks for making this!

Re: Z Depth Shader?

Posted: Sun Jul 01, 2018 12:15 am
by aoktar
You are welcome guys!

Re: Z Depth Shader?

Posted: Sun Jul 01, 2018 10:15 pm
by roeland
For reference I'll add another common definition of Z depth: the distance from the film plane measured parallel to camera view vector. This is equivalent to what Octane renders in the Z-depth pass.

Code: Select all

shader zdepth
(
    float dmax=10[[float min=0, float max=100, float sliderexponent=4]],
    output color col = 0
)
{
    point pCam = transform("common", "camera", P);
    // the camera view vector is the negative Z axis in camera space:
    col = -pCam[2] / dmax;
}