[ISL] Rendering depth maps

Tutorials/guides/tips on how to use Indigo and the Indigo exporters
User avatar
fused
Developer
Posts: 3648
Joined: Fri Sep 22, 2006 7:19 am
Location: Berlin, Germany
3D Software: Cinema 4D

[ISL] Rendering depth maps

Post by fused » Thu Jul 02, 2009 8:51 pm

Update: cahnged the shader to use the 11% faster lenght()

ZomB asked me yesterday, if it was somehow possbile to get C4D to render a depth map that fits the Indigo viewport (the C4D viewport does not 1:1 match with the Indigo viewport). This is of course close to impossible.

But then i had the idea to make Indigo render the depth map:

By using an ISL shader it should be possible to calculate the distance between the surface point to be shaded and the camera. The shader is used as an emission shader in a diffuse material with bure black albedo. The pure black albedo is to prevent the objects to illuminate each other as rays will be absorbed as soon as they hit the pure black albedo.

So much for the idea, heres how i did it.

This material has to be applied to all meshes. The shader calculates the distance between the camera position(hardcoded) and the surface point:

Code: Select all

    <material>
        <name>depthMap shader</name>
        <diffuse>
            <random_triangle_colours>false</random_triangle_colours>
            <albedo>
                <constant>
                    <rgb>
                        <rgb>0.000000 0.000000 0.000000</rgb>
                        <gamma>2.200000</gamma>
                    </rgb>
                </constant>
            </albedo>
            <base_emission>
                <constant>
                    <rgb>
                        <rgb>1000.000000 1000.000000 1000.000000</rgb>
                        <gamma>1.000000</gamma>
                    </rgb>
                </constant>
            </base_emission>
            <layer>1</layer>
            <emission>
                <shader>
                    <shader>
                        <![CDATA[def calcDistance(vec3 a, vec3 b) real: length(a - b)

def eval(vec3 pos) vec3: vec3(calcDistance(vec3(0.17073, -4.39744, -0.77524), pos))]]>
</shader>
                </shader>
            </emission>
        </diffuse>
    </material>
The emission should not be scaled on each mesh, so that every object emits the correct relative ammount of light.

That works pretty well already, but i does give us an inverted depth map (usually white represents close and black far). This not that bad since we can just invert the image afterwards, but after that definiton the background would be close (since its black). We need to add a background material.

Code: Select all

    <background_settings>
        <background_material>
            <material>
                <name>background_material</name>
                <diffuse>
                    <base_emission>
                        <constant>
                            <rgb>
                                <rgb>1000.000000 1000.000000 1000.000000</rgb>
                                <gamma>1.000000</gamma>
                            </rgb>
                        </constant>
                    </base_emission>
                    <layer>0</layer>
                </diffuse>
            </material>
        </background_material>
    </background_settings>
Both should be in seperate layers, because you would want to scale the background layer so its pure white.

Heres a quick test, i converted the image to greyscale in gimp and then inverted it. It rendered reasonably fast.
depth.png
indigo output (to greyscale)
depth.png (126.47 KiB) Viewed 9737 times
depth_inv.png
inverted with gimp
depth_inv.png (125.36 KiB) Viewed 9736 times

User avatar
Pibuz
1st Place 100
Posts: 2646
Joined: Tue Dec 11, 2007 7:58 am
Location: Padua, Italy
3D Software: SketchUp

Re: [ISL] Rendering depth maps

Post by Pibuz » Thu Jul 02, 2009 10:04 pm

Hey fused!
This is definitely useful!!!!!
I'd very like to have this shader integrated within Indigo!

Congratulations for your work!

User avatar
zeitmeister
2nd Place 100
Posts: 2010
Joined: Tue Apr 22, 2008 4:11 am
Location: Limburg/Lahn, Germany
Contact:

Re: [ISL] Rendering depth maps

Post by zeitmeister » Thu Jul 02, 2009 11:26 pm

Super!!!

Just make it accessable as an render-option, like "render alpha", "render clay": "render depth".
Rendering this depthmap at the same time when rendering the original image would be a killer, too.

User avatar
pixie
Indigo 100
Posts: 2345
Joined: Sat Dec 29, 2007 4:54 am
Location: Away from paradise
3D Software: Cinema 4D
Contact:

Re: [ISL] Rendering depth maps

Post by pixie » Thu Jul 02, 2009 11:39 pm

zeitmeister wrote:Super!!!

Just make it accessable as an render-option, like "render alpha", "render clay": "render depth".
Rendering this depthmap at the same time when rendering the original image would be a killer, too.
If someone is able to do it is Fused!!
Go Fused, go!! Fused for president! :D

User avatar
Zom-B
1st Place 100
Posts: 4701
Joined: Tue Jul 04, 2006 4:18 pm
Location: ´'`\_(ò_Ó)_/´'`
Contact:

Re: [ISL] Rendering depth maps

Post by Zom-B » Fri Jul 03, 2009 12:02 am

Here is my test with this shader:
Attachments
indigo_depth_pp.jpg
inverted and tweaked..
indigo_depth_pp.jpg (178.97 KiB) Viewed 11191 times
indigo_depth_origuinal.jpg
output with shader
indigo_depth_origuinal.jpg (135.76 KiB) Viewed 9689 times
indigo.jpg
original Indigo output
indigo.jpg (165.29 KiB) Viewed 25451 times
polygonmanufaktur.de

User avatar
suvakas
3rd Place Winner
Posts: 2613
Joined: Mon Sep 04, 2006 11:08 pm
Location: Estonia
Contact:

Re: [ISL] Rendering depth maps

Post by suvakas » Fri Jul 03, 2009 12:51 am

Very nice scene ZomB !
Is it yours? Can you show us more?

User avatar
lycium
Posts: 1216
Joined: Wed Sep 12, 2007 7:46 am
Location: Leipzig, Germany
Contact:

Re: [ISL] Rendering depth maps

Post by lycium » Fri Jul 03, 2009 12:53 am

that's a really cool idea fused :D it should definitely become part of the rendering core, allowing for advanced compositing. depth of field, antialiasing and now also motion blur complicate matters a bit however...


ps. ZomB, omg, that render of yours is beauuutiful!

User avatar
CTZn
Posts: 7240
Joined: Thu Nov 16, 2006 4:34 pm
Location: Paris, France

Re: [ISL] Rendering depth maps

Post by CTZn » Fri Jul 03, 2009 2:13 am

Wow fused ! I agree, it's fitting nicely beside the alpha render.

edit: there is another one that can be usefull as a shading parameter, it's the camera facing ratio, or angle between the camera ray and the normal at surface (fresnel effects, ghost/xray shaders).
obsolete asset

User avatar
fused
Developer
Posts: 3648
Joined: Fri Sep 22, 2006 7:19 am
Location: Berlin, Germany
3D Software: Cinema 4D

Re: [ISL] Rendering depth maps

Post by fused » Fri Jul 03, 2009 7:42 am

thank you all for your comments :)

hope this turns out to be useful for someone...

User avatar
Stur
Posts: 594
Joined: Fri Nov 10, 2006 11:52 pm
Location: Nancy, France

Re: [ISL] Rendering depth maps

Post by Stur » Fri Jul 03, 2009 7:46 am

Excellent idea Fused.

User avatar
OnoSendai
Developer
Posts: 6243
Joined: Sat May 20, 2006 6:16 pm
Location: Wellington, NZ
Contact:

Re: [ISL] Rendering depth maps

Post by OnoSendai » Fri Jul 03, 2009 12:32 pm

Fused, you are a crazy genius!

User avatar
Zom-B
1st Place 100
Posts: 4701
Joined: Tue Jul 04, 2006 4:18 pm
Location: ´'`\_(ò_Ó)_/´'`
Contact:

Re: [ISL] Rendering depth maps

Post by Zom-B » Fri Jul 03, 2009 2:06 pm

yes, abusing your shadercode for funny stuff :)

Now tell us Ono how can we speed this up?? setting Indigo render Depth to 1 and other Advanced tweaks... ?!
How ist the chance for some updated LLVM JIT backend, and will it be availible for 64builds too???
polygonmanufaktur.de

User avatar
OnoSendai
Developer
Posts: 6243
Joined: Sat May 20, 2006 6:16 pm
Location: Wellington, NZ
Contact:

Re: [ISL] Rendering depth maps

Post by OnoSendai » Fri Jul 03, 2009 2:09 pm

The 64 bit build will use the LLVM JITing backend, when LLVM supports 64 bit JITing without crashing and burning :)

User avatar
benn
Posts: 1046
Joined: Mon Dec 08, 2008 12:47 pm
Location: Wellington, New Zealand
Contact:

Re: [ISL] Rendering depth maps

Post by benn » Fri Jul 03, 2009 2:10 pm

Awesome fused - well done :)

User avatar
lycium
Posts: 1216
Joined: Wed Sep 12, 2007 7:46 am
Location: Leipzig, Germany
Contact:

Re: [ISL] Rendering depth maps

Post by lycium » Fri Jul 03, 2009 4:18 pm

another way to possibly speed it up (a lot) is to replace those two pow() calls with a multiplication.

Post Reply
34 posts

Who is online

Users browsing this forum: No registered users and 2 guests