5

I am looking for ways to generate the bevel/emboss effect for a set of random closed beizier shapes. I came across the following post which seems to match my requirement.

https://dsp.stackexchange.com/questions/530/bitmap-alpha-bevel-algorithm

How do i get this ported to C# ? Are there any algorithms available that i can use? Or alternately are there any .NET imaging libraries to use or some code snippets to get me started ?

I would need to be running this code on a server to generate dynamic shapes that have transparency around them.

Community
  • 1
  • 1
user3526
  • 1,412
  • 1
  • 19
  • 26
  • 4
    the example in the post you referenced is written in openCV, there is already a c# .net wrapper of openCV called Emgucv – elasticrash Feb 19 '13 at 13:07
  • 1
    @elasticrash.. thank you. I did further search and this link seems helpful http://stackoverflow.com/questions/85569/net-dotnet-wrappers-for-opencv – user3526 Feb 21 '13 at 00:28

1 Answers1

1
  1. create 'mesh' from your closed polygon/polyline/path
    • base is enlarged basic shape by bevel/sunken width
    • top on or below it is your shape
    • enlargement is done by scaling around center for basic symmetric shapes
    • or by perpendicular shift + line/curve enlarging/intersect cuting to join
    • second choice is complex to code but always shape correct
  2. create normals
    • normal to light source RED (usually light is on upper left corner)
    • and surface normals on the 'mesh' GREEN (for every edge,area or pixel)
    • light normal can be constant for whole area for direction light (far light source like sunlight)
    • or computed for every point for point light (close light source)
    • all normal must be unit 3D vectors !!!
  3. render 'mesh' with light (simple normal lighting will be enough)

    lighted color = base color * dot_product(light normal,surface normal)
    
    • dot product is scalar vector multiplication like this

      (A.B) 
      = dot_product(A(x1,y1,z1),B(x2,y2,z2))
      = (x1*x2)+(y1*y2)+(z1*z2)
      
    • when A,B are unit vectors then the result is <-1,+1>

    • 0 means A,B are perpendicular
    • +/- 1 means they are parallel
    • -1 means they have opposite direction

See image for more clarity

enter image description here

PS. 'mesh' can be still 2D only the normals must be 3D

Spektre
  • 49,595
  • 11
  • 110
  • 380