目标
结合官方的文档:HDK: Custom Viewport Rendering
- 搞清楚 “Scene Render Hook” 的基本概念与用途
- 尝试运行范例并简单分析其代码
渲染钩子函数(Rendering Hooks)
Houdini offers several rendering hooks that allow you to augment or replace rendering in the Houdini viewport. There are two main types of hooks - primitive hooks, and scene hooks.
Houdini提供了几种渲染钩子函数(rendering hooks) 允许你对Houdini视窗中的渲染进行补充或者替换。有两种主要类型的hook:
- 图元钩子函数(primitive hooks)
- 场景钩子函数(scene hooks)
Primitive hooks execute rendering code based on specific primitives found within a displayed GU_Detail. They can be used to implement viewport rendering code for custom-designed primitives, add decorations and guides to existing primitives, or replace the Houdini rendering of a native primitive.
“图元钩子函数”根据显示的GU_Detail
来找到特定的图元类型,然后执行渲染代码。一些用途例如:
- 自定义新的图元并实现其在视窗中的渲染。
- 对已有的图元添加装饰或指引
- 替换掉Houdini原生对图元的渲染
Scene hooks are not tied to any given geometry, and instead operate at the viewport level. They can do things such as render additional material to the beauty pass, draw in the overlay plane, or do a framebuffer effect such as a depth of field.They allow you to render text in the viewport, apply effects to the beauty pass, draw your own background, or entirely replace the Houdini viewport.
“场景钩子函数”并不会绑定于特定的几何体,而是作用于视窗。一些用途例如:
- 在 beauty pass(渲染不透明物体的pass)渲染额外的材质
- 画一些东西覆盖上去
- 做后处理特效,如“景深”等
- 在视窗中渲染文字
- 在 beauty pass 做应用特效
- 画你自己的背景
- 完全替换掉Houdini本身的视窗
本篇将只关注 “场景钩子函数”。
场景渲染的钩子
按照顺序,可以在下面的阶段中放钩子:
钩子 | 描述 |
---|---|
DM_HOOK_BACKGROUND | The first element drawn to the viewport, without any camera transform applied |
背景 | 第一个画在视窗上的元素,没有应用任何相机矩阵 |
DM_HOOK_PRE_RENDER | Elements drawn before the beauty pass, with a camera transform. The background image is drawn in the Houdini native pre-render pass |
前渲染Pass | 在 beauty pass 之前画的元素,应用相机矩阵。背景图像就是在Houdini原生的pre-render pass画的 |
DM_HOOK_BEAUTY | All opaque user-generated geometry is drawn in this pass. |
不透明Pass | 所有不透明的用户生成几何体都在这个pass中画。 |
DM_HOOK_BEAUTY_TRANSPARENT | Any transparent user-generated geometry is drawn in this pass, after the opaque beauty pass. |
半透明Pass | 所有半透明的用户生成几何体都在这个pass中画,处于不透明Pass之后。 |
DM_HOOK_UNLIT | Unlit (non-lit, non-shadowed) geometry is drawn in this pass. Guide and template geometries are a good example of what is drawn in this pass. |
无光照Pass | 不接受光照的几何体(无光照,无影子)在这个Pass中画,“指引性几何体”和“模板几何体”是个很好的例子。 |
DM_HOOK_XRAY | Objects with the X-ray flag set (such as bones) are drawn in this pass. Objects should only draw as wireframe in this pass. |
X射线Pass | 有“X射线Flag”的对象(例如骨骼),就在这个Pass中画。这个Pass中的对象都应该只画线框。 |
DM_HOOK_POST_RENDER | Elements drawn after all the scene geometry, but still with the camera transform, are drawn. The origin, field guide and safe area are drawn in the native Houdini post-render pass. |
后渲染Pass | 所有场景内几何体之后画的元素,但是仍旧有相机矩阵。 |
DM_HOOK_FOREGROUND | The last elements drawn in the viewport. No native Houdini elements are drawn in this pass. |
前景 | 视窗中最后画的元素。Houdini中没有原生的元素在此Pass中画。 |
范例
DM_BackgroundHook 背景
DM_InfoHook 显示信息
DM_SceneBoundsHook 场景包围盒
DM_LightBloomHook 泛光后期效果