Home Technical Talk

[3ds max] flow map creator script - problems

1
polycounter lvl 8
Offline / Send Message
MaVCArt polycounter lvl 8
hi everyone,

I've been working on a water shader that has custom flows in it, and it seems that I am stuck at the flow maps. The thing is, I would like not to have to paint them in photoshop, but I would rather have something like Valve has; a plugin for your 3D software (in my case 3ds max) that allows you to sculpt normals to generate the flow map.

The thing is, generating the normal map once you have the vectors is easy, but you need to have the vectors first.
Max has this modifier called "edit normals", that seems to fix that problem, but moving the normals around one by one is just not acceptable.

I want to have my script/rollout/plugin to be brush-based, using the ThePainterInferface in MaxScript or something, but that is precisely where I am stuck.

for one, I have never worked with this "ThePainterInterface" before, and from what I've been reading about it, it is only usable for things like bitmap painting, and general data getting and setting. I have no idea how to make it into the 3ds max equivalent of the move brush in zbrush though.

can anyone provide any help for me on this? it would be greatly appreciated :D

oh, and once this is done I will put it on scriptspot so everyone can download it.

Replies

  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    for those of you who have trouble picturing what I'm trying to do:

    basically I want to combine the brush interface like the one of the hair and fur modifier with the possibility to grab the handles of normals in the edit normals modifier
  • Eric Chadwick
    Options
    Offline / Send Message
    This is a great idea. I would ask over on Tech-Artists.Org. We had a discussion about this a couple years ago.
    http://tech-artists.org/forum/showthread.php?t=429
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    thanks for that link, it gave me a great idea! I found out that this brush interface isn't going to work unless I use full on C++, so I'm gonna go for a different way if no one comes up with an easy solution :)

    i'm now going for the painting way: paint directly onto your mesh, with a brush that changes direction depending on which direction you're going. it's the same as the one ben cloward made really, but made by me :p he ofcourse hasn't put it online, which i will do
  • Slum
    Options
    Offline / Send Message
    Slum polycounter lvl 18
    I did a bunch of experimentation with this stuff.

    A few things I tried:

    1) Wrote a tool for max that would push verts on a grid plane and move them away from colliding verts. That gives you a base "flow" around geo (like rocks in a pond)

    2) Wrote an external tool that takes a mask image, and generates a 2d flow offset map using a fluid dynamics solver. That was pretty good, but I didn't quite get what I wanted out of it.

    3) Use a dense grid plane as your base map with 1:1 uv's. Using transform tools (move with soft select, etc) deform this mesh by hand, then bake out the uv's to a map (or project the uv's onto vertex colors of a more sparse mesh.

    4) Painting in photoshop - works OK, but isn't intuitive and is a pain for iteration.

    All of these things provided results of varying usefulness.. In the end, just do whatever looks good. You need surprisingly little data to actually get a flow that is better than nothing. Doing a full simulation is a bit overkill. What Valve did with Houdini was quite nice, but honestly the final in game result didn't seem to warrant the R&D time - at least what I could see in L4D2 and portal.
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    that is true, but it would be nice if I could develop something easy to use that has great results :) at this point i'm planning on creating two versions, release them to you guys and then see what is like best.

    the two options at this point are:

    - painting directly onto your mesh or in 2D using a brush that changes to the correct colors depending on which direction you are moving in

    - drawing vectors in max using dummies (just click twice, once for the start and once for the end point), and then automatically get a generated flow map out of that by sampling the nearest vertices of the mesh to the vectors, and setting the vertex colors of the mesh depending on how close they are to the vector.

    the downs/ups of both:

    the first method uses painting, which is pretty intensive if it's used in max, and tends not to work a lot, together with being pretty demanding on your computer. the up side is that it's very user friendly ofcourse.

    the second method on the other hand is not that intensive to get to work. the massive down side is that you need lots and lots of vertices to make this map look sharp enough. at least in some cases; most of the time a flow map is only made worse by sharpness.

    which would you guys prefer at this point, listening to the plans?
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Is the second method based upon splines?
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    uhm I could make it based on splines, yes, but for now the plan is to make it work with two points per vector, and then I'll see where i can go from there :)
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    I was researching stuff the other day as I reminded myself I wanted to make this (though for Maya) and found Rob's video ([ame="http://www.youtube.com/watch?v=5n6OSWcThQM&feature=player_embedded"]NormalsToolbox : Maya2009 - YouTube[/ame]) so need to look into the artisan tool also there was this (http://vimeo.com/29796585)
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    damn, that's like... exactly what i'm trying to do, only it's in maya :|

    anyone have any idea of how to influence the brush tool in max to have this?
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    ah wish that NormalsToolbox tools was public haiddasalami been looking for something like that for maya for a long time.
  • Norman3D
    Options
    Offline / Send Message
    Norman3D polycounter lvl 14
    This seems pretty doable. I might give it a shot one of these days!
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    ya the painting normals, and being able to use a object to attract or repell the normals in a certain radius would be very usefull.

    especially if it worked on the objects volume, so i could say import in level geometry and have it slightly repell the normals.
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    I could ofcourse include that in the script, yes, but the idea is to be really able to "comb" the normals, mostly because that's just the most natural feeling way a flow map would be created imho :)
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Trying to wrap my head around how the artUserpaintContext works for Maya. Wish I could help on the Max side :( Maybe try and see if anyone has any scripts where they use a brush and hope its not encrypted?

    What Ben from tech-artists was talking about:

    http://www.kxcad.net/autodesk/Autodesk_MAXScript_Reference_9/How_To_Introduction_to_the_Tutorials.htm [Scroll down to the Painting tutorial]
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    yeah i've seen that one :) the big problem with that is that all the ThePainterInterface does is get or set data like positions, vectors and stuff. now that sounds like it's the perfect tool for the job, but at this moment I would have no idea how to use it to influence the handles of anything like the Edit Normals modifier
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    here is an example of what i want to achieve:

    captureytf.jpg

    this is taken from this paper:

    http://www.valvesoftware.com/publications/2010/siggraph2010_vlachos_waterflow.pdf
  • e-freak
    Options
    Offline / Send Message
    Valve doesn't paint Flowmaps as far as I understood that paper. They are importing level geometry and using the geometry normals as influences on a forcefield simulation in houdini (probably plus a general flow direction). the massive advantage of doing it that way is that you can batch through large amounts of flowmaps at once instead of just creating a tool to making the authering easier.
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Isn't that what the guys are talking about? Combing the Normals in Max, baking it, minus the Blue channel?
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    yep, it is :) i'm working on a possible solution that might still use the brush interface from maxscript right now.

    in any case, i'm still open to suggestions on how to do this in max, if anyone's got anything good :)
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    You could force the Camera perspective to 'Top' so the amount of 'shot' vertices would not be an issue, in some scripts, I noticed a nasty habit of Max shooting through the surface of the mesh and onto other assets in the scene.

    I remember some guy in Tech Talk topic (the pinned topic up top) made a Fracture/Vornoi scrip for Max, which essentially allows you to 'paint' the stokes of the fracture outline in a spline like fashion from screen position before breaking the mesh. That could be a good way to go about, it might sound limited, but in practice, it works.

    Will post a link to the script once I find it.

    Found it, here is what I mean: http://folk.ntnu.no/havardsc/site/wordpress/?page_id=15
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    yeah i've seen that too :)
    thanks for sharing :D

    I will definitely try that if it turns out that my current prospective doesn't work
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    small question to everyone here:

    i've come across this function in the painter interface in maxscript here:

    thePainterInterface.buildNormals

    it sounds like it might be something that I can use, but I can't find it's use anywhere, can anyone fill me in please?
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    *bump*

    right, so I managed to make the painter interface work the way i wanted and originally intended it to, meaning, you can now create actual flow maps with my script, if you render to texture manually.

    the problem, though, is performance; around 2000 or so vertices, the script stops working entirely (at least, smoothly)

    so, that is simply not acceptable, since I aim to be brushing normals on terrain meshes, that can easily go over 100 k.

    now, I have decided to convert my script to a full-fledged plugin, meanin I will have to use the 3ds max sdk and program in the C++ coding language.
    This should not be a big problem, since I have a pretty solid base of the C++ language.

    however, i've been at it all day now, and I haven't gotten anything to work, not even the tutorial lessons. I always get error messages, the lesson doesn't compile and i get external linking errors. at first this was due to some windows 7 persmission issues, that I fixed, but now that I fixed that, the problems have gotten even worse....

    is there anyone here with some experience with the 3ds max 2012 or earlier SDK that can help me out here? I realise my explanation isn't really that specific, but it's the best I can do for now, the whole thing would be too confusing....
  • Computron
    Options
    Offline / Send Message
    Computron polycounter lvl 7
    I love what your making. Are you planning to to release it to the public?

    This would be awesome with a live viewport shader, although I don't know how you could extract the flow map in real-time.
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    about the public release: more info on that later :)

    about the live shader: i'm afraid that won't be possible, not even valve has that, so I certainly won't be able to do that :p it would require live gpu streaming and recompiling of the shader in real time, which is something not a single hardware configuration that I know of can do at the moment :)
  • Computron
    Options
    Offline / Send Message
    Computron polycounter lvl 7
    What about RTT? do screenspace capture of the plane's normals, subtract blue and use it aas the input.
  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    MaVCArt wrote: »
    here is an example of what i want to achieve:

    captureytf.jpg

    this is taken from this paper:

    http://www.valvesoftware.com/publications/2010/siggraph2010_vlachos_waterflow.pdf
    There is a more in depth explanation of the Houdini part in this PDF:
    http://valvesoftware.com/publications/2011/gdc_2011_grimes_nonstandard_textures.pdf
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    that's a great read :)

    unfortunately it's not exactly what I need to complete my plugin :p the combing itself is pretty simple actually, it's just that the performance of it when using maxscript sucks incredibly, so I'll have to do it with C++

    the problems that I had with the SDK are solved in the meantime, so the development can now begin properly :)

    i'll keep you all updated on my development and on whether or not i'll release it to public.
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    Awesome sauce mate, awesome!
  • Ben Cloward
    Options
    Offline / Send Message
    Ben Cloward polycounter lvl 18
    I wrote a tool to do this a couple of years ago - although it sounds like yours is going in a bit of a different direction than mine. I just wrote a paint tool using MaxScript and made the color that the brush painted be based on the direction that the brush was moving.

    The paint tool part of it is easy. You can just base it off of the tutorial in the MaxScript documentation on creating a paint tool here:

    http://docs.autodesk.com/3DSMAX/14/ENU/MAXScript%20Help%202012/index.html?url=files/GUID-FA2D9E9C-90EA-4E95-926E-29BB2FA416F-329.htm,topicNumber=d28e110104

    Once you've got that bit of it implemented, you can just put in some code to replace the color of the brush strokes with the color-encoded vectors. I'll dig around a bit and see if I can find my script. I'll post it for you to grab if I can find it.
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    that would be great ^^ i'll certainly look at that :D thank you!

    one thing though; the reason I went for normal vector "brushing" is because it's clearer for the user -> you can review and go over your level without having to think in color values in your head :)
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    @Rose75: could you please fix your images? i can't see them :s
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    sorry for the triple post, but I gotta announce something :)

    I just got approvement to release my plugin open source, so you guys can be expecting it to be put online as soon as I finish it ^^
  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    how about showing something instead of all this text. Got some screens or video to share?
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    i'll post what my script can do later today (i'm at work now, lunch break), but the plugin is still in the phase of "learning what the SDK can do" right now, so that'll probably take a while longer :p
  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    Just saying this thread is boring without pictures- need to see some action, not just talking.
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    @renderjhs: you're absolutely right, which is why I decided to just go ahead and take some screens :)

    step 1: pick the object you wish to render your normals from:
    91066972.jpg

    step 2: enable the comb Normals button. this disables buttons that would screw up vertex ID's and other script functions
    22020217.jpg

    step 3: comb your normals!
    23685107.jpg
    54788850.jpg

    step 4: render to texture a normals map using the projection modifier;
    the script automatically copies your original mesh before you start sculpting your normals, so you'll always have a mesh to RTT from
    34505321.jpg

    step 5: resulting render :)
    88716627.jpg


    the resulting render's R and G channels can now be used to offset the time factor of a panner that is panning the UV coordinates of your textures. the result will be that your textures will have "flows" in them corresponding to where your vectors were sculpted.

    ps: the resulting render looks weird, I know, but that's because I used my script on a box that I used flatten mapping on. the goal was to be able to use this script on a plane, but I was having trouble with convex/concave meshes, more precisely, the normal ID's didn't correspond to the vertex ID's, no matter how many different ways I converted / transferred the ID's. I won't have this problem with the SDK though.

    pps: you will also note that I used a fairly un-tesselated box for this example. the reason for this is that my script stops working at around 1 k vertices; another reason why I'm switching to the SDK :)
  • renderhjs
    Options
    Offline / Send Message
    renderhjs sublime tool
    thx, cool stuff btw.
  • Xoliul
    Options
    Offline / Send Message
    Xoliul polycounter lvl 14
    Can't you paint flow directions into the Vertexcolor X and Y (R/G) channels? I see you are RTT'ing the edited normals afterwards, which is extra work. While if you paint the flow directions into the vertex colors it should be the same but not require baking + possibly allow more control and be live viewable ?
    Al there is to assuming you'll have to re-expand the R and G channels (times 2 minus 1, just like normalmaps), then using that knowledge, paint directions into vertexcolors (by getting the direction from the delta between brush updates or something like that, you must already have code for this I assume). You could even use the Blue or Alpha channel for speed.
    And if necessary, you could transfer the vertex color directions into normals and bake them in some sort of final processing step.
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    @Xoliul:

    yes, I thought about that, and actually that was my first intention. The problem is not that it's not doable, because as you say I do indeed have the code for that (or at least most of it, since most of it is the same as the code needed for sculpting the normals.).

    the problem with that suggestion, is that it's not very clear to the user what his/her final result will look like. With the normal sculpting method, you can instantly see the direction your normals will flow in by the direction the normals are pointing at. It's much harder to "convert" so to speak, color values in your head than it is to foresee what the normals will look like if you can instantly see them like in my script :)

    I will, though, seriously consider that option for usage instead of rendering a normal map.

    about the render to texture though; I intended that to be automatic, but since the script wasn't finished because I changed from maxscript to plugin, that option wasn't implemented yet :)

    about using the B channel as speed: I will certainly use that, that's a great suggestion :)

    I will still create a plug-in instead of a maxscript though, since performance will still be a problem no matter what kind of implementation you use; I'm assuming vertex color painting will become a problem on a mesh of around 10 K vertices.

    also, there is still the very impractical problem with convex/concave meshes that is easily solvable in C++, and insanely elusive in maxscript :)
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Awesome stuff Mattias! Are you just using the buildNormals stuff you mentioned before or doing some Math like getting the normals of the vertices being hit and aiming them in the direction the brush is moving (factoring in intensity and falloff)
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    Awesome stuff Mattias! Are you just using the buildNormals stuff you mentioned before or doing some Math like getting the normals of the vertices being hit and aiming them in the direction the brush is moving (factoring in intensity and falloff)

    the second :) actually that's exactly what i'm doing :p

    the problem with performance though, is caused by the fact that every normal in the mesh has to be tested against a hit with the brush, every time the brush is used and on every tick of the brush, and then if the hit is true, the normal has to be moved. this is very calculation-intensive, so that's why i've chosen to go from maxscript to C++, because it's much more performant :)

    thanks for the compliment btw
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    So much coolness, it's amazing!
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    nice, dam nice
  • MaVCArt
    Options
    Offline / Send Message
    MaVCArt polycounter lvl 8
    @Ace-Angel and passerby:

    thanks guys :)
  • Computron
    Options
    Offline / Send Message
    Computron polycounter lvl 7
    Hot damn, cant wait!
  • e-freak
    Options
    Offline / Send Message
    only thing I can come up with is maybe get a tickbox to tesselate the painting mesh and create a plane with no subdivisions at all for the bake?

    good work though :)
  • leslievdb
    Options
    Offline / Send Message
    leslievdb polycounter lvl 15
    seems to be coming along nicely ^^
    gj m8
  • Xoliul
    Options
    Offline / Send Message
    Xoliul polycounter lvl 14
    MaVCArt wrote: »
    @Xoliul:

    yes, I thought about that, and actually that was my first intention. The problem is not that it's not doable, because as you say I do indeed have the code for that (or at least most of it, since most of it is the same as the code needed for sculpting the normals.).

    the problem with that suggestion, is that it's not very clear to the user what his/her final result will look like. With the normal sculpting method, you can instantly see the direction your normals will flow in by the direction the normals are pointing at. It's much harder to "convert" so to speak, color values in your head than it is to foresee what the normals will look like if you can instantly see them like in my script :)

    I will, though, seriously consider that option for usage instead of rendering a normal map.

    about the render to texture though; I intended that to be automatic, but since the script wasn't finished because I changed from maxscript to plugin, that option wasn't implemented yet :)

    about using the B channel as speed: I will certainly use that, that's a great suggestion :)

    I will still create a plug-in instead of a maxscript though, since performance will still be a problem no matter what kind of implementation you use; I'm assuming vertex color painting will become a problem on a mesh of around 10 K vertices.

    also, there is still the very impractical problem with convex/concave meshes that is easily solvable in C++, and insanely elusive in maxscript :)

    If it's not very clear to the user, what about having a preview shader ? I can write you one quickly if you want. It seems like that's a very minor disadvantage compared to the advantages of vertexcolors (no texture memory used, just light vertexcolor data, no pre-processign RTT step, live viewable...).
    Also vertex color painting should be pretty fast. Access to the vertex colors is meant to be efficient, that's the whole idea: low overhead ata. I remember a tutorial from 2004 or something that showed someone painting vertexcolors on a SubD object, with hardware from back then.
  • Computron
    Options
    Offline / Send Message
    Computron polycounter lvl 7
    Does Max not have any live RTT like UDK for its viewport?
1
Sign In or Register to comment.