Round corners don't render.

Round corners don't render.

pcrawley
Advisor Advisor
10,092 Views
28 Replies
Message 1 of 29

Round corners don't render.

pcrawley
Advisor
Advisor

If I import a model in from another Autodesk application - say, Inventor - it brings with it the Autodesk Material assignment from the sending application.

 

In the case of the attached sample, I put "Wall Paint" on the object in Inventor, then imported it into max.

 

In the slate material editor, I can see the default "Round_Corner_Source" option - but it's not supported by either the ART or Arnold renderers.

 

Any idea how I can simulate a similar effect in max 2018 or 2019?  (Reference material here.)

 

Ideally, I'd like to find a shader solution if possible because there are hundreds of objects in hundreds of files that need updating and they don't look as good without the rounded corners provided by the old mental ray shader.

 

Peter
0 Likes
Accepted solutions (2)
10,093 Views
28 Replies
Replies (28)
Message 2 of 29

madsd
Advisor
Advisor
We actually talked about this yesterday. You can do an approximation with OSL which will look fine from a distance since it works on the normals. I don't have time right now, else I was already on the move to implement a first attempt to replicate the one you mention, as OSL or C .dll in worst case scenario. I hope I can find time, it is an interesting task to solve.
0 Likes
Message 3 of 29

Anonymous
Not applicable
This should be in Arnold. Also the ability to bake it in normal maps https://forums.autodesk.com/t5/3ds-max-ideas/bake-rounded-edge-shader-to-normal-maps/idi-p/7894686 Apparently they are considering the possibility of baking textures with Arnold, that I think is quite basic and should be implemented since it was integrated in Max. https://forums.autodesk.com/t5/3ds-max-ideas/bake-rounded-edge-shader-to-normal-maps/idi-p/7894686
0 Likes
Message 4 of 29

pcrawley
Advisor
Advisor

I'm not there yet, but the Arnold Curvature map does an excellent job of finding concave and convex edges. Now I need to turn that into a highlight, not a flipped normal!

 

Judging by the comments, I'm not alone. OSL sounds like a good plan, but no use for a customer stuck at 2018 😞 I'm looking at this for someone who moved from 2016 to 2018 and lost mental ray but doesn't yet have access to OSL.

 

Looking good from a distance is all I'm after - the models are all machinery clad in painted sheet metal, so it doesn't require subdivision or displacement techniques. "Round Edges" was such a useful tick-box option - I had no idea how hard it was to replicate!

Peter
0 Likes
Message 5 of 29

madsd
Advisor
Advisor
Accepted solution

Check this one, works fine, you can make a dublicate and do the convex part as well and mix them together.

Also added a max file saved back to 2016.

 

2018-04-18_07-11-55.jpg

Message 6 of 29

Anonymous
Not applicable

Great! We only need it to bake as normal maps... but even without it is cool.

This is also using denoise.

image.pngimage.png

0 Likes
Message 7 of 29

madsd
Advisor
Advisor
Super, Baking is not yet supported, but dev knows the need for it.
0 Likes
Message 8 of 29

pcrawley
Advisor
Advisor
@madsd - I want to mark your post as the solution because it apparently works. But I am missing something... Your result looks great, but my render of your file has dark edges where I should see highlights. I've attached my rendering - the small box is a chamfer-box from the extended primitives to show the effect I was hoping for, but your renderings are much closer to this effect than mine. What am I missing?
Peter
0 Likes
Message 9 of 29

madsd
Advisor
Advisor
Accepted solution

The "nice" one looks good. We already talked about this another place, Martin Breidt caught it some days ago and told me. I found that installing a domelight with no maps in solved a uniform distribution, it is like the normals are inverted, but not in a way you would expect. Now, here is a thing to try first, Martin mentioned that if you restart the render session it will clear up, it should only happen if you are moving around in the view. It has been reported as a bug report already. I will however, look into it and see if we can fix it with some work around, or just aviod what breaks it.

 

Try disable the HDR map, and use just pure white in a test.

 

As you can see here, the technical foundament is working. Evenly distributed masks.

2018-04-24_11-54-59.jpg

Message 10 of 29

RGhost77
Advisor
Advisor
I remember old thread in blender comunnity where Round corners was coded on OSL for blender https://blenderartists.org/forum/showthread.php?329295-Bevel-shader

Royal Ghost | veda3d.com
0 Likes
Message 11 of 29

madsd
Advisor
Advisor
Right, that also works in max.
0 Likes
Message 12 of 29

Anonymous
Not applicable

Here's an OSL rounded edges shader from 2014, created for Blender. I'm no programmer but I'm guessing that the script is universal across all renderers considering the whole OSL factor..... 🙂 Just thought I'd post it here in case somebody like Mads knows what to do with it.(if anything)

 

void rng_seed(output int rng, int seed){
  int chash = seed;
  if (chash == 0) chash = 1;
  rng = chash * 30391861;
}

float rng_uniform(output int rng){
  float res = rng / float(2137483647) * 0.5 + 0.5;
  rng *= 30391861;
  return res;
}

void to_unit_disk(float x, float y, output float x_out, output float y_out){
  float r, phi;
  float a = 2.0 * x - 1.0;
  float b = 2.0 * y - 1.0;
    
  if(a > -b) 
  { if(a > b) 
    { r = a;
      phi = M_PI_4 *(b/a);
    }
    else 
    { r = b;
      phi = M_PI_4 *(2.0 - a/b);
  } }
  else 
  { if(a < b) 
    { r = -a;
      phi = M_PI_4 *(4.0 + b/a);
    }
    else 
    { r = -b;
      if(b != 0.0) phi = M_PI_4 *(6.0 - a/b);
      else phi = 0.0;
  } }
  x_out = r * cos(phi);
  y_out = r * sin(phi);
}

void make_orthonormals(vector N, output vector a, output vector b){
  if(N[0] != N[1] || N[0] != N[2]) a = cross(vector(1, 1, 1), N);
  else a = cross(vector(-1, 1, 1), N);
  
  a = normalize(a);
  b = cross(N, a);
}

vector sample_cos_hemisphere(vector N, float randu, float randv){
  vector T, B;
    
  make_orthonormals(N, T, B);
  to_unit_disk(randu, randv, randu, randv);
  float costheta = sqrt(max(1.0 - randu * randu - randv * randv, 0.0));

  return randu * T + randv * B + costheta * N;
}

shader node_occlusion2(  color Effect = color(0),
  color No_Effect = color(1),
  int Mode = 0, /* 0: Concave (AO) 1:Convex (Wear) 2:Both */
  int InvertEffect = 0,
  float Distance = 0.2,
  int Samples = 1,
  output color Color = 0,
  output float Fac = 0,
  output normal outNormal = N
)
{
  int i, rng;
  float f, randu, randv, ray_t, hits = 0;
  vector ray_P, ray_R;
  normal hit_normal = N;
  float hit_dist;

  f = fmod(cellnoise(P*123456.0), 1.0);
  rng_seed(rng, int(f * 21374647));
  
  for(i = 0; i < Samples; i++) 
  { randu = rng_uniform(rng);
    randv = rng_uniform(rng);
       
    ray_P = P;
    ray_R = sample_cos_hemisphere(-N, randu, randv);
    ray_t = Distance;
    
        
    if (!Mode)
    { if(trace(ray_P, -ray_R, "maxdist", ray_t)) {
            hits += 1.0;
            int HitNormal = getmessage ("trace", "N", hit_normal);
            outNormal = outNormal + (hit_normal);
        }
    }
    else if (Mode == 1)
    { if(trace(ray_P, ray_R, "maxdist", ray_t)) {
           hits += 1.0;
           int HitNormal = getmessage ("trace", "N", hit_normal);
           outNormal = outNormal - (hit_normal);
        }
    }
    else { 
        if(trace(ray_P, -ray_R, "maxdist", ray_t)) {
            hits += 1.0;
            int HitNormal = getmessage ("trace", "N", hit_normal);
            outNormal = outNormal + (hit_normal);
        }
        if(trace(ray_P, ray_R, "maxdist", ray_t)) {
           hits += 1.0;
           int HitNormal = getmessage ("trace", "N", hit_normal);
           outNormal = outNormal - (hit_normal);
        }
    } 
  }
  Fac = 1.0 - (hits/Samples);
  if(InvertEffect) Color = mix(No_Effect, Effect, Fac);
  else Color = mix(Effect, No_Effect, Fac);
  outNormal = normalize(outNormal);
}
0 Likes
Message 13 of 29

madsd
Advisor
Advisor

I had to correct 4 things for it to compile in 3dsmax, else base is identical to the one I posted in "OSL tip of the day thread" - with a normal hook in addition.

 

0 Likes
Message 14 of 29

Anonymous
Not applicable

Thanks Mads, can you post up the recompiled version? There are people going insane at Polycount forums for this feature to be native in Max. Baking clean tangent Normal maps from rounded edges shader is like the holy grail to us game asset creators. 🙂 Who knows, maybe someday we'll have the open-source MIKK tangent basis added to Max so we can finally be on par with every other program.....RTT certainly needs some love after all these years.

0 Likes
Message 15 of 29

madsd
Advisor
Advisor

Got a link to this open source code? I'd like to port it to OSL if possible.

 

I'm making an attempt to make xNormal redundant, I have a good stack of features done already, including some of the tool converters. Bitmap to Normal and Cavity / displacement, reflection etc are done already. AO I suspect wont take long either, a guy requested Density and Subsurfacemap, I looked into those too, but need to study some more.

 

Attached the fixed recomile.

 https://www.dropbox.com/s/9xblpttxyys4hf3/Normal_Mesh.osl?dl=0

Message 16 of 29

Anonymous
Not applicable

Mads, that is some seriously encouraging news. I know you're probably creating this with Arch-vis/VFX artists in mind, but we poor folk in the games industry could do with some love. :)And the one single thing that would change people's entire concept of baking in Max is the MIKK Tangent basis. It basically ensures that tangents and bi-normals are synced across all programs that use it. f you were to implement MikkT into Max you better be prepared for some serious adulation from the games dev community! The main maps we bake in game dev are: (straight from substance)

Normal map

ID map

World space normal

AO

Curvature

Position

Thickness

 

 

Here's the MIKKT source code. It comes in 2 files: mikktspace.h and mikktspace.c

And here's the link to the Blender dev page where the file links are located with a description. https://wiki.blender.org/index.php/Dev:Shading/Tangent_Space_Normal_Maps

 

And thanks a lot for the recompile. Excited to test it. Will post results.

 

Cheers man,

 

Danny.

 

Edit: I pasted the code here but it exceeds the post character amount.

0 Likes
Message 17 of 29

madsd
Advisor
Advisor

Ok super, I'll have a go at it.

Everyone is on my mind, VFX, game devs, viz folks 🙂

 

0 Likes
Message 18 of 29

Anonymous
Not applicable

Brilliant. I'm very nerdy when it comes to normal maps so I'm very excited. Haha! Looking forward to seeing how you go.

Message 19 of 29

Anonymous
Not applicable

First test of the OSL you recompiled. Not really sure how to proceed. 🙂 Obviously it's picking up convex/concave normals and intersecting geo, but not the rounded edges effect.

E1PzjRmD1TTYGW

0 Likes
Message 20 of 29

madsd
Advisor
Advisor

Yeah that's not how you would want to do it.

You need to create a filter, you do that with sampling the edges first with the mode 2 convex/concave, you parse that into an RGBA Mix OSL node, and pipe the filter to mix and the normals to color A and color B is 50% grey, this way all your edges gets normal if you pipe it to color.

Using diffuse slot is good for debugging.

0 Likes