标题中的“PT”表示:Procedural Texture(过程纹理)。表示该章节属于“过程纹理”的内容。
当前章节在“过程纹理”内容中的位置:
过程纹理(0)——概述
过程纹理(1)——方格纹理(1)——3D方格纹理
过程纹理(1)——方格纹理(2)——2D方格纹理(1)——平面2D方格纹理
过程纹理(1)——方格纹理(2)——2D方格纹理(2)——球面2D方格纹理
过程纹理(1)——方格纹理(2)——2D方格纹理(3)——圆柱2D方格纹理
过程纹理(2)——纹理的仿射变换
过程纹理(3)——基于噪声的纹理(0)——概述
过程纹理(3)——基于噪声的纹理(1)——Basic Noise Texture
过程纹理(3)——基于噪声的纹理(2)——Wrapped Noise Texture
过程纹理(3)——基于噪声的纹理(3)——Marble
过程纹理(3)——基于噪声的纹理(4)——Sandstone Texture
过程纹理(3)——基于噪声的纹理(5)——Wood Texture
0,引言
该章节的内容理论参考:
《Advanced RenderMan》2000版本的12.4章节”Wood Grain”。
代码来自与《Ray Tracing from the Ground Up》作者按照《Advanced RenderMan》算法整理的C++代码。
本章节的内容,主要是个人对上面这两部分知识的理解和测试。
1,Wood类的基本版本
测试代码:
#define TYPE 0
// TYPE = 0: (0,1,0)
// TYPE = 1: (0,0,1)
void
World::build(void) {
int num_samples = 9;
vp.set_hres(300);
vp.set_vres(300);
vp.set_samples(num_samples);
tracer_ptr = new RayCast(this);
background_color = black;
Ambient* ambient_ptr = new Ambient;
ambient_ptr->scale_radiance(1.0);
set_ambient_light(ambient_ptr);
Pinhole* pinhole_ptr = new Pinhole;
#if TYPE == 0
pinhole_ptr->set_eye(0, 100, 0);
#else
pinhole_ptr->set_eye(0, 0, 100);
#endif // TYPE
pinhole_ptr->set_lookat(0.0);
pinhole_ptr->set_view_distance(15000.0);
pinhole_ptr->compute_uvw();
set_camera(pinhole_ptr);
Directional* light_ptr = new Directional;
#if TYPE == 0
light_ptr->set_direction(0, 1, 0);
#else
light_ptr->set_direction(0, 0, 1);
#endif // TYPE
light_ptr->scale_radiance(4.0);
add_light(light_ptr);
// wood texture
// This Wood constructor just specifies the light and dark colors.
// The other parameters are defaults.
RGBColor light_color(0.5, 0.2, 0.065);
RGBColor dark_color(0.05);
Wood* wood_ptr = new Wood(light_color, dark_color);
wood_ptr->set_grainy(1.0);
wood_ptr->set_ringy(1.0);
InstanceTexture* transformed_wood_ptr = new InstanceTexture(wood_ptr);
transformed_wood_ptr->scale(0.4);
// transformed_wood_ptr->rotate_x(5); // for figure 3
// material
SV_Matte* sv_matte_ptr = new SV_Matte;
sv_matte_ptr->set_ka(0.75);
sv_matte_ptr->set_kd(0.85);
sv_matte_ptr->set_cd(transformed_wood_ptr);
// plane
Point3D p0(0.0, 0.0, 0.0);
#if TYPE == 0
Plane* plane_ptr = new Plane(p0, Normal(0, 1, 0));
#else
Plane* plane_ptr = new Plane(p0, Normal(0, 0, 1));
#endif // TYPE
plane_ptr->set_material(sv_matte_ptr);
add_object(plane_ptr);
}
输出图形:
(前边的是从+y方向向原点看的图形;后边的是从+z方向向原点看的图形)
2,添加各种噪声
2.1 第一步:添加“整体噪声”
输出图形:
(前边的是从+y方向向原点看的图形;后边的是从+z方向向原点看的图形)
2.2 第二步:给树干添加噪声
输出图形:
(前边的是从+y方向向原点看的图形;后边的是从+z方向向原点看的图形)
2.3 第三步:给年轮加“角度噪声”
输出图形:
(前边的是从+y方向向原点看的图形;后边的是从+z方向向原点看的图形)
2.4 第四步:给年轮的半径加噪声
输出图形:
(前边的是从+y方向向原点看的图形;后边的是从+z方向向原点看的图形)
(这种状态的木纹纹理,远看还OK,但是近看则显得有失真实)
2.5 第五步:加产生“细碎纹理”的噪声
输出图形:
(前边的是从+y方向向原点看的图形;后边的是从+z方向向原点看的图形)
(从这个图形中可以看出前面提到的“细长细长的细碎纹理”)
3,其他测试图形
3.1 测试代码
void
World::build(void) {
int num_samples = 16;
vp.set_hres(300);
vp.set_vres(300);
vp.set_samples(num_samples);
vp.set_gamut_display(true);
background_color = RGBColor(0.5);
tracer_ptr = new RayCast(this);
Pinhole* pinhole_ptr = new Pinhole;
pinhole_ptr->set_eye(0, 20, 100); // sphere: (0, 0, 100)
pinhole_ptr->set_lookat(0.0);
pinhole_ptr->set_view_distance(4750.0);
pinhole_ptr->compute_uvw();
set_camera(pinhole_ptr);
PointLight* light_ptr = new PointLight;
light_ptr->set_location(10, 10, 20);
light_ptr->scale_radiance(2.5);
add_light(light_ptr);
// wood texture
// This Wood constructor just specifies the light and dark colors.
// The other parameters are defaults.
RGBColor light_color(0.5, 0.2, 0.065);
RGBColor dark_color(0.05);
Wood* wood_ptr = new Wood(light_color, dark_color);
wood_ptr->set_grainy(1.0);
wood_ptr->set_ringy(1.0);
InstanceTexture* transformed_wood_ptr = new InstanceTexture(wood_ptr);
transformed_wood_ptr->scale(0.4);
// transformed_wood_ptr->rotate_z(110);
// material:
SV_Matte* sv_matte_ptr = new SV_Matte;
sv_matte_ptr->set_ka(0.25);
sv_matte_ptr->set_kd(0.85);
sv_matte_ptr->set_cd(transformed_wood_ptr);
// the sphere:
// Sphere* sphere_ptr = new Sphere();
SolidCylinder* sphere_ptr = new SolidCylinder();
Instance* instance_ptr = new Instance(sphere_ptr);
instance_ptr->scale(2.0);
// instance_ptr->rotate_x(-60);
// instance_ptr->rotate_y(-30);
instance_ptr->set_material(sv_matte_ptr);
add_object(instance_ptr);
}
3.2 输出图形
给球面添加木纹:
给圆柱添加木纹:
4,其他说明
完整代码下载路径:http://download.csdn.net/detail/libing_zeng/9800234
Referrance:
[1]. Kevin Suffern, Ray Tracing from theGround Up, A K PetersLtd, 2007.
[2]. Anthony A. Apodaca, Larry Gritz, Advanced RenderMan, Academic Press, 2000.