Datasets:

ArXiv:
License:
File size: 13,280 Bytes
ae81f33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/******************************************************************************
 *     Copyright 2024 NVIDIA Corporation. All rights reserved.
 ******************************************************************************
 
Permission is hereby granted by NVIDIA Corporation ("NVIDIA"), free of charge,
to any person obtaining a copy of the sample definition code that uses our 
Material Definition Language (the "MDL Materials"), to reproduce and distribute
the MDL Materials, including without limitation the rights to use, copy, merge,
publish, distribute, and sell modified and unmodified copies of the MDL 
Materials, and to permit persons to whom the MDL Materials is furnished to do
so, in all cases solely for use with NVIDIA's Material Definition Language,
subject to the following further conditions:

1. The above copyright notices, this list of conditions, and the disclaimer
that follows shall be retained in all copies of one or more of the MDL
Materials, including in any software with which the MDL Materials are bundled,
redistributed, and/or sold, and included either as stand-alone text files,
human-readable headers or in the appropriate machine-readable metadata fields
within text or binary files as long as those fields can be easily viewed by the
user, as applicable.
2. The name of NVIDIA shall not be used to promote, endorse or advertise any 
Modified Version without specific prior written permission, except a) to comply
 with the notice requirements otherwise contained herein; or b) to acknowledge
the contribution(s) of NVIDIA.

THE MDL MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR 
ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, 
INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF 
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE
THE MDL MATERIALS OR FROM OTHER DEALINGS IN THE MDL MATERIALS.
*/

mdl 1.4;
import ::df::*;
import ::base::*;
import ::math::*;
import ::anno::*;
import ::tex::*;
import ::nvidia::core_definitions::dimension;


const string COPYRIGHT = 
" Copyright 2024 NVIDIA Corporation. All rights reserved.\n"
" MDL MATERIALS ARE PROVIDED PURSUANT TO AN END USER LICENSE  AGREEMENT,\n"
" WHICH WAS ACCEPTED IN ORDER TO GAIN ACCESS TO THIS FILE.  IN PARTICULAR,\n" 
" THE MDL MATERIALS ARE PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n"
" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF\n"
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF\n" 
" COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL NVIDIA\n"
" CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY\n"
" GENERAL, SPECIAL,  INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN\n"
" AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR\n"
" INABILITY TO USE THE MDL MATERIALS OR FROM OTHER DEALINGS IN THE MDL MATERIALS.\n";


uniform float4x4 rotation_translation_scale(
    uniform float3 rotation = float3(0.)
        [[ ::anno::description("Rotation applied to every UVW coordinate.") ]],
    uniform float3 translation = float3(0.)
        [[ ::anno::description("Offset applied to every UVW coordinate.") ]],
    uniform float3 scaling = float3(1.)
        [[ ::anno::description("Scale applied to every UVW coordinate.") ]]
)
[[
    ::anno::description("Construct transformation matrix from Euler rotation, translation and scale."),
    ::anno::hidden()
]]
{
    float4x4 scale =
        float4x4(scaling.x        , 0.               , 0.               , 0.,
                 0.               , scaling.y        , 0.               , 0.,
                 0.               , 0.               , scaling.z        , 0.,
                 translation.x, translation.y, translation.z, 1.);

    float3 s = ::math::sin(rotation);
    float3 c = ::math::cos(rotation);
    float4x4 rotate =
        float4x4(  c.y*c.z ,  -c.x*s.z + s.x*s.y*c.z ,  s.x*s.z + c.x*s.y*c.z , 0.0,
                   c.y*s.z ,   c.x*c.z + s.x*s.y*s.z , -s.x*c.z + c.x*s.y*s.z , 0.0,
                  -s.y     ,   s.x*c.y               ,  c.x*c.y               , 0.0,
                   0.     ,   0                   ,  0                   , 1.);

    return   scale*rotate;
}


export material Cardboard(
	// Appearance Group
    float brightness = .6f
    [[
        ::anno::display_name("Cardboard Brightness"),
        ::anno::description("Brightness of the cardboard."),
        ::anno::hard_range(0.0f,1.f),
		::anno::in_group("Appearance")
    ]],
    float reflectivity = .35f
    [[
        ::anno::display_name("Reflection weight"),
        ::anno::description("Strength of cardboard reflectivity."),
        ::anno::hard_range(0.0f,1.f),
		::anno::in_group("Appearance")
    ]],
    uniform float bump_amount = 0.3f
    [[
        ::anno::display_name("Bumps"),
        ::anno::description("Attach bump or normal maps here."),
		::anno::hard_range(0.0f,1.f),
		::anno::in_group("Appearance")
    ]],
	
	// Adjustments Group
	uniform float2 texture_translate =  float2(0.0f)
	[[
		::anno::display_name("Translate"),
		::anno::description("Controls the position of the texture."),
		::anno::in_group("Adjustments")
	]],
	uniform float texture_rotate =  0.f
	[[
		::anno::display_name("Rotate"),
		::anno::description("Rotates angle of the texture in degrees."),
		::anno::in_group("Adjustments")
	]],
	uniform float2 texture_scale =  float2(1.0f)
	[[
		::anno::display_name("Scale"),
		::anno::description("Larger numbers increase the size."),
		::nvidia::core_definitions::dimension(float2(1.0f, 1.0f)),
		::anno::in_group("Adjustments")
	]],
	
	//-----------------------Advanced----------------------------------
	uniform int uv_space_index =  0
	[[
		::anno::display_name("UV Space Index"),
		::anno::description("UV Space Index."),
		::anno::in_group("Advanced"),
		::anno::hard_range(0, 3)
	]]
)
[[
    ::anno::author("NVIDIA vMaterials"),
    ::anno::display_name("Cardboard New"),
    ::anno::description("A cardboard material."),
	::anno::created(2019, 5, 5, ""),
    ::anno::key_words(string[]("paper", "cardboard", "box", "mailbox", "carton", "card", "new")),
	::anno::thumbnail("./.thumbs/Cardboard.Cardboard.png"),
    ::anno::copyright_notice(COPYRIGHT)
]]
 = let{
	uniform texture_2d diffuse_texture = texture_2d("./textures/cardboard_new_01_diff.jpg", ::tex::gamma_srgb);
	uniform texture_2d roughness_texture = texture_2d("./textures/cardboard_new_01_rough.jpg", ::tex::gamma_srgb);
	uniform texture_2d normal_texture = texture_2d("./textures/cardboard_new_01_norm.jpg", ::tex::gamma_linear);	
	
	::base::texture_coordinate_info uvw = ::base::coordinate_source(
								coordinate_system: ::base::texture_coordinate_uvw,
								texture_space: uv_space_index
	);
	
	::base::texture_coordinate_info  transformed_uvw =  ::base::transform_coordinate(
								transform: rotation_translation_scale(
									scaling: float3(2.5f/texture_scale.x, 2.5f/texture_scale.y, 1.0),
									rotation: float3(0.0, 0.0, texture_rotate/180.*::math::PI ),
									translation: float3(texture_translate.x, texture_translate.y, 0.0)
								),
								coordinate: uvw
	);
	
	float roughness_lookup = ::base::file_texture(
							texture: roughness_texture,
							color_offset: color(0.0, 0.0, 0.0),
							color_scale: color(1.0, 1.0, 1.0),
							mono_source: ::base::mono_average,
							uvw: transformed_uvw,
							clip: false		
	).mono;
	
	color diffuse_lookup = ::base::file_texture(
							texture: diffuse_texture,
							color_offset: color(0.0, 0.0, 0.0),
							color_scale: color(brightness),
							mono_source: ::base::mono_average,
							uvw: transformed_uvw,
							clip: false		
	).tint;
	
	// Normal lookup
	float3 the_normal = ::base::tangent_space_normal_texture(
											texture: 		normal_texture,
											factor:         bump_amount,
											uvw:            transformed_uvw,
											flip_tangent_u: false,
											flip_tangent_v: false
	);
	
	bsdf diffuse_bsdf = ::df::diffuse_reflection_bsdf(
							roughness: 0.0,
							tint: diffuse_lookup
    );

    bsdf glossy_bsdf = ::df::microfacet_ggx_smith_bsdf(
        mode: ::df::scatter_reflect,
        tint: color(1.),
        roughness_u: roughness_lookup,
        roughness_v: roughness_lookup
    );
	
	bsdf custom_curve_layer_bsdf = ::df::custom_curve_layer(
		normal_reflectivity: 0.08 * reflectivity,		
		grazing_reflectivity: 1.0,
		exponent:	5.0,
		weight:		1.0,
		layer: 		glossy_bsdf,
		base:		diffuse_bsdf
	);
	
} 
in material(
    thin_walled: true,
	surface: material_surface(
		scattering: custom_curve_layer_bsdf
	),
	geometry: material_geometry(
		normal: the_normal
	)
);


export material Cardboard_Worn(
    float brightness = .6
    [[
        ::anno::display_name("Cardboard Brightness"),
        ::anno::hard_range(0.0,1.),
        ::anno::description("Brightness of the cardboard.")
    ]],
	float reflectivity = 0.6
    [[
        ::anno::display_name("Cardboard Reflectivity"),
        ::anno::hard_range(0.0, 1.0),
        ::anno::description("Strength of cardboard reflectivity.")
    ]],
    uniform float bump_amount = 0.3
    [[
        ::anno::display_name("Bump Amount"),
        ::anno::description("The intensity of the cardboard bumpmap.")
    ]],
	
	// Adjustments Group
	uniform float2 texture_translate =  float2(0.0f)
	[[
		::anno::display_name("Translate"),
		::anno::description("Controls the position of the texture."),
		::anno::in_group("Adjustments")
	]],
	uniform float texture_rotate =  0.f
	[[
		::anno::display_name("Rotate"),
		::anno::description("Rotates angle of the texture in degrees."),
		::anno::in_group("Adjustments")
	]],
	uniform float2 texture_scale =  float2(1.0f)
	[[
		::anno::display_name("Scale"),
		::anno::description("Larger numbers increase the size."),
		::anno::in_group("Adjustments"),
		::nvidia::core_definitions::dimension(float3(1.0f, 1.0f, 1.0f))
	]],
	
	//-----------------------Advanced----------------------------------
	uniform int uv_space_index =  0
	[[
		::anno::display_name("UV Space Index"),
		::anno::description("UV Space Index."),
		::anno::in_group("Advanced"),
		::anno::soft_range(0, 3)
	]]
)
[[
    ::anno::author("NVIDIA vMaterials"),
    ::anno::display_name("Cardboard Worn"),
    ::anno::description("A worn cardboard material."),
	::anno::created(2019, 5, 5, ""),
    ::anno::key_words(string[]("paper", "cardboard", "box", "mailbox", "carton", "card", "used", "worn", "dirty")),
	::anno::thumbnail("./.thumbs/Cardboard.Cardboard_Worn.png"),
    ::anno::copyright_notice(COPYRIGHT)
]]
 = let{
	uniform float ior = 1.4;
	
	uniform texture_2d diffuse_texture = texture_2d("./textures/cardboard_worn_01_diff.jpg", ::tex::gamma_srgb);
	uniform texture_2d roughness_texture = texture_2d("./textures/cardboard_worn_01_rough.jpg", ::tex::gamma_srgb);
	uniform texture_2d normal_texture = texture_2d("./textures/cardboard_worn_01_norm.jpg", ::tex::gamma_linear);	
	
	::base::texture_coordinate_info uvw = ::base::coordinate_source(
								coordinate_system: ::base::texture_coordinate_uvw,
								texture_space: uv_space_index
	);
	
	::base::texture_coordinate_info  transformed_uvw =  ::base::transform_coordinate(
								transform: rotation_translation_scale(
									scaling: float3(2.5f/texture_scale.x, 2.5f/texture_scale.y, 1.0),
									rotation: float3(0.0, 0.0, texture_rotate/180.*::math::PI ),
									translation: float3(texture_translate.x, texture_translate.y, 0.0)
								),
								coordinate: uvw
	);
	
	float roughness_lookup = ::base::file_texture(
							texture: roughness_texture,
							color_offset: color(0.0, 0.0, 0.0),
							color_scale: color(1.0, 1.0, 1.0),
							mono_source: ::base::mono_average,
							uvw: transformed_uvw,
							clip: false		
	).mono;
	
	color diffuse_lookup = ::base::file_texture(
							texture: diffuse_texture,
							color_offset: color(0.0, 0.0, 0.0),
							color_scale: color(brightness),
							mono_source: ::base::mono_average,
							uvw: transformed_uvw,
							clip: false		
	).tint;
	
	// Normal lookup
	float3 the_normal = ::base::tangent_space_normal_texture(
											texture: 		normal_texture,
											factor:         bump_amount,
											uvw:            transformed_uvw,
											flip_tangent_u: false,
											flip_tangent_v: false
	);
	

    bsdf glossy_bsdf = ::df::simple_glossy_bsdf(
        mode: ::df::scatter_reflect,
        tint: color(1.),
        roughness_u: roughness_lookup,
        roughness_v: roughness_lookup
    );
	
} 
in material(
    thin_walled: true,
    surface: material_surface(
        scattering: ::df::weighted_layer(
            weight: 1.,
            normal: the_normal,
            layer: ::df::fresnel_layer(
                ior: ior,
                weight: reflectivity,
                layer: glossy_bsdf,
                base: ::df::diffuse_reflection_bsdf(
                    roughness: 0.0,
                    tint: diffuse_lookup
                ),
                normal: the_normal
            )
        )
    )
);