View Full Version : Barycentric point

02 February 2009, 03:29 AM

Let's suppose I have a mesh composed of a single face (triangle).

Using barycentric coordinates, how can I change the colour of a point inside the triangle?

Right now I know how to change the colour of each of the vertexes that form the triangle, but I need to be able access and change more information.

Thank you.

02 February 2009, 10:57 AM
What do you mean by "point inside the triangle" ?

If there is no vertex inside this triangle (which is then not a triangle, but three triangles) you cannot change its color (Pure logic). Only vertices, faces and edges can store color information.

02 February 2009, 11:54 AM
Hello Groucho, thanks for your reply.

By "point" I mean anything inside the triangle that can be accesed by barycentric coordinates using the three vertexes that define the triangle.

For example, I can assign one colour to each vertex. But how can I assign a different colour to the middle (the barycentric centre) of the triangle?

For example, how can I make the triangle have two different colours? Like half white half black divided by an imaginary line defined by barycentric coordinates.

For example, I want to apply a procedural texture written by me, without using the material editor. Using only the information provided by the vertexes, this doesn't look good.

02 February 2009, 12:32 PM
nope - you would have to refine your mesh (or, in theory, the CPV data - but I'm not sure that actually works)

02 February 2009, 01:47 PM
As far as I know, you cannot modify the way two colors interpolate from one vertex to another along a given edge. It is always a linear interpolation so that at the middle of the edge, the color is 50% mix between vertex A and vertex B.

02 February 2009, 01:48 PM
Or, to put it another way, the "point" doesn't exist until render time / viewport render time. It's an artefact of the render pipeline.

02 February 2009, 03:04 PM
Maybe with Nurbs you can access precisely a given point on a NURBS surface, voxel like.

02 February 2009, 04:40 PM
So let me get this straight...

If I have a huge mesh plane consisting of only two faces (the two triangles), I cannot WRITE a procedural texture to make it have a chess board texture, or to make it have all the colours of the rainbow, or whatever procedural texture I want. Right? I have to go to the Material Editor and work in a non-script related manner?

Thanks again

02 February 2009, 05:24 PM
That is correct. The only way to do what you want would be to refine your mesh (e.g. via the Tesselate modifier) and then affect vertices from there. But you're going to end up with a looooooooooot of vertices.

If you want a programmable shader, wait for 2010 which has the mental mill thing going on, or find somebody to recompile MaxShade (it's in SourceForge).. it had a renderman-like shading language support for textures.. anything, including the scanline renderer, would render those. Tad slow, tho'.

In the end, you may have to learn C++ and get down and dirty with the 3ds Max SDK :)

02 February 2009, 05:28 PM
Of course you can create, modify and apply materials using MAXscript only, without accessing the Material editor, but what we are telling you is that you cannot act directly on the geometry, you must use maps to apply on your object.

theMaterial = standard "myMaterial"
theMaterial.shadertype = 1 -- Blinn shader
theMaterial.diffusemap = checker

myPlane.material = theMaterial

02 February 2009, 03:05 PM
Ok, one last question.

Can I do this at render time? Maybe at render time I'll be able to run a loop by screen pixel? No?

02 February 2009, 03:51 PM
You could write a render effect that writes colored pixels to the rendered image based on the object, its UV coordinates, etc. That's gonna be slow, though, and you're really only messing with the pixels - so it's not exactly a proper procedural.

I'd almost say you'd be better off rendering your procedural straight to a bitmap and using that bitmap as the map for the object.

Your best bet is still going to be either writing a full texture plugin, or playing with the plugins that let you render e.g. Direct3D shaders directly in-render.. and author Direct3D shaders (or wait for later max versions with mental mill, etc.)

02 February 2009, 12:15 PM
I'd almost say you'd be better off rendering your procedural straight to a bitmap and using that bitmap as the map for the object.

Can I do this using MAXScript? Any example available?

Your best bet is still going to be either writing a full texture plugin.

This means I must use the SDK, right?

Ok. I know C++, so this won't be a problem. The thing is: I have no idea how to actually install this SDK and work with it. I've been looking for examples, tutorials, etc., but it is as if the 3DStudio SDK developers work in a Top Secret way or something like that. =/

Any thoughts?

02 February 2009, 01:53 PM
the bitmap thing - check the help file for getPixels and setPixels

The other bit - yep, would require the max SDK. This forum section covers the 3dsMax SDK as well, I'm sure there's others here who have gone through the SDK setup. The SDK help file seems to have a small 'quick start'-ish section using the app wizard, but I wouldn't know the finer details of what goes where and how to link things :)

02 February 2009, 02:02 PM
you dont need sdk for that. this is a bit of code i stripped so may not work.
pposx and pposy are bitmap pixel coordinates. so top left would be 1,1 etc

screen_width = 256
screen_height = 256

theCanvasBitmap = bitmap screen_width screen_height color:black
setPixels theCanvasBitmap [pposx,pposy] pixel_color

display theCanvasBitmap
theCanvasBitmap.filename = "c:\\test.tga"
save theCanvasBitmap

02 February 2009, 05:58 PM
you do need the SDK for the latter bit; "Your best bet is still going to be [...] writing a full texture plugin."

CGTalk Moderation
02 February 2009, 05:58 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.