PDA

View Full Version : supersampling materials


namoi
03-14-2005, 07:05 PM
I'm trying to write a script to enable the default local supersampler (max 3.5 star) for all the materials (including multi-sub materials) of a specific selection...but without success.
Basically, i know the method :mymaterial.sampler.enable = true, but it gives no result, even if i create a box mybox and giving it a boxmaterial on it :

boxmaterial = $mybox.material
-->standard
boxmaterial.samplerEnable = true
-->true

Everything seems ok, but the defined mat is not affected by the script...

Could someone help me ?

Thanks

prettyPixel
03-14-2005, 07:47 PM
The global setting is active by default.
I presume It is the source of the error?

boxmaterial.samplerUseGlobal = false
boxmaterial.samplerEnable = true

namoi
03-15-2005, 06:08 PM
Yes, thanks, that was this omission.
Now i'll try to complete the script.
'Hope i won't need more help. ;)

thanks again

namoi
03-15-2005, 06:18 PM
Ok i did it :)

if someone is intersted, here is the basic script :

on execute do (

sel = selection
for i in sel do (
g = i.material
g.samplerUseGlobal = false
g.samplerEnable = true )
)

It should be tuned to check, for example, for empty selection or invalid selection and it will be.

hope this helps

namoi
03-15-2005, 06:30 PM
Again me, with another question (eventualy, i need help isn't it ?).

I would like to filter the selection. I know already how to do it, but i'm sure there's a faster and more "elegant" way to do it. Basically, i would like to write something like this :

sel = selection
for i in sel where i iskindof geometry do (....)

but it doesn't work

Does someone know a trick ?

prettyPixel
03-15-2005, 10:12 PM
sel = selection
for i in sel where i iskindof geometry do (....)

The solution is not far.
But the class and the order of the arguments are wrong:
for obj in selection where iskindof obj geometryClass do (format "object=%\n" obj)

And It is the same that to say:
for obj in geometry do (format "object=%\n" obj)

Have a good day

namoi
03-16-2005, 10:47 AM
Thank you again

I'll try it.

namoi
03-16-2005, 11:59 AM
Did it,

Here is the code if someone is interested

(on execute do
(

sel = selection
for obj in sel where iskindof obj geometryClass do
(
g = obj.material
if classof g == multimaterial then
(for i in g.count to 1 by -1 do
(g[i].sampleruseglobal = false
g[i].samplerenable = true
g[i].samplerbyname = "Max 2.5 Star")
)
else(
h = obj.material
h.samplerUseGlobal = false
h.samplerEnable = true
h.samplerbyname = "Max 2.5 Star"
)
)
)
)

For now, it handles only standard, architectural (perhaps some other mat ?) and multimaterial. I will tune it, with a case of: loop for all materials supporting supersampling.

Thanks again for helping

namoi
03-17-2005, 09:01 PM
I'm coming again to ask for help.

Now, my script works well. It can handles almost all kind of Max standard material, but i realise it will be much more difficult to finish it that i first expected.
The problem is that this script works only with the first nested level of material.

Lets be more specific :

for example, if an object has a multimaterial, or a composite, or a blend (etc...) applied to it, the script will enable the supersampling for the standard material used in the this material material. But what if a multimaterial has another multimaterial has a submaterial (getting confused isn't it ,) ? My script is unable to handle these situations. It doesn't crash because i catch the error message, but the submaterials aren't supersampled.

So here is my question :

Does it exist a "simple" way to check for all nested materials of an object and -first- determine if they could be supersampled and -then- enable the supesampling for these materials ?

Here is my code for now:

*********

on button1 pressed do
(sel = selection
for obj in sel where iskindof obj geometryClass do
(case of
(
(d = obj.material
classof d == blend):
(try (d.map1.sampleruseglobal = false
d.map1.samplerenable = true
d.map1.samplerbyname = "Max 2.5 Star"
d.map2.sampleruseglobal = false
d.map2.samplerenable = true
d.map2.samplerbyname = "Max 2.5 Star"
)
catch ()
)


(f = obj.material
classof f == compositematerial):
(try (e = f.materiallist
for i in e.count to 1 by -1 where e[i] != undefined do
(e[i].sampleruseglobal = false
e[i].samplerenable = true
e[i].samplerbyname = "Max 2.5 Star"
)
)
catch ()
)

(g = obj.material
classof g == multimaterial):
(try (for i in g.count to 1 by -1 do
(g[i].sampleruseglobal = false
g[i].samplerenable = true
g[i].samplerbyname = "Max 2.5 Star"
)
)
catch ()
)

default:
(try (g = obj.material
g.samplerUseGlobal = false
g.samplerEnable = true
g.samplerbyname = "Max 2.5 Star"
)
catch ()
)
)
)
)

********

Thanks for help

prettyPixel
03-18-2005, 01:18 AM
No offense, but your code is unreadable :o) Add spaces help to understand a code and It does not slow down the program...

The solution is to use an recursive function.

utility setSamplerRollout "setSampler"
(
button setSampler_osd "setSampler"

fn setSampler mat =
(
case classof mat of
(
blend: (setSampler mat.map1; setSampler mat.map2)
compositematerial: (for thisMat in mat.materiallist where thisMat!=undefined do setSampler thisMat)
multimaterial: (for thisMat in mat.materiallist where thisMat!=undefined do setSampler thisMat)
standardmaterial:
(
mat.samplerUseGlobal = false
mat.samplerEnable = true
mat.samplerbyname = "Max 2.5 Star"
)
)--case
)--fn

on setSampler_osd pressed do
(
matSel=#()
for obj in selection where isKindOf obj GeometryClass do
(
mat=obj.material
if mat!=undefined do ( if findItem matSel mat==0 then append matSel mat )
)
for mat in matSel do setSampler mat
)--on

)--utility

namoi
03-18-2005, 08:07 AM
Thanks for your answer and sorry for the "look" of the code. It became like this when i pasted it. Looks stupid, but i don't know how to create a window like you did in your post to display script :wip:

I willl try your solution. Thanks again

namoi
03-18-2005, 08:23 AM
I tried, it's perfect and elegant.
Thanks again, i've learned a lot because of you.

Hope other people benefited of this thread.

prettyPixel
03-18-2005, 12:43 PM
i don't know how to create a window like you did in your post to display script

It's pretty simple :o) You have just to select your code and press # in the toolbar.

namoi
03-19-2005, 06:38 PM
Here I am again, with another question related to this script.

Now the script is ok, it can handles all the standard materials of max (except raytrace in whixh the samplerUseGlobal propertie doesn't seems to be exposed in maxscript and the morpher mat, because i'm lazy ;)

But I want to complicate a little more the script...In fact it could be great to enable the kind of filtering (in this case "summed Area") i want for each texturemap of each material and nested material.

For now i can do this for standard mat and "simple" multimaterial (with only standard mat used in it).
The problem is (again - i know, this time, i need a recursive loop to achieve this -) for multimaterial inside multimaterial.
In those cases my script crash.

Here is the code i use:


fn setFiltering mat =
(case classof mat of
(multimaterial: (matlist = #()
matlist = mat.materiallist as array
for i=1 to matlist.count do
(for j=1 to matlist[i].maps.count where classof matlist[i].maps[j] == bitmaptexture do
(matlist[i].maps[j].filtering = 1)
)
)
default: (for obj in selection where iskindof obj geometryclass do mat = obj.material.maps
for i = 1 to mat.count where classof mat[i] == bitmaptexture do mat[i].filtering = 1)
)--case
)--fn

on setFiltering_osd pressed do
(matSel=#()
for obj in selection where isKindOf obj GeometryClass do
(mat=obj.material
if mat!=undefined do (if findItem matSel mat==0 then append matSel mat)
)
for mat in matSel do setFiltering mat
)--on

prettyPixel
03-19-2005, 09:37 PM
Never use the default mode in this case. It is too dangerous, It's certainly the source of the error.
And the recursive function receive already selected materials (called "mat" in all cases).
the function is really similar to the previous...

fn setFiltering mat =
(case classof mat of
(multimaterial: (for thisMat in mat.materiallist where thisMat!=undefined do setFiltering thisMat)
standardmaterial: (if classof mat.diffusemap == Bitmaptexture do mat.diffusemap.filtering = 1)
)--case
)--fn

The principe of an recursive function is that it call itself without in one case: when It find the value to change (standardmaterial here).


You can extend this function to others types now :) composite materials, ...

namoi
03-20-2005, 09:03 AM
Thank you again to answer me and so fast.

I understand the point.

But what if i want to filter ALL the maps in a material (not only the diffusemap), can i write this :

standardmaterial: (if classof mat.MAPS == Bitmaptexture do mat.MAPS.filtering = 1)

-- I could try it, but i'm not in front of my workstation right now --
:hmm:

prettyPixel
03-20-2005, 01:33 PM
can i write this :
standardmaterial: (if classof mat.MAPS == Bitmaptexture do mat.MAPS.filtering = 1)

I don't believe.That is a bit more complex because you have to scan all mat.maps by using mat.mapEnables and make the test for each.

standardmaterial:
(listMats=mat.maps
listMatEnables=mat.mapEnables
for sm=1 to listMats.count do
(if listMatEnables[sm] do
(if classOf listMats[sm]==Bitmaptexture do listMats[sm].filtering = 1)
)--for
)--standardmaterial

It's possible that It exist a faster method but I don't know it.

What are your projects for your script ?

namoi
03-20-2005, 06:22 PM
Thanks again,

I will try your method.

About this script, that i will post soon, it's just to help me manage big architectural scenes.
It's a common problem when you make a movie with that kind of scenes (lot of building textures) to have some flicking and waving textures, mostly when faces become coplanar with the camera.
Enable supersampling for a building handling a lot of different textures at once is very nice and when the problem still remain, enabling a summed area filtering for all maps again at once is a big help.
Voila

I just upgrade this script. Now you can choose the supersampling method, the filtering method and the kind of texturemap you want to apply on (diffuse, opacity, bump and self-illum, which are the most impacted by the filtering).

I post this soon,

namoi
03-21-2005, 06:51 PM
OK, that's it. Now it's done and improve.
1. You can choose the kind of supersampling for all kind of materials and nested one too.
2. You can choose the kind of filtering and on which maps you want to apply it. A "All" button let you apply the filtering for all kind of maps in material and nested ones.
3. A show/Hide materials for selected objects or selected MEdit slot in viewport has been added.

limitations:
1. Sampling and filtering doesn't work on raytrace and morpher material.
2.Show/hide materials only works for standard and multimaterial for now.

to do:
1.Fix the above limitations.
2.add the options for Supersampling like quality, threshold...

Hope this help

Thanks again to PrettyPixel for his help on this script. I wouldn't have done it alone.

CGTalk Moderation
03-21-2005, 06:51 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.