Tag Archives: real-time

Vray to Blender PBR/FBX

Im often exporting models from 3dsmax to Blender and this is a fast way to import the models so that the material is automatically converted and imported into Blender with PBR materials applied with correct default settings.

What does it do?

It takes a Vray Material with Roughness workflow, converts it to Standard (Legacy) material and is ready for export to FBX. You can extend on the script or modify it for your needs. This is the workflow:

Blender to GLB/GLTF for real-time:

A secondary benefit to this workflow is that once the file is imported into Blender as FBX it can be directly exported to GLB/GLTF for real-time workflow. If you want to include ambient occlusion you will have to do this manually for now. I might create a script in future, no promises on that one since its usually very simple with two additional nodes in the shader editor as shown in the Blender manual.

Converts:

  • Diffuse texture, Diffuse Color, VrayColor in Diffuse
  • Roughness texture
  • Metal texture
  • Opacity texture
  • Normal texture
  • Normal DirectX to OpenGL (3dsmax uses DirectX & Blender uses OpenGL, its done via naming convention – Optional)
  • Sets the correct Specular level for Blender
  • Sets Reflection to White
  • Sets Dielectric or Metallic material for Blender (depending on if Metal texture is used)
  • Sets Gamma settings for sRGB and Linear images
  • Can convert VrayMtl, Vray2SidedMtl, Multi-Material. You can edit the functions in the script to add more material types if you use them

Export Options in FBX:

Comparisons:

3dsmax Vray Roughess Material:

Standard (Legacy) Material – Converted with Script

Blender Principled BRDF Shader – Imported FBX (Automatic Settings)

3dsmax Script download:

https://github.com/jmdvella/VrayToFBX

3dsmax (.ms) Code:

/*
3dsmax to Blender FBX Material Converter 
jmdvella@gmail.com
2022
*/

macroscript VrayToFBX
	category:"Vella" 
	internalcategory:"Automate"
	tooltip:"Automate VrayToFBX"
	buttonText:"Vray To FBX"
	Icon:#("SchematicView",2)

(
	-- Function to replace Vray with Standard and setup PBR settings for FBX/Blender
	fn convert_to_stdmtl i =
	(
		-- Standard Settings for PBR export
		newMat = Standardmaterial ()
		newMat.name = i.name
		newMat.diffuse = i.diffuse
		newMat.bumpMapAmount = 100
		newMat.specularLevel = 25
		
		-- Replace VrayColor with Standard Diffuse Color
		if (classof i.texmap_diffuse == VrayColor) then
		(
			newMat.diffuse = i.texmap_diffuse.color
		)
		else
		-- Replace Diffuse texture with node in Diffuse slot
		(
			if i.texmap_diffuse != undefined then
			newMat.diffusemap = i.texmap_diffuse
		)
		
		-- Replace Roughness texture
		if i.texmap_reflectionGlossiness != undefined then
		(
			newMat.glossinessMap = i.texmap_reflectionGlossiness
		)
		
		-- Replace Metal texture
		if i.texmap_metalness == undefined then
		(
			newMat.reflectionMapEnable = on
			newMat.reflectionMapAmount = 0
		)
		else
		(
			newMat.reflectionMapEnable = on
			newMat.reflectionMap = i.texmap_metalness
		)
		
		-- Replace Opacity
		if i.texmap_opacity != undefined then
		(
			newMat.opacityMap = i.texmap_opacity
		)
		
		-- Replace Normal texture
		if i.texmap_bump != undefined then
		(
			newMat.bumpMap = i.texmap_bump.normal_map
		)
		
		-- Convert DirectX Normal texture to OpenGL (Optional) 	<--------------
		if i.texmap_bump != undefined then
		(
			i.texmap_bump.normal_map.filename = substituteString i.texmap_bump.normal_map.filename "DirectX" "OpenGL"
		)
		
		-- Convert Vray to Standard Mtl
		i = newMat

	)
	
	-- Function to replace VRay2SidedMtl with VrayMtl
	fn convert_Vray2Sided_to_VrayMtl i = 
	(
		newMat = i.frontMtl 
		
		-- Convert Vray to VrayMtl
		i = newMat
		
		-- Convert from VrayMtl to StandardMtl using convert_to_stdmtl Function
		convert_to_stdmtl i
	)
	
	-- Find all VRay2SidedMtl and replace with VrayMtl in the scene
	for i in sceneMaterials do
	(
		if (classof i == VRay2SidedMtl) do
		(
			p = convert_Vray2Sided_to_VrayMtl i
			
			if (i.name == p.name) and (i.name != undefined) do
			(
				replaceinstances i p
			)
		)
	)		
	
	-- Find all VrayMtls and VrayMtls in Multi-Sub in the scene
	for i in sceneMaterials do
	(
		-- Convert VrayMtl to StandardMtl using convert_to_stdmtl function
		if (classof i == VrayMtl) do 
		(
			p = convert_to_stdmtl i
			
			if (i.name == p.name) and (i.name != undefined) do
			(
				replaceinstances i p
			)
			
		)
		
		-- Find Multi-Sub Materials
		if (classof i == Multimaterial) do 
		(
			-- Convert VrayMtl to StandardMtl using convert_to_stdmtl function
			for n in i do
			(
				if (classof n == VrayMtl) do 
				(
					p = convert_to_stdmtl n
					
					if (n.name == p.name) and (n.name != undefined) do
					(
						replaceInstances n p
					)
					
				)	
			) 
		)
	)
			
	-- refresh asset tracker
	ATSOps.Refresh()
)