Page 5 of 9 FirstFirst ... 34567 ... LastLast
Results 81 to 100 of 178

Thread: Bevel shader

  1. #81
    Member
    Join Date
    Sep 2012
    Posts
    2,578
    Keep this thread for Bevel shader.
    'Dirt & Decay' with OSL continues here: http://blenderartists.org/forum/show...th-Osl-shading
    Great works btw.



  2. #82
    Member J_the_Ninja's Avatar
    Join Date
    Sep 2010
    Location
    Portland, OR, USA
    Posts
    1,664
    Does anyone know if it's possible to bake this with the new Cycles bake function. Baking normals (without selected to active) doesn't seem to include bump/normal maps



  3. #83
    Not right now. I expect it should work as soon there's support for normal/bump maps in the source meshes.



  4. #84
    You Could probably bake the corresponding bump map using the color output of the node but not directly a normal map (even if converting this kind of bump map to normal map is not really difficult using blender or other software)

    boby



  5. #85
    Not sure that will work, Cycles uses negative values for its internal WS normals, and i'm not sure any image format can store negative color values. But if you figured out how to convert that into your standard OS normal map, and put that solution into a node group, yeah, you might be able to do it. Seems like more trouble than it's worth though.



  6. #86
    Member J_the_Ninja's Avatar
    Join Date
    Sep 2010
    Location
    Portland, OR, USA
    Posts
    1,664
    Originally Posted by Piotr Adamowicz View Post
    Not sure that will work, Cycles uses negative values for its internal WS normals, and i'm not sure any image format can store negative color values. But if you figured out how to convert that into your standard OS normal map, and put that solution into a node group, yeah, you might be able to do it. Seems like more trouble than it's worth though.

    Negative values are kosher in EXR files, they're used all the time for data passes.



  7. #87
    Member J_the_Ninja's Avatar
    Join Date
    Sep 2010
    Location
    Portland, OR, USA
    Posts
    1,664
    It occurred to me today that you can bake this (or any shader output you want, actually) by plugging it into an emission shader and baking the emit layer. But when I tried it, something odd happened. The shader appears to work correctly on intersecting faces, but it doesn't seem to register the face edges.

    float_bake_target.jpg

    bevel-bake-test.zip

    I attached the test file I was working. Don't worry about the missing hdri (forgot about it, sorry), it's just demo lighting and has no affect on anything. Replace or delete it as you like.



  8. #88
    Comment out lines 111 and 113 - this prevents black edges normally, but depends on the incident vector which doesn't make sense in baking.



  9. #89
    Member
    Join Date
    Mar 2008
    Location
    france
    Posts
    199
    looks great !!!!
    i tried some time ago to implement this in unity. This was working but problems occured on very flat faces....

    have to dig in this further !
    Thanks for the OSL code



  10. #90
    Member fahr's Avatar
    Join Date
    Apr 2009
    Posts
    1,237
    OMG this is awesome! I've been waiting for this for YEARS!! Thanks so much!
    Chad Gleason
    Cinematic Animator / Deck Nine Games
    http://www.chadgleason.com



  11. #91
    While trying to develop the bevel shader, it seems that you(osl coders) may find also some kind of freestyle like shader for cycles. I guess it will be very cool. Especially for people like me, who use Blender for visualisation of technical stuff and want to use cycles.

    If somewhere in the forum there is a thread for that kind of shaders and I missed it, sorry for wasting your time on reading this.



  12. #92
    Stupid oneliner optimization made this script 25% faster. No idea why I never thought of it before, it's so obvious...

    Code:
    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,
      int Backfacing = 1,
      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;
      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 && raytype("camera")) {
          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 (Backfacing==1 || dot(I, -hit_normal) > 0.0) {
                            outNormal = Normal - (hit_normal*normal_blend);
                        }
                        break;
                    }
                }
          }
        }
      outNormal = normalize(outNormal);
    }
    Note however that the smooth edges won't show up in glossy reflections anymore. So if you need that for whatever reason, use an older version.

    Also, made the backface culling easily toggleable for J_the_Ninja (not that baking is supported yet).

    Something seems wrong at intersecting geometry, but I don't currently have the time to investigate what I broke and when exactly. Sorry
    Last edited by Piotr Adamowicz; 26-May-14 at 03:15.



  13. #93
    Member Marc Clint Dion's Avatar
    Join Date
    Dec 2012
    Location
    Victoria BC
    Posts
    498
    Baking the VarkenVarken shader works beautifully. I think the issues around the seems could be cleared up by rendering at a higher resolution.
    bakeRender.png
    Last edited by Marc Clint Dion; 09-Jul-14 at 06:55.



  14. #94
    Hey Piotr,
    Is it possible for you to keep the "fac" B/W output in your script ?
    Thanks !



  15. #95
    Member
    Join Date
    Feb 2013
    Location
    Russia
    Posts
    27
    Can not run script.OSL script compilation error- why so?



  16. #96
    Can not run script.OSL script compilation error- why so?
    same thing
    Attached Images Attached Images



  17. #97
    Member cekuhnen's Avatar
    Join Date
    Mar 2003
    Location
    Grosse Pointe Woods, Michigan, USA
    Posts
    11,981
    woah fantastic edge based rounded corner shader! too bad this is not GPU friendly!
    3D Design Generalist - Faculty Industrial + Interior Design
    Chair Interior Design - Wayne State University



  18. #98
    Hi, looks really great, is there anything usable for beginners? Something Addon like? Or maybe a step by step tutorial on how to set this up?



  19. #99
    jimmy.b,

    activate Open Shading Language in render properties, render tab. Add a script node in your material and link it to an internal text in which you pasted the osl code, or to an external osl file. Now you can use the script node as a shader node as usual.

    Here's some info.
    Competition is great and fun for things like sports and games. For more serious matters cooperation might be a better approach.

    It is time - ecogood.org



  20. #100
    Does anyone know the technical reasons why it's not possible to bake with this shader? It would be pretty fantastic to properly bake tangent/object space normals here. I'd love to get some more info so we can at least begin to talk to the right folks about getting a fix for that.



Page 5 of 9 FirstFirst ... 34567 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •