Notifications
Clear all

[Closed] Problems extending the DX9 Material

I try to extend the DX9 Material.

The Idea ist to get an UI with Buttons and Fields for customizing a shader.

Works so far (Refraction etc. works fine with delegate …), but i got Problems with delegating the Bitmaps.


  try 
  (
  	plugin Material YDDX9
  	name:"ydShader"
  	classID:#(0x7f24579e, 0x5caf6eb9)
  	extends:DirectX_9_Shader
  	replaceUI:true
  	version:1
  	(
  		parameters main rollout:params 	(
 			FXFile type:#string default:"C:\Material\Material.fx" ui:FXFile
  			ShaderID type:#integer ui:shadID
  			g_DiffuseTexture type:#BitMap 
  			g_NormalTexture type:#BitMap
 			g_SpecularPower type:#float default:9.0 ui:g_SpecularPower
 			g_DisplacementFactor type:#float default:0.005 ui:g_DisplacementFactor
 			g_RefractionIndex type:#float default:0.15 ui:g_RefractionIndex
  			AlphaBlend type:#integer default:0 ui:AlphaBlend
  			AlphaTest type:#integer default:0 ui:AlphaTest
  			AlphaTestRef type:#integer default:127 ui:AlphaTestRef
  			g_SpecularLUTexture type:#BitMap
  			
  			on ShaderID set val do (
  				try ( 
 					delegate.ShaderID = val 
 		 		Y_Log_Info ("DX9 Extend: parameter: delegate ShaderID")
  				) catch (
 		 		Y_Log_Error ("DX9 Extend: parameter: delegate ShaderID " + getCurrentException())
  				)
  			)
  			
  			on FXFile set val do (
  				try ( 
 					delegate.effectfile = val
 		 		Y_Log_Info ("DX9 Extend: parameter: delegate fxfile") 
  				) catch (
 		 		Y_Log_Error ("DX9 Extend: parameter: delegate fxfile " + getCurrentException())
  				)
  			)	
  			
  			on g_SpecularPower set val do (
  				try ( 
 					delegate.g_SpecularPower = val
 		 		Y_Log_Info ("DX9 Extend: parameter: delegate SpecularPower") 
  				) catch (
 		 		Y_Log_Error ("DX9 Extend: parameter: delegate SpecularPower " + getCurrentException())
  				)
  			)
  			
  			on g_DisplacementFactor set val do (
  				try ( 
 		 		delegate.g_DisplacementFactor = val
 		 		Y_Log_Info ("DX9 Extend: parameter: delegate DisplacementFactor") 
  				) catch (
 		 		Y_Log_Error ("DX9 Extend: parameter: delegate DisplacementFactor " + getCurrentException())
  				)
  			)
  			
  			on g_RefractionIndex set val do (
  				try ( 
 					delegate.g_RefractionIndex = val
 		 		Y_Log_Info ("DX9 Extend: parameter: delegate RefractionIndex") 
  				) catch (
 		 		Y_Log_Error ("DX9 Extend: parameter: delegate RefractionIndex " + getCurrentException())
  				)
  			)
  			
  			on AlphaBlend set val do (
  				try ( 
 					delegate.AlphaBlend = val
 		 		Y_Log_Info ("DX9 Extend: parameter: delegate AlphaBlend") 
  				) catch (
 		 		Y_Log_Error ("DX9 Extend: parameter: delegate AlphaBlend " + getCurrentException())
  				)
  			)
  			
  			on AlphaTest set val do (
  				try ( 
 					delegate.AlphaTest = val
 		 		Y_Log_Info ("DX9 Extend: parameter: delegate AlphaTest") 
  				) catch (
 		 		Y_Log_Error ("DX9 Extend: parameter: delegate AlphaTest " + getCurrentException())
  				)
  			)
  			
  			on AlphaTestRef set val do (
  				try ( 
 					delegate.AlphaTestRef = val
 		 		Y_Log_Info ("DX9 Extend: parameter: delegate AlphaTestRef") 
  				) catch (
 		 		Y_Log_Error ("DX9 Extend: parameter: delegate AlphaTestRef " + getCurrentException())
  				)
  			)
  			
  			
  			/*
  			on g_DiffuseTexture set val do (
  				try ( 
 					delegate.g_DiffuseTexture = val
 		 		Y_Log_Info ("DX9 Extend: parameter: delegate diffuse") 
  				) catch (
 		 		Y_Log_Error ("DX9 Extend: parameter: delegate diffuse " + getCurrentException())
  				)
  
  			)
  			
  			on g_NormalTexture set val do (
  				try ( 
 					delegate.g_NormalTexture = val
 		 		Y_Log_Info ("DX9 Extend: parameter: delegate normal")
  				) catch (
 		 		Y_Log_Error ("DX9 Extend: parameter: delegate normal " + getCurrentException())
  				)
  			)
  			*/
  				
  		)
  		
  		rollout params "YD Parameters"	(
 			label 		shadIDl 	"Shader ID"	pos:[10,10] 	width:140 height:20
 		 spinner		shadID 	""		pos:[260,10] 	width:60 height:20 type:#integer
 			editText 	FXFile	 ""		pos:[150,30] width:170 height:20
 			button 		setFXFile 	"FX File"	pos:[10,30]	width:90 height:27 toolTip:"Choose the FX File for current Shader"
  			
 		 button		setDiffuse 	"Set Diffuse" 	pos:[10,60] 	width:90 height:27 toolTip:"Choose the Diffuse Map for current Shader"
 			imgTag 		DiffMap ""		pos:[10,100] width:128 height:128
 		 editText	DiffName ""		pos:[10,240] width:120 height:20
 		 button		showDiff "Show"	 pos:[10,270]	width:100 height:20
  			
  			
 			button 		setNormal 	"Set Normal"	 pos:[230,60] 	width:90 height:27 toolTip:"Choose the Normal Map for current Shader"
 			imgTag 		NormMap 	""	 pos:[190,100] 	width:128 height:128
 		 editText	NormName ""		pos:[190,240] 	width:120 height:20
 		 button		showNorm "Show"	 pos:[190,270]	width:100 height:20
  			
 		 slider	 g_SpecularPower	"Specular" pos:[10,300]	width:300 height:20 type:#float 
 		 slider	 g_DisplacementFactor	"Displacement" 	pos:[10,350]	width:300 height:20 type:#float
 		 slider	 g_RefractionIndex	"Refraction" pos:[10,400]	width:300 height:20 type:#float
 		 slider	 AlphaBlend	"Alpha Blend" pos:[10,450]	width:300 height:20 type:#integer
 		 slider		AlphaTest "Alpha Key" 	pos:[10,500]	width:300 height:20 type:#integer
 		 slider	 AlphaTestRef	"Alpha Key Ref" pos:[10,550]	width:300 height:20 type:#integer
 			button 		reloadFX "Reload FX"	pos:[10,600] 	width:170 height:30 toolTip:"Reload the current Shader"
  			
 			-- on open set technique to 0 (Shader 1.1)		
  			on params open do (
 				shadID.value = delegate.ShaderID
  				sRootFolder = GetDir #maxroot
  				oSpecLUTex = BitMapTexture()
 		 	oSpecLUTex.filename = sRootFolder + "maps/difspeclut.dds"
 				delegate.g_SpecularLUTexture = oSpecLUTex.bitmap 
  				delegate.technique = 0
  				print delegate.technique
  					
  			)
  			
  			--spinner picker buttons
  			on setFXFile pressed do (
  				try (
 					FXFile.text = getOpenFileName()
  				) catch (
 		 		 Y_Log_Error ("DX9 Extend: setting FXFile " + getCurrentException())
  				)
  			)
  			
  			on setDiffuse pressed do (
  				try (
 					DiffTex = selectBitmap()
 					if DiffTex != undefined then (
 		 			DiffMap.bitmap = DiffTex
 		 			DiffName.text = DiffTex.filename
 		 		 delegate.g_DiffuseTexture = DiffTex
 		 			Y_Log_Info ("DX9 Extend: set the diffuse texture: " + DiffTex.filename)
  					)
  				) catch (
 		 		Y_Log_Error ("DX9 Extend: set the diffuse texture: " + getCurrentException())
  				)
  			)
  			
  			on showDiff pressed do (
  				try (
  		    	    delegate.g_DiffuseTexture.viewImage()
 					--DiffTex.viewImage()
  				) catch (
 		 		Y_Log_Error ("DX9 Extend: show the diffuse texture: " + getCurrentException())	
  				)
  					
  			)
  			
  			on setNormal pressed do (
  				try (
 					NormTex = selectBitmap()
 					if NormTex != undefined then (
 		 			NormMap.bitmap = NormTex
 		 			NormName.Text = NormTex.filename
 		 			Y_Log_Info ("DX9 Extend: set the diffuse texture: " + NormTex.filename)
  					)
  				) catch (
 		 		Y_Log_Error ("DX9 Extend: set the normal texture: " + getCurrentException())
  				)
  			)
  			
  			on showNorm pressed do (
  				try (
 					NormTex.viewImage()
  				) catch (
 		 		Y_Log_Error ("DX9 Extend: show the normal texture: " + getCurrentException()) 	
  				)
  					
  			)
  			
  			on reloadFX pressed do (
  				try (
 					delegate.reloadeffect()
 		 		Y_Log_Info ("DX9 Extend: Reload Effect ")
  				)
  				catch (
 		 		Y_Log_Error ("DX9 Extend: Reload Effect: " + getCurrentException())	
  				)
 		 )		 	
  		)	--end rollout
  	)	--end plugin
  )
  catch (
  	 Y_Log_Error ("DX9 Extend: " + getCurrentException())
  )
  

Somebody with experience in delegating bitmaps in an extending PlugIn ???

8 Replies

Ok the delegating of the bitmaps seems to work …
but the scene has a wrong lighting. so i hope to fix it

the problem is the shader wants a float4 light direction, max originaly set light dir by index (all lights in the scene enumerated).

Are you making your material for manipulating shader parameters?

If you define your .fx file with proper semantics, the DX9 shader will expose those controls in the rollout. That is the beauty of it. If you can find it, try to get notes or slides from some of the GDC talks this year. The one by Neil Hazzard and Adam Pletcher of Volition talked about this particular subject.

I work right next to Adam, so if you have any questions, I can probably answer them.

You can only have 1 light in Max affecting DX9 materials. We have noticed that lighting seems to get out of sync with the shader, so we wrote a tool that loops through the shader materials and forces a update of the textures.

If you can give more specifics to your problem, I can probably help more.

The bitmap delegation works fine now. i had a problem with delegate them in the parameters main block with on set val (because i had problems to set a ui element for the bitmaps that works correctly). Now i delegate it in Rollout Params in a on pressed button block directly. The lighting is ok, only problem is if i add lights, i don’t know how to update the material, so i can choose the new light for lighting.
before the parameters main block i do


 objectsarray = lights
 					aLights = #()
 					aLights[1] = "DefaultLight"
 					j=2
 					for oItem in objectsarray do (
 		    			if (superClassOf oItem == Light) do (
 		    		    	aLights[j] = oItem.name
 		    		    	j = j +1
 						)
 					)
 

The array is complete but i don’t know how to update the light dropdownlist.
if i change the active material in the material editor two times, i got the new added lights in my dropdownlist.

What we do is loop through the scene materials and force the .delegate.lightpos of each material to point to the selected light in the scene. Try doing that and see if it helps.

Thanks i will try it soon as possible …

Holy shit, i got a problem: i cannot load scenes containing the new material … i hope i can fix it … . max crashes with “An Error occured … blah blah message …” possible a mem leak (the viewport borders are drawed, the scene not. Then a few seconds nothing and then the crash …) mhm i will see …

hi,

Could You show how did You do bitmap delegate?
I’v created very similar material,and and exporter (Panda exporter) exports texture filename not correctly if slot is empty.

ragards
Artur

you can look in the first post, there i post my complete source