Z Depth Shader?

Generic forum to discuss Octane Render, post ideas and suggest improvements.
Forum rules
Please add your OS and Hardware Configuration in your signature, it makes it easier for us to help you analyze problems. Example: Win 7 64 | Geforce GTX680 | i7 3770 | 16GB
Post Reply
User avatar
Bulwerk
Licensed Customer
Posts: 236
Joined: Sun Aug 01, 2010 8:04 pm

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!
User avatar
Phantom107
Licensed Customer
Posts: 686
Joined: Tue Jul 24, 2012 11:31 am
Location: The Netherlands

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
User avatar
aoktar
Octane Plugin Developer
Posts: 16065
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye
Contact:

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;
}
Octane For Cinema 4D developer / 3d generalist

3930k / 16gb / 780ti + 1070/1080 / psu 1600w / numerous hw
User avatar
Bulwerk
Licensed Customer
Posts: 236
Joined: Sun Aug 01, 2010 8:04 pm

Exactly what I was looking for!

Thanks!
User avatar
Phantom107
Licensed Customer
Posts: 686
Joined: Tue Jul 24, 2012 11:31 am
Location: The Netherlands

Thanks for making this!
User avatar
aoktar
Octane Plugin Developer
Posts: 16065
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye
Contact:

You are welcome guys!
Octane For Cinema 4D developer / 3d generalist

3930k / 16gb / 780ti + 1070/1080 / psu 1600w / numerous hw
User avatar
roeland
OctaneRender Team
Posts: 1823
Joined: Wed Mar 09, 2011 10:09 pm

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;
}
Post Reply

Return to “General Discussion”