Everything related to SDK.
User avatar
By seghier
#395926
Hello
i want use an external script to apply smooth edges to objects and materials
i found this free script in blender forum and it give very nice results ( i think this script need modification to work with maxwell )
so is it possible to use this script with pymaxwell or studio ?
Code: Select all
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 edge_smooth(
  int Concave = 1,
  int Convex = 1,
  int Samples = 4,
  float Mask = 1,
  float Distance = 0.1,
  normal Normal = N,
  output normal outNormal = 0
)
{
  int i, rng;
  float f, randu, randv, ray_t, hits = 0;
 // int Samples = 2;
  vector ray_P, ray_R;
  normal hit_normal = N;
  outNormal = Normal;
  float hit_dist;
  float normal_blend;
  float s_weight = 1/Samples;

  f = fmod(cellnoise(P*123456.0), 1.0);
  rng_seed(rng, int(f * 21374647));

    if (Mask > 0.5) {
      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 (Concave == 1)
            { if(trace(ray_P, -ray_R, "maxdist", ray_t)) {
                    getmessage ("trace", "N", hit_normal);
                    getmessage ("trace", "hitdist", hit_dist);
                    normal_blend = 1-(hit_dist/Distance);
                    outNormal = Normal + (hit_normal*normal_blend);
                    break;
                }
            }
            if (Convex == 1) {
                if(trace(ray_P, ray_R, "maxdist", ray_t)) {
                    getmessage ("trace", "N", hit_normal);
                    getmessage ("trace", "hitdist", hit_dist);
                    normal_blend = 1-(hit_dist/Distance);
                    if (dot(I, -hit_normal) > 0.0) {
                        outNormal = Normal - (hit_normal*normal_blend);
                    }
                    break;
                }
            }
      }
    }
  outNormal = normalize(outNormal);
}
User avatar
By Brany
#395953
It seems a shader to modify the geometry normals, I guess you can try to translate it into python, but I don't know if it makes sense to translate a shader into a "static scene geometry modifier". Maybe thera are more specific algorithms to smooth normals outside the GPU pipeline.
User avatar
By seghier
#395954
thanks Brany
yes this method using normal used with game engines and many render engines like vray to render smooth edges.
i hope see similar feature in maxwell render
in studio using normal map (created with blender or substance) to smooth edges give very nice result.
and studio already have wireframe texture which find all sharp edges but need sharpness option like in checker texture or feature to use it as normal map.
is it difficult to add this feature ? i asked for it since years
and thanks again
User avatar
By seghier
#395956
The sharpness with another option if it is possible like noise in brick texture will be useful to create dirt/weathering effect.
For normal map maybe an option to convert bump to normal , i have no idea how but many render engine use something like that.
Anyway i hope see this feature :) , it add more realistic effects to the scene
Thanks Brany

...and 3 Days later, 82.528 Views !!! ...NL, every[…]

Hello dear customers, We have just released a new[…]

grass generator extension

Just downloaded MWR5 for Rhino 6 and want to use g[…]

Hello everyone, I have a new bug with the latest M[…]