©Anton Podvalny

Table of Contents

Introduction


In this chapter we'll cover important utility about texturing - UVW coordinate generators, or for short - UVWGens. Generally the UVW data is stored in the geometry, in GeomStaticMesh::map_channels. It has the following format:

# map_channels describe the UVW coordinates used to map a texture to the geometry surface.
geometry.map_channels = [
	[
		# channel index
		1,
		# List of UVW coordinates.
		# The W coordinate has to be set (0.0 in this case) even when performing 2D texturing.
		vray.VectorList(
			vray.Vector(0.0, 0.0, 0.0),
			vray.Vector(0.0, 1.0, 0.0),
			vray.Vector(1.0, 0.0, 0.0),
			vray.Vector(1.0, 1.0, 0.0)
		),
		# List of indices from the UVW list. 
		# Each three consecutive indices are used for a single triangle.
		# They correspond directly to the vertex indices in the 'faces' array.
		vray.IntList(
			2, 0, 1,
			1, 3, 2,
			2, 0, 1,
			1, 3, 2,
			2, 0, 1,
			1, 3, 2,
			2, 0, 1,
			1, 3, 2,
			2, 0, 1,
			1, 3, 2,
			2, 0, 1,
			1, 3, 2
		)
	]
]
// The W coordinate has to be set (0.0 in this case) even when performing 2D texturing.
Vector uvwCoords[] = {
	Vector(0.0, 0.0, 0.0),
	Vector(0.0, 1.0, 0.0),
	Vector(1.0, 0.0, 0.0),
	Vector(1.0, 1.0, 0.0)
};
// Each three consecutive indices are used for one triangle. 
// They correspond directly to the vertex indices in the 'faces' array.
int uvwIndices[] = {
	2, 0, 1,
	1, 3, 2,
	2, 0, 1,
	1, 3, 2,
	2, 0, 1,
	1, 3, 2,
	2, 0, 1,
	1, 3, 2,
	2, 0, 1,
	1, 3, 2,
	2, 0, 1,
	1, 3, 2
};
ValueList list;
list.push_back(Value(1));             // channel index
list.push_back(Value(uvwCoords));     // list of UVW coordinates
list.push_back(Value(uvwIndices));    // list of indices from the UVW list
// map_channels describe the UVW coordinates used to map a texture to the geometry surface
ValueList channels;
channels.push_back(Value(list));
geometry.set_map_channels(channels);
List<object> channels = new List<object>();
channels.Add(new List<object> {
	// Channel index.
	1,
	// List of UVW coordinates.
	// The W coordinate has to be set (0.0 in this case) even when performing 2D texturing.
	new Vector[] {
		new Vector(0.0, 0.0, 0.0),
		new Vector(0.0, 1.0, 0.0),
		new Vector(1.0, 0.0, 0.0),
		new Vector(1.0, 1.0, 0.0)
	},
	// List of indices from the UVW list. 
	// Each three consecutive indices are used for one triangle.
	// They correspond directly to the vertex indices in the 'faces' array.
	new int[] {
		2, 0, 1,
		1, 3, 2,
		2, 0, 1,
		1, 3, 2,
		2, 0, 1,
		1, 3, 2,
		2, 0, 1,
		1, 3, 2,
		2, 0, 1,
		1, 3, 2,
		2, 0, 1,
		1, 3, 2
	}
});
// MapChannels describe the UVW coordinates used to map a texture to the geometry surface.
geometry.MapChannels = channels;
// The W coordinate has to be set (0.0 in this case) even when performing 2D texturing.	
var uvwCoords = vray.VectorList(
	vray.Vector(0.0, 0.0, 0.0),
	vray.Vector(0.0, 1.0, 0.0),
	vray.Vector(1.0, 0.0, 0.0),
	vray.Vector(1.0, 1.0, 0.0)
);
// Each three consecutive indices are used for one triangle. 
// They correspond directly to the vertex indices in the 'faces' array.
var uvwIndices = vray.IntList(
	2, 0, 1,
	1, 3, 2,
	2, 0, 1,
	1, 3, 2,
	2, 0, 1,
	1, 3, 2,
	2, 0, 1,
	1, 3, 2,
	2, 0, 1,
	1, 3, 2,
	2, 0, 1,
	1, 3, 2
);	
var map_channel = vray.List();
map_channel.push(1);             // channel index
map_channel.push(uvwCoords);     // list of UVW coordinates
map_channel.push(uvwIndices);    // list of indices from the UVW list
// map_channels describe the UVW coordinates used to map a texture to the geometry surface.
var channels = vray.List();
channels.push(map_channel);
geometry.map_channels = channels;

UVWGenChannel


Modifier for UVW data coming from the geometry source. The main parameter is uvw_channel - the index of the mapping channel data to use (i.e. GeomStaticMesh::map_channels). The default is 1 as in 3dsMax where indexing starts from 1, but in your application this may be 0 or something else. If you set an index of -1 V-Ray will take the first available channel. This plugin also has transform, wrap and crop parameters as well as the option to get UVW data from another UVWGen plugin.

Parameters

  • uvw_transform - Initial transformation on the uvw coordinates, before mirror, crop etc
  • uvw_transform_tex - Same as uvw_transform, but receives texture with transformations.
  • tex_transform - Final transformation on the resulting uvw coordinates, after mirror, crop etc
  • nsamples - Number of uvw transform samples
  • wrap_u/v/w - 0 - no wrapping, 1 - wrap, 2 - mirror tile
  • crop_u/v/w - 1 to crop in the u/v/w-direction
  • coverage - Coverage
  • uvw_coords - The uvw coordinates for the specified channel at the current shading point
  • wrap_mode - Wrap mode (0 - wrap on 0.5 boundary; 1 - wrap on integer boundary)
  • duvw_scale - Additional scale factor for the texture derivatives
  • uvw_channel - Described above
  • uvwgen - Optional UVWGen from which the initial uvw coordinates will be taken, instead of the surface point
  • use_double_sided_mode - If this is true then we will use uvw_channel for front-side and uvw_channel + 1 for back-side contexts. This is primarily for V-Ray for SketchUp.

Examples

With the help of TexUVW we can visualize the different UVW spaces we can create using the UVW generators. Here's the code we use:

# Create a new UVWGenChannel
UVWGen = renderer.classes.UVWGenChannel()
 
# Create a new TexUVW. It allows displaying of UVW space as RGB
uvwTex = renderer.classes.TexUVW()
uvwTex.uvwgen = UVWGen
// Create a new UVWGenChannel
UVWGenChannel UVWGen = renderer.newPlugin<UVWGenChannel>();
 
// Create a new TexUVW. It allows displaying of UVW space as RGB
TexUVW uvwTex = renderer.newPlugin<TexUVW>();
uvwTex.set_uvwgen(UVWGen);
// Create a new UVWGenChannel
UVWGenChannel UVWGen = renderer.NewPlugin<UVWGenChannel>();
 
// Create a new TexUVW. It allows displaying of UVW space as RGB
TexUVW uvwTex = renderer.NewPlugin<TexUVW>();
uvwTex.Uvwgen = UVWGen;
// Create a new UVWGenChannel
var UVWGen = renderer.classes.UVWGenChannel();
 
// Create a new TexUVW. It allows displaying of UVW space as RGB
var uvwTex = renderer.classes.TexUVW();
uvwTex.uvwgen = UVWGen;

UVWGenEnvironment


Used to map spherical, cube, etc. textures on the environment color slot or on dome lights.

Parameters

  • uvw_matrix - Transformation of the input directions
  • uvw_transform - Transformation of the resulting UVW coordinates
  • mapping_type - One of "angular", "cubic", "spherical", "mirror_ball", "screen", "max_spherical", "spherical_vray", "max_cylindrical" or "max_shrink_wrap"
  • wrap_u/v/w - 0 - no wrapping, 1 - wrap, 2 - mirror tile
  • crop_u/v/w - 1 to crop in the u/v/w-direction
  • duvw_scale - Additional scale factor for the texture derivatives
  • ground_on -
  • ground_position - Normal vector of the ground plane
  • ground_radius - Radius of the ground circle

 

Example

In this example we'll create a textured dome light with spherical mapping of the UVWGen:

# The UVWGenEnvironment allows spherical, cube, etc. textures to be mapped on the environment color slot or dome lights.
uvwgen = renderer.classes.UVWGenEnvironment()
# Specify the type and shape of the texture.
uvwgen.mapping_type = 'spherical'
# Specify transformation of the input directions.
uvwgen.uvw_matrix = vray.Matrix( vray.Vector(1, 0, 0), vray.Vector(0, 0, 1), vray.Vector(0, -1, 0))
uvwgen.ground_on = 1

bitmap = renderer.classes.BitmapBuffer()
# unlike JPG files, HDR files are linear
bitmap.transfer_function = 0
bitmap.file = os.path.join(SCENE_PATH, 'assets', 'Sea_D.hdr')

texture = renderer.classes.TexBitmap()
# Specify UVW generator for the texture.
texture.uvwgen = uvwgen
# Specify the bitmap that the texture will be using.
texture.bitmap = bitmap

light = renderer.classes.LightDome()
# Switches between a hemispherical or (full) spherical shape of the light.
# Possible values are: True (Sphere), False (Hemisphere)
light.dome_spherical = True
# Specify the light texture.
light.dome_tex = texture
# Enable the use of a light texture.
# If "use_dome_tex = False" the 'color' of the light will be used instead.
light.use_dome_tex = True
// The UVWGenEnvironment allows spherical, cube, etc. textures to be mapped on the environment color slot or dome lights.
UVWGenEnvironment uvwgen = renderer.newPlugin<UVWGenEnvironment>();
// Specify the type and shape of the texture.
uvwgen.set_mapping_type("spherical");
// Specify transformation of the input directions.
uvwgen.set_uvw_matrix( Matrix( Vector(1.0, 0.0, 0.0), Vector(0.0, 0.0, 1.0), Vector(0.0, -1.0, 0.0)));
uvwgen.set_ground_on(1);

BitmapBuffer bitmap = renderer.newPlugin<BitmapBuffer>();
// unlike JPG files, HDR files are linear
bitmap.set_transfer_function(0);
bitmap.set_file("assets" PATH_DELIMITER "Sea_D.hdr");

TexBitmap texture = renderer.newPlugin<TexBitmap>();
// Specify UVW generator for the texture.
texture.set_uvwgen(uvwgen);
// Specify the bitmap that the texture will be using.
texture.set_bitmap(bitmap);

LightDome light = renderer.newPlugin<LightDome>();
// Switches between a hemispherical or (full) spherical shape of the light.
// Possible values are: true (Sphere), false (Hemisphere) - default
light.set_dome_spherical(true);
// Specify the light texture.
light.set_dome_tex(texture);
// Enable the use of a light texture.
// If "use_dome_tex = false" the 'color' of the light will be used instead.
light.set_use_dome_tex(true);
// The UVWGenEnvironment allows spherical, cube, etc. textures to be mapped on the environment color slot or dome lights.
UVWGenEnvironment uvwgen = renderer.NewPlugin<UVWGenEnvironment>();
// Specify the type and shape of the texture.
uvwgen.MappingType = "spherical";
// Specify transformation of the input directions.
uvwgen.UvwMatrix = new Matrix( new Vector(1, 0, 0), new Vector(0, 0, 1), new Vector(0, -1, 0));
uvwgen.GroundOn = 1;

BitmapBuffer bitmap = renderer.NewPlugin<BitmapBuffer>();
// unlike JPG files, HDR files are linear
bitmap.TransferFunction = 0;
bitmap.File = Path.Combine("assets", "Sea_D.hdr");

TexBitmap texture = renderer.NewPlugin<TexBitmap>();
// Specify UVW generator for the texture.
texture.Uvwgen = uvwgen;
// Specify the bitmap that the texture will be using.
texture.Bitmap = bitmap;

LightDome light = renderer.NewPlugin<LightDome>();
// Switches between a hemispherical or (full) spherical shape of the light.
// Possible values are: true (Sphere), false (Hemisphere)
light.DomeSpherical = true;
// Specify the light texture.
light.DomeTex = texture;
// Enable the use of a light texture.
// If "use_dome_tex = False" the 'color' of the light will be used instead.
light.UseDomeTex = true;
// The UVWGenEnvironment allows spherical, cube, etc. textures to be mapped on the environment color slot or dome lights.
var uvwgen = renderer.classes.UVWGenEnvironment();
// Specify transformation of the input directions.
uvwgen.uvw_matrix = vray.Matrix( vray.Vector(1, 0, 0), vray.Vector(0, 0, 1), vray.Vector(0, -1, 0));
// Specify the type and shape of the texture.
uvwgen.mapping_type = "spherical";
uvwgen.ground_on = 1;

var bitmap = renderer.classes.BitmapBuffer();
// unlike JPG files, HDR files are linear
bitmap.transfer_function = 0;
bitmap.file = path.join(SCENE_PATH, "assets", "Sea_D.hdr");

var texture = renderer.classes.TexBitmap();
// Specify UVW generator for the texture.
texture.uvwgen = uvwgen;
// Specify the bitmap that the texture will be using.
texture.bitmap = bitmap;

var light = renderer.classes.LightDome();
// Switches between a hemispherical or (full) spherical shape of the light.
// Possible values are: true (Sphere), false (Hemisphere)
light.dome_spherical = true;
// Specify the light texture.
light.dome_tex = texture;
// Enable the use of a light texture.
// If "use_dome_tex = false" the 'color' of the light will be used instead.
light.use_dome_tex = true;

UVWGenExplicit


Define explicit UVW data from a texture.

Parameters

  • u - the U input of floats
  • v - the V input of floats
  • w - the W input of floats
  • uvw - input as UVW texture

 

UVWGenMayaPlace2dTexture


Similar to UVWGenChannel, but with more options.

Parameters

  • uvw_channel_tex - Used when more than one mesh has UV linking specified for this 2d placement. If present will override uvw_channel.
  • uvwgen - Optional UVWGen from which the initial uvw coordinates will be taken, instead of the surface point
  • nsamples - The number of parameter samples to take for motion blur. 0 means the global value. 1 means motion blur should be disabled for this plugin.
  • uv_set_name - The name of the uv channel that should be used.

 

UVWGenObject


This generator transforms world-space coordinates into object space.

Parameters

  • uvw_transform - Initial transformation on the uvw coordinates
  • duvw_scale - Additional scale factor for the texture derivatives


UVWGenPlanarWorld


This generator returns the UVW coordinates in world space.

Parameters

  • uvw_transform - Initial transformation on the uvw coordinates, before mirror, crop etc
  • uvw_transform_tex - TextureTransform
  • tex_transform - Final transformation on the resulting uvw coordinates, after mirror, crop etc
  • nsamples - Number of uvw transform samples
  • wrap_u/v/w - 0 - no wrapping, 1 - wrap, 2 - mirror tile
  • crop_u/v/w - 1 to crop in the u/v/w-direction
  • coverage - Coverage
  • uvw_coords - The uvw coordinates for the specified channel at the current shading point
  • wrap_mode - Wrap mode (0 - wrap on 0.5 boundary; 1 - wrap on integer boundary
  • duvw_scale - Additional scale factor for the texture derivatives
  • No labels
Was this helpful?