Trying to modify the script 'Show textures in viewport' for Redshift


#1

Hello Guys!

A newbie here… Haven’t done with scripting before.
Recentrly I started learning Redshift and some features don’t work as expected.
This is a free script from Spline Dynamics, which allows me to toggle Show shaded material in viewport with shortcut.
It worked well with other renderers such as V-ray, Corona, Fstorm but it didn’t work with Redshift so I was trying to edit the script.
The person who wrote this script allows people to modify the script as they desire!

I changed “Fstorm” to “redshift4max” and also changed “FStormBitmap” to “rsBitmap” and all of a sudden it started working for Redshift!

Now I can’t use this feature for Fstorm right…?
I don’t know how to make this for both Fstorm and Redshift…
You guys might think I’m dumb lol but I have changed like, “redshift3max or FStorm” and somehow it doesn’t work!
I would be appreciative if there’s anyone who can “add” Redshift using the same logic with the Fstorm codes…
Thank you for your time guys!

(
local state = false --this variable lives in the Macro and controls its checked state

fn showTexMap mat newState =
(
	if classof mat != Multimaterial then (
		if (classOf mat)==FStorm then (
			if (classOf mat.diffuse_tex)==FStormBitmap then showTexturemap mat mat.diffuse_tex newState
		) else (
			showTexturemap mat newState
		)
	) else (
		for n=1 to mat.numsubs do (
			subMat = mat[n]
			if subMat!=undefined then (
				if (classOf subMat)==FStorm then (
					if (classOf subMat.diffuse_tex)==FStormBitmap then showTexturemap subMat subMat.diffuse_tex newState
				) else (
					showTexturemap subMat newState
				)
			)
		)
	)
)

fn ShowAllTextures newState =
(
	for matClass in material.classes do (
		for mat in (getclassinstances matClass processChildren:true) do (
			if (refs.dependentNodes mat).count>0 then (
				if classof mat != Multimaterial then (
					if (classOf mat)==FStorm then (
						if (classOf mat.diffuse_tex)==FStormBitmap then showTexturemap mat mat.diffuse_tex newState
					) else (
						showTexturemap mat newState
					)
				)
			)
		)
	)
)

on isChecked return state --check or uncheck the Macro button
on execute do --if the Macro button was pressed,
(
	state = not state --switch the checked state
	setWaitCursor()
	if selection.count>0 then (
		for obj in selection where (superClassOf obj)==GeometryClass do showTexMap obj.material state
	) else (
		ShowAllTextures state
	)
	setArrowCursor() 
)

)


#2

I can’t test Fstorm /Redshift, but something like this should work.

(
	local state = false --this variable lives in the Macro and controls its checked state
	
	fn ShowBitmap mat newState = if mat != undefined do
	(
		-- Here you can add/mofidy the different materials/textures classes
		case classof mat of
		(
			FStorm:
			(
				if classof mat.diffuse_tex == FStormBitmap do showtexturemap mat mat.diffuse_tex newState
			)
			RS_Material:
			(
				if (classof mat.diffuse_color_map == RS_Bitmap) or (classof mat.diffuse_color_map == BitmapTexture) do showtexturemap mat mat.diffuse_color_map newState
			)
			default:
			(
				showtexturemap mat newState
			)
		)
	)
	
	fn ShowTexMap mat newState =
	(
		if classof mat != multimaterial then
		(
			ShowBitmap mat newState
		)else(
			for n = 1 to mat.numsubs do ShowBitmap mat[n] newState
		)
	)
	
	fn ShowAllTextures newState =
	(
		for matClass in material.classes do
		(
			for mat in (getclassinstances matClass processChildren:true) do
			(
				if (refs.dependentnodes mat).count > 0 do ShowTexMap mat newState
			)
		)
	)
	
	on isChecked return state --check or uncheck the Macro button
	
 	on execute do --if the Macro button was pressed,
 	(
		state = not state --switch the checked state
		setWaitCursor()
		if selection.count>0 then (
			for obj in selection where (superClassOf obj)==GeometryClass do showTexMap obj.material state
		) else (
			ShowAllTextures state
		)
		setArrowCursor() 
 	)
)

#4

Thank you so much for your time!
Somehow, it doesn’t work…
I have tried again changing the words which worked earlier, apparently it doesn’t work either
I tried to find the file I modifed (the one which worked) but I don’t think I saved it Darn…
Probably, I mixed it up, or I might have simply thought it worked (like setting another rednerer as default and thought it was Redshift)
Is there any other ways to modify it for adding Redshift bitmap support do you think?
Really appreciate you again.


#5

Can you test if it works for Fstorm?

Also, since this is a MacroScript, are you adding the macro header (you didn’t include it in your post)?


#7

Yes. I added the macro header to make it a toolbar toggle button.

Yes, it does work well with V-ray, Corona, Arnold and Fstorm. it just doesn’t work with Redshift :frowning:
Also, when any mesh which doesn’t have materials assigned selected, the script shows error message saying
–Unable to convert: undefined to type: material
and in the maxcript, the line “showtexturemap mat newState” part highlighted.


#8

It’s a little hard to debug this without having RedShift but I’ll try.

First, the “- Unable to convert: undefined to type: material” error, does exist in the original script, so is not a new bug. However, I fixed it (check the previous code)

Second, you said:
I changed “Fstorm” to “redshift4max” and also changed “FStormBitmap” to “rsBitmap” and all of a sudden it started working for Redshift!

Since I don’t have RedShift, I can’t confirm/test/debug this, so I trusted your word, but I really doubt what you did worked. That’s why the script is failing.

There could be several problems, which you should investigate and find out.
redshift4max (does this class exist?)
rsBitmap (does this class exist?, isn’t it RS_Bitmap instead?)
diffuse_tex (does the RedShift material have such a property?)
Does RedShift also support Bitmaptexture? If so, should them be displayed?

Let’s try something:

  1. Select one object that has a RedShift material, with a RedShift texture in the diffuse map.
  2. Run this script and put what you get in the Listener.
(
	format "Material Class: %\n\n" (classof $.mat)
	show $.mat
)

#10

Thank you for your help although you don’t have Redshift.

Yes… I doubt myself as well. Since it clearly doesn’t work.
I put redshift4max and rsBitmap from the Maxscript’s autofill. (Like, just gussing kinda same logic for FStorm ones…)

For Redsfhit, the Show Shaded Material in Viewport icon button in Slate Material Editor is not activated when the Redshift Material slected.
To use it, I have to click RS Bitmap.
I thought it would work like that because FStorm behaves the same.
I should also click FStorm Bitmap to be able to use Show Shaded Material in Viewport icon button.

I don’t know how to check if Redshift has diffuse_tex property… Sorry

Yes, I can use Max’s regular bitmap node for Redshift.
For FStorm, It doesn’t allow me to connect regular bitmap node to FStorm Material. I should use FStorm Bitmap

I used RS Bitmap connected to diffuse slot of RS Material.
Applied the material to the object and run the scriptd after selecting the object.
This is what I have for from the listener. (Sorry I don’t know how to put all this in the box like you did)

Also, I clicked Reply button under your comment but it didn’t mention you so I kept deleting my comments and repost it if that makes sense!

“tab 1”
“tab 1”

Material Class: RS_Material

.preset : integer
.diffuse_color : color
.diffuse_color_map : texturemap
.diffuse_color_mapenable : boolean
.diffuse_color_mapamount : percent
.diffuse_weight : float
.diffuse_weight_map : texturemap
.diffuse_weight_mapenable : boolean
.diffuse_weight_mapamount : percent
.diffuse_roughness : float
.diffuse_roughness_map : texturemap
.diffuse_roughness_mapenable : boolean
.diffuse_roughness_mapamount : percent
.transl_color : color
.transl_color_map : texturemap
.transl_color_mapenable : boolean
.transl_color_mapamount : percent
.transl_weight : float
.transl_weight_map : texturemap
.transl_weight_mapenable : boolean
.transl_weight_mapamount : percent
.refl_color : color
.refl_color_map : texturemap
.refl_color_mapenable : boolean
.refl_color_mapamount : percent
.refl_weight : float
.refl_weight_map : texturemap
.refl_weight_mapenable : boolean
.refl_weight_mapamount : percent
.refl_roughness : float
.refl_roughness_map : texturemap
.refl_roughness_mapenable : boolean
.refl_roughness_mapamount : percent
.refl_samples : integer
.refl_brdf : integer
.refl_aniso : float
.refl_aniso_map : texturemap
.refl_aniso_mapenable : boolean
.refl_aniso_mapamount : percent
.refl_aniso_rotation : float
.refl_aniso_rotation_map : texturemap
.refl_aniso_rotation_mapenable : boolean
.refl_aniso_rotation_mapamount : percent
.refl_fresnel_mode : integer
.refl_reflectivity : color
.refl_reflectivity_map : texturemap
.refl_reflectivity_mapenable : boolean
.refl_reflectivity_mapamount : percent
.refl_edge_tint : color
.refl_edge_tint_map : texturemap
.refl_edge_tint_mapenable : boolean
.refl_edge_tint_mapamount : percent
.refl_ior3 : point3
.refl_ior3_map : texturemap
.refl_ior3_mapenable : boolean
.refl_ior3_mapamount : percent
.refl_k3 : point3
.refl_k3_map : texturemap
.refl_k3_mapenable : boolean
.refl_k3_mapamount : percent
.refl_metalness : float
.refl_metalness_map : texturemap
.refl_metalness_mapenable : boolean
.refl_metalness_mapamount : percent
.refl_ior : float
.refl_ior_map : texturemap
.refl_ior_mapenable : boolean
.refl_ior_mapamount : percent
.sheen_color : color
.sheen_color_map : texturemap
.sheen_color_mapenable : boolean
.sheen_color_mapamount : percent
.sheen_weight : float
.sheen_weight_map : texturemap
.sheen_weight_mapenable : boolean
.sheen_weight_mapamount : percent
.sheen_roughness : float
.sheen_roughness_map : texturemap
.sheen_roughness_mapenable : boolean
.sheen_roughness_mapamount : percent
.sheen_samples : integer
.refr_color : color
.refr_color_map : texturemap
.refr_color_mapenable : boolean
.refr_color_mapamount : percent
.refr_weight : float
.refr_weight_map : texturemap
.refr_weight_mapenable : boolean
.refr_weight_mapamount : percent
.refr_roughness : float
.refr_roughness_map : texturemap
.refr_roughness_mapenable : boolean
.refr_roughness_mapamount : percent
.refr_samples : integer
.refr_ior : float
.refr_ior_map : texturemap
.refr_ior_mapenable : boolean
.refr_ior_mapamount : percent
.refr_use_base_IOR : boolean
.refr_abbe : float
.refr_abbe_map : texturemap
.refr_abbe_mapenable : boolean
.refr_abbe_mapamount : percent
.refr_thin_walled : boolean
.ss_unitsMode : integer
.refr_transmittance : color
.refr_transmittance_map : texturemap
.refr_transmittance_mapenable : boolean
.refr_transmittance_mapamount : percent
.refr_absorption_scale : float
.refr_absorption_scale_map : texturemap
.refr_absorption_scale_mapenable : boolean
.refr_absorption_scale_mapamount : percent
.ss_extinction_coeff : color
.ss_extinction_coeff_map : texturemap
.ss_extinction_coeff_mapenable : boolean
.ss_extinction_coeff_mapamount : percent
.ss_extinction_scale : float
.ss_extinction_scale_map : texturemap
.ss_extinction_scale_mapenable : boolean
.ss_extinction_scale_mapamount : percent
.ss_scatter_coeff : color
.ss_scatter_coeff_map : texturemap
.ss_scatter_coeff_mapenable : boolean
.ss_scatter_coeff_mapamount : percent
.ss_amount : float
.ss_amount_map : texturemap
.ss_amount_mapenable : boolean
.ss_amount_mapamount : percent
.ss_phase : float
.ss_samples : integer
.ms_amount : float
.ms_amount_map : texturemap
.ms_amount_mapenable : boolean
.ms_amount_mapamount : percent
.ms_radius_scale : float
.ms_mode : integer
.ms_samples : integer
.ms_include_mode : integer
.ms_color0 : color
.ms_color0_map : texturemap
.ms_color0_mapenable : boolean
.ms_color0_mapamount : percent
.ms_weight0 : float
.ms_weight0_map : texturemap
.ms_weight0_mapenable : boolean
.ms_weight0_mapamount : percent
.ms_radius0 : worldUnits
.ms_radius0_map : texturemap
.ms_radius0_mapenable : boolean
.ms_radius0_mapamount : percent
.ms_color1 : color
.ms_color1_map : texturemap
.ms_color1_mapenable : boolean
.ms_color1_mapamount : percent
.ms_weight1 : float
.ms_weight1_map : texturemap
.ms_weight1_mapenable : boolean
.ms_weight1_mapamount : percent
.ms_radius1 : worldUnits
.ms_radius1_map : texturemap
.ms_radius1_mapenable : boolean
.ms_radius1_mapamount : percent
.ms_color2 : color
.ms_color2_map : texturemap
.ms_color2_mapenable : boolean
.ms_color2_mapamount : percent
.ms_weight2 : float
.ms_weight2_map : texturemap
.ms_weight2_mapenable : boolean
.ms_weight2_mapamount : percent
.ms_radius2 : worldUnits
.ms_radius2_map : texturemap
.ms_radius2_mapenable : boolean
.ms_radius2_mapamount : percent
.coat_color : color
.coat_color_map : texturemap
.coat_color_mapenable : boolean
.coat_color_mapamount : percent
.coat_weight : float
.coat_weight_map : texturemap
.coat_weight_mapenable : boolean
.coat_weight_mapamount : percent
.coat_roughness : float
.coat_roughness_map : texturemap
.coat_roughness_mapenable : boolean
.coat_roughness_mapamount : percent
.coat_samples : integer
.coat_brdf : integer
.coat_fresnel_mode : integer
.coat_reflectivity : color
.coat_reflectivity_map : texturemap
.coat_reflectivity_mapenable : boolean
.coat_reflectivity_mapamount : percent
.coat_ior3 : point3
.coat_ior3_map : texturemap
.coat_ior3_mapenable : boolean
.coat_ior3_mapamount : percent
.coat_ior : float
.coat_ior_map : texturemap
.coat_ior_mapenable : boolean
.coat_ior_mapamount : percent
.coat_transmittance : color
.coat_transmittance_map : texturemap
.coat_transmittance_mapenable : boolean
.coat_transmittance_mapamount : percent
.coat_thickness : worldUnits
.coat_thickness_map : texturemap
.coat_thickness_mapenable : boolean
.coat_thickness_mapamount : percent
.coat_bump_input : point3
.coat_bump_input_map : texturemap
.coat_bump_input_mapenable : boolean
.coat_bump_input_mapamount : percent
.overall_color : color
.overall_color_map : texturemap
.overall_color_mapenable : boolean
.overall_color_mapamount : percent
.opacity_color : color
.opacity_color_map : texturemap
.opacity_color_mapenable : boolean
.opacity_color_mapamount : percent
.emission_color : color
.emission_color_map : texturemap
.emission_color_mapenable : boolean
.emission_color_mapamount : percent
.emission_weight : float
.bump_input : point3
.bump_input_map : texturemap
.bump_input_mapenable : boolean
.bump_input_mapamount : percent
.displacement_input : point3
.displacement_input_map : texturemap
.displacement_input_mapenable : boolean
.displacement_input_mapamount : percent
.depth_override : boolean
.refl_depth : integer
.refl_enablecutoff : boolean
.refl_cutoff : float
.skip_inside_refl : boolean
.refr_depth : integer
.refr_enablecutoff : boolean
.refr_cutoff : float
.combined_depth : integer
.diffuse_direct : float
.diffuse_indirect : float
.refl_direct : float
.refl_indirect : float
.refl_isGlossiness : boolean
.coat_direct : float
.coat_indirect : float
.coat_isGlossiness : boolean
.sheen_direct : float
.sheen_indirect : float
.sheen_isGlossiness : boolean
.refr_isGlossiness : boolean
.decoupleIORFromRoughness : boolean
.shadow_opacity : float
.affects_alpha : boolean
.block_volumes : boolean
.energyCompMode : integer
.overallAffectsEmission : boolean
.refl_endmode : integer
.anisotropy_orientation : integer
.anisotropy_tangentChannel : integer
false


#11

Ok, I’ve updated the code, let’s see if it works now.

redshift4max -> RS_Material
diffuse_tex -> diffuse_color_map
rsBitmap -> RS_Bitmap


#12

OMG It works for everything!!! Thank you so much…
I’ve tested all renderers I have V-ray, Corona, Arnold, FStorm and Redshift

There’s a small issue for only Resfhit though, when I run the script there’s no reaction, after moving viewport or clicking anywhere in the viewport, it immediately shows the bitmap
When I turn it off, the bitmap very slowly fading out and same, if I click anywhere once, it updates immediately.

If it’s tricky to define what cuases this issus, especially when you don’t have Redshift installed,
That’s totally fine. I can use it like this just one click wouldn’t be that a huge issue.
I really really appreciate you!


#13

Try adding redrawViews() or completeRedraw() just after setArrowCursor().


#14

It works perfectly! Appreciate you again… you are a hero!!!